Overall Statistics |
Total Trades 111 Average Win 0% Average Loss 0.00% Compounding Annual Return 0.143% Drawdown 0.100% Expectancy -1 Net Profit 0.019% Sharpe Ratio 0.803 Loss Rate 100% Win Rate 0% Profit-Loss Ratio 0 Alpha 0.005 Beta -0.269 Annual Standard Deviation 0.001 Annual Variance 0 Information Ratio -9.947 Tracking Error 0.001 Treynor Ratio -0.004 Total Fees $0.00 |
from System import * from QuantConnect import * from QuantConnect.Data.Consolidators import * from QuantConnect.Data.Market import * from QuantConnect.Orders import OrderStatus from QuantConnect.Algorithm import QCAlgorithm from QuantConnect.Indicators import * import numpy as np from datetime import timedelta, datetime import decimal as d class MultipleSymbolConsolidationAlgorithm(QCAlgorithm): def Initialize(self): self.SetStartDate(2018, 2, 1) self.SetEndDate(2018, 3, 21) self.SetCash(50000) BarPeriod = TimeSpan.FromHours(1) SimpleMovingAveragePeriodfast = 9 SimpleMovingAveragePeriodslow = 2 ADXPeriod = 9 RollingWindowSize = 5 self.Data = {} ForexSymbols =["EURAUD"]#, "USDJPY", "EURGBP", "EURCHF", "USDCAD", "USDCHF", "AUDUSD","NZDUSD", "EURUSD"] for symbol in ForexSymbols: forex = self.AddForex(symbol) self.Data[symbol] = SymbolData(forex.Symbol, BarPeriod, RollingWindowSize) for symbol, symbolData in self.Data.items(): symbolData.SMAfast = SimpleMovingAverage(self.CreateIndicatorName(symbol, "SMA" + str(SimpleMovingAveragePeriodfast), Resolution.Hour), SimpleMovingAveragePeriodfast) symbolData.SMAslow = SimpleMovingAverage(self.CreateIndicatorName(symbol, "SMA" + str(SimpleMovingAveragePeriodslow), Resolution.Hour), SimpleMovingAveragePeriodslow) symbolData.ADX = AverageDirectionalIndex(self.CreateIndicatorName(symbol, "ADX" + str(ADXPeriod), Resolution.Hour), ADXPeriod) consolidator = QuoteBarConsolidator(BarPeriod) consolidator.DataConsolidated += self.OnDataConsolidated self.SubscriptionManager.AddConsolidator(symbolData.Symbol, consolidator) def OnDataConsolidated(self, sender, bar): self.Data[bar.Symbol.Value].SMAfast.Update(bar.Time, bar.Close) self.Data[bar.Symbol.Value].SMAslow.Update(bar.Time, bar.Close) # self.Data[bar.Symbol.Value].ADX.Update(IBaseDataBar) self.Data[bar.Symbol.Value].Bars.Add(bar) def OnData(self, data): for symbol in self.Data.keys(): symbolData = self.Data[symbol] if symbolData.IsReady() and symbolData.WasJustUpdated(self.Time): symbolData.smaWin.Add(symbolData.SMAfast.Current.Value) if symbolData.smaWin.Count == 5: window_list = [i for i in symbolData.smaWin] fast = symbolData.SMAfast.Current.Value slow = symbolData.SMAslow.Current.Value if not self.Portfolio[symbol].Invested: if fast > slow: self.MarketOrder(symbol, 1000) if slow < fast: self.Liquidate(symbol) class SymbolData(object): def __init__(self, symbol, barPeriod, windowSize): self.Symbol = symbol self.BarPeriod = barPeriod self.Bars = RollingWindow[IBaseDataBar](windowSize) self.SMAfast = None self.SMAslow = None self.ADX = None self.BB = None self.smaWin = RollingWindow[float](5) def IsReady(self): return self.Bars.IsReady and self.SMAfast.IsReady and self.SMAslow.IsReady def WasJustUpdated(self, current): return self.Bars.Count > 0 and self.Bars[0].Time == current - self.BarPeriod