A newbie question. I know how to initialize algorithm with cash via SetCash method. How about initializing with equities? What if I have a portfolio of cash and equities at a certain point in time and I want to start with that portfolio to backtest? Not sure how I would "setEquity" basically. It'd be also useful to manually enter stats like "buy price" for these equities so I can properly track gains.
Daniel Chen
Hi Mete,
Welcome to QuantConnect! One possible way to initialize with equities is to use Portfolio[symbol].SetHoldings(averagePrice, quantity) in Initialize method. For example, Portfolio["AAPL"].SetHoldings(200, 2) means that we hold 2 shares of AAPL with average buy-in price 200 in Initialize.
In this case, please be careful that we should set the average price reasonably to avoid conflicts with reality. For example, it doesn't make sense to set the average buy-in price of AAPL to be 100 on July 24th, 2019, since the price is around 200. Thank you for your question. Hope it helps!
Mete Atamel
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!