Back

Issues with order fills and execution

Using ImmediateExecutionModel() with EqualWeightingPortfolioConstructionModel() runs for about half a year, then returns:

Backtest Handled Error: You have exceeded maximum number of orders (10000), for unlimited orders upgrade your account

while total insights are only 1000-1500.

Using it with MeanVarianceOptimizationPortfolioConstructionModel() runs a few days, then returns multiple:
 

 

Backtest Handled Error: Order Error: id: 5266, Insufficient buying power to complete order (Value:7955.22), Reason: Id: 5266, Initial Margin: 7233.4281818181818181818181819, Free Margin: 17.2091834683213636363637
557

 

The logic of the algorithm is: 1. Compute something every day before market open, set a boolean to True if it works 2. Within OnData, if boolean is True then compute something and emit insights 3. Further insights are emitted only if certain conditions are met

What I've tried:

  • Created custom Optimizer class with a buffer on portfolio weights (i.e. sum of weights <= 0.95, rather than 1)
  • Custom Portfolio Construction and Optimizer classes (helpfully provided by Emilio here) but this introduces other errors which I am still in the process of debugging

Any suggestions on where else to look? I've tried re-scaling the weights in Portfolio Construction (in case the optimizer was not converging), but this didn't do anything. The ImmediateExecutionModel() source code suggests that previous holdings and open orders are taken into account when placing new trades, so I'm not quite sure where else the error may be coming from.

Edit: Previous insights should be overwritten by new insights emitted (impression is that this is true by default looking at execution models, but maybe it isn't?)

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.


Hi Adam,

Can you attach a backtest you've run with this code? It will be easier for us to debug the issue if we can see exactly how the framework models are being used. If not, providing a skeleton of the code would be helpful as well.

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 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