Back

Cant figure out why filll_price is changing

Upon running the backtest, i see that the logs show "Opened at 0.0 and closed at 0.83048", for example. The this log is caused by the following line:

self.Log("Opened at {} and closed at {}".format(self.OpenPrice,self.ClosePrice))

and OpenPrice and ClosePrice are in turn found by using the fillprice of an OnOrderEvent function. Can anyone help determine why my OpenPrice is always 0 but the ClosePrice works?

 

 

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

The reason the OpenPrice always prints 0 is because the OnOrderEvent method is defined to assign the fill price of the order event every time the method is called.

Instead, what we should do is only assign the fill price if we know the OrderStatus of the order event is `Filled`. To accomplish this, we can add the following guard to the OnOrderEvent definition:

if orderEvent.Status != OrderStatus.Filled:
return

View the attached backtest for reference.

Best,
Derek Melchin

1

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.


I understand now, thanks so much derek!

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