Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Guidelines for minimizing impact of trading costs

This is a backtest of an extremely simple strategy which I'll also try to attach to this post. It's long only, just holding a bigger position when SPY goes above a moving average, and going to cash when it goes below. It has positive (not necessarily good, just positive) returns. It also has a stop loss.

As soon as I turn on any commission or slippage, though, it gets absolutely destroyed and the only thing that remains consistent is losing money :)

I'm tracking the amount of trades, and it's 35000 in SPY trades in about 20 years, or about 7 trades per day. It trades a lot some days, even 100 times; other days it trades two times.

What's surprising to me is that I wouldn't think this amount of trading would make a profitable algorithm just consistently lose money. I thought this wouldn't be considered that many trades. I bet there are retail traders who have made a similar amount of trades!

So where's the big problem I'm overlooking? Is there some tool to analyze intraday algorithms, quantify the impacts of slippage and commissions and then optimize the algorithm to reduce them?

4 responses

@Eugenio,

This may help

    record(leverage = context.account.leverage, round_trips = context.round_trips)  

146 round_trips.

The lesson here being just to reduce the amount of trades? I really thought that amount of trading wouldn't be too much. Maybe it's also a matter of the alpha being too weak for the amount of trades?

@ Eugenio,
in your hypothetical back-test (does not include the cost of slippage and commission)
alpha is 0.03, beta 0.10.

My back test takes into account slippage and commission costs,
alpha is 0.09, beta 0.19.

What alpha are you looking for?

My hypothetical backtest is not something I'd actually want to trade live on my account. I'm not saying it's a good algorithm, or sharing it because it's interesting.

It is clear that your algorithm is better, but my algorithm was just an example to ask about how to deal with slippage and commission destroying the alpha of an algorithm. I think what I'm looking for is mostly a general explanation or some practical rules of thumb about the amount of trades or something along those lines