Hi everyone, please can someone can help me find whatever (likely stupid and obvious) mistake I've made?!
I'm using self.Portfolio.MarginRemaining (and self.Portfolio.CashBook["USD"].Amount gives the same problem) to get my available USD balance, then using that to calculate a quantity for an order, but in page 30 of the orders all orders come back invalid with the following error:
"Order Error: id: 294, Insufficient buying power to complete order (Value:493.1365), Reason: Your portfolio holds 493.6146195684653 USD, 0 USD of which are reserved for open orders, but your Buy order is for 3.73107731 ETH. Your order requires a total value of 493.1364880627 USD, but only a total value of 492.8710531713554 USD is available."Seems to me that self.Portfolio.MarginRemaining is giving the wrong value, but there's a good chance I'm missing something obvious?
I'm new to Quantconnect so this algo was supposed to be an easy exercise to get me used to the platform. I've got a bit of experience with Python from my days as an engineering student, but I'm sure that my code is somewhat lacking, so i've tried to make up for it with a tonne of comments to keep things organised.
Would really appreciate any input, either to fix the problem or just any improvements I can make to my code!
Thanks, Ben
Shile Wen
Hi Ben,
The issue is that we are using self.quantity = (self.Portfolio.MarginRemaining * 0.99) / self.limitPrice when we should be using the value from the CashBook, i.e. self.quantity = (self.Portfolio.CashBook['USD'].Amount * 0.99) / self.limitPrice. I've shown the fix in the attached backtest.
Best,
Shile Wen
Ben Matthews
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.
To unlock posting to the community forums please complete at least 30% of Boot Camp.
You can continue your Boot Camp training progress from the terminal. We hope to see you in the community soon!