Bitcoin Forum
May 08, 2024, 08:05:49 AM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: « 1 [2] 3 4 5 6 7 8 »  All
  Print  
Author Topic: Bitcoin arbitrage on GitHub: ~2% monthly return, market-neutral long/short  (Read 38227 times)
Mieehayii
Hero Member
*****
Offline Offline

Activity: 490
Merit: 500



View Profile
March 19, 2015, 05:12:29 AM
 #21

thank you, i will take it a look.

███████████████████████████████████████████████████████████████████▀███▀████
████████████████████████████████████████████████████████████████████▄▀▄█████
███████████████████████████████████████████████████████████████████▀▄█▄▀████

███▀▀▀▀▀▀▀▀██████▀▀▀████████▀▀▀██▀▀▀███████████▀▀▀██▀▀▀▀▀▀▀▀████████▀▀▀█████
███          ▀███   ████████   ██    ▀█████████   ██           ▀████   █████
███   █████▄   ██   ████████   ██      ▀███████   ██   ██████▄   ███   █████
███   ██████   ██   ████████   ██   █▄   ▀█████   ██   ████████   ██   █████
███   █████▀   ██   ████████   ██   ███▄   ▀███   ██   ████████   ██   █████
███          ▄███   ▀██████▀   ██   █████▄   ▀█   ██   ███████▀   ██   █████
███   ▄▄▄▄▄███████   ▀▀▀▀▀▀   ███   ███████▄      ██   ▀▀▀▀▀▀   ▄███   █████
███   █████████████▄        ▄████   █████████▄    ██        ▄▄▄█████   █████
████████████████████████████████████████████████████████████████████████████
████████████████████████████████████████████████████████████████████████████
██
██
██
██
██
██
██
██
██
██
██
██
██
.Any Store Can Buy, Sell and Accept Cryptocurrency.██
██
██
██
██
██
██
██
██
██
██
██
██
[[[ Whitepaper    Twitter     Facebook]]]
[[[  Telegram      Medium     Youtube ]]]
"Your bitcoin is secured in a way that is physically impossible for others to access, no matter for what reason, no matter how good the excuse, no matter a majority of miners, no matter what." -- Greg Maxwell
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction.
1715155549
Hero Member
*
Offline Offline

Posts: 1715155549

View Profile Personal Message (Offline)

Ignore
1715155549
Reply with quote  #2

1715155549
Report to moderator
spin
Sr. Member
****
Offline Offline

Activity: 362
Merit: 261


View Profile
March 19, 2015, 07:55:59 AM
 #22

Even if it's true, the impact of that default risk is pretty much the same whether you are on an arbitrage strategy or a buy and hold strategy.
Not true strictly as you can buy limited amount (say $1000) at a time and transfer bitcoin off the exchange. So you are only exposed to $1000 exchange risk but may be holding $10 000 worth of bitcoin in your own wallet.

The problem with arbitrage is you are always risking your principal on 2 exchanges.  You need the full amount on exchange to do the arbitrage and to maximise profits that are usually a small % of principal.  So if one of them goes you lose half your principal.

If you liked this post buy me a beer.  Beers are quite cheap where I live!
bc1q707guwp9pc73r08jw23lvecpywtazjjk399daa
butor (OP)
Newbie
*
Offline Offline

Activity: 49
Merit: 0


View Profile WWW
March 19, 2015, 01:01:26 PM
Last edit: March 19, 2015, 01:19:13 PM by butor
 #23

Very interesting concept.

I hope you don't abandon it.

Thank you. I won't. My goal now is really to find C++ enthusiasts that can help me improve the code quality and build new stuff.


Not true strictly as you can buy limited amount (say $1000) at a time and transfer bitcoin off the exchange. So you are only exposed to $1000 exchange risk but may be holding $10 000 worth of bitcoin in your own wallet.

This is not a buy and hold strategy.


The problem with arbitrage is you are always risking your principal on 2 exchanges.  You need the full amount on exchange to do the arbitrage and to maximise profits that are usually a small % of principal.  So if one of them goes you lose half your principal.

Actually the risk assessment is the same: twice the risk but only of half your investment.

The interesting question here is: in case of an exchange default, do you consider that you're going to lose 1) only your Bitcoins or 2) all your Bitcoins and all your cash on that exchange?

  • case 1: arbitrage is less risky than buy and hold since in arbitrage you spent lots of time in cash.
  • case 2: this is a real problem with arbitrage because if you want to do arbitrage on, say, 8 exchanges with $1000 cash on each then your total exposure to exchange default is $8000 even though your long/short Bitcoin exposure will be only $2000 at a time.


spin
Sr. Member
****
Offline Offline

Activity: 362
Merit: 261


View Profile
March 19, 2015, 02:33:15 PM
 #24

...
Not true strictly as you can buy limited amount (say $1000) at a time and transfer bitcoin off the exchange. So you are only exposed to $1000 exchange risk but may be holding $10 000 worth of bitcoin in your own wallet.
This is not a buy and hold strategy.
The problem with arbitrage is you are always risking your principal on 2 exchanges.  You need the full amount on exchange to do the arbitrage and to maximise profits that are usually a small % of principal.  So if one of them goes you lose half your principal.

Actually the risk assessment is the same: twice the risk but only of half your investment.

The interesting question here is: in case of an exchange default, do you consider that you're going to lose 1) only your Bitcoins or 2) all your Bitcoins and all your cash on that exchange?

  • case 1: arbitrage is less risky than buy and hold since in arbitrage you spent lots of time in cash.
  • case 2: this is a real problem with arbitrage because if you want to do arbitrage on, say, 8 exchanges with $1000 cash on each then your total exposure to exchange default is $8000 even though your long/short Bitcoin exposure will be only $2000 at a time.
