Hi! Currently by default, the benchmark is plotted on a different window from the strategy equity. I'm trying to make it so that the benchmark performance is overlayed on the strategy equity instead of being plotted separately.
To start, I tried out the idea from this post.
By cloning the attached algorithm in the post above, the function worked just fine, but when I applied it to another algorithm that uses a technical indicator, I encounter an error:
:: self.benchmarkValue = (currentBenchmarkPrice / self.initBenchmarkPrice) * self.initBenchmarkCash
ZeroDivisionError : float division by zero
It shouldn't be dividing by zero, so I'm not sure why the algorithm is doing this. I attached the algorithm I tried to apply the function on to this post; I had to comment out the self.plot in OnData in order to generate a backtest.
Thanks!
Vncne
I noticed that if I removed self.SetWarmUp in Initialize, it seems to work fine, but obviously SetWarmUp is going to be needed..
Frank Giardina
Vncne,
I copied this code from the thread from the In-Out strategy algo that some ex Quantopian folks created. It works well for me
in the Initalize place this
self.spy_chart = [] #use to hold the values for plotting
self.MRKT = self.AddEquity('SPY', Resolution.Daily).Symbol #this is the symbol we are using as the market
in the OnData place this
self.plot_market()
def plot_market(self): #plot the market on the Startegy Equity Chart with your portfolio
hist = self.History([self.MRKT] , 252, Resolution.Daily)['close'].unstack(level=0).dropna()
self.spy_chart.append(hist[self.MRKT].iloc[-1])
spy_perf = self.spy_chart[-1] / self.spy_chart[0] * self.cap
self.Plot("Strategy Equity", "SPY", spy_perf)
Vncne
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!