Overall Statistics
Total Trades
27
Average Win
0.52%
Average Loss
-0.98%
Compounding Annual Return
10.306%
Drawdown
3.200%
Expectancy
0.062
Net Profit
1.108%
Sharpe Ratio
1.033
Probabilistic Sharpe Ratio
49.856%
Loss Rate
31%
Win Rate
69%
Profit-Loss Ratio
0.53
Alpha
0.053
Beta
-0.192
Annual Standard Deviation
0.086
Annual Variance
0.007
Information Ratio
1.246
Tracking Error
0.221
Treynor Ratio
-0.463
Total Fees
$39.48
from dateutil import parser
import pickle

class statusObj:
      def __init__(self):
        self.invested = False
        self.positionDay = '2020-01-01'

class ResistanceUncoupledThrustAssembly(QCAlgorithm):

    def Initialize(self):
        self.SetStartDate(2020, 8, 13)  # Set Start Date
        self.SetCash(100000)  # Set Strategy Cash
        self.spy = self.AddEquity('SPY', Resolution.Daily).Symbol
        if self.ObjectStore.ContainsKey("MyObject"):
            #self.ObjectStore.Delete("MyObject")
            #initialization check
            self.Log('initializing: stored object detected!')
            deserialized=bytes(self.ObjectStore.ReadBytes("MyObject"))
            storedStatus=pickle.loads(deserialized)
            self.Log('stored day in stored object: '+str(storedStatus.positionDay))
            
        self.status=statusObj()
        
    def OnData(self, data):
        if not self.Portfolio.Invested:
            self.SetHoldings(self.spy, 1)
            self.status.invested=True
            self.status.positionDay=str(self.Time.day)
            self.Log('position day in status object: '+str(self.status.positionDay))
            serialized=pickle.dumps(self.status)
            self.ObjectStore.SaveBytes("MyObject", serialized)
            #after save check
            deserialized=bytes(self.ObjectStore.ReadBytes("MyObject"))
            storedStatus=pickle.loads(deserialized)
            self.Log('position day in stored object: '+str(storedStatus.positionDay))
            
        else:
            if self.ObjectStore.ContainsKey("MyObject"):
                deserialized = bytes(self.ObjectStore.ReadBytes("MyObject"))
                storedStatus = (pickle.loads(deserialized))
                #additional check
                self.Log('position day in stored object: '+str(storedStatus.positionDay))
                #date = parser.parse(storedStatus.positionDay)
                self.Liquidate(self.spy)
                self.status.invested=False
                self.status.positionDay = '2020-01-01'