Overall Statistics
Total Trades
15
Average Win
0.92%
Average Loss
-0.24%
Compounding Annual Return
50.005%
Drawdown
0.900%
Expectancy
1.722
Net Profit
3.965%
Sharpe Ratio
6.51
Probabilistic Sharpe Ratio
98.178%
Loss Rate
43%
Win Rate
57%
Profit-Loss Ratio
3.76
Alpha
0.182
Beta
0.547
Annual Standard Deviation
0.046
Annual Variance
0.002
Information Ratio
1.999
Tracking Error
0.042
Treynor Ratio
0.548
Total Fees
$25.39
Estimated Strategy Capacity
$500000000.00
Lowest Capacity Asset
SPY R735QTJ8XC9X
# region imports
from AlgorithmImports import *
# endregion

class QuantumVerticalProcessor(QCAlgorithm):

    chart = None
    series = None

    def Initialize(self):
        self.SetStartDate(2019, 11, 8) # Set Start Date
        self.SetEndDate(2019,12,12)
        self.SetCash(100000) # Set Strategy Cash
        self.AddEquity("SPY", Resolution.Daily)

        self.candles = Series('Second', SeriesType.Candle)
        self.chart = Chart('Candles')
        self.chart.AddSeries(self.candles)
        
        self.enter = self.Time.day
       
        self.chart.AddSeries(Series('Longs', SeriesType.Scatter, "", Color.Green, ScatterMarkerSymbol.Triangle))
        self.AddChart(self.chart)
        #sec_Consolidator = TradeBarConsolidator(timedelta(seconds=45))
        #sec_Consolidator.DataConsolidated += self.Sec_BarHandler
        #self.SubscriptionManager.AddConsolidator("SPY", sec_Consolidator)

    def OnData(self, data):
        if not data.ContainsKey("SPY"): return
        tradeBar = data["SPY"]
        self.candles.AddPoint(tradeBar.EndTime - timedelta(minutes=59), tradeBar.Open)
        self.candles.AddPoint(tradeBar.EndTime - timedelta(minutes=58), tradeBar.High)
        self.candles.AddPoint(tradeBar.EndTime - timedelta(minutes=57), tradeBar.Low)
        self.candles.AddPoint(tradeBar.EndTime, tradeBar.Close)

        if not self.Portfolio.Invested:
            self.SetHoldings("SPY", 1)
            self.Plot( 'Candles', 'Longs', self.Securities["SPY"].Price - 10)
            self.enter = self.Time.day
        if self.Portfolio.Invested and self.Time.day > self.enter + 2:
            self.SetHoldings("SPY", 0)
    '''        
    def Sec_BarHandler(self, sender, consolidated):
        time = self.UtcTime
        
        # NOTE: order is important and each point has to be one minute apart because reasons.
        self.candles.AddPoint(time + timedelta(seconds=1), consolidated.Open)
        self.candles.AddPoint(time + timedelta(seconds=2), consolidated.High)
        self.candles.AddPoint(time + timedelta(seconds=3), consolidated.Low)
        self.candles.AddPoint(time + timedelta(seconds=4), consolidated.Close)
        #self.Debug(f"{consolidated.EndTime} >> Open >> {consolidated.EndTime - timedelta(seconds=1)}")
        self.Debug("OnDataConsolidated time: " + str(time))
    '''