Overall Statistics |
Total Trades 287 Average Win 2.30% Average Loss -1.18% Compounding Annual Return 5.378% Drawdown 24.900% Expectancy 0.136 Net Profit 23.321% Sharpe Ratio 0.38 Probabilistic Sharpe Ratio 6.566% Loss Rate 62% Win Rate 38% Profit-Loss Ratio 1.95 Alpha 0.026 Beta 0.171 Annual Standard Deviation 0.115 Annual Variance 0.013 Information Ratio -0.412 Tracking Error 0.144 Treynor Ratio 0.255 Total Fees $32675.02 Estimated Strategy Capacity $470000.00 Lowest Capacity Asset O R735QTJ8XC9X |
from InconsistentAlphaModel import InconsistentAlphaModelConfig from InconsistentAlphaModel import InconsistentAlphaModel RESOLUTION = Resolution.Minute STARTING_CASH = 1000000 AMT = Symbol.Create("AMT", SecurityType.Equity, Market.USA) CCI = Symbol.Create("CCI", SecurityType.Equity, Market.USA) EQIX = Symbol.Create("EQIX", SecurityType.Equity, Market.USA) DLR = Symbol.Create("DLR", SecurityType.Equity, Market.USA) O = Symbol.Create("O", SecurityType.Equity, Market.USA) O_InconsistentAlphaModelConfig = InconsistentAlphaModelConfig(O) class WeightedConstructionModel(PortfolioConstructionModel): def CreateTargets(self, algorithm, insights): targets = [] for insight in insights: targets.append(PortfolioTarget.Percent(algorithm, insight.Symbol, insight.Weight)) return targets class Fullblend(QCAlgorithm): def Initialize(self): self.SetBrokerageModel(BrokerageName.AlphaStreams) self.SetCash(STARTING_CASH) self.SetStartDate(2016, 1, 1) self.SetEndDate(2020, 1, 1) # entire tradable universe self.UniverseSettings.Resolution = RESOLUTION self.AddUniverseSelection(ManualUniverseSelectionModel([AMT, CCI, EQIX, DLR, O])) # set alpha models self.AddAlpha(InconsistentAlphaModel(self, O_InconsistentAlphaModelConfig)) # set portfolio weightings self.SetPortfolioConstruction(WeightedConstructionModel()) # set execution model self.SetExecution(ImmediateExecutionModel()) # set risk management model self.AddRiskManagement(NullRiskManagementModel())
import numpy as np class InconsistentAlphaModelConfig: def __init__(self, SYMBOL ): if not SYMBOL: raise ValueError("[{}] No symbol".format(self.__class__.__name__)) self.SYMBOL = SYMBOL class InconsistentAlphaModel(AlphaModel): def __init__(self, algorithm, CONFIG): self.algorithm = algorithm self.config = CONFIG self.symbol = CONFIG.SYMBOL self.symbol_roc = RateOfChange(20) self.weight = 1.0 self.Warmup( [self.symbol], 30, Resolution.Hour, [self.symbol_roc], ) def Warmup(self, symbols, lookback, resolution, indicators): history = self.algorithm.History(symbols, lookback, Resolution.Hour) for time, row in history["close"].unstack(level = 0).iterrows(): indicators[0].Update(time, row[symbols[0]]) def Update(self, algorithm, slice): insights = [] if algorithm.Time.minute == 0: if (self.symbol in algorithm.Securities): self.symbol_roc.Update(algorithm.Time, algorithm.Securities[self.symbol].Close) cutloss = algorithm.Securities[self.symbol].Holdings.UnrealizedProfitPercent < -0.05 if algorithm.Portfolio[self.symbol].Quantity != 0 and cutloss: insights.append(Insight.Price(self.symbol, timedelta(minutes = 300), InsightDirection.Flat, None, None, None, 0.00)) if algorithm.Time.hour == 10: if (self.symbol_roc.Current.Value > 0): if algorithm.Portfolio[self.symbol].Quantity == 0: insights.append(Insight.Price(self.symbol, timedelta(minutes = 300), InsightDirection.Up, None, None, None, self.weight)) elif algorithm.Portfolio[self.symbol].Quantity != 0: insights.append(Insight.Price(self.symbol, timedelta(minutes = 300), InsightDirection.Flat, None, None, None, 0.00)) return Insight.Group(insights)