Bitcoin Forum
November 11, 2024, 06:47:18 AM *
News: Latest Bitcoin Core release: 28.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: Spot/Futures Arbitrage (with some bots source code)  (Read 6300 times)
Fireball (OP)
Hero Member
*****
Offline Offline

Activity: 674
Merit: 500


View Profile WWW
December 19, 2012, 04:07:58 PM
 #1

Hello,
in this thread I would like to discuss spot/futures arbitrage basic ideas, provide reference implementations and listen to your suggestions.

Classical Arbitrage
Wikipedia explanation: http://en.wikipedia.org/wiki/Spot-future_parity
Basically, arbitraging means that you get the profit no matter which way the price moves. Futures arbitrage is a way of taking advantage from price difference of the underlying asset and the price of its futures contract.
Every futures contract gets mispriced from time to time and arbitragers can profit from that.
For example, right now average rate of BTC/USD futures at ICBIT is $14.66 and spot price at MtGox is $13.30, hence the difference being $1.30 !

How to actually get profit from that? Two ways exist:
1. "Long the basis":
 a. Buy BTC on MtGox for USD (which you own) and sell futures contracts on ICBIT.
 b. Close positions (buy futures contracts on ICBIT and sell BTC on MtGox) when the futures spread (spot/futures price difference) changed enough for you to get profit.
or
 c. Wait till futures contract is settled and sell BTC on MtGox

2. "Short the basis":
 a. Sell BTC (which you own) on MtGox for USD and buy futures contracts on ICBIT
 b. Close positions (sell futures contracts on ICBIT and buy BTC on MtGox back) when the futures spread (spot/futures price difference) changed enough for you to get profit.
or
 c. Wait till futures contract is settled and buy BTC on MtGox

Both ways will get you profit.
As it's already noted, it's not necessary to wait till futures settlement. Many (the vast majority of traders on fiat-money exchanges for example) trade futures spread instead: open arbitrage positions when the spread is high, close arbitrage positions when the spread is low.

