Overall Statistics |
Total Trades 1073 Average Win 3.14% Average Loss -0.95% Compounding Annual Return 52.508% Drawdown 22.800% Expectancy 2.439 Net Profit 10009791.919% Sharpe Ratio 2.341 Probabilistic Sharpe Ratio 100.000% Loss Rate 20% Win Rate 80% Profit-Loss Ratio 3.32 Alpha 0.331 Beta 0.359 Annual Standard Deviation 0.151 Annual Variance 0.023 Information Ratio 1.698 Tracking Error 0.171 Treynor Ratio 0.985 Total Fees $0.00 Estimated Strategy Capacity $0 Lowest Capacity Asset QQQ.QQQ 2S |
class AccelDualMomentum(QCAlgorithm): def Initialize(self): self.SetStartDate(1995, 1, 3) # Set Start Date #self.SetEndDate(2022,2,28) # Set End Date self.SetCash(10000) # Set Strategy Cash self.aVFINX = self.AddData(VFINX, "VFINX", Resolution.Daily).Symbol self.aQQQ = self.AddData(QQQ, "QQQ", Resolution.Daily).Symbol self.aVINEX = self.AddData(VINEX, "VINEX", Resolution.Daily).Symbol self.aVUSTX = self.AddData(VUSTX, "VUSTX", Resolution.Daily).Symbol self.aLBMA = self.AddData(LBMA, "LBMA", Resolution.Daily).Symbol #self.aGLD = self.AddData(GLD, "GLD", Resolution.Daily).Symbol self.aVIPSX = self.AddData(VIPSX, "VIPSX", Resolution.Daily).Symbol self.aCASH = self.AddData(CASH, "CASH", Resolution.Daily).Symbol self.indicator = self.AddData(MOMENTUM, "MOMENTUM", Resolution.Daily).Symbol self.leverage = 1 # Set leverage | A value of 1 indicates no leverage | A value of 2 indicates 100% leverage self.Securities["VFINX"].SetLeverage(self.leverage) self.Securities["QQQ"].SetLeverage(self.leverage) self.Securities["VINEX"].SetLeverage(self.leverage) self.Securities["VUSTX"].SetLeverage(self.leverage) self.Securities["LBMA"].SetLeverage(self.leverage) #self.Securities["GLD"].SetLeverage(self.leverage) self.Securities["VIPSX"].SetLeverage(self.leverage) self.Securities["CASH"].SetLeverage(self.leverage) # Set trading frequency self.monthly = 0 self.annual = 0 self.daily = 1 self.trading_fee = 5 # Fee per trade self.trading_day = 21 # Set trading day | Value = 21 is last trading day of month self.GetParameter("trading_day") def shiftAssets(self, target): if not (self.Portfolio[target].Invested): for symbol in self.Portfolio.Keys: self.Liquidate(symbol) if not self.Portfolio.Invested: self.SetHoldings(target, 1*self.leverage) def getMonthTradingDay(self): month_last_day = DateTime(self.Time.year, self.Time.month, DateTime.DaysInMonth(self.Time.year, self.Time.month)) tradingDays = self.TradingCalendar.GetDaysByType(TradingDayType.BusinessDay, DateTime(self.Time.year, self.Time.month, 1), month_last_day) tradingDays = [day.Date.date() for day in tradingDays] return tradingDays[-22 + self.trading_day] def getYearLastTradingDay(self): year_last_day = DateTime(self.Time.year, 12, DateTime.DaysInMonth(self.Time.year, 12)) tradingDays = self.TradingCalendar.GetDaysByType(TradingDayType.BusinessDay, DateTime(self.Time.year, 12, 1), year_last_day) tradingDays = [day.Date.date() for day in tradingDays] return tradingDays [-1] def OnData(self, data): if (self.daily ==1): if data.ContainsKey(self.indicator): ticker = data[self.indicator].GetProperty('Indicator') if (ticker =="VINEX"): #self.Securities["VINEX"].SetFeeModel(MonthlyCustomFeeModel()) self.shiftAssets(self.aVINEX) elif (ticker =="QQQ"): #self.Securities["QQQ"].SetFeeModel(MonthlyCustomFeeModel()) self.shiftAssets(self.aQQQ) elif (ticker =="VUSTX"): #self.Securities["VUSTX"].SetFeeModel(MonthlyCustomFeeModel()) self.shiftAssets(self.aVUSTX) elif (ticker =="LBMA"): #self.Securities["LBMA"].SetFeeModel(MonthlyCustomFeeModel()) self.shiftAssets(self.aLBMA) elif (ticker =="VIPSX"): #self.Securities["VIPSX"].SetFeeModel(MonthlyCustomFeeModel()) self.shiftAssets(self.aVIPSX) elif (ticker =="CASH"): #self.Securities["CASH"].SetFeeModel(MonthlyCustomFeeModel()) self.shiftAssets(self.aCASH) elif (ticker =="GLD"): #self.Securities["GLD"].SetFeeModel(MonthlyCustomFeeModel()) self.shiftAssets(self.aGLD) if (self.monthly ==1): if (self.Time.date() == self.getMonthTradingDay()): if data.ContainsKey(self.indicator): ticker = data[self.indicator].GetProperty('Indicator') if (ticker =="VINEX"): self.Securities["VINEX"].SetFeeModel(MonthlyCustomFeeModel()) self.shiftAssets(self.aVINEX) elif (ticker =="QQQ"): self.Securities["QQQ"].SetFeeModel(MonthlyCustomFeeModel()) self.shiftAssets(self.aQQQ) elif (ticker =="VUSTX"): self.Securities["VUSTX"].SetFeeModel(MonthlyCustomFeeModel()) self.shiftAssets(self.aVUSTX) elif (ticker =="LBMA"): self.Securities["LBMA"].SetFeeModel(MonthlyCustomFeeModel()) self.shiftAssets(self.aLBMA) elif (ticker =="VIPSX"): self.Securities["VIPSX"].SetFeeModel(MonthlyCustomFeeModel()) self.shiftAssets(self.aVIPSX) elif (ticker =="CASH"): self.Securities["CASH"].SetFeeModel(MonthlyCustomFeeModel()) self.shiftAssets(self.aCASH) elif (ticker =="GLD"): self.Securities["GLD"].SetFeeModel(MonthlyCustomFeeModel()) self.shiftAssets(self.aGLD) if (self.annual ==1): if (self.Time.date() == self.getYearLastTradingDay()): if data.ContainsKey(self.indicator): ticker = data[self.indicator].GetProperty('Indicator') if (ticker =="VINEX"): self.Securities["VINEX"].FeeModel = ConstantFeeModel(self.trading_fee) self.shiftAssets(self.aVINEX) elif (ticker =="QQQ"): self.Securities["QQQ"].FeeModel = ConstantFeeModel(self.trading_fee) self.shiftAssets(self.aQQQ) elif (ticker =="VUSTX"): self.Securities["VUSTX"].FeeModel = ConstantFeeModel(self.trading_fee) self.shiftAssets(self.aVUSTX) elif (ticker =="LBMA"): self.Securities["LBMA"].FeeModel = ConstantFeeModel(self.trading_fee) self.shiftAssets(self.aLBMA) elif (ticker =="VIPSX"): self.Securities["VIPSX"].FeeModel = ConstantFeeModel(self.trading_fee) self.shiftAssets(self.aVIPSX) elif (ticker =="CASH"): self.Securities["CASH"].FeeModel = ConstantFeeModel(self.trading_fee) self.shiftAssets(self.aCASH) elif (ticker =="GLD"): self.Securities["GLD"].FeeModel = ConstantFeeModel(self.trading_fee) self.shiftAssets(self.aGLD) # Charts self.Plot("Margin", "Remaining", self.Portfolio.MarginRemaining) self.Plot("Margin", "Used", self.Portfolio.TotalMarginUsed) self.Plot("Cash", "Remaining", self.Portfolio.Cash) self.Plot("Cash", "Remaining", self.Portfolio.TotalHoldingsValue) self.Plot("VFINX", "Held", self.Portfolio["VFINX"].Quantity) self.Plot("VINEX", "Held", self.Portfolio["VINEX"].Quantity) self.Plot("VUSTX", "Held", self.Portfolio["VUSTX"].Quantity) self.Plot("VIPSX", "Held", self.Portfolio["VIPSX"].Quantity) #self.Plot("GLD", "Held", self.Portfolio["GLD"].Quantity) self.Plot("CASH", "Held", self.Portfolio["CASH"].Quantity) self.Plot("LBMA", "Held", self.Portfolio["LBMA"].Quantity) class LBMA(PythonData): def GetSource(self, config, date, isLiveMode): return SubscriptionDataSource("https://www.dropbox.com/s/81ixmlr8cx1uxgq/LBMA.csv?dl=1", SubscriptionTransportMedium.RemoteFile) def Reader(self, config, line, date, isLive): if not (line.strip() and line[0].isdigit()): return None index = LBMA() index.Symbol = config.Symbol data = line.split(',') index.Time = datetime.strptime(data[0], "%d/%m/%Y") index.EndTime = index.Time + timedelta(days=1) index.Value = data[1] index["LBMA"] = float(data[1]) return index class VIPSX(PythonData): def GetSource(self, config, date, isLiveMode): return SubscriptionDataSource("https://www.dropbox.com/s/51npkwxesct345x/VIPSX.csv?dl=1", SubscriptionTransportMedium.RemoteFile) def Reader(self, config, line, date, isLive): if not (line.strip() and line[0].isdigit()): return None index = VIPSX() index.Symbol = config.Symbol data = line.split(',') index.Time = datetime.strptime(data[0], "%d/%m/%Y") index.EndTime = index.Time + timedelta(days=1) index.Value = data[4] index["Open"] = float(data[1]) index["High"] = float(data[2]) index["Low"] = float(data[3]) index["Close"] = float(data[4]) return index class VUSTX(PythonData): def GetSource(self, config, date, isLiveMode): return SubscriptionDataSource("https://www.dropbox.com/s/hnv2swusm9wra5w/VUSTX.csv?dl=1", SubscriptionTransportMedium.RemoteFile) def Reader(self, config, line, date, isLive): if not (line.strip() and line[0].isdigit()): return None index = VUSTX() index.Symbol = config.Symbol data = line.split(',') index.Time = datetime.strptime(data[0], "%d/%m/%Y") index.EndTime = index.Time + timedelta(days=1) index.Value = data[4] index["Open"] = float(data[1]) index["High"] = float(data[2]) index["Low"] = float(data[3]) index["Close"] = float(data[4]) return index class VFINX(PythonData): def GetSource(self, config, date, isLiveMode): return SubscriptionDataSource("https://www.dropbox.com/s/zzh0ydo8t8l5ds4/VFINX.csv?dl=1", SubscriptionTransportMedium.RemoteFile) def Reader(self, config, line, date, isLive): if not (line.strip() and line[0].isdigit()): return None index = VFINX() index.Symbol = config.Symbol data = line.split(',') index.Time = datetime.strptime(data[0], "%d/%m/%Y") index.EndTime = index.Time + timedelta(days=1) index.Value = data[4] index["Open"] = float(data[1]) index["High"] = float(data[2]) index["Low"] = float(data[3]) index["Close"] = float(data[4]) return index class VINEX(PythonData): def GetSource(self, config, date, isLiveMode): return SubscriptionDataSource("https://www.dropbox.com/s/3otgob32pyl0hz8/VINEX.csv?dl=1", SubscriptionTransportMedium.RemoteFile) def Reader(self, config, line, date, isLive): if not (line.strip() and line[0].isdigit()): return None index = VINEX() index.Symbol = config.Symbol data = line.split(',') index.Time = datetime.strptime(data[0], "%d/%m/%Y") index.EndTime = index.Time + timedelta(days=1) index.Value = data[4] index["Open"] = float(data[1]) index["High"] = float(data[2]) index["Low"] = float(data[3]) index["Close"] = float(data[4]) return index class GLD(PythonData): def GetSource(self, config, date, isLiveMode): return SubscriptionDataSource("https://www.dropbox.com/s/c9asn799ugf8kja/GLD.csv?dl=1", SubscriptionTransportMedium.RemoteFile) def Reader(self, config, line, date, isLive): if not (line.strip() and line[0].isdigit()): return None index = GLD() index.Symbol = config.Symbol data = line.split(',') index.Time = datetime.strptime(data[0], "%d/%m/%Y") index.EndTime = index.Time + timedelta(days=1) index.Value = data[4] index["Open"] = float(data[1]) index["High"] = float(data[2]) index["Low"] = float(data[3]) index["Close"] = float(data[4]) return index class CASH(PythonData): def GetSource(self, config, date, isLiveMode): return SubscriptionDataSource("https://www.dropbox.com/s/496wpuy5qrlq9za/CASH.csv?dl=1", SubscriptionTransportMedium.RemoteFile) def Reader(self, config, line, date, isLive): if not (line.strip() and line[0].isdigit()): return None index = CASH() index.Symbol = config.Symbol data = line.split(',') index.Time = datetime.strptime(data[0], "%d/%m/%Y") index.EndTime = index.Time + timedelta(days=1) index.Value = data[1] index["Close"] = float(data[1]) return index class QQQ(PythonData): def GetSource(self, config, date, isLiveMode): return SubscriptionDataSource("https://www.dropbox.com/s/53tqrfh84h7h1ax/QQQ.csv?dl=1", SubscriptionTransportMedium.RemoteFile) def Reader(self, config, line, date, isLive): if not (line.strip() and line[0].isdigit()): return None index = QQQ() index.Symbol = config.Symbol data = line.split(',') index.Time = datetime.strptime(data[0], "%Y-%m-%d") index.EndTime = index.Time + timedelta(days=1) index.Value = data[1] index["Close"] = float(data[1]) return index class MOMENTUM(PythonData): def GetSource(self, config, date, isLiveMode): return SubscriptionDataSource("https://www.dropbox.com/s/j9lacl1a67xpdpx/Indicator_QQQ.csv?dl=1", SubscriptionTransportMedium.RemoteFile) def Reader(self, config, line, date, isLive): if not (line.strip() and line[0].isdigit()): return None index = MOMENTUM() index.Symbol = config.Symbol data = line.split(',') index.Time = datetime.strptime(data[0], "%Y-%m-%d") index.EndTime = index.Time + timedelta(days=1) index.SetProperty("Indicator", str(data[1])) return index class MonthlyCustomFeeModel: def GetOrderFee(self, parameters): self.margin_rate = 0.015 #Set Margin Fee self.trading_fee = 5 #Set fee per trade fee = self.trading_fee + (parameters.Security.Leverage-1)*parameters.Security.Price*parameters.Order.AbsoluteQuantity*(self.margin_rate/12) return OrderFee(CashAmount(fee, 'USD'))