Buying and holding bitcoin should have less risk of exchanges crashing as you can hold your balance off exchange.  It has of course more price movement risk.  Not sure what you mean by buy and hold. 

Exchange risk is about losing both fiat and bitcoin balances.  These may have slightly different risks though.  But at some point an exchange can be completely gone in which case both balances will be gone.
Case 1: Arbitrage is less risky not because you spend time in cash, but because you are not taking views on prices and betting on that.
Case 2: Adding the exchanges distributes the risk.  This is good.  But of course typically you might end up with more total exposure, so it's a bit of a balance, as you point out. 

If you liked this post buy me a beer.  Beers are quite cheap where I live!
bc1q707guwp9pc73r08jw23lvecpywtazjjk399daa
butor (OP)
Newbie
*
Offline Offline

Activity: 49
Merit: 0


View Profile WWW
March 19, 2015, 02:43:38 PM
 #25

Buying and holding bitcoin should have less risk of exchanges crashing as you can hold your balance off exchange. 

I see your point now and yes you're perfectly right. You can keep your Bitcoin investment off exchange. Now I don't know whether a Bitcoin wallet also has a risk of default...  Tongue
butor (OP)
Newbie
*
Offline Offline

Activity: 49
Merit: 0


View Profile WWW
May 31, 2015, 06:07:31 PM
 #26

For information I added a new exchange, Bitstamp, to my arbitrage system.

https://github.com/butor/blackbird
Lawk
Newbie
*
Offline Offline

Activity: 6
Merit: 0


View Profile
June 09, 2015, 01:54:08 PM
 #27

Very cool stuff!

Couple of questions:

- Why C++? Maybe porting it to a Ruby or Python would give you more success in finding the coder you need?
- Any plans of adding USD/LTC? Since the framework is already there and all the major exchanges support it, why not add it too, it will increase the arbitrage opportunities a lot right?
- What other exchanges do you plan on adding? BTC-E? BTER?

butor (OP)
Newbie
*
Offline Offline

Activity: 49
Merit: 0


View Profile WWW
June 10, 2015, 02:45:26 AM
 #28


Thats great progress. Do you have a donation address or anything as such?
Thank you Bitcoin Explorer it's always appreciated. Here is my address: 3NmAGEeRmbdeMyaNjUaASr9Dv2NEssmafY


Lawk to answer your three questions:

Why C++? Maybe porting it to a Ruby or Python would give you more success in finding the coder you need?
Because of the speed. C++ is the main language for this kind of automatic trading program in the industry anyway (quantitative trading, HFT, etc). As you probably know compiled languages are usually far more faster than interpreted languages like Python.
For the moment my program analyzes the market every 5 seconds (can be adapted) and simply computes then compares the spreads between the exchanges. But in the future I would like to add more features within these 5-second loops, e.g. check the short-term volatility or save all the data in a database. So it's good to know that speed shouldn't be an issue. But yes, C++ is a pretty challenging language.


Any plans of adding USD/LTC? Since the framework is already there and all the major exchanges support it, why not add it too, it will increase the arbitrage opportunities a lot right?
Yes and that's something I want to do. Doing arbitrage on multiple exchanges between multiple cryptocurrencies is a great project. Note that the cryptocurrencies have to be liquid enough to allow fast order execution.


What other exchanges do you plan on adding? BTC-E? BTER?
The next exchange will probably be Kraken. As for now, the bid/ask information from Kraken is displayed but the system won't trade it. Again, since the orders have to be quickly executed we need to only add exchanges that offer good liquidity.
Also, it's now possible to short sell on OkCoin so I will need to add that too.
tofm2
Newbie
*
Offline Offline

Activity: 40
Merit: 0


View Profile
June 10, 2015, 09:46:36 AM
 #29

Hello, thanks for this work

I am trying to install it on my Linux mint 17 box but got this error message at make :

$HOME/blackbird-master > make
g++ -c -g -Wall -O2  base64.cpp -o base64.o
g++ -c -g -Wall -O2  bitcoin.cpp -o bitcoin.o
g++ -c -g -Wall -O2  bitfinex.cpp -o bitfinex.o
bitfinex.cpp: In function ‘bool Bitfinex::isOrderComplete(CURL*, Parameters, int)’:
bitfinex.cpp:91:68: error: ‘json_boolean_value’ was not declared in this scope
   isComplete = !json_boolean_value(json_object_get(root, "is_live"));
                                                                    ^
make: *** [bitfinex.o] Erreur 1


have you got any clues what went wrong

arunka71
Sr. Member
****
Offline Offline

Activity: 410
Merit: 257


View Profile
June 11, 2015, 07:24:45 PM
 #30

I'm more a java guy, but I'd be interested to discuss strategies and such with you. I also have quite some implementations for other exchanges.

At the moment, I'd like to get rid of the REST APIs and move on to FIX. Should be quicker, I guess.

PM me, if you are interested in any form of a collab.
butor (OP)
Newbie
*
Offline Offline

Activity: 49
Merit: 0


View Profile WWW
July 11, 2015, 03:27:22 PM
 #31

 
Just wanted to show you guys the actual output of an arbitrage trade if you are interested. It might help to understand the mechanism. Note that this is a real example with real money.

When we start the software it will first check the balances on all our Bitcoin exchanges. As you can see we don't have any Bitcoin (except a negligible amount on OKCoin) but only USD:

Blackbird Bitcoin Arbitrage
Version 0.0.2
DISCLAIMER: USE THE SOFTWARE AT YOUR OWN RISK.

[ Targets ]
   Spread to enter: 0.20%
   Spread to exit: -0.30%

