Overall Statistics
Total Trades
1
Average Win
0%
Average Loss
0%
Compounding Annual Return
1.980%
Drawdown
3.500%
Expectancy
0
Net Profit
0.167%
Sharpe Ratio
0.213
Probabilistic Sharpe Ratio
40.264%
Loss Rate
0%
Win Rate
0%
Profit-Loss Ratio
0
Alpha
0.02
Beta
0.826
Annual Standard Deviation
0.099
Annual Variance
0.01
Information Ratio
0.415
Tracking Error
0.047
Treynor Ratio
0.026
Total Fees
$15.41
Estimated Strategy Capacity
$120000000.00
Lowest Capacity Asset
SPY R735QTJ8XC9X
from QuantConnect.Data.Custom.CBOE import CBOE
from QuantConnect.Data.Custom.Fred import *

class RSIAlgorithm(QCAlgorithm):

    def Initialize(self):
        
        self.SetStartDate(2020, 1, 1)
        self.SetEndDate(2020, 2, 1)
        self.SetCash(1000000)
        
        self.SetBrokerageModel(BrokerageName.AlphaStreams)

        self.buffer = 0.02
        self.Settings.FreePortfolioValuePercentage = self.buffer

        self.vix   = self.AddData(CBOE, 'VIX', Resolution.Daily).Symbol

        self.symbolData = {}
        for ticker in ['SPY']:
            symbol = self.AddEquity("SPY").Symbol
            self.symbolData[symbol] = SymbolData(self, symbol)

        self.SetWarmUp(100)


    def OnData(self, data):
        if self.IsWarmingUp or self.vix not in data:
            return
        
        self.Log(f'Time: {self.Time}')
        
        count = len(self.symbolData)

        for symbol, symbolDatum in self.symbolData.items():
            symbolDatum.consolidator.Scan(self.Time)
        
            if not self.Portfolio[symbol].Invested:
                if symbolDatum.Close > symbolDatum.SMA.Current.Value:
                    self.SetHoldings(symbol, 1/count)
                    
            self.Log(f'Value Close: {symbolDatum.Close}')
            self.Log(f'Value SMA: {symbolDatum.SMA.Current.Value}')
            self.Log("-------------------")
            

class SymbolData:
    def __init__(self, algorithm, symbol):
        self.algorithm = algorithm
        self.SMA  = SimpleMovingAverage(30)
        self.Close = 0

        self.consolidator = TradeBarConsolidator(timedelta(1))
        self.consolidator.DataConsolidated += self.ValueDailyBarHandler
        algorithm.RegisterIndicator(symbol, self.SMA, self.consolidator)

    def ValueDailyBarHandler(self, sender, bar):
        self.algorithm.Debug(f'New Bar: {bar.Close} @ {self.algorithm.Time}')
        
        # Saving new bar to variable:
        self.Close = bar.Close