Overall Statistics |
Total Trades 159 Average Win 1.90% Average Loss -1.37% Compounding Annual Return 150.300% Drawdown 11.100% Expectancy 0.418 Net Profit 52.466% Sharpe Ratio 1.709 Loss Rate 41% Win Rate 59% Profit-Loss Ratio 1.38 Alpha 0 Beta 52.161 Annual Standard Deviation 0.419 Annual Variance 0.175 Information Ratio 1.676 Tracking Error 0.419 Treynor Ratio 0.014 Total Fees $0.00 |
from datetime import datetime class MACDNaiveBTCTrader(QCAlgorithm): def Initialize(self): self.SetStartDate(2019,1,1) #Set Start Date self.SetCash(1000000) #Set Strategy Cash self.AddCrypto("BTCUSD", Resolution.Daily) self.Securities["BTCUSD"].SetDataNormalizationMode(DataNormalizationMode.Raw); # daily macd(12,26) with a 9 day signal self.__macd = self.MACD("BTCUSD", 12, 26, 9, MovingAverageType.Exponential, Resolution.Daily) self.__previous = datetime.min self.PlotIndicator("MACD", True, self.__macd, self.__macd.Signal) self.PlotIndicator("BTCUSD", self.__macd.Fast, self.__macd.Slow) def OnData(self, data): # wait for macd to initialize if not self.__macd.IsReady: return # only once per day if self.__previous.date() == self.Time.date(): return # small tolerance to avoid bouncing tolerance = 0.0001; # get holdings amount holdings = self.Portfolio["BTCUSD"].Quantity # calculate signal delta signalDeltaPercent = (self.__macd.Current.Value - self.__macd.Signal.Current.Value)/self.__macd.Fast.Current.Value # if no holdings and macd is greater than signal, then go long (90% of equity) if holdings <= 0 and abs(signalDeltaPercent) > tolerance: self.SetHoldings("BTCUSD", 0.9) # if some holdings are here and macd is greater than signal, then liquidate elif holdings > 0 and abs(signalDeltaPercent) > tolerance: self.Liquidate("BTCUSD") # run once per day self.__previous = self.Time