| Overall Statistics |
|
Total Orders 1534 Average Win 0.52% Average Loss -0.59% Compounding Annual Return 21.513% Drawdown 47.000% Expectancy 0.623 Start Equity 100000 End Equity 2437005.29 Net Profit 2337.005% Sharpe Ratio 0.765 Sortino Ratio 0.835 Probabilistic Sharpe Ratio 17.366% Loss Rate 14% Win Rate 86% Profit-Loss Ratio 0.88 Alpha 0 Beta 0 Annual Standard Deviation 0.189 Annual Variance 0.036 Information Ratio 0.871 Tracking Error 0.189 Treynor Ratio 0 Total Fees $2383.28 Estimated Strategy Capacity $45000000.00 Lowest Capacity Asset WMT R735QTJ8XC9X Portfolio Turnover 0.48% Drawdown Recovery 751 |
from AlgorithmImports import *
ETF_TICKER = "QQQ"
UNIVERSE_SIZE = 10
class TopWeightedAlgorithm(QCAlgorithm):
def initialize(self):
self.set_start_date(2010, 1, 1)
self.universe_settings.leverage = 1.0
self.universe_settings.resolution = Resolution.MINUTE
self.set_brokerage_model(BrokerageName.INTERACTIVE_BROKERS_BROKERAGE, AccountType.MARGIN)
self._universe = self.universe.etf(ETF_TICKER, self.universe_settings, self._etf_constituents_filter)
self.add_universe(self._universe)
etf_symbol = self.add_security(ETF_TICKER).symbol
self.schedule.on(self.date_rules.month_end(etf_symbol),
self.time_rules.before_market_close(etf_symbol, 30),
self._rebalance)
self.set_benchmark(ETF_TICKER)
def _etf_constituents_filter(self, constituents: List[ETFConstituentUniverse]) -> List[Symbol]:
selected = sorted(constituents, key=lambda c: c.weight or 0.0, reverse=True)[:UNIVERSE_SIZE]
return [c.symbol for c in selected]
def _rebalance(self):
self.set_holdings(
[PortfolioTarget(symbol, 1 / len(self._universe.selected)) for symbol in self._universe.selected],
liquidate_existing_holdings=True)