How to plot Benchmark in Strategy Equity to compare the charts?
Moreover, can it be done without code change?
Maybe I can do something like
self.Plot('Strategy Equity', 'Benchmark', data.X)
But I can't find how to get Benchmark value or accumulated SPY in data slice. Thanks!
Rahul Chowdhury
Hey Shih,
Unfortunately, it's not currently possible to plot on the strategy equity graph. However you can using self.Plot to create a chart with both the benchmark and portfolio values.
Since we want to measure performance rather than absolute value. We need to scale our benchmark to the inital value of our portfolio. Then we can track our benchmark by calculating its daily performance, computing today's value and plotting it.
To plot our strategy equity, we can just plot our total portfolio value.
Here's an example with a buy and hold strategy.
Robert A
Hi,
Now QC interface looks different and that example does not work. It looks different in Lab than in that Discussion Forum.
How to plot benchmark on strategy equity chart?
Robert
Jared Broad
Hey Robert, sorry about the delay. To plot on the Strategy Equity plot you just need to use the chart name:
self.Plot("Strategy Equity", "MyBenchmark", myValue)
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.
Marcelo Eden
I have created a simple method to get that:
benchmarkShares = None initCash = 10000 # whatever is your init cash def getBenchmarkPerformance(self): price = self.Securities["SPY"].Close # if not self.benchmarkShares: self.benchmarkShares = self.initCash / price return self.benchmarkShares * price # You can plot it like this def OnData(self, data): self.Plot("Compare", "Benchmark", self.getBenchmarkPerformance()) self.Plot("Compare", "Portfolio", self.Portfolio.TotalPortfolioValue) ...
Vladimir
Here is my way to plot performance comparison strategy with a benchmark.
Dan Partington
Thanks Vladimir, I just used this in my project and it worked great!
Vladimir
A cleaner version
Ethereal
Thanks a lot Vladimir - incredibly helpful!
Shih Devin
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!