Overall Statistics |
Total Orders 0 Average Win 0% Average Loss 0% Compounding Annual Return 0% Drawdown 0% Expectancy 0 Start Equity 100000 End Equity 100000 Net Profit 0% Sharpe Ratio 0 Sortino Ratio 0 Probabilistic Sharpe Ratio 0% Loss Rate 0% Win Rate 0% Profit-Loss Ratio 0 Alpha 0 Beta 0 Annual Standard Deviation 0 Annual Variance 0 Information Ratio 0 Tracking Error 0 Treynor Ratio 0 Total Fees $0.00 Estimated Strategy Capacity $0 Lowest Capacity Asset Portfolio Turnover 0% |
# region imports from AlgorithmImports import * # endregion class UglyBlackDog(QCAlgorithm): def initialize(self): self.spy = self.add_equity("SPY", Resolution.DAILY).symbol #1 Warming up indicators with history data self.sma = self.SMA(self.spy, 30, Resolution.DAILY) history = self.History(self.spy, 30, Resolution.DAILY) if self.spy in history.index: closing_prices = history.loc[self.spy]["close"] for time, price in closing_prices.iteritems(): self.sma.update(time, price) else: self.Debug(f"No historical data available for {self.spy}") #2 Making sure your algorithm deploys immediately self.rebalance_period = 30 # Rebalance monthly self.next_rebalance = self.Time + timedelta(days = self.rebalance_period) # This will start your algorithm a month after deployment self.next_rebalance = self.Time # This will start your algorithm immediately #3 Use dummy algorithms to your advantage self.bnd = self.add_equity("BND", Resolution.DAILY).symbol #4 Expand the universe or lower the trading criteria self.tickers = ['AAPL', 'MSFT', 'GOOGL', 'AMZN', 'NVDA', 'META', 'TSLA', 'JNJ', 'JPM', 'V'] self.symbols = [] for ticker in self.tickers: self.symbols.append(self.AddEquity(ticker, Resolution.Daily).Symbol) # This is a tiny, manual universe self.add_universe_selection(EmaCrossUniverseSelectionModel()) # This is a larger, dynamic universe self.add_universe_selection(FundamentalUniverseSelectionModel()) def on_data(self, data: Slice): #2 Rebalance Monthly if self.Time < self.next_rebalance: return # Rebalance the portfolio # Update the next rebalance time self.next_rebalance = self.Time + timedelta(days = self.rebalance_period) #3 Invest the cash while you are finalizing your algorithm # Deploy a dummy algorithm and then update it once you are finalized self.set_holdings(self.bnd, 1) #4 Some very specific trading requirement will leave your algorithm idle for a large portion of the competition for symbol in self.symbols: pass