Overall Statistics |
Total Trades 9 Average Win 0.41% Average Loss -0.13% Compounding Annual Return 1.315% Drawdown 0.500% Expectancy 1.827 Net Profit 0.650% Sharpe Ratio 1.01 Probabilistic Sharpe Ratio 50.133% Loss Rate 33% Win Rate 67% Profit-Loss Ratio 3.24 Alpha 0.004 Beta -0.055 Annual Standard Deviation 0.011 Annual Variance 0 Information Ratio 1.285 Tracking Error 0.1 Treynor Ratio -0.194 Total Fees $0.00 Estimated Strategy Capacity $9400000.00 |
from datetime import datetime import decimal import numpy as np class DynamicBreakoutAlgorithm(QCAlgorithm): def Initialize(self): self.SetStartDate(2010,1,1) self.SetEndDate(2010,6,30) self.SetCash(100000) self.numdays = 20 self.ceiling,self.floor = 60,20 self.buypoint, self.sellpoint= None, None self.longLiqPoint, self.shortLiqPoint, self.yesterdayclose= None, None, None self.bband = {} for ticker in ["EURUSD", "GBPUSD"]: symbol = self.AddForex(ticker, Resolution.Hour, Market.Oanda).Symbol self.bband[symbol] = self.BB(symbol, self.numdays, 2, MovingAverageType.Simple, Resolution.Daily) self.Schedule.On(self.DateRules.EveryDay(symbol), self.TimeRules.BeforeMarketClose(symbol,1),Action(self.SetSignal)) self.SetBenchmark(symbol) def SetSignal(self): for symbol, bband in self.bband.items(): close = self.History(symbol, 31, Resolution.Daily)['close'] todayvol = np.std(close[1:31]) yesterdayvol = np.std(close[0:30]) deltavol = (todayvol - yesterdayvol) / todayvol self.numdays = int(round(self.numdays * (1 + deltavol))) if self.numdays > self.ceiling: self.numdays = self.ceiling elif self.numdays < self.floor: self.numdays = self.floor self.high = self.History(symbol, self.numdays, Resolution.Daily)['high'] self.low = self.History(symbol, self.numdays, Resolution.Daily)['low'] self.buypoint = max(self.high) self.sellpoint = min(self.low) historyclose = self.History(symbol, self.numdays, Resolution.Daily)['close'] self.longLiqPoint = np.mean(historyclose) self.shortLiqPoint = np.mean(historyclose) self.yesterdayclose = historyclose.iloc[-1] # wait for our BollingerBand to fully initialize if not all([bband.IsReady for symbol, bband in self.bband.items()]): return holdings = self.Portfolio[symbol].Quantity bb = self.bband[symbol] if self.yesterdayclose > bb.UpperBand.Current.Value and self.Portfolio[symbol].Price >= self.buypoint: self.SetHoldings(symbol, .1) elif self.yesterdayclose < bb.LowerBand.Current.Value and self.Portfolio[symbol].Price <= self.sellpoint: self.SetHoldings(symbol, -.1) if holdings > 0 and self.Portfolio[symbol].Price <= self.shortLiqPoint: self.Liquidate(symbol) elif holdings < 0 and self.Portfolio[symbol].Price >= self.shortLiqPoint: self.Liquidate(symbol) def OnData(self,data): return