[ Current balances ]
   Bitfinex:    1,299.15 USD   0.000000 BTC
   OKCoin:      1,318.32 USD   0.000582 BTC
   Bitstamp:    1,237.33 USD   0.000000 BTC
   Kraken:      0.00 USD       0.000000 BTC

After this initialization, the system starts to analyze all the spreads between Bitfinex, OKCoin, Bitstamp and Kraken every five seconds. It's only possible to short sell on Bitfinex and Kraken. The targets are different because the trading fees can vary depending on the exchange.

[ 07/10/2015 16:15:55 ]
   Bitfinex:    293.54 / 293.57
   OKCoin:      295.40 / 295.61
   Bitstamp:    291.40 / 292.43
   Kraken:      292.20 / 294.11
   ----------------------------
   Bitfinex/Kraken:     -0.47% [target  1.10%, min -0.47%, max -0.47%]
   OKCoin/Bitfinex:     -0.70% [target  1.00%, min -0.70%, max -0.70%]
   OKCoin/Kraken:       -1.15% [target  1.10%, min -1.15%, max -1.15%]
   Bitstamp/Bitfinex:    0.38% [target  1.10%, min  0.38%, max  0.38%]
   Bitstamp/Kraken:     -0.08% [target  1.20%, min -0.08%, max -0.08%]
   Kraken/Bitfinex:     -0.19% [target  1.10%, min -0.19%, max -0.19%]

[ 07/10/2015 16:16:00 ]
   Bitfinex:    293.54 / 293.57
   OKCoin:      294.65 / 295.28
   Bitstamp:    291.40 / 292.43
   Kraken:      292.20 / 294.11
   ----------------------------
   Bitfinex/Kraken:     -0.47% [target  1.10%, min -0.47%, max -0.47%]
   OKCoin/Bitfinex:     -0.59% [target  1.00%, min -0.70%, max -0.59%]
   OKCoin/Kraken:       -1.04% [target  1.10%, min -1.15%, max -1.04%]
   Bitstamp/Bitfinex:    0.38% [target  1.10%, min  0.38%, max  0.38%]
   Bitstamp/Kraken:     -0.08% [target  1.20%, min -0.08%, max -0.08%]
   Kraken/Bitfinex:     -0.19% [target  1.10%, min -0.19%, max -0.19%]

The software will continue to loop every five seconds, until there is an opportunity at 17:46:55: the spread between OKCoin (long) and Bitfinex (short) equals our 1.00% entry target:

[ 07/10/2015 17:46:50 ]
   Bitfinex:    286.67 / 286.87
   OKCoin:      284.24 / 284.25
   Bitstamp:    286.48 / 286.49
   Kraken:      285.16 / 287.24
   ----------------------------
   Bitfinex/Kraken:     -0.60% [target  1.10%, min -0.94%, max  0.29%]
   OKCoin/Bitfinex:      0.85% [target  1.00%, min -1.11%, max  0.92%]
   OKCoin/Kraken:        0.32% [target  1.10%, min -1.45%, max  0.95%]
   Bitstamp/Bitfinex:    0.06% [target  1.10%, min -0.59%, max  0.67%]
   Bitstamp/Kraken:     -0.46% [target  1.20%, min -0.60%, max  0.68%]
   Kraken/Bitfinex:     -0.20% [target  1.10%, min -1.22%, max  0.50%]

[ 07/10/2015 17:46:55 ]
   Bitfinex:    286.67 / 286.87
   OKCoin:      283.80 / 283.82
   Bitstamp:    285.94 / 286.49
   Kraken:      285.16 / 287.24
   ----------------------------
   Bitfinex/Kraken:     -0.60% [target  1.10%, min -0.94%, max  0.29%]
   OKCoin/Bitfinex:      1.00% [target  1.00%, min -1.11%, max  1.00%]

[ ENTRY FOUND ]
   Date & Time:       07/10/2015 17:46:55
   Exchange Long:     OKCoin (id 1)
   Exchange Short:    Bitfinex (id 0)
   Fees:              0.20% / 0.20%
   Price Long:        $283.82 (target)
   Price Short:       $286.67 (target)
   Spread:            1.00%
   Cash used:         $1,286.16 on each exchange

<OKCoin> Trying to send a "buy" limit order: 4.53@$284.10...
<OKCoin> Done (order ID: xx,xxx,xxx)

<Bitfinex> Trying to send a "sell" limit order: 4.49@$286.39...
<Bitfinex> Done (order ID: xxx,xxx,xxx)

Waiting for the two orders to be filled...
Done

Now that the orders are filled and that we are in the market, we are looking every five seconds for the spread to pass under our exit limit (-0.30%):

[ 07/10/2015 17:47:05 IN MARKET: Long OKCoin / Short Bitfinex ]
   Bitfinex:    286.54 / 286.85
   OKCoin:      283.80 / 283.82
   Bitstamp:    285.94 / 286.49
   Kraken:      285.16 / 287.24
   ----------------------------
   OKCoin/Bitfinex:      1.07% [target -0.30%, min  1.07%, max  1.07%]

[ 07/10/2015 17:47:10 IN MARKET: Long OKCoin / Short Bitfinex ]
   Bitfinex:    286.58 / 286.82
   OKCoin:      283.86 / 284.10
   Bitstamp:    286.02 / 286.60
   Kraken:      285.16 / 287.24
   ----------------------------
   OKCoin/Bitfinex:      1.04% [target -0.30%, min  1.04%, max  1.07%]

Then, at 19:04:10 the spread is under the exit limit (-0.32%). We close the two positions and compute the performance:

[ 07/10/2015 19:04:10 IN MARKET: Long OKCoin / Short Bitfinex ]
   Bitfinex:    284.32 / 284.40
   OKCoin:      285.31 / 285.50
   Bitstamp:    284.29 / 285.00
   Kraken:      284.50 / 288.79
   ----------------------------
   OKCoin/Bitfinex:     -0.32% [target -0.30%, min -0.32%, max  1.07%]

