Overall Statistics |
Total Trades 283 Average Win 2.28% Average Loss -1.20% Compounding Annual Return 5.045% Drawdown 25.900% Expectancy 0.127 Net Profit 21.770% Sharpe Ratio 0.363 Probabilistic Sharpe Ratio 6.047% Loss Rate 61% Win Rate 39% Profit-Loss Ratio 1.89 Alpha 0.025 Beta 0.16 Annual Standard Deviation 0.114 Annual Variance 0.013 Information Ratio -0.428 Tracking Error 0.144 Treynor Ratio 0.258 Total Fees $31796.87 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([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)