Saturday, April 26, 2014

Algorithmic Trading System and Trades Section Update 4/26/2014

Time is scarce when you're determined to get something right. I lack the personality and charisma to obtain a multi million dollar leadership job. I'm missing the creativity to create a multi million dollar business. My last chance at riches and leaving the rat race is the stock market.

Before I start with the Algo updates, I've refreshed trading section. You can follow me on twitter to see my trades in real time, but the trading section is a convenient reporting tool which tracks my older trades much better.

In the time between now and the previous update, here are the things that I've done:

  • Unsuccessfully create a trading strategy which expands my pairs to triplets / baskets
  • Create a wildly profitable momentum strategy using technical analysis
  • Discover that my wildly profitable momentum strategy was the result of bug / data errors. Some of my data shows prices of 0. The way my code is written, when I place a buy limit order, it checks if the price is less than the limit price, and then fills at the limit price, leading to fills that can never happen.
  • Enhanced my cloud infrastructure. I used to be burdened with the tedious task of manually deploying code to each of my cloud boxes. Then, I had to manually turn on the backtesters on each machine. I now have infrastructure in place to do a one-click deployment which will pull the latest code and start up all of the backtesters.
  • Allow my backtester to process price bars of different frequencies. I can now run a 8 year backtest using 1 minute bars in 6 seconds, vs the 8 year backtest using 1 second bars in 4 minutes.
  • Fix an enormous number of bugs, including things like equity curves not generating properly, improper calculation of commissions. Fortunately, the errors are small relative to the overall shape of the curve, but it's good to be diligent.
  • Discovered situations where I should not execute on my trading signals. I'm not going to go int detail on this, but I suspect this might be why many people are unable to generate profitable backtests for basic pairs trading. There is a problem which is extremely difficult to code for, and I admit that I have not been able to solve it. It's one of those problems where a human can easily solve it visually, but it's extremely difficult to write a program to do it.
  • I've never turned on the full automation for my system, and I am even more certain that I should leave it off due to the previous point.
Here is an equity curve of my live trading. This equity curve accurately reflects the pnl in my account, to the point of including dividends and payments in lieu of dividends. The curve does not include Hard To Borrow fees, or margin interest. I'm estimating the sum of both to be less than 300 dollars, based on my brokerage statements, so it's relatively small compared to the displayed PnL.
PnL of my Live Trading

Notice the large drawdown from the beginning of 2014 to middle of January. I introduced a very nasty bug into my system which caused all of the quantities from the generated trade signals to be wrong. The errors were small enough where I wouldn't have caught them unless I hand calculate to check, but the errors were large enough to cause significant losses. Every trade generated in the 2 week period were losing trades, because the hedge ratios were wrong. It wasn't until after 2 weeks that I started suspecting that this was no longer a coincidence.

The result is the loss of about 6K worth of profit + the profit of the 2 weeks of correctly generated trades. Although I think of myself as a very good programmer, I am only human. Let this be a lesson to everyone else that the dangers are very real, and that there will always be new ways to screw up. Performance returned to normal after fixing the code, but this leaves a permanent blemish in my trading record to remind me that I am fallible.

It's been almost a year that I had real money in my system. I am now more confident than ever that the results are not due to luck. I am considering increasing my leg sizes for the trades, which will require me to liquidate some of my non-algo holdings.


  1. I have interest in doing something similar in terms of back-testing strategies. Unfortunately I can only get my hands on daily data scrapping from yahoo / google for my own personal use.

    If you don't mind me asking, where are you pulling 1 minute bars / 1 second bars for data from?

    1. I actually work at a data company, so use it from from work. You may be able to make use of You can build a strategy there in python and test against their 1 sec data. There are a many places where you can purchase it too. Pricing generally depends on how granular you want the data to be.