Overall Statistics |
Total Trades 788 Average Win 0.20% Average Loss -0.19% Compounding Annual Return 13.147% Drawdown 11.300% Expectancy 0.122 Net Profit 13.147% Sharpe Ratio 0.83 Probabilistic Sharpe Ratio 40.548% Loss Rate 45% Win Rate 55% Profit-Loss Ratio 1.04 Alpha 0.123 Beta -0.028 Annual Standard Deviation 0.143 Annual Variance 0.02 Information Ratio -0.088 Tracking Error 0.221 Treynor Ratio -4.301 Total Fees $2626.68 |
from QuantConnect.Data.UniverseSelection import * from Selection.FundamentalUniverseSelectionModel import FundamentalUniverseSelectionModel class DynamicNadionCircuit(QCAlgorithm): def Initialize(self): self.SetStartDate(2010, 1, 1) # Set Start Date self.SetEndDate(2011, 1, 1) # Set Start Date self.SetCash(100000) # Set Strategy Cash self.UniverseSettings.Resolution = Resolution.Daily self.SetUniverseSelection(MyUniverseSelectionModel()) self.SetAlpha(MaAlpha()) self.SetPortfolioConstruction(EqualWeightingPortfolioConstructionModel()) self.SetExecution(ImmediateExecutionModel()) self.SetRiskManagement(NullRiskManagementModel()) class MyPortfolioConstructionModel(PortfolioConstructionModel): # Create list of PortfolioTarget objects from Insights def CreateTargets(self, algorithm, insights): targets = list() for symbol in algorithm.ActiveSecurities.Keys: target = PortfolioTarget.Percent(algorithm, symbol, 0.1) targets.append(target) return targets # OPTIONAL: Security change details def OnSecuritiesChanged(self, algorithm, changes): # Security additions and removals are pushed here. # This can be used for setting up algorithm state. # changes.AddedSecurities: # changes.RemovedSecurities: pass class MaAlpha(AlphaModel): def __init__(self): self.ma = [] def OnSecuritiesChanged(self, algorithm, changes): # 1. Initialize a 14-day momentum indicator for each symbol for security in changes.AddedSecurities: symbol = security.Symbol self.ma.append({"symbol": symbol, "indicator": algorithm.EMA(symbol, 100, Resolution.Daily), "close": security.Close}) pass def Update(self, algorithm, data): priceUnderEMA = [] for maItem in self.ma : if maItem["indicator"].Current.Value > maItem["close"] : priceUnderEMA.append(Insight.Price(maItem["symbol"], timedelta(1), InsightDirection.Up)) insightsGroup = Insight.Group(priceUnderEMA) return insightsGroup class MyUniverseSelectionModel(FundamentalUniverseSelectionModel): def __init__(self): super().__init__(True, None, None) def SelectCoarse(self, algorithm, coarse): filtered = [x for x in coarse if x.HasFundamentalData and x.Price > 0] sortedByDollarVolume = sorted(filtered, key=lambda x: x.DollarVolume, reverse=True) return [x.Symbol for x in sortedByDollarVolume][:10] def SelectFine(self, algorithm, fine): filtered = [f for f in fine if f.AssetClassification.MorningstarSectorCode == MorningstarSectorCode.Technology] self.technology = sorted(filtered, key=lambda f: f.MarketCap, reverse=True)[:3] #filtered = [f for f in fine if f.AssetClassification.MorningstarSectorCode == MorningstarSectorCode.FinancialServices] #self.financialServices = sorted(filtered, key=lambda f: f.MarketCap, reverse=True)[:2] #filtered = [f for f in fine if f.AssetClassification.MorningstarSectorCode == MorningstarSectorCode.ConsumerDefensive] #self.consumerDefensive = sorted(filtered, key=lambda f: f.MarketCap, reverse=True)[:1] #return [x.Symbol for x in self.technology + self.financialServices + self.consumerDefensive] return [x.Symbol for x in self.technology]