Being able to build an algorithm and run a backtest using lean is fantastic!
But in reality most people are either of working age and therefore making regular DEPOSITS into their trading strategy, or are retired and making regular WITHDRAWALS from their trading account. The optimum strategy for each of these situations could be very different! For example, a higher volatility strategy is much more appropriate for someone making regular contributions, while lower volatility is desirable for someone making regular withdrawals.
It would be a fantastic if we could incorporate these factors into our backtesting (and our live trading) to see the impact of regular Deposits & Withdrawals, thereby optimising strategies for whether they are regularly receiving funds, funding neutral, or regularly suffering withdrawals.
Any input into the idea would be warmly welcomed…
Thanks!
Mark
Varad Kabade
Hi Mark Reeve,
We can simulate the above behavior in the backtest by the AddAmount method of the cashbook object. We can use the Scheduled events method of the QCAlgorithm class to incorporate the factor of withdrawing each month. Refer to the following snippet:
Note that we recommend liquidating the holdings before withdrawing from the account.
Best,
Varad Kabade
Mark Reeve
Thanks Varad!
That is exactly the functionality I am looking for… except I cannot get this implementation to work…
I receive the following error:
Mark Reeve
I also note there is nothing in the Docs about Cashbook or AddAmount?
Varad Kabade
Hi Mark Reeve,
Unfortunately, there was a typo in the above-attached code snippet; the correct attribute name is CashBook. Refer to the updated code snippet:
We are currently working on new docs, and we will cover the CashBook and the AddAmount method. Also, we recommend following the link for a detailed description of the API. You can find details about AddAmount and CashBook here[1, 2].
Best,
Varad Kabade
Mark Reeve
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!