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 Initialize(self):
        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.SetSecurityInitializer(BrokerageModelSecurityInitializer(self.BrokerageModel, FuncSecuritySeeder(self.GetLastKnownPrices)))
        self.AddEquity("SPY", Resolution.Minute)
        self._BuildHistory('SPY')
        self.Schedule.On(self.DateRules.EveryDay("SPY"), self.TimeRules.AfterMarketOpen('SPY', 1), self._PrintPrice)

    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("_BuildHistory" + 'Failed to load history for '+sym)
            return
        
        try:
            equityHistory = historyDF.loc[sym]
        except:
            self.Debug("_BuildHistory" + 'No history located for '+sym)
            return

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

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

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