Overall Statistics |
Total Trades 397 Average Win 0.59% Average Loss -0.06% Compounding Annual Return 12.628% Drawdown 41.500% Expectancy 9.118 Net Profit 715.407% Sharpe Ratio 0.76 Probabilistic Sharpe Ratio 9.876% Loss Rate 3% Win Rate 97% Profit-Loss Ratio 9.43 Alpha 0.125 Beta -0.093 Annual Standard Deviation 0.152 Annual Variance 0.023 Information Ratio 0.078 Tracking Error 0.242 Treynor Ratio -1.25 Total Fees $0.00 |
from execution import * from alpha import * class NadionCalibratedCircuit(QCAlgorithm): def Initialize(self): self.SetStartDate(2003, 1, 1) self.SetCash(100000) self.Resolution = Resolution.Daily self.UniverseSettings.Resolution = Resolution.Daily self.risk = "QQQ" self.safe = "SHY" symbols = [ Symbol.Create(self.risk, SecurityType.Equity, Market.USA), Symbol.Create(self.safe, SecurityType.Equity, Market.USA) ] self.AddUniverseSelection(ManualUniverseSelectionModel(symbols)) self.AddAlpha( RiskBalance(symbols[0], symbols[1], self, self.Resolution) ) self.Settings.RebalancePortfolioOnInsightChanges = False self.Settings.RebalancePortfolioOnSecurityChanges = False self.SetPortfolioConstruction( InsightWeightingPortfolioConstructionModel(self.RebalanceFunction) ) self.SetExecution( SlowExecutionModel() ) self.AddRiskManagement( MaximumDrawdownPercentPortfolio(0.03) ) self.month = -1 def RebalanceFunction(self, time): if self.month == -1: self.month = time.month return time if self.month != time.month: self.month = time.month return time return None def OnSecuritiesChanged(self, changes): self.Securities[self.risk].FeeModel = ConstantFeeModel(0) self.Securities[self.safe].FeeModel = ConstantFeeModel(0)
from clr import AddReference AddReference("System") AddReference("QuantConnect.Common") AddReference("QuantConnect.Algorithm") AddReference("QuantConnect.Algorithm.Framework") from System import * from QuantConnect import * from QuantConnect.Orders import * from QuantConnect.Algorithm import * from QuantConnect.Algorithm.Framework import * class RiskBalance: def __init__(self, risk, safe, algorithm, resolution): self.algorithm = algorithm self.risk = risk self.safe = safe self.resolution = resolution self.psars = {} self.bull_insights = Insight.Group([ Insight.Price(self.risk, timedelta(days = 30), InsightDirection.Up, None, None, None, 0.90), Insight.Price(self.safe, timedelta(days = 30), InsightDirection.Up, None, None, None, 0.10) ]) self.bear_insights = Insight.Group([ Insight.Price(self.risk, timedelta(days = 30), InsightDirection.Up, None, None, None, 0.50), Insight.Price(self.safe, timedelta(days = 30), InsightDirection.Up, None, None, None, 0.50) ]) self.month = -1 def Update(self, algorithm, slice): if self.month == -1: self.month = algorithm.Time.month return self.bull_insights if self.month != algorithm.Time.month: self.month = algorithm.Time.month if self.algorithm.Securities[str(self.risk)].Price > self.psars[str(self.risk)].Current.Value: return self.bull_insights elif self.algorithm.Securities[str(self.risk)].Price < self.psars[str(self.risk)].Current.Value: return self.bear_insights return [] def OnSecuritiesChanged(self, algorithm, changes): for security in changes.AddedSecurities: self.psar = ParabolicStopAndReverse(5) consolidator = TradeBarConsolidator(timedelta(days=30)) self.algorithm.SubscriptionManager.AddConsolidator(str(security.Symbol), consolidator) self.algorithm.RegisterIndicator(str(security.Symbol), self.psar, consolidator) self.psars[str(security.Symbol)] = self.psar
from clr import AddReference AddReference("System") AddReference("QuantConnect.Common") AddReference("QuantConnect.Algorithm") AddReference("QuantConnect.Algorithm.Framework") from System import * from QuantConnect import * from QuantConnect.Orders import * from QuantConnect.Algorithm import * from QuantConnect.Algorithm.Framework import * from QuantConnect.Algorithm.Framework.Execution import * from QuantConnect.Algorithm.Framework.Portfolio import * class SlowExecutionModel(ExecutionModel): def __init__(self): self.targetsCollection = PortfolioTargetCollection() self.month = -1 def Execute(self, algorithm, targets): self.targetsCollection.AddRange(targets) if self.targetsCollection.Count > 0: if self.month == -1: self.PlaceOrders(algorithm, 1) self.month = algorithm.Time.month return if self.month != algorithm.Time.month: self.month = algorithm.Time.month self.PlaceOrders(algorithm, (1/12)) def PlaceOrders(self, algorithm, factor): for target in self.targetsCollection.OrderByMarginImpact(algorithm): quantity = OrderSizing.GetUnorderedQuantity(algorithm, target) if quantity != 0: quantity = quantity*factor algorithm.MarketOrder(target.Symbol, quantity) self.targetsCollection.ClearFulfilled(algorithm)