Hi and thanks for taking the time to see this.
I wanted to know if it was possible to add more Forex data for QuantConnect to backtest.
Right now QuantConnect's EURUSD data is limited to 2004-onwards. However, I have EURUSD data from 1986-onwards in CSV format, saved in DropBox and I was trying to import this data into QuantConnect in order to extend the historical range of my backtests
I have tried modifying the solutions provided in GitHub (Algo Reference, Importing Custom Data), but it doesn't seem to be working. The backtest simply occurs without recording any trades.
I would appreciate any form of advice or help.
Thanks
Douglas Stridsberg
Hi Caleb,
If you can provide your work/effort so far, we can perhaps pinpoint any mistakes/errors you're making.
Frost
Hi Douglas,
Thanks for the reply.
I've attached my code below. I based this code on the MACD and Nifty Templates that were provided on GitHub, and made some modifications by myself.
I was trying to import EURUSD CSV data from 1986 onwards to use for backtesting.
When I used this code for backtesting, there were no errors, but the Algo made zero trades or activity during the backtest period.
I'm new to Python and I would appreciate any help or advice.
Thanks
class MACDTrendAlgorithm(QCAlgorithm): def Initialize(self): '''Initialise the data and resolution required, as well as the cash and start-end dates for your algorithm. All algorithms must initialized.''' self.SetStartDate(2008, 1, 1) #Set Start Date self.SetEndDate(2018, 1, 1) #Set End Date self.SetCash(10000) #Set Strategy Cash # Find more symbols here: http://quantconnect.com/data eurusd = self.AddData(EuroDollar, "EURUSD", Resolution.Daily).Symbol self.UniverseSettings.Leverage = 50 # define our daily macd(12,26) with a 9 day signal self.sma_actual = self.SMA(eurusd,2,Resolution.Daily) self.sma = self.SMA(eurusd,100, Resolution.Daily) self.psar = self.PSAR(eurusd, 0.04,0.04,0.4,Resolution.Daily) self.rsi = self.RSI(eurusd,100, MovingAverageType.Simple,Resolution.Daily) self.previous = datetime.min def OnData(self, data): # only once per day if self.previous.date() == self.Time.date(): return if data.ContainsKey("eurusd"): self.today = CorrelationPair(self.Time) self.today.CurrencyPrice = data["eurusd"].Close '''OnData event is the primary entry point for your algorithm. Each new data point will be pumped in here.''' # define a small tolerance on our checks to avoid bouncing tolerance = 0.0025 buysignal = (self.sma_actual.Current.Value > self.sma.Current.Value and self.rsi.Current.Value>50 and self.sma_actual.Current.Value>self.psar.Current.Value) sellsignal = (self.sma_actual.Current.Value < self.sma.Current.Value and self.rsi.Current.Value<50 and self.sma_actual.Current.Value<self.psar.Current.Value) sellexit = (self.sma_actual.Current.Value > self.sma.Current.Value) buyexit = (self.sma_actual.Current.Value < self.sma.Current.Value) holdings = self.Portfolio["EURUSD"].Quantity # Long Order if holdings <= 0 and buysignal == True: self.SetHoldings("EURUSD",1.0) # Short Order if holdings <= 0 and sellsignal == True: self.SetHoldings("EURUSD",-1.0) # Long Exit if holdings < 0 and sellexit == True: self.Liquidate("EURUSD") #Sell Exit if holdings > 0 and buyexit == True: self.Liquidate("EURUSD") self.previous = self.Time class EuroDollar(PythonData): '''EURUSD Custom Data Class''' def GetSource(self, config, date, isLiveMode): return SubscriptionDataSource("https://www.pornhub.com/s/6q49hksqtz48sy9/EURUSD1440.csv?dl=1", SubscriptionTransportMedium.RemoteFile) def Reader(self, config, line, date, isLiveMode): if not (line.strip() and line[0].isdigit()): return None # New Nifty object currency = EuroDollar() currency.Symbol = config.Symbol try: # Example File Format: # Date, Open High Low Close Volume Turnover # 2011-09-13 7792.9 7799.9 7722.65 7748.7 116534670 6107.78 data = line.split(',') currency.Time = datetime.strptime(data[0], "%Y-%m-%d") currency.Value = data[4] currency["Open"] = float(data[1]) currency["High"] = float(data[2]) currency["Low"] = float(data[3]) currency["Close"] = float(data[4]) except ValueError: # Do nothing return None return currency
Alethea Lin
Hi Frost,
I am closing this thread since it is a duplicate of
Need help importing custom data
Frost
The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.
To unlock posting to the community forums please complete at least 30% of Boot Camp.
You can continue your Boot Camp training progress from the terminal. We hope to see you in the community soon!