Hi All,
We noticed some strange behavior in the backtest when using the second resolution and switching from a single ticker to multiple tickers. One would expect the sum of all trades to be: (Ticker 1 No. of Trades) + (Ticker 2 No. of Trades) = Total trades. In this case we noticed that the number of trades on a single ticker was greater than the number of trades when using two tickers. Upon looking into our backtest results we discovered missing trades when using two tickers. Our two tickers should be trading repeatedly throughout our trading window, and simultaneously, but it appears that this is not the case.
In the attached backtest we trade the two tickers ['OCGN', CLOV'], the total number of trades in this case is 62. Which is the same number of trades that we get when trading just ['OCGN'], upon inspection we notice missing trades.
For example, in the following image we can see that OCGN made trades on 03/04/21, when using just this single ticker.
However, when making trades using both tickers we see that the OCGN trade for that date is missing (see below image):
No changes have been made to the code, other than adding the second ticker and this pattern of missing trades is prevalent throughout our backtesting.
Could this be the result of a bug in the backtest node, or are we missing something in our code?
We would greatly appreciate any help from the community on this.
Adam W
Change `self.previous_bar_close`, `self.lowestPrice`, etc to a dictionary as it's being overwritten in the loop
Christopher Phillips
Adam W Thanks so much for the suggestion! Unfortunately though I am encountering a ‘float’ object is not subscriptable, error when converting them to a dict. I assume that I should define these as empty dictionaries in the initialization phase? i.e:: `self.previous_bar_close = dict()`
Varad Kabade
Hi Christopher Phillips,
In the above algorithm, `self.previous_bar_close`, `self.lowestPrice` and 'self.ticket' are being overwritten. To resolve this, we recommend using a dictionary to store the above variables keyed by the Symbol object. In the attached backtest, we have shifted the above field to SymbolData class. Note that, keeping best practices, we have made the following changes to the above algorithm.
3. Used the symbol object to place different kinds of orders in the algorithm.
Refer to the attached backtest
.Best,
Varad Kabade
Christopher Phillips
Varad kabade This worked excellently, thank you so much!
I am also trying to add another indicator to the SymbolData class, but I am receiving errors.
I am pretty sure the issue is how I am adding it to the SymbolData class, but I don't know what the best way to go about this is, do you have any idea what I am doing wrong?
Best,
Christopher
Louis Szeto
Hi Christopher
public variable using prefix self. can only be retrieved within class object. If you're calling a public variable from another class, you'll need to call the class then its attribute/method: self.window → self.dataBySymbol[Symbol].window. Otherwise, python will only find the variable/attribute/method from same class.
BTW I don't get your 3rd consolidator's usage, so I didn't do anything to it. Can you explain more?
Cheers
Louis
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.
Christopher Phillips
Hi Louis Szeto , the third consolidator is meant to obtain the previous days close using the rolling window. It is based on this method:
What I was trying to do was integrated this indicator into the SymbolData class, because the backtest was producing erroneous results, i.e not trading multiple tickers, and not trading multiple times per day. It looked like my previous method for calculating previous days closing price was not working, so I was hoping this would remedy the situation.
If you have a better solution for obtaining previous days closing price for each symbol I would love to hear it, or if you think this is the way to proceed, I would also like to know if I am taking the correct approach?
Best,
Christopher
Louis Szeto
Then your way using it looks good to me
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.
Christopher Phillips
Louis Szeto Awesome! Thanks. It is working now, except now I have an issue with the timed exit no liquidating trades, which to be honest I don't think it ever worked. I have tried multiple methods of using time to liquidate trades after 15 mins, but none seems to work. Have you used timed exits in trading before?
Christopher Phillips
No worries, I fixed it! Thanks for your help everyone.
Christopher Phillips
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!