Back

Algorithm Framework Systematically Generates Too Many Insights

Hello,

I am learning to use the algorithm framwork, and to do this I am trying to whip up a quick simple moving average cross model between two assets. I've noticed a systematic error when it comes to insights. On backtest, the insight count always shows 782 though when I debug the number of insights it correctly reveals 2 (one for each asset). I think as a result of these extra unknown 780 insights, the algorithm decides to do over 2000 trades in only 9 trading days despite having the universe resolution to be daily. Anyone have an idea of what is going on?

Update Backtest








0

The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.


Update: I took the framework tutorial in the boot camp because I know that works and then modified that code little by little until it matched the code from the backtest I posted above and then it started working appropriately. Guess there was a small mistake somewhere I don't notice?

0

Hi Trevor, 

you haven't specified the resolution of your Benchmark (SPY)

self.SetBenchmark(self.AddEquity('SPY').Symbol)

By default it gets Resolution.Minute and thus your Update() method get called every minute. In addition, you haven't specify a rebalancing method/frequency for you EqualWeightingPortfolioConstructionModel so that your algo is rebalancing the portfolio every minute. I think this explains the many insights. 

When we set the Resolution of SPY to Resolution.Minute there will be only 2 insights per day. 

self.spy = self.SetBenchmark(self.AddEquity('SPY', Resolution.Daily).Symbol

Is that what you were looking for?

A monthly rebalancing can be obtained by passing a rebalancing timer function to your EWPCM, for example: 

self.SetPortfolioConstruction(EqualWeightingPortfolioConstructionModel(lambda time: Expiry.EndOfMonth(time), portfolioBias = PortfoloioBias.LongShort)
self.Settings.RebalancePortfolioOnInsightChanges = False
self.Settings.RebalancePortfolioOnSecurityChanges = False

For demonstration purposes I've changed your insight durations to Expiry.EndOfMonth and added to following lines to make sure the alpha model emit insights once a month:

# in __init__
self.month = None

# in Update():
if self.month == algorithm.Time.month: return []
self.month = algorithm.Time.month

Of course there are other ways for rebalancing available. The EWPCM can also handle a more complex rebalancing function. If you dont't want to rebalance at all just use:

self.SetPortfolioConstruction(EqualWeightingPortfolioConstructionModel(lambda time: None))

 

2


Ah, that explains it. Thank you so much this is super helpful!

0

Update Backtest





0

The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.


Loading...

This discussion is closed