Overall Statistics
Total Trades
15372
Average Win
0.01%
Average Loss
0.00%
Compounding Annual Return
16.590%
Drawdown
19.100%
Expectancy
2.885
Net Profit
123.878%
Sharpe Ratio
1.116
Probabilistic Sharpe Ratio
54.159%
Loss Rate
36%
Win Rate
64%
Profit-Loss Ratio
5.11
Alpha
0.173
Beta
-0.116
Annual Standard Deviation
0.129
Annual Variance
0.017
Information Ratio
-0.415
Tracking Error
0.254
Treynor Ratio
-1.239
Total Fees
$15464.08
Estimated Strategy Capacity
$0
Lowest Capacity Asset
LINTA TIIB7Z82AFS5
# Creating our own Index Fund
# https://www.quantconnect.com/forum/discussion/12347/creating-our-own-index-fund

# ----------------------
ETF = "QQQ"; LEV = 1.00;
# ----------------------

class IndexInvesting(QCAlgorithm):

    def Initialize(self):
        self.SetStartDate(2016, 6, 24)  
        self.InitCash = 1000000
        self.SetCash(self.InitCash)
        self.SetBenchmark(ETF)
        self.initBenchmarkPrice = None
        self.UniverseSettings.Resolution = Resolution.Daily
        self.etf = self.AddEquity(ETF, Resolution.Hour).Symbol
        self.AddUniverse(self.Universe.ETF(self.etf, self.UniverseSettings, self.ETFConstituentsFilter))
        self.Settings.FreePortfolioValuePercentage = 0.50   #example 50%        
        self.weights = {}
        self.Schedule.On(self.DateRules.WeekStart(self.etf), self.TimeRules.AfterMarketOpen(self.etf, 31),
            self.Rebalance)
            
    
    def ETFConstituentsFilter(self, constituents):
        self.weights = {c.Symbol: c.Weight for c in constituents}
        return list(self.weights.keys())
                
    
    def OnSecuritiesChanged(self, changes):
        for security in changes.RemovedSecurities:
            if security.Invested:
                self.Liquidate(security.Symbol, 'No longer in universe')
                if security.Symbol in self.weights.keys(): del self.weights[security.Symbol]
        
    
    def Rebalance(self):
        for symbol, weight in self.weights.items():
            if symbol in self.ActiveSecurities:
                if weight is not None:
                    self.SetHoldings(symbol, weight)  # Market cap weighted
                    # self.SetHoldings(symbol, LEV / len(self.weights))  # Equally weighted   
                    
                    
    def UpdateBenchmarkValue(self):
        if self.initBenchmarkPrice is None:
            self.initBenchmarkCash = self.InitCash
            self.initBenchmarkPrice = self.Benchmark.Evaluate(self.Time)
            self.benchmarkValue = self.initBenchmarkCash
        else:
            currentBenchmarkPrice = self.Benchmark.Evaluate(self.Time)
            self.benchmarkValue = (currentBenchmarkPrice / self.initBenchmarkPrice) * self.initBenchmarkCash 
            
            
    def OnEndOfDay(self): 
        self.UpdateBenchmarkValue()
        self.Plot('Strategy Equity', ETF, self.benchmarkValue)