[ EXIT FOUND ]
   Date & Time:       07/10/2015 19:04:10
   Duration:          77.25 minutes
   Price Long:        $285.31 (target)
   Price Short:       $284.40 (target)
   Spread:            -0.32%
   ---------------------------
   Target Perf Long:  0.12% (fees incl.)
   Target Perf Short: 0.39% (fees incl.)
   ---------------------------

BTC exposure on OKCoin: 4.522520
BTC exposure on Bitfinex: -4.486550

<OKCoin> Trying to send a "sell" limit order: 4.52@$284.40...
<OKCoin> Done (order ID: xx,xxx,xxx)

<Bitfinex> Trying to send a "buy" limit order: 4.49@$284.59...
<Bitfinex> Done (order ID: xxx,xxx,xxx)

Waiting for the two orders to be filled...
Done

New balance on Bitfinex:        1,303.81 USD (perf $4.66), 0.000000 BTC
New balance on OKCoin:          1,319.06 USD (perf $0.74), 0.000520 BTC
New balance on Bitstamp:        1,237.33 USD (perf $0.00), 0.000000 BTC
New balance on Kraken:          0.00 USD (perf $0.00), 0.000000 BTC

ACTUAL PERFORMANCE: $5.40 (0.21%)

The system can send us an e-mail with our trade:


So we made $5.40 (+0.21%) in about 1 hour and 17 minutes with an exposure of $2,572.32 and no market risk. Note that the $5.40 is the actual profit after fees. To make sure that all the fees are taken into account the $5.40 amount comes from a straight comparison between the Bitcoin accounts (before the trade and after the trade). +0.21% doesn't seem a lot but remember that with this mechanism you don't get any losing trades since the system always waits for the spread to close (which can take days).

We are currently using the parameters enter=0.20% (plus fees, in this example the fees were 0.80%) and exit=-0.30% that are narrower than a few months ago. The reason being that the Bitcoin volatility these weeks is pretty low. The system needs a volatile market so that arbitrage opportunities can occur. As you can see in the following chart the Bitcoin volatility is pretty low these days (~1.86%):


Our hope is that the Bitcoin volatility re-increases so the spreads can be wider again. The volatility is a key factor of success in this kind of strategy.

I hope this post helped you understand the long/short arbitrage mechanism.


arunka71
Sr. Member
****
Offline Offline

Activity: 410
Merit: 257


View Profile
July 11, 2015, 10:13:01 PM
 #32

I'm working on just this, but I'm using java for now. If you are interested in a collab, let me know.
mattsun
Newbie
*
Offline Offline

Activity: 2
Merit: 0


View Profile
August 16, 2015, 08:11:23 PM
 #33

Hi, I'm really inspired by your job. But have a couple of questions about details of 'How it works'.
1. The 'short term' buy/sell, how is that operated? Do you buy BTC from an exchange (e.g. bitstamp), withdraw it from bitstamp then deposit to another exchange (e.g. bitfinex) and sell it? If that's the case, the long confirmation time might reduce the price difference or even switch the price position, how do you deal with that? If that's not the case, what do you mean by 'short sell'?
2. Still the 'short sell', so far as I know, bitstamp doesn't have an API for 'Instant Transaction', you can only place a buy/ask offer by API. How do you 'short sell'?
3. Do you always see the price position switch between the bitcoin exchanges you selected? I found some exchanges price position maintains the same all the time. For example, bitkonan's price are always higher than bitstamp.
4. The spreadEntry and spreadExit point, how do you decide the value? Do you have any reference or analysis behind?

Thanks. Smiley
Blawpaw
Legendary
*
Offline Offline

Activity: 1596
Merit: 1027



View Profile
August 17, 2015, 04:21:20 AM
 #34


Just wanted to show you guys the actual output of an arbitrage trade if you are interested. It might help to understand the mechanism. Note that this is a real example with real money.

When we start the software it will first check the balances on all our Bitcoin exchanges. As you can see we don't have any Bitcoin (except a negligible amount on OKCoin) but only USD:

Blackbird Bitcoin Arbitrage
Version 0.0.2
DISCLAIMER: USE THE SOFTWARE AT YOUR OWN RISK.

[ Targets ]
   Spread to enter: 0.20%
   Spread to exit: -0.30%

[ Current balances ]
   Bitfinex:    1,299.15 USD   0.000000 BTC
   OKCoin:      1,318.32 USD   0.000582 BTC
   Bitstamp:    1,237.33 USD   0.000000 BTC
   Kraken:      0.00 USD       0.000000 BTC

After this initialization, the system starts to analyze all the spreads between Bitfinex, OKCoin, Bitstamp and Kraken every five seconds. It's only possible to short sell on Bitfinex and Kraken. The targets are different because the trading fees can vary depending on the exchange.

[ 07/10/2015 16:15:55 ]
   Bitfinex:    293.54 / 293.57
   OKCoin:      295.40 / 295.61
   Bitstamp:    291.40 / 292.43
   Kraken:      292.20 / 294.11
   ----------------------------
   Bitfinex/Kraken:     -0.47% [target  1.10%, min -0.47%, max -0.47%]
   OKCoin/Bitfinex:     -0.70% [target  1.00%, min -0.70%, max -0.70%]
   OKCoin/Kraken:       -1.15% [target  1.10%, min -1.15%, max -1.15%]
   Bitstamp/Bitfinex:    0.38% [target  1.10%, min  0.38%, max  0.38%]
   Bitstamp/Kraken:     -0.08% [target  1.20%, min -0.08%, max -0.08%]
   Kraken/Bitfinex:     -0.19% [target  1.10%, min -0.19%, max -0.19%]

