Portfolio.Invested shows false but Portfolio.Cash indicates Insufficient buying power - Invested

Back

Hello guys,

i need some help to understand how the engine is working. It is a simple strategy that just buys two assets and sells them the day after.

I worked with it even in a debuger to trace the issue. 

self.Portfolio.Cash

This property above should represent how much available cash my algo has. But, for some reason it is lagging, it shows very low cash available, which suggests that portfolio is invested. But at the same time self.Portfolio.Invested returns false. 

Which creates a margin warning:

Backtest Handled Error: Order Error: id: 7, Insufficient buying power to complete order (Value:99774.36), Reason: Id: 7, Initial Margin: 99775.89, Free Margin: 331.12

And the next asset can not be bought. For some reason this script can only work with one asset. Do i use the Engine the wrong way? Where is the misstake i make?

 

Thanks in advance :)

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

The IB Brokerage Model simulates order settlement when using `AccountType.Cash`. In this situation, it takes 3 days for the portfolio to receive cash from the sale of stock. See the attached backtest for reference.

To avoid simulating order settlement, change the AccountType to `AccountType.Margin` or remove the brokerage model.

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.


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