Overall Statistics
Total Trades
49
Average Win
0.08%
Average Loss
0%
Compounding Annual Return
54.309%
Drawdown
3.600%
Expectancy
0
Net Profit
20.800%
Sharpe Ratio
3.085
Probabilistic Sharpe Ratio
88.447%
Loss Rate
0%
Win Rate
100%
Profit-Loss Ratio
0
Alpha
0.528
Beta
-0.082
Annual Standard Deviation
0.143
Annual Variance
0.02
Information Ratio
-1.808
Tracking Error
0.341
Treynor Ratio
-5.381
Total Fees
$49.05
class GetCurrentPositions(QCAlgorithm):

    def Initialize(self):
        self.SetStartDate(2019, 2, 19)  # Set Start Date
        self.SetStartDate(2020, 3, 19)  # Set Start Date
        self.SetCash(100000)  # Set Strategy Cash
        self.SPYSecurity = self.AddEquity("SPY", Resolution.Daily)
        
        self.isFirst = True
        self.Schedule.On(self.DateRules.EveryDay(self.SPYSecurity.Symbol)
                         , self.TimeRules.AfterMarketOpen(self.SPYSecurity.Symbol, 1)
                         , self.__TestCB)
        self.month = None


    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
        '''
        if self.isFirst:
            self.SetHoldings(self.SPYSecurity.Symbol, 0.5);
            self.isFirst = False
            
        num_holdings = len(self.Portfolio)
        if num_holdings != 0:
        
            for symbol, securityHolding in self.Portfolio.items():
                self.SetHoldings(symbol, .5 / num_holdings)
                # securityEquity = securityHolding.AveragePrice * securityHolding.Quantity
                # securityEquity = securityHolding.AveragePrice * securityHolding.Quantity + securityHolding.TotalCloseProfit()
                # self.Log("symbol: {} ratio: {}".format(symbol, securityEquity / self.Portfolio.TotalPortfolioValue))

        # if not self.Portfolio.Invested:
        #    self.SetHoldings("SPY", 1)
        
    def __TestCB(self):
        if not self.month == self.Time.month:
            self.month = self.Time.month
            self.SetHoldings(self.SPYSecurity.Symbol, 0.5);
            self.Log("After rebalance")