Arbitraging with bitcoins is not harder than arbitraging on fiat-money exchanges, even simpler, but you need to understand a few important points:
1. BTCUSD futures contracts price is in USD, however profit/loss is accounted in BTC. Every contract is for $10. This makes it a bit harder to understand, but it makes it very easy to arbitrage (you have the same price scale: US dollars per 1 bitcoin). Contract explained here: https://icbit.se/BUH3
2. To buy/sell contracts on ICBIT you only need bitcoins. Marginal trading is available at no additional cost.
3. To buy/sell BTC on MtGox, you need to either have US dollars, or to have BTC which you want to sell in exchange for US dollars.
4. If you want to get your profit in US dollars, you may need to convert it to US dollars on some exchange (might be using ICBIT's exchange section, but it lacks volume now).

Example:
John opens his arbitrage position by buying 100 BTC on MtGox spending $1330, and selling 133 futures contracts on ICBIT for $14.66 (requiring a maintenance deposit of 14 BTC on his account there).
Some hours later the prices converge a bit, with MtGox being at $13.8, and ICBIT being $14.0.
So John buys back 133 futures contracts for $14.00 providing him positive variation margin on ICBIT equal to Profit = ((1 / 14.0 - 1 / 14.66) * -10) * -133 =  4.277 BTC (converted to US dollars that's $59)
and sells his position on MtGox which gives him $1380, plus $59 on ICBIT's account in BTC, thus totalling in $109 profit.

Another example:
John opens his arbitrage position by buying 100 BTC on MtGox spending $1330, and selling 133 futures contracts on ICBIT for $14.66 (requiring a maintenance deposit of 14 BTC on his account there).
Some days later the contract is settled on the sport price at MtGox being $13.0.
So John gets his 133 futures contracts settled on $13.00 providing him positive variation margin on ICBIT equal to Profit = ((1 / 13.0 - 1 / 14.66) * -10) * -133 =  11.585 BTC (converted to US dollars that's $150)
and sells his position on MtGox which gives him $1300 (a loss of $30 bucks) and $150 on ICBIT's account in BTC, thus totalling in $120 profit.

The basic idea is, wherever market moves, your profit is guaranteed.

Capt. Obvious suggests that automated arbitrage would be the best Smiley I will edit this post to add information about actual automated trading bots and API discussion, but before I do that, please let me know if you have any questions about the above.

Margin trading platform OrderBook.net (ICBIT): https://orderbook.net
Follow us in Twitter: https://twitter.com/orderbooknet
Fireball (OP)
Hero Member
*****
Offline Offline

Activity: 674
Merit: 500


View Profile WWW
December 19, 2012, 04:08:29 PM
Last edit: December 23, 2012, 07:22:53 PM by Fireball
 #2

Reference library for accessing ICBIT and MtGox APIs using node.js: https://github.com/icbit/trader.nodejs
Other stuff: To Be Added

Disclaimer: Always check and understand the code yourself before using it! Neither ICBIT nor its founders are liable for your profits or losses made using the above code. ICBIT API is subject to change, make sure to watch ICBIT website's API page and its official Twitter channel for possible announcements about API changes!

Margin trading platform OrderBook.net (ICBIT): https://orderbook.net
Follow us in Twitter: https://twitter.com/orderbooknet
ThePok
Full Member
***
Offline Offline

Activity: 131
Merit: 100


View Profile
December 19, 2012, 07:45:18 PM
 #3

no code no fun Grin
newminer7950
Full Member
***
Offline Offline

Activity: 124
Merit: 100


View Profile
February 08, 2013, 09:29:52 PM
 #4

I am try to write programm, but have not full information about api.
Exemple of problem: when i subscribed to chanell 'orderbook_BUH3', i dont recieve  messages about available orders!
Who can help me??? (I using socket.io in node.js)

Donations: 1BKA3FsvrZzznSJueXbx3qokHYqmwe9QQC
Fireball (OP)
Hero Member
*****
Offline Offline

Activity: 674
Merit: 500


View Profile WWW
February 09, 2013, 09:01:28 PM
 #5

I am try to write programm, but have not full information about api.
Exemple of problem: when i subscribed to chanell 'orderbook_BUH3', i dont recieve  messages about available orders!
Who can help me??? (I using socket.io in node.js)


Try to put the following code in a simple html file, open it up with your browser and check whether it works, try to see what messages you get, etc.

Code:
<script src="https://api.icbit.se/socket.io/socket.io.js"></script>
<script src='https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js'></script>
<script>
$(document).ready(function () {
var conn = io.connect('https://api.icbit.se:443/icbit?AuthKey=YOUR_AUTH_KEY&UserId=YOUR_USER_ID');
conn.on('connect', function () {
alert('Connected to ICBIT API server!');
});

conn.on('message', function (data) {
// Handle incoming data object.
if (data.op == 'private')
   alert('Incoming message: ' + data.private);
});
});
</script>

Margin trading platform OrderBook.net (ICBIT): https://orderbook.net
Follow us in Twitter: https://twitter.com/orderbooknet
navaman
Full Member
***
Offline Offline

Activity: 163
Merit: 100


View Profile
February 12, 2013, 02:26:25 AM
 #6



Classical Arbitrage
Wikipedia explanation: http://en.wikipedia.org/wiki/Spot-future_parity
Basically, arbitraging means that you get the profit no matter which way the price moves. Futures arbitrage is a way of taking advantage from price difference of the underlying asset and the price of its futures contract.
Every futures contract gets mispriced from time to time and arbitragers can profit from that.
Actually, to be pedantic, pure arbitrage is the near simultaneous buying and selling of a security.  What you are going for is risk arbitrage.  Risk arbitrage is different in that positions in securities are still open which can lead to exposure to other sources of problems.  Even further, theoretical arbitrage is valuation based on models and the buying and selling of securities is based on these.  You want to to do the second.  The common risk referenced in risk arb is direction risk which is how you want to use it.  There is still tremendous risk after a position is put on though.  Interest rate risk, pin risk, credit risk and final settlement price manipulation can all affect the outcome and lead to ruin.  Oh yeah, a lot direction risk arb still carry directional risk.  Can you guess why?
Quote
For example, right now average rate of BTC/USD futures at ICBIT is $14.66 and spot price at MtGox is $13.30, hence the difference being $1.30 !



Both ways will get you profit.
As it's already noted, it's not necessary to wait till futures settlement. Many (the vast majority of traders on fiat-money exchanges for example) trade futures spread instead: open arbitrage positions when the spread is high, close arbitrage positions when the spread is low.

Arbitraging with bitcoins is not harder than arbitraging on fiat-money exchanges, even simpler, but you need to understand a few important points:
1. BTCUSD futures contracts price is in USD, however profit/loss is accounted in BTC. Every contract is for $10. This makes it a bit harder to understand, but it makes it very easy to arbitrage (you have the same price scale: US dollars per 1 bitcoin). Contract explained here: https://icbit.se/BUH3
2. To buy/sell contracts on ICBIT you only need bitcoins. Marginal trading is available at no additional cost.
3. To buy/sell BTC on MtGox, you need to either have US dollars, or to have BTC which you want to sell in exchange for US dollars.
4. If you want to get your profit in US dollars, you may need to convert it to US dollars on some exchange (might be using ICBIT's exchange section, but it lacks volume now).

I agree it isn't harder that's because you are not dealing with interest rate.  There isn't a viable one to base it on as the Bitcoin equivalent of Broker/Dealers aren't sophisticated enough yet.  Arbitrage is profitable in the regulated securities market because of leverage.  Otherwise, opportunity would present itself a lot more in these markets.  Arb will exist until somebody in the Bitcoin universe can figure out how to do it more efficiently.

Honestly, I'm too worried about credit risk to put too much money into it.  I'll just buy an odd bitcoin here and there and play BJ.

Help develop DarkClam.  The Just-Dice currency of the future.  Helps is needed with development, funding and a lot of ideas.

Go here:

https://bitcointalk.org/index.php?topic=1362098.msg13861544#msg13861544
Fireball (OP)
Hero Member
*****
Offline Offline

Activity: 674
Merit: 500


View Profile WWW
February 12, 2013, 09:16:08 AM
 #7


Classical Arbitrage
Wikipedia explanation: http://en.wikipedia.org/wiki/Spot-future_parity
Basically, arbitraging means that you get the profit no matter which way the price moves. Futures arbitrage is a way of taking advantage from price difference of the underlying asset and the price of its futures contract.
Every futures contract gets mispriced from time to time and arbitragers can profit from that.
Actually, to be pedantic, pure arbitrage is the near simultaneous buying and selling of a security.  What you are going for is risk arbitrage.  Risk arbitrage is different in that positions in securities are still open which can lead to exposure to other sources of problems.

Sorry, but to be pedantic, I have to answer Smiley
a. Arbitrage (in economics and finance) is the practice of taking advantage of a price difference between two or more markets [1]
b. Risk arbitrage is a totally different thing that you are trying to explain to me. One way of defining Risk arbitrage is given in [2], and confirmed in [1] too.
c. What I am describing is the known for many decades spot/futures arbitrage. See second paragraph in section Examples of [1] for an example involving american stock exchanges.


References
1. http://en.wikipedia.org/wiki/Arbitrage
2. http://en.wikipedia.org/wiki/Risk_arbitrage
I realize Wikipedia may not be scientifically correct, however I consider these specific articles above to be good enough for referencing.

Margin trading platform OrderBook.net (ICBIT): https://orderbook.net
Follow us in Twitter: https://twitter.com/orderbooknet
navaman
Full Member
***
Offline Offline

Activity: 163
Merit: 100


View Profile
February 12, 2013, 07:21:59 PM
 #8


Classical Arbitrage
Wikipedia explanation: http://en.wikipedia.org/wiki/Spot-future_parity
Basically, arbitraging means that you get the profit no matter which way the price moves. Futures arbitrage is a way of taking advantage from price difference of the underlying asset and the price of its futures contract.
Every futures contract gets mispriced from time to time and arbitragers can profit from that.
Actually, to be pedantic, pure arbitrage is the near simultaneous buying and selling of a security.  What you are going for is risk arbitrage.  Risk arbitrage is different in that positions in securities are still open which can lead to exposure to other sources of problems.

Sorry, but to be pedantic, I have to answer Smiley
a. Arbitrage (in economics and finance) is the practice of taking advantage of a price difference between two or more markets [1]
b. Risk arbitrage is a totally different thing that you are trying to explain to me. One way of defining Risk arbitrage is given in [2], and confirmed in [1] too.
c. What I am describing is the known for many decades spot/futures arbitrage. See second paragraph in section Examples of [1] for an example involving american stock exchanges.


References
1. http://en.wikipedia.org/wiki/Arbitrage
2. http://en.wikipedia.org/wiki/Risk_arbitrage
I realize Wikipedia may not be scientifically correct, however I consider these specific articles above to be good enough for referencing.
A. No, which is why I made the distinction between different arbs.  Arbitrage is risk free in pure form but in practice it refers to buy and selling near simultaneously to a net closed position.  There are no risks involved once the buying and selling are completed.

B. Risk arb is just as I explained which I may have done badly but Wikipedia entry is even worse.  Risk arb isn't just about mergers and what hedge funds do.  It is buy and selling a security with the same risk characterics but not resulting in closed positions.  The open position means that there are somewhere, something that can blow up your arb position.  There is still some sort of risk.  You are just taking advantage of price discrepancies of one sort or another.  THIS WAS THE POINT OF MY POST.  ARBITRAGE AS IS PRACTICED STILL HAS RISKS AND I JUST WANTED TO POINT THAT OUT.  Sorry, for yelling, but you need to think through the question "how does this blow up in my face?"

C. I have been a member of a variety of those exchanges and have done various forms of arbitrage.  Surprisingly, I am now an academic or a few months short of it technically.

Help develop DarkClam.  The Just-Dice currency of the future.  Helps is needed with development, funding and a lot of ideas.

Go here:

https://bitcointalk.org/index.php?topic=1362098.msg13861544#msg13861544
Fireball (OP)
Hero Member
*****
Offline Offline

Activity: 674
Merit: 500


View Profile WWW
February 12, 2013, 09:09:54 PM
 #9

A. No, which is why I made the distinction between different arbs.  Arbitrage is risk free in pure form but in practice it refers to buy and selling near simultaneously to a net closed position.  There are no risks involved once the buying and selling are completed.

B. Risk arb is just as I explained which I may have done badly but Wikipedia entry is even worse.  Risk arb isn't just about mergers and what hedge funds do.  It is buy and selling a security with the same risk characterics but not resulting in closed positions.  The open position means that there are somewhere, something that can blow up your arb position.  There is still some sort of risk.  You are just taking advantage of price discrepancies of one sort or another.  THIS WAS THE POINT OF MY POST.  ARBITRAGE AS IS PRACTICED STILL HAS RISKS AND I JUST WANTED TO POINT THAT OUT.  Sorry, for yelling, but you need to think through the question "how does this blow up in my face?"

C. I have been a member of a variety of those exchanges and have done various forms of arbitrage.  Surprisingly, I am now an academic or a few months short of it technically.

There is no question about your education, especially when you provide correct answers now (which contradict to what you said one post earlier) Smiley

And btw, nitpicking, you are still slightly wrong in the point A. In real world in spot/futures arbitrage there still is a risk that the trader can't manage to keep up his margin to a level preventing forced liquidation of his open positions in case of a big and rapid market movement against one side of his position in futures.

For the readers who are following this topic, I will quote "Options, Futures and other Derivatives" by John C. Hull book, Chapter 1, section 1.9:
Quote
Arbitrageurs are a third important group of participants in futures... market. Arbitrage involves locking in a riskless profit by simulteneously entering into transactions in two or more markets.


Margin trading platform OrderBook.net (ICBIT): https://orderbook.net
Follow us in Twitter: https://twitter.com/orderbooknet
romang
Member
**
Offline Offline

Activity: 112
Merit: 10


View Profile
March 23, 2014, 04:37:32 PM
 #10

Any updates?

Pages: [1]
  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!