I want my algorithm to

  1. screen for securities
  2. buy those securities
  3. hold them for a year
  4. liquidate them
  5. repeat

Unfortunately I'm running into problems at the hold them for a year part. My solution was to emit insights with an expiration of 254 days, which is about a year's worth of trading days. It seemed to be working fine when I was doing short tests, but once I tried to backtest from 2000, I started running into problems.

I thought that once my insights expired, the securities would be liquidated, but it looks like there might be some stragglers that don't get liquidated. I am using

if not self.Portfolio.Invested:

to trigger my universe selection and insight emission to happen, so if there are stragglers in the portfolio then it won't fire for years, which looks like what is happening in my attached backtest.

What is the easiest way to make my algorithm work the way I want it to? I was hoping to have to do universe selection only once a year to make my backtest faster and more efficient.

Author