Overall Statistics
Total Trades
342
Average Win
0.11%
Average Loss
-0.09%
Compounding Annual Return
1.748%
Drawdown
0.600%
Expectancy
0.154
Net Profit
3.497%
Sharpe Ratio
1.514
Probabilistic Sharpe Ratio
82.449%
Loss Rate
49%
Win Rate
51%
Profit-Loss Ratio
1.28
Alpha
0.014
Beta
0.003
Annual Standard Deviation
0.009
Annual Variance
0
Information Ratio
-0.57
Tracking Error
0.135
Treynor Ratio
4.254
Total Fees
$353.25
#from Execution.VolumeWeightedAveragePriceExecutionModel import VolumeWeightedAveragePriceExecutionModel

import numpy as np

class MultidimensionalModulatedRegulators(QCAlgorithm):

    def Initialize(self):
        self.SetStartDate(2018, 1, 16)  # Set Start Date
        self.SetCash(100000)  # Set Strategy Cash
        #self.SetExecution(VolumeWeightedAveragePriceExecutionModel())

        self.symbols = [Symbol.Create("USO", SecurityType.Equity, Market.USA),
        Symbol.Create("SCO", SecurityType.Equity, Market.USA),
        Symbol.Create("ERX", SecurityType.Equity, Market.USA),
        Symbol.Create("SHV", SecurityType.Equity, Market.USA),
        Symbol.Create("SHY", SecurityType.Equity, Market.USA),
        Symbol.Create("VGT", SecurityType.Equity, Market.USA),
        Symbol.Create("OIH", SecurityType.Equity, Market.USA),
        Symbol.Create("XLB", SecurityType.Equity, Market.USA),
        Symbol.Create("GDX", SecurityType.Equity, Market.USA),
        Symbol.Create("XLY", SecurityType.Equity, Market.USA),
        Symbol.Create("SLV", SecurityType.Equity, Market.USA),
        Symbol.Create("XLF", SecurityType.Equity, Market.USA),
        Symbol.Create("SMH", SecurityType.Equity, Market.USA),
        Symbol.Create("XLI", SecurityType.Equity, Market.USA),
        Symbol.Create("XLU", SecurityType.Equity, Market.USA),
        Symbol.Create("XLV", SecurityType.Equity, Market.USA),
        Symbol.Create("GLD", SecurityType.Equity, Market.USA),
        Symbol.Create("QQQ", SecurityType.Equity, Market.USA),
        Symbol.Create("IEI", SecurityType.Equity, Market.USA),
        Symbol.Create("XLE", SecurityType.Equity, Market.USA),
        Symbol.Create("VDE", SecurityType.Equity, Market.USA)]
        
        self.SetUniverseSelection( ManualUniverseSelectionModel(self.symbols) )
        
        
        self.UniverseSettings.Resolution = Resolution.Minute
        
    # Schedule the rebalance function to execute at the begining of each month
    #    self.Schedule.On(self.DateRules.MonthStart(self.spy), 
    #    self.TimeRules.BeforeMarketClose(self.spy, 30), Action(self.rebalance))
        

    def OnData(self, data):
        '''def rebalance(self):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
        '''
        
        self.constant_weights = [-0.255348, -0.131087, -0.101415, -0.054271, -0.026654, -0.014632, -0.010338, -0.006401, -0.003293,
        -0.002393, -0.002374, -0.001465, 0.001768, 0.006987, 0.007043, 0.008843, 0.011171, 0.016230, 0.039692, 0.134397, 0.164197]
        
        self.rebalance = False
        
        if self.Portfolio.TotalHoldingsValue > 0:
            total = 0.0
            for i, sym in enumerate(self.symbols):
                curr = (self.Securities[sym].Holdings.HoldingsValue/self.Portfolio.TotalHoldingsValue)
                total += np.abs(self.constant_weights[i] - curr)
            if total > 0.05: 
                self.Debug(total)
                self.rebalance = True

        if self.rebalance:
            for i, sym in enumerate(self.symbols):                
                oq = self.CalculateOrderQuantity(sym, self.constant_weights[i])
                lp = self.Securities[sym].AskPrice
                if oq > 0: lp = self.Securities[sym].BidPrice
                if oq != 0: self.LimitOrder(sym, oq, lp)

        if not self.Portfolio.Invested:
            for i, sym in enumerate(self.symbols):
                self.SetHoldings(sym, self.constant_weights[i])