Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Tax Harvesting Long Only

I've been playing around with a random selection algo that was recently shared, mostly testing how many securities are needed to effectively diversify (I think most academic studies put the number at about 15 before you hit diminishing returns).

Anyways, the results from those test got me thinking about this algo, a tax efficient approach that attempts to give you a beta of 1, while selling off losing stocks to "harvest" the tax benefit (see investopedia tax harvesting). This algo starts with 30 random stocks picked from the sp500. Each month it checks to see which stocks have unrealized losses, sells them, and blacklists them for 31 days to avoid running into a wash sale. It then randomly picks a few more stocks to replace the ones that were sold and rebalances everything to equal weighting. Additionally, each year, it increases the number of holdings by 5 to inject some fresh blood (otherwise, the companies get stale)

Right now, I'm measuring the tax benefit with a back of the envelope calculation that says (cost basis - current price) * shares, which I expect to be a reasonable proxy for the losses. Also, I would expect that splits and dividends complicate it in ways that I haven't accounted for, but I think it should be pretty close.

I've run the backtest 8 times over the same time to see how the random selection effects it and this was the worst result. The other returns were 270%, 307%, 451%, 337%, 308%, 406%, and 407%. I tried getting a notebook going so I can run a batch of test, but ran into trouble with that.

3 responses

@James

Just cloned and ran this algorithm, not sure yet why my run had better results. Interesting idea and hope to study your concept in the future.

The underlying stock selection is done randomly, so each backtest is going to be different. What's interesting to me is that I've run this backtest 10 times, and the worst one matched SP500 returns.

It'd be awesome if someone could create a notebook where we could run a bunch of backtests at once to see how the randomness materializes. I tried, but I'm not familiar enough with zipline to run a dynamic stock selection backtest

I did not realize the stocks were selected randomly. That makes testing the concept a real challenge.