Order execution and stop loss implementation using Python

Discussion in 'Order Execution' started by newdog, Apr 16, 2017.

  1. newdog

    newdog

    I am thinking about trading futures and using Interactive Brokers TWS as my platform for order and stop loss execution.

    I will code in Python and this will be my first algorithmic trading experience on retail side.

    I plan to start trading using very small amount of dollar of order 10-20 grand initially. I plan to trade up to 10 future contracts (5 in and 5 out per day) and don't want to pay too much in commission either.

    Is IB TWS good for my purpose or should I consider something else?
     
  2. KeLo

    KeLo

    Try it in Sim mode first before risking real $.
     
  3. Simples

    Simples

    Automation is the easy part. Do you have a viable and tested trading plan?
     
  4. newdog

    newdog

    I did out of sample backtesting on daily data and it appears viable. But I don't know how viable it is in reality so just want to start dipping my toe in it and if it works out increase the dollar. Viability is decided very much by stop loss and order execution. Before doing the viability testing with IB I am going to do the backtest on 1 min data.
     
  5. Simples

    Simples

    For medium/short-term have you considered costs of commissions and spread as well? Liquidity also important to include as backtest need to be realistic, not hypothetical. Ie. check if some outlier-returns are unrealistic, find ways to weed them out.

    When the backtesting code is realistic enough, it should work unless dependent on market conditions that may change. It is less demanding to do this theoretically first than hoping everything works out live.

    If all is go, I'd say just go for it. Spend as little as you can on costs though, as you may want to try different software and brokers in the future, or even diversify among them.
     
  6. newdog

    newdog

    Liquidity and transaction costs are accounted for.

    But it is a good point to look at how many of those returns are extreme returns because I did snip out the extreme losses through stop loss. I will snip out any returns higher than 2 standard deviation also and check the sharpe. Is there any statistical way to remove the higher returns from sample?

    I also haven't figured out yet how to statistically set the stop loss. Looking at 1 min bar might give me some clue but any suggestion is appreciated.
     
  7. Simples

    Simples

    The trading logic should do that for you, as ie. the stop-loss need to be realistic and even include slippage. Statistically you can easily do it by either filtering above 90% percentile or using 3 * stddev above average to filter. However, in reality, the real higher returns may be those trades that pay for your trading and losses, though some extreme outliers in backtesting may mean a weakness in the system that is not realistic. It's good to understand your distribution though, and also check if it's statistically meaningful, ie. how many trades are considered and wether there are any biases like selecting period or markets.
     
    newdog likes this.