Hi,
When running my algo I decided to keep track of my cash position, and it seems like Portfolio.Cash would only decrease (even below 0) with each iteration of rebalancing of my portfolio. I thought it might be because there was cash left unsettled but it Portfolio.UnsettledCash always returns 0, so I don't think that's the case.
I do not face issues with orders not going through due to insufficient funds, so I'm not quite sure what's the problem here, or if I am misunderstanding how Portfolio.Cash works. I have attached a backtest to this thread. I tracked the state of my cash position in the logs. I would be really grateful if anyone could dispel this mystery :p Thanks!
Derek Melchin
Hi Han,
Our portfolio cash can go negative when rebalancing the portfolio because of the slippage involved with placing overnight trades. Refer to the attached backtest for an example. In the example below, our position size is calculated on the closing price of the bar stamped 2020-09-02 ($475.05). However, the orders are filled at the market open price of 2020-09-03 ($479), requiring more cash than initially anticipated. To avoid a negative cash balance, we can always increase the cash buffer.
self.Settings.FreePortfolioValuePercentage = 0.1
Best,
Derek Melchin
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.
Han Ruobin
Thanks Derek!
Han Ruobin
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!