[ 07/10/2015 16:16:00 ]
   Bitfinex:    293.54 / 293.57
   OKCoin:      294.65 / 295.28
   Bitstamp:    291.40 / 292.43
   Kraken:      292.20 / 294.11
   ----------------------------
   Bitfinex/Kraken:     -0.47% [target  1.10%, min -0.47%, max -0.47%]
   OKCoin/Bitfinex:     -0.59% [target  1.00%, min -0.70%, max -0.59%]
   OKCoin/Kraken:       -1.04% [target  1.10%, min -1.15%, max -1.04%]
   Bitstamp/Bitfinex:    0.38% [target  1.10%, min  0.38%, max  0.38%]
   Bitstamp/Kraken:     -0.08% [target  1.20%, min -0.08%, max -0.08%]
   Kraken/Bitfinex:     -0.19% [target  1.10%, min -0.19%, max -0.19%]

The software will continue to loop every five seconds, until there is an opportunity at 17:46:55: the spread between OKCoin (long) and Bitfinex (short) equals our 1.00% entry target:

[ 07/10/2015 17:46:50 ]
   Bitfinex:    286.67 / 286.87
   OKCoin:      284.24 / 284.25
   Bitstamp:    286.48 / 286.49
   Kraken:      285.16 / 287.24
   ----------------------------
   Bitfinex/Kraken:     -0.60% [target  1.10%, min -0.94%, max  0.29%]
   OKCoin/Bitfinex:      0.85% [target  1.00%, min -1.11%, max  0.92%]
   OKCoin/Kraken:        0.32% [target  1.10%, min -1.45%, max  0.95%]
   Bitstamp/Bitfinex:    0.06% [target  1.10%, min -0.59%, max  0.67%]
   Bitstamp/Kraken:     -0.46% [target  1.20%, min -0.60%, max  0.68%]
   Kraken/Bitfinex:     -0.20% [target  1.10%, min -1.22%, max  0.50%]

[ 07/10/2015 17:46:55 ]
   Bitfinex:    286.67 / 286.87
   OKCoin:      283.80 / 283.82
   Bitstamp:    285.94 / 286.49
   Kraken:      285.16 / 287.24
   ----------------------------
   Bitfinex/Kraken:     -0.60% [target  1.10%, min -0.94%, max  0.29%]
   OKCoin/Bitfinex:      1.00% [target  1.00%, min -1.11%, max  1.00%]

[ ENTRY FOUND ]
   Date & Time:       07/10/2015 17:46:55
   Exchange Long:     OKCoin (id 1)
   Exchange Short:    Bitfinex (id 0)
   Fees:              0.20% / 0.20%
   Price Long:        $283.82 (target)
   Price Short:       $286.67 (target)
   Spread:            1.00%
   Cash used:         $1,286.16 on each exchange

<OKCoin> Trying to send a "buy" limit order: 4.53@$284.10...
<OKCoin> Done (order ID: xx,xxx,xxx)

<Bitfinex> Trying to send a "sell" limit order: 4.49@$286.39...
<Bitfinex> Done (order ID: xxx,xxx,xxx)

Waiting for the two orders to be filled...
Done

Now that the orders are filled and that we are in the market, we are looking every five seconds for the spread to pass under our exit limit (-0.30%):

[ 07/10/2015 17:47:05 IN MARKET: Long OKCoin / Short Bitfinex ]
   Bitfinex:    286.54 / 286.85
   OKCoin:      283.80 / 283.82
   Bitstamp:    285.94 / 286.49
   Kraken:      285.16 / 287.24
   ----------------------------
   OKCoin/Bitfinex:      1.07% [target -0.30%, min  1.07%, max  1.07%]

[ 07/10/2015 17:47:10 IN MARKET: Long OKCoin / Short Bitfinex ]
   Bitfinex:    286.58 / 286.82
   OKCoin:      283.86 / 284.10
   Bitstamp:    286.02 / 286.60
   Kraken:      285.16 / 287.24
   ----------------------------
   OKCoin/Bitfinex:      1.04% [target -0.30%, min  1.04%, max  1.07%]

Then, at 19:04:10 the spread is under the exit limit (-0.32%). We close the two positions and compute the performance:

[ 07/10/2015 19:04:10 IN MARKET: Long OKCoin / Short Bitfinex ]
   Bitfinex:    284.32 / 284.40
   OKCoin:      285.31 / 285.50
   Bitstamp:    284.29 / 285.00
   Kraken:      284.50 / 288.79
   ----------------------------
   OKCoin/Bitfinex:     -0.32% [target -0.30%, min -0.32%, max  1.07%]

[ EXIT FOUND ]
   Date & Time:       07/10/2015 19:04:10
   Duration:          77.25 minutes
   Price Long:        $285.31 (target)
   Price Short:       $284.40 (target)
   Spread:            -0.32%
   ---------------------------
   Target Perf Long:  0.12% (fees incl.)
   Target Perf Short: 0.39% (fees incl.)
   ---------------------------

BTC exposure on OKCoin: 4.522520
BTC exposure on Bitfinex: -4.486550

<OKCoin> Trying to send a "sell" limit order: 4.52@$284.40...
<OKCoin> Done (order ID: xx,xxx,xxx)

<Bitfinex> Trying to send a "buy" limit order: 4.49@$284.59...
<Bitfinex> Done (order ID: xxx,xxx,xxx)

Waiting for the two orders to be filled...
Done

New balance on Bitfinex:        1,303.81 USD (perf $4.66), 0.000000 BTC
New balance on OKCoin:          1,319.06 USD (perf $0.74), 0.000520 BTC
New balance on Bitstamp:        1,237.33 USD (perf $0.00), 0.000000 BTC
New balance on Kraken:          0.00 USD (perf $0.00), 0.000000 BTC

