Hi, I am trying to use a SymbolData class to store securities specific values but am not able to get it to work properly. I have simplified my algorithm to illustrate the problem below:
Algo Strategy: The illiustrative algo uses fast and slow SMAs to generate buy and sell signals. Buy signals are generated when fast SMA moves above slow SMA and Sell signals are generated when slow SMA moves above fast SMA. The algo then extends to invest in multiple securities.
For the signals, in OnData(), I use a bsignal boolean to store the buy signal then reset its value at the end of OnData(), vice versa for sell signal using ssignal boolean. Orders are then placed according to these signals. Additionally, if the security was originally long in the portfolio, and a sell signal comes in, then the portfolio should liquidate the long and enter a short, vice versa for original short in the portfolio.
The problem is: I could get this working with one security, but when I try to implement this for multiple securities, the algo just breaks down: in particular, i. the buy and sell signal vars (ie. bsignal and ssignal) for each Symbol Data instance do no reset at the end of OnData() shown in the logs. ii. the liquidationplaced var also does not reset at the end of OnData()
Result of the problem: the strategy kept making duplicated trade pairs when I included more than one security to be invested since the bsignal and ssignal were not resetting. liquidationplaced not resetting also caused more problems in my actual extended algo.
Any help on this is deeply appreciated. Thanks a lot!
Shile Wen
Hi Big Chai,
The "resetting" of these fields is done after the Log function is called, hence why they don't seem to be reset.
Please try
symbolList = ["AAPL"]
instead of
symbolList = ["AAPL", "GOOG"]
To see if it matches the 1-symbol version, and if so, the algorithm is working the same but doesn't handle two securities well.
Best,
Shile Wen
Big Chai
Thanks Shile. I realized what was wrong, I wasn't initiating the symboldata class instances correctly. The security specific attributes were being declared as class vars rather than object vars. Thanks!
Big Chai
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!