Overall Statistics
Total Trades
0
Average Win
0%
Average Loss
0%
Compounding Annual Return
0%
Drawdown
0%
Expectancy
0
Net Profit
0%
Sharpe Ratio
0
Probabilistic Sharpe Ratio
0%
Loss Rate
0%
Win Rate
0%
Profit-Loss Ratio
0
Alpha
0
Beta
0
Annual Standard Deviation
0
Annual Variance
0
Information Ratio
-3.593
Tracking Error
0.242
Treynor Ratio
0
Total Fees
$0.00
Estimated Strategy Capacity
$0
Lowest Capacity Asset
# region imports
from AlgorithmImports import *
# endregion

class LongShortAlgo(QCAlgorithm):
    NUM_DAYS = 12
    START_YEAR = 2022
    START_MONTH = 10
    START_DAY = 3
    END_YEAR = 2022
    END_MONTH = 10
    END_DAY = 30

    def _BuildHistory(self, sym):
        # get the history for the time period.  Remember if we print this,
        # it will be off by 1 day as the time is the END of the period (so actual
        # day is 1 before date printed with it)
        try:
            historyDF = self.History([sym], self.NUM_DAYS+1, Resolution.Daily)
        except:
            self.Debug('Failed to load history for '+sym)
            return
        
        try:
            equityHistory = historyDF.loc[sym]
        except:
            self.Debug('No history located for '+sym)
            return

        try:
            openPrices = equityHistory['open']
        except:
            self.Debug('Failed to get open/close history for '+sym)
            return

        # calculate last N days of change
        self.Log(openPrices)
        self.Log(str(self.Time) +' '+str(self.Securities[sym]))
        self.Log(str(self.Time) +' '+'open: '+str(self.Securities[sym].Open))
        self.Log(str(self.Time) +' '+'price now: '+str(self.Securities[sym].Price))

    
    def _PrintPrice(self):
        self.Log(str(self.Time) +' '+'print price')
        self.Log(str(self.Time) +' '+'spy open is : '+str(self.Securities['SPY'].Open))

    def _Initialize(self):
        self.AddEquity("SPY", Resolution.Minute)
        self._BuildHistory('SPY')
        if self.Securities['SPY'].Open < 0.001:
            self.Schedule.On(self.DateRules.EveryDay(), self.TimeRules.AfterMarketOpen('SPY', 0), self._PrintPrice)
        else:
            self.Log(str(self.Time) +' '+'spy price: '+str(self.Securites['SPY'].Open))
        return

    def Initialize(self):
        if not self.LiveMode:
            self.SetStartDate(self.START_YEAR, self.START_MONTH, self.START_DAY)  # Set Start Date
            self.SetEndDate(self.END_YEAR, self.END_MONTH, self.END_DAY)
        
            self.SetCash(1000000)  # Set Strategy Cash
            self.SetWarmup(timedelta(self.NUM_DAYS))
        else:
            self.SetWarmup(1)
    
    def OnWarmupFinished(self):
        self.Debug(str(self.Time)+ ': Warmup finished')
        self._Initialize()

    def OnData(self, data: Slice):
        return