This project is to build a fully-functioning executable using Java or C++ that will automatically trade stocks using Interactive Brokers' API. A basic understanding of stock trading and familiarity with Interactive Brokers API are a must. See Interactive Brokers' website ([login to view URL]) for further information. The trading program will execute paired trades to arbitrage differences in stock prices between related stocks.
?
## Deliverables
General Description: program would auto-trade a simple arbitrage / statistical-arbitrage of two US-listed stocks. The program should be able to play the pair either way (long A short B and long B short A); the program should be capable of running multiple instances at the same time to trade multiple pairs of stocks.
1. Settings - the program should have the following user-modifiable settings. It would also be good to be able to save the settings for each arbitrage trade to a file so that I do not have to re-enter the details each time I open the program.
- Tickers - there would be two, of course
- Shares of stock to be traded (should be separately variable for each stock). The program should allow for unequal shares (e.g., BRK-A and BRK-B, which trade at a 1:30 ratio). If the share amounts are unequal, the lower-priced stock should be converted by the share price ratio to calculate the triggers (so if BRK-B is at $4,000 and BRK-A is at $125,000, the difference between the two would be $5,000 ($125,000 - 30 * $4000) and the percentage difference would be 4%).
- Exchange - I should be able to choose any stock exchange, ECN, or IB smart-routing to send the trades to.
- Trigger Difference - I should be able to set a trigger point for each potential trade. This trigger can be entered either as a percent difference or as a dollar amount difference. For example, I may want to short CMG-B and go long CMG when CMG is less than $4 greater than CMG-B or when CMG is less than 10% higher than CMG-B. The trigger for the inverse trade (long CMG-B, short CMG) should be separate, so I could set it to do this trade for example when CMG-B is $6 less than CMG or when it is 15% less than CMG.
--I would also like a Trigger point based on the ratio of any two stock prices. For example? if the pair of stock's hit a certain? price ratio it would trigger a market order to buy, and? the oppossite should hold true if the pair of stock's hit a certain price ratio it should? trigger an order to sell. This function should not just be limited to buying long, but also selling short.? ?
- Take profit setting. The program should be adjustable so that it takes profits when a specific target dollar profit or % profit is made, OR, when the spread on the closing trade reaches a certain level (dollar or percent). For example, I may set the program to take profits from long CMG-B / short CMG when CMG-B is less than 15% below CMG.
- Stop-losses - there should be a stop-loss setting that is at a dollar or percent loss. I should be able to disable the stop-loss
- One-sided pairs trading - there should be an option to only trade one of the two stocks (eg., buy or sell CMG-B only, but in response to spread between it and CMG) or to only take one type of position (short only or long only).
- I should be able to determine whether the program submits market orders or limit orders, and be able to set an offset amount for limit orders so that I could have the program routinely place limit orders at a point that I can be sure to be filled (e.g., an offset of $0.10 so that the limit order will be executed at most $0.10 above the current best bid or below the best ask)
- there should be a way to keep the program open but pause trading; also, it should display the relevant dollar and percent spread between the stock pair at all times, even when paused
2. Failsafes / checks / requirements - the program should check the following to make sure problems do not occur
- it should always check to make sure the stock is borrowable to short before placing a short order.
- it should always check to make sure that both sides of the trade execute completely; if they do not it should alert me (pop-up window and user-selectable sound would be nice) or automatically close the positions. I should be able to set an option whether it alerts me or closes the positions itself.
- the program should not make any new trades if I have either of the stock pair in my account already.
- the program should be able to deal with different amounts of stocks and high-priced / low-priced stocks. For example, I may wish to trade BRK-A / BRK-B, for which the stock prices are very high, and the amount of stock traded is very low
- the program should show an alert when any of the above are true and it thus cannot trade
- the program should calculate entry/exit points based not on the last price but on the bid/ask prices, because many of the stocks I may trade are not very liquid. So, for example, if BRK-B is at a bid of $3900 ask of $4000 and BRK-A is at a bid of $121,000, ask of $121,500, the percent difference for short BRK-A / long BRK-B would be ($121,000 - 30*$4,000) / $121,000, while the percentage difference for the opposite trade would be ($121,500 - $3900*30) / $121,500. The relevant bid/ask should also be used to calculate potential profit/loss for the take profit and stop loss subroutines.
- the program should not attempt to trade outside of regular market hours and it should only trade when there is a listed bid and ask for both stocks it is trading
3. Potential features (but not if they are too expensive)
- If possible, I would like to have the program automatically calculate the average of the spread ($ or %) between the two stocks over the past X trading days, where X can be changed by the user. It would then display this and I would use it to set the trigger price or percent. If there is a fairly easy way to get this data from the IB API, this would be great.