Hi Guys,

Just sharing a little function to plot the Benchmark curve along with the Strate Equity. See template code attached.

Essentially, when you add a benchmark using

self.SetBenchmark()

, you can retrieve its price during the backtest usingĀ 

self.Benchmark.Evaluate(self.Time)

The function I wrote is just:

def UpdateBenchmarkValue(self): ''' Simulate buy and hold the Benchmark ''' if self.initBenchmarkPrice is None: self.initBenchmarkCash = self.Portfolio.Cash self.initBenchmarkPrice = self.Benchmark.Evaluate(self.Time) self.benchmarkValue = self.initBenchmarkCash else: currentBenchmarkPrice = self.Benchmark.Evaluate(self.Time) self.benchmarkValue = (currentBenchmarkPrice / self.initBenchmarkPrice) * self.initBenchmarkCash

Enjoy!

Emilio

InnoQuantivity.com