ACTUAL PERFORMANCE: $5.40 (0.21%)

The system can send us an e-mail with our trade:


So we made $5.40 (+0.21%) in about 1 hour and 17 minutes with an exposure of $2,572.32 and no market risk. Note that the $5.40 is the actual profit after fees. To make sure that all the fees are taken into account the $5.40 amount comes from a straight comparison between the Bitcoin accounts (before the trade and after the trade). +0.21% doesn't seem a lot but remember that with this mechanism you don't get any losing trades since the system always waits for the spread to close (which can take days).

We are currently using the parameters enter=0.20% (plus fees, in this example the fees were 0.80%) and exit=-0.30% that are narrower than a few months ago. The reason being that the Bitcoin volatility these weeks is pretty low. The system needs a volatile market so that arbitrage opportunities can occur. As you can see in the following chart the Bitcoin volatility is pretty low these days (~1.86%):


Our hope is that the Bitcoin volatility re-increases so the spreads can be wider again. The volatility is a key factor of success in this kind of strategy.

I hope this post helped you understand the long/short arbitrage mechanism.




This is a great explanation! And an excellent strategy to use when doing arbitrage trading.
I'll be sure to take this in mind.
stash
Full Member
***
Offline Offline

Activity: 173
Merit: 100

btcmy.net


View Profile WWW
August 19, 2015, 02:50:29 PM
Last edit: August 20, 2015, 05:49:44 AM by stash
 #35

solved.

Tehtarik Fund : 1KxyB3iauJzLvDnZuchekGkB2D7p4UMvuq
BTCitcoin : Mathematical Logic to Eliminate Human Greed
butor (OP)
Newbie
*
Offline Offline

Activity: 49
Merit: 0


View Profile WWW
August 25, 2015, 03:08:10 AM
Last edit: August 25, 2015, 03:19:23 AM by butor
 #36

Hi Mattsun,

Thank you for your message.

1. The 'short term' buy/sell, how is that operated? Do you buy BTC from an exchange (e.g. bitstamp), withdraw it from bitstamp then deposit to another exchange (e.g. bitfinex) and sell it? If that's the case, the long confirmation time might reduce the price difference or even switch the price position, how do you deal with that? If that's not the case, what do you mean by 'short sell'?

