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.

Clone Algorithm
13
Loading...
Backtest from to with initial capital
Total Returns
--
Alpha
--
Beta
--
Sharpe
--
Sortino
--
Max Drawdown
--
Benchmark Returns
--
Volatility
--
Returns 1 Month 3 Month 6 Month 12 Month
Alpha 1 Month 3 Month 6 Month 12 Month
Beta 1 Month 3 Month 6 Month 12 Month
Sharpe 1 Month 3 Month 6 Month 12 Month
Sortino 1 Month 3 Month 6 Month 12 Month
Volatility 1 Month 3 Month 6 Month 12 Month
Max Drawdown 1 Month 3 Month 6 Month 12 Month
# Backtest ID: 58d41bd3c83aa51b440d2354
There was a runtime error.
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.

Clone Algorithm
8
Loading...
Backtest from to with initial capital
Total Returns
--
Alpha
--
Beta
--
Sharpe
--
Sortino
--
Max Drawdown
--
Benchmark Returns
--
Volatility
--
Returns 1 Month 3 Month 6 Month 12 Month
Alpha 1 Month 3 Month 6 Month 12 Month
Beta 1 Month 3 Month 6 Month 12 Month
Sharpe 1 Month 3 Month 6 Month 12 Month
Sortino 1 Month 3 Month 6 Month 12 Month
Volatility 1 Month 3 Month 6 Month 12 Month
Max Drawdown 1 Month 3 Month 6 Month 12 Month
# Backtest ID: 58d4b6bdc0b6811c1addb390
There was a runtime error.

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.