Overall Statistics
Total Trades
1
Average Win
0%
Average Loss
0%
Compounding Annual Return
13.234%
Drawdown
33.700%
Expectancy
0
Net Profit
116.466%
Sharpe Ratio
0.831
Probabilistic Sharpe Ratio
29.072%
Loss Rate
0%
Win Rate
0%
Profit-Loss Ratio
0
Alpha
0.18
Beta
-0.185
Annual Standard Deviation
0.183
Annual Variance
0.033
Information Ratio
0.002
Tracking Error
0.281
Treynor Ratio
-0.819
Total Fees
$2.73
Estimated Strategy Capacity
$380000000.00
from io import StringIO
import pandas as pd
from datetime import datetime


class PensiveTanAnguilline(QCAlgorithm):

    key = "test_v1.0.10"
    string_object = ""

    def Initialize(self):
        self.SetStartDate(2015,1,1)
        
        self.tvp = f'{self.UtcTime.date()},{self.Portfolio.TotalPortfolioValue}'
        self.benchmark = {}
        
        self.spy = self.AddEquity("SPY", Resolution.Daily).Symbol 
        
        reset = False
        if reset and self.ObjectStore.ContainsKey(self.key):
            self.ObjectStore.Delete(self.key)

        # ObjectStore for custom Benchmark
        if self.ObjectStore.ContainsKey(self.key):
            values = self.ObjectStore.Read(self.key)
            for row in values.split('\n'):
                info = row.split(',')
                self.benchmark[info[0]] = float(info[1])

            def customBenchmark(time):
                return self.benchmark.get(f'{time:%Y-%m-%d}', 0)
                
            self.SetBenchmark(customBenchmark)

    def OnEndOfDay(self, symbol):
        if symbol == self.spy:
            time = self.UtcTime + timedelta(1)
            self.tvp += f'\n{time:%Y-%m-%d},{self.Portfolio.TotalPortfolioValue}'

    def OnEndOfAlgorithm(self):
        self.ObjectStore.Save(self.key, self.tvp)            

    def OnData(self, data):
        if not self.Portfolio.Invested:
            self.SetHoldings(self.spy, 1)