Overall Statistics
Total Trades
1
Average Win
0%
Average Loss
0%
Compounding Annual Return
-12.568%
Drawdown
28.900%
Expectancy
0
Net Profit
-2.254%
Sharpe Ratio
0.163
Probabilistic Sharpe Ratio
36.360%
Loss Rate
0%
Win Rate
0%
Profit-Loss Ratio
0
Alpha
-0.067
Beta
0.977
Annual Standard Deviation
0.695
Annual Variance
0.482
Information Ratio
-2.819
Tracking Error
0.025
Treynor Ratio
0.116
Total Fees
$1.00
from clr import AddReference
AddReference("System")
AddReference("QuantConnect.Algorithm")
AddReference("QuantConnect.Indicators")
AddReference("QuantConnect.Common")

from System import *
from QuantConnect import *
from QuantConnect.Algorithm import *
from QuantConnect.Indicators import *
from QuantConnect.Python import PythonQuandl
from QuantConnect.Securities.Equity import EquityExchange
from datetime import datetime, timedelta
import math

class Testing(QCAlgorithm):
    
    spy_bar = None

    def Initialize(self):
        self.SetStartDate(2020, 3, 1)  # Set Start Date
        self.SetEndDate(2020, 4, 30)  # Set Start Date
        self.SetCash(10000)  # Set Strategy Cash
        self.SetWarmup(timedelta(31))
        
        self.AddEquity("SPY", Resolution.Minute)
        #self.spy = self.Symbol("SPY")
        #self.df = self.History(self.Symbol("SPY"), 62, Resolution.Daily)
        self.Consolidate("SPY", CalendarType.Monthly, self.CalendarTradeBarHandler); 
        
        
        self.Securities["SPY"].SetDataNormalizationMode(DataNormalizationMode.Raw)
        
        
        #spy_month_bar = self.spy
        
        


    
    def CalendarTradeBarHandler(self, tradeBar):
        self.Log(f'{self.Time} :: {tradeBar.Time} {tradeBar.Close} {tradeBar.High} {tradeBar.Low}')
        
        self.spy_bar = tradeBar
        
        
        #self.spy_month_high = self.spy_last_bar.High
        #self.Log(self.spy_month_high)
        #example of above output
        #2020-04-01 00:00:00 :    2020-04-01 00:00:00 :: 2020-03-01 00:00:00 257.7
        #close = tradeBar.Close
        
        
    #def startOfMonth(self):
        #spy_month_bar = self.History(self.spy, 1, self.CalendarTradeBarHandler)
        #spy_month_bar = self.History(self.spy, 1, self.CalendarTradeBarHandler)
        #self.spy_month_high = spy_month_bar.High
        
        
        #self.Debug(str(self.spy_month_high))

    def OnData(self, data):
        '''OnData event is the primary entry point for your algorithm. Each new data point will be pumped in here.
            Arguments:
                data: Slice object keyed by symbol containing the stock data
        '''
        
        #spy_month_high = slice[self.spy].High
        #spy_month_bar = self.History(self.spy,1, tradeBar)
        if self.Portfolio.Invested or self.spy_bar is None:
            return
        

        if not self.Portfolio.Invested and self.spy_bar.High > data["SPY"].Close:
            self.SetHoldings("SPY", 1)
            self.Log(f'{self.Time} :: {self.spy_bar.Time} {self.spy_bar.Close} {self.spy_bar.High} {self.spy_bar.Low}')
        #spy_month_high = self.spy_month_high
        
        
        #self.Log(self.spy_month_high)
        #if close < 300:
            #self.MarketOrder("SPY",6)