Again, there is no USD transfer and no BTC transfer between the exchanges. So we don't have to deal with the latency of withdraws and deposits. That's one of the advantages of long/short strategies. But let me explain what short selling means and maybe it will help you and others on this forum to understand how the strategy works. Short selling is not a Bitcoin thing and it is common in the financial market industry. I actually work on Wall Street so my examples will be closer to my actual job than Bitcoin.

  • First the basics: Let's say you think, based on your financial analysis or your favorite crystal ball, that the Apple stock will go up within the next few weeks and you want to profit from that. So today you buy 10 shares of AAPL at $100. Then the stock price goes up (your crystal ball was right!) and after two week AAPL is priced at $120. You decide to sell your 10 shares of AAPL. Your profit: 10x$120 - 10x$100 = $1,200 - $1,000 = $200. Well done! We say that you were long on this position (buy then sell later).

  • Now let's say that you think that the Apple stock will drop. You don't own any AAPL shares but you want to profit from that drop. So this is what you can do: you can ask your broker to borrow from him, say, 10 shares of AAPL and you promise that you will give him back these 10 shares later. Once your broker agrees to lend you the 10 shares (I won't go into the details about margin accounts) you can go to the market and sell these 10 shares, even if you don't actually own them!
    Let's say today AAPL is at $100. You borrow 10 shares from your broker and sell them on the market at $100. You make $1,000 of that selling, but you still have a debt of 10 shares towards your broker. Two weeks later, your crystal ball is right (again!) and the price of AAPL drops to $80. You decide to buy 10 shares on the market at $80 and give them back to your broker. That's it! You cleared your debt towards your broker and this is your profit on the operation: sell 10x$100 then buy back 10x$80 = $1,000 - $800 = $200. Well done again! The whole operation you just did is called short selling and we say you were short on this position (sell then buy later).

The examples I gave are speculative ones where you try to forecast the market. But short selling is also used to protect your investments against market fluctuation, in particular sudden market falls. Here is an oversimplified example to illustrate:

AAPL is at $100 and MSFT (Microsoft) is at $50. To be market-neutral (i.e. protected against market fluctuation) you can be long on AAPL and short on MSFT at the same time. For that you would buy 10 shares of AAPL (long $1,000) and short sell 20 shares of MSFT (short $1,000). Now let's see what happens when the market suddenly drops by 20%!
  • AAPL price goes from $100 to $80 (-20%).
  • MSFT price goes from $50 to $40 (-20%).

You decide to exit the market by closing your two positions:
  • You sell your AAPL shares for $800 (10x$80). You originally bought them $1,000: you lose $200 on that long position.
  • You buy back your MSFT shares for $800 (20x$40). You originally sold them for $1,000: you make $200 on that short position.

As you can see your loss is $0 thanks of the long/short strategy you used (long AAPL, short MSFT).

As you can imagine, if the whole market goes up your profit will be ...$0. So how do we make money in a long/short strategy? By betting on the discrepancy between the positions and this is exactly what we do with Blackbird on Bitcoin: if Bitfinex prices Bitcoin at $240 and Bitstamp prices at $200 we think that Bitfinex is overpriced while Bitstamp is underpriced: we go short on Bitfinex and go long on Bitstamp until the two prices are similar again. You will have more details about how the long/short strategy works with Blackbird on the GitHub page of the project.



2. Still the 'short sell', so far as I know, bitstamp doesn't have an API for 'Instant Transaction', you can only place a buy/ask offer by API. How do you 'short sell'?

You're right: as of today it's not possible to short sell on Bitstamp. However, it's possible to short sell on Bitfinex, OKCoin and others. Note that the short selling operation is usually pretty straightforward and the Bitcoin lending part is automatically done for you by the exchanges.



3. Do you always see the price position switch between the bitcoin exchanges you selected? I found some exchanges price position maintains the same all the time. For example, bitkonan's price are always higher than bitstamp.

Between Bitfinex, OKCoin and Bitstamp we see price discrepancies pretty often. It really depends on the overall Bitcoin volatility: the higher the volatility the higher the spreads between the exchanges. But check the prices right now (08/24/2015 21:55:25 EDT):

   Bitfinex:  204.54 / 204.55
   OKCoin:    201.13 / 201.27
   Bitstamp:  204.29 / 204.48

As you can see there is a good opportunity right now between Bitfinex (short) and OKCoin (long) with a 1.62% spread. A word to the wise...



4. The spreadEntry and spreadExit point, how do you decide the value? Do you have any reference or analysis behind?

Good question and that's all the challenge: SpreadEntry and SpreadExit are set based on the historical relationship between the exchanges. If you use values closer to zero you will get more trades, but less profit on each trade. Also, as explained above if the Bitcoin volatility is very low you will have difficulties to get trades and might need to lower your values. The Bitcoin volatility is now at 3.51%. You can check it here in realtime.

Note that I have some ideas to implement using dynamic spreads based on:
1. the short-term historical volatility
2. the fact that we want to let the profits run.

Stay tuned!
mattsun
Newbie
*
Offline Offline

Activity: 2
Merit: 0


View Profile
August 28, 2015, 04:39:18 AM
 #37

Hi Butor,

So much thanks for you detailed answer! It really gives me a brand new perspective of btc arbrtriage. Honestly I'm an engineer mostly good at programming, I don't quite understand these 'short sell' 'long buy' very much, I have to spend some time to teach myself how it works... But anyway, this is a fantastic strategy I've ever seen. If you don't mind, i have several 'follow-ups', just short answer is fair enough I believe...
1. How fast is your trading? I believe c++ is fast, but using API to do trade is mostly network bound ( I assume your algorithms don't take very much time...). Are there any special tricks that makes you trading bot fast other than multi-threading pulling real-time data (and use websocket stream whereever you can)?
2. Have you considered using some machine learning or statistics algorithm to train the bot? Such as using historical data to predict the trend the exchange price, or decide spreadEntry and spreadExit dynamicly? I have seen a article about 'statistical arbitrage', which using statistical method to make profit. Their annual revenue goes up to 280%, which is really amazing.

Hi Mattsun,

Thank you for your message.

1. The 'short term' buy/sell, how is that operated? Do you buy BTC from an exchange (e.g. bitstamp), withdraw it from bitstamp then deposit to another exchange (e.g. bitfinex) and sell it? If that's the case, the long confirmation time might reduce the price difference or even switch the price position, how do you deal with that? If that's not the case, what do you mean by 'short sell'?

Again, there is no USD transfer and no BTC transfer between the exchanges. So we don't have to deal with the latency of withdraws and deposits. That's one of the advantages of long/short strategies. But let me explain what short selling means and maybe it will help you and others on this forum to understand how the strategy works. Short selling is not a Bitcoin thing and it is common in the financial market industry. I actually work on Wall Street so my examples will be closer to my actual job than Bitcoin.

  • First the basics: Let's say you think, based on your financial analysis or your favorite crystal ball, that the Apple stock will go up within the next few weeks and you want to profit from that. So today you buy 10 shares of AAPL at $100. Then the stock price goes up (your crystal ball was right!) and after two week AAPL is priced at $120. You decide to sell your 10 shares of AAPL. Your profit: 10x$120 - 10x$100 = $1,200 - $1,000 = $200. Well done! We say that you were long on this position (buy then sell later).

  • Now let's say that you think that the Apple stock will drop. You don't own any AAPL shares but you want to profit from that drop. So this is what you can do: you can ask your broker to borrow from him, say, 10 shares of AAPL and you promise that you will give him back these 10 shares later. Once your broker agrees to lend you the 10 shares (I won't go into the details about margin accounts) you can go to the market and sell these 10 shares, even if you don't actually own them!
    Let's say today AAPL is at $100. You borrow 10 shares from your broker and sell them on the market at $100. You make $1,000 of that selling, but you still have a debt of 10 shares towards your broker. Two weeks later, your crystal ball is right (again!) and the price of AAPL drops to $80. You decide to buy 10 shares on the market at $80 and give them back to your broker. That's it! You cleared your debt towards your broker and this is your profit on the operation: sell 10x$100 then buy back 10x$80 = $1,000 - $800 = $200. Well done again! The whole operation you just did is called short selling and we say you were short on this position (sell then buy later).

The examples I gave are speculative ones where you try to forecast the market. But short selling is also used to protect your investments against market fluctuation, in particular sudden market falls. Here is an oversimplified example to illustrate:

AAPL is at $100 and MSFT (Microsoft) is at $50. To be market-neutral (i.e. protected against market fluctuation) you can be long on AAPL and short on MSFT at the same time. For that you would buy 10 shares of AAPL (long $1,000) and short sell 20 shares of MSFT (short $1,000). Now let's see what happens when the market suddenly drops by 20%!
  • AAPL price goes from $100 to $80 (-20%).
  • MSFT price goes from $50 to $40 (-20%).

You decide to exit the market by closing your two positions:
  • You sell your AAPL shares for $800 (10x$80). You originally bought them $1,000: you lose $200 on that long position.
  • You buy back your MSFT shares for $800 (20x$40). You originally sold them for $1,000: you make $200 on that short position.

As you can see your loss is $0 thanks of the long/short strategy you used (long AAPL, short MSFT).

As you can imagine, if the whole market goes up your profit will be ...$0. So how do we make money in a long/short strategy? By betting on the discrepancy between the positions and this is exactly what we do with Blackbird on Bitcoin: if Bitfinex prices Bitcoin at $240 and Bitstamp prices at $200 we think that Bitfinex is overpriced while Bitstamp is underpriced: we go short on Bitfinex and go long on Bitstamp until the two prices are similar again. You will have more details about how the long/short strategy works with Blackbird on the GitHub page of the project.



2. Still the 'short sell', so far as I know, bitstamp doesn't have an API for 'Instant Transaction', you can only place a buy/ask offer by API. How do you 'short sell'?

You're right: as of today it's not possible to short sell on Bitstamp. However, it's possible to short sell on Bitfinex, OKCoin and others. Note that the short selling operation is usually pretty straightforward and the Bitcoin lending part is automatically done for you by the exchanges.



3. Do you always see the price position switch between the bitcoin exchanges you selected? I found some exchanges price position maintains the same all the time. For example, bitkonan's price are always higher than bitstamp.

Between Bitfinex, OKCoin and Bitstamp we see price discrepancies pretty often. It really depends on the overall Bitcoin volatility: the higher the volatility the higher the spreads between the exchanges. But check the prices right now (08/24/2015 21:55:25 EDT):

   Bitfinex:  204.54 / 204.55
   OKCoin:    201.13 / 201.27
   Bitstamp:  204.29 / 204.48

As you can see there is a good opportunity right now between Bitfinex (short) and OKCoin (long) with a 1.62% spread. A word to the wise...



4. The spreadEntry and spreadExit point, how do you decide the value? Do you have any reference or analysis behind?

Good question and that's all the challenge: SpreadEntry and SpreadExit are set based on the historical relationship between the exchanges. If you use values closer to zero you will get more trades, but less profit on each trade. Also, as explained above if the Bitcoin volatility is very low you will have difficulties to get trades and might need to lower your values. The Bitcoin volatility is now at 3.51%. You can check it here in realtime.

Note that I have some ideas to implement using dynamic spreads based on:
1. the short-term historical volatility
2. the fact that we want to let the profits run.

Stay tuned!
Lawk
Newbie
*
Offline Offline

Activity: 6
Merit: 0


View Profile
August 28, 2015, 12:45:00 PM
 #38

Hi Butor,

Thanks for all the elaborate answers.
Any updates on the software as of may/june?

Greets,

Lawk
butor (OP)
Newbie
*
Offline Offline

Activity: 49
Merit: 0


View Profile WWW
September 01, 2015, 12:06:10 AM
 #39

Hi Mattsun,

So much thanks for you detailed answer! It really gives me a brand new perspective of btc arbitrage.
You're welcome. I'm glad it can help you to understand how arbitrage works.


1. How fast is your trading? I believe c++ is fast, but using API to do trade is mostly network bound ( I assume your algorithms don't take very much time...). Are there any special tricks that makes you trading bot fast other than multi-threading pulling real-time data (and use websocket stream wherever you can)?
By default Blackbird gets the prices from the exchanges and analyzes all the spreads every 5 seconds. That 5-second loop is pretty large but it's a simple parameter that you can adjust depending on your machine and Internet connection speed. You shouldn't get any latency issues with the parameter by default and the system can handle temporary network issues: if there is an network problem the system will stop the analysis and check the market data connection every two seconds.
Also, a contributor just found some promising C++ optimizations to make Blackbird more robust and faster. Thanks to him. This will be part of a future release. But if you have some network or C++ knowledge and have some optimization ideas, please reach out on the GitHub page! We use cURL to handle the HTTP requests.


2. Have you considered using some machine learning or statistics algorithm to train the bot? Such as using historical data to predict the trend the exchange price, or decide spreadEntry and spreadExit dynamically?
Absolutely. As I said in a previous post, we are going to dynamically adapt SpreadEnter and SpreadExit based on the short-term volatility. We are also going to use some historical data, however note that it's very tricky to train a system on historical prices because you never know what were the volumes of the historical bids and asks. This can lead to very inaccurate simulations.
Let's say that at a given time, the BTC bid price is $130.00 on a given exchange. It means that a trader is ready to buy some Bitcoin at $130.00. That's great, but how many Bitcoin? 0.10 BTC or 10,000.00 BTC? That makes a huge difference! I won't go into too much details but as a general advice: be always very careful when you backtest a strategy on historical prices only, specially for short-term strategies on illiquid markets like it's the case with Blackbird.

butor (OP)
Newbie
*
Offline Offline

Activity: 49
Merit: 0


View Profile WWW
September 12, 2015, 04:30:22 PM
 #40


Any updates on the software as of may/june?

Hi Lawk,

Currently we are working on improving the code itself. No new features but lots of code improvements for better performance and stability. Thanks to a great contributor, Julian Miller, who made many improvements to the code, we have now a better version of Blackbird which is under validation. You can check the details of his work on his GitHub pull request and this will be merged to the main code very soon as everything looks good so far.

Also, we are working on new ideas to optimize the arbitrage mechanism. The current Bitcoin market conditions are not ideal for exchange arbitrage: the low volatility means a more efficient market and thus less arbitrage opportunities. Two examples of new features: trailing stop and parameter adjustments based on the volatility.

Another idea: to do the arbitrage between Bitcoin exchanges in different currencies: the extra layer of currency conversion generates more inefficiencies that can be captured as opportunities. This will be an interesting implementation challenge because we will need to add the real-time currency rate into the spread calculation.


Pages: « 1 [2] 3 4 5 6 7 8 »  All
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!