Overall Statistics |
Total Orders 33088 Average Win 0.05% Average Loss -0.05% Compounding Annual Return -26.401% Drawdown 75.300% Expectancy -0.157 Start Equity 10000000 End Equity 2716933.56 Net Profit -72.831% Sharpe Ratio -1.262 Sortino Ratio -1.511 Probabilistic Sharpe Ratio 0.000% Loss Rate 56% Win Rate 44% Profit-Loss Ratio 0.93 Alpha -0.185 Beta -0.493 Annual Standard Deviation 0.168 Annual Variance 0.028 Information Ratio -1.047 Tracking Error 0.256 Treynor Ratio 0.431 Total Fees $430142.57 Estimated Strategy Capacity $0 Lowest Capacity Asset FDEF R735QTJ8XC9X Portfolio Turnover 10.73% |
# region imports from AlgorithmImports import * # endregion class GeekyAsparagusViper(QCAlgorithm): def initialize(self): self.set_start_date(2021, 1, 1) self.set_end_date(2025, 4, 1) self.set_cash(10_000_000) # Add a universe of the 100 smallest assets in IWM. etf = Symbol.create('IWM', SecurityType.EQUITY, Market.USA) date_rule = self.date_rules.week_start(etf, 1) self.universe_settings.schedule.on(date_rule) self._week = 0 self._universe = self.add_universe(self.universe.etf(etf, universe_filter_func=self._select_assets)) # Rebalance the portfolio every 2 weeks. self.schedule.on(date_rule, self.time_rules.after_market_open(etf, 1), self._rebalance) def _select_assets(self, constituents): # Only update the universe every 2 weeks. week = self.time.isocalendar()[1] if abs(week - self._week) < 2: return [] self._week = week # Select the 100 smallest constituents. symbols = [c.symbol for c in constituents] # Calculate factors for all the assets. history = self.history(symbols, timedelta(1), Resolution.MINUTE) factors = pd.DataFrame(columns=['price_volatility', 'volume_volatility', 'vwap_deviation'], index=symbols) for symbol in symbols: if symbol not in history.index: continue df = history.loc[symbol][['close', 'volume']] df['vwap'] = self.indicator_history(IntradayVwap(''), symbol, timedelta(1)).data_frame.current.reindex(df.index).ffill() factors.loc[symbol] = [ -df.close.std() / df.close.mean(), # price_volatility df.volume.std() / df.volume.mean(), # volume_volatility -np.mean(np.abs(df.close - df.vwap)) / df.vwap.mean() # vwap_deviation ] factors.dropna(inplace=True) # Split assets into long/short groups based on factor values. sorted_by_factors = list(factors.rank().sum(axis=1).sort_values().index) assets_per_side = int(len(sorted_by_factors)/2) self._longs = sorted_by_factors[-100:] self._shorts = sorted_by_factors[:100] return self._longs + self._shorts def _rebalance(self): if not self._longs: return self.set_holdings([PortfolioTarget(s, 0.5/len(self._longs)) for s in self._longs] + [PortfolioTarget(s, -0.5/len(self._shorts)) for s in self._shorts], True) self._longs = []