Help in developing a strategy
-
Hi!
For a client I have I'm developing an indicator based strategy on the market EURUSD and, in general, for FX markets.
To be honest I'm developing this strategy on a competitor platform, QuantConnect, but on this competitor platform parameter optimization is not free.So I thought about doing some backtests on various Indicators on legacy Quantiacs platform, which has the "ToolBox"
-
import numpy as np from scipy.signal import lfilter def mySettings(): settings={} settings['markets'] = ['F_ED'] settings['beginInSample'] = '19900101' settings['slippage'] = 0.05 settings['budget'] = 1000000 # settings['beginInSample'] = '20050101' settings['endInSample'] = '20201227' settings['lookback'] = 504 return settings def myTradingSystem(DATE, OPEN, HIGH, LOW, CLOSE, VOL, OI, P, R, RINFO, exposure, equity, settings): period1 = 260 #%[100:20:504]# rsi1 = RSI(CLOSE,period1) period2= 40 #%[1:50:200]# p = rsi1 - period2 return p, settings def RSI(CLOSE,period): closeMom = CLOSE[1:,:] - CLOSE[:-1,:] upPosition = np.where(closeMom >= 0) downPosition = np.where(closeMom < 0) upMoves = closeMom.copy() upMoves[downPosition] = 0 downMoves = np.abs(closeMom.copy()) downMoves[upPosition] = 0 out = 100 - 100 / (1 + (np.mean(upMoves[-(period+1):,:],axis=0) / np.mean(downMoves[-(period+1):,:],axis=0))) return out def nDayEMA(field, period): ep = 2.0/(period+1) aa= np.array([ep]) bb = np.array([1, -(1-ep)]) zInit = np.array(field[1,:]*(1-ep))[np.newaxis] out = lfilter(aa, bb, field[1:,:], zi=zInit,axis=0) out = out[0] out[:period-1,:] = np.NaN return out # Evaluate trading system defined in current file. if __name__ == '__main__': from quantiacsToolbox import runts import quantiacsToolbox quantiacsToolbox.optimize(__file__) #results = runts(__file__)
And so I developed this prototype of code by editing a strategy present on the legacy Quantiacs. Is it running on Eurodollar futures, right?
-
Can you help me understand when the backtest starts? Does it start from 1990, right?
Is the RSI code implemented correctly? Can I test more than just 2 parameters at once?I'm hoping to find the "best" parameters for RSI without overfitting and then trying the same parameters on QuantConnect to see if the performance improves...
-
@magenta-grimer Hello, this is legacy code, and legacy Quantiacs has been phased out. We will release a new optimizer for the new Quantiacs. Here you are using the symbol "F_ED": this is an interest rate contract (Eurodollars). Eurodollars are a type of U.S. dollar deposit held in a bank outside of the United States (originally in Europe). The symbol for the EUR/USD rate is "F_EC".
-
@magenta-grimer The backtest starts in 1990 and can be set using the instruction:
settings['beginInSample'] = '19900101'
-
@magenta-grimer RSI is ok, you can read (one) definition here:
You can also test more than 2 parameters at once.
-
@support fantastic answers! Really on target and appropriate! I couldn't be more satisfied!
-
Sorry to disturb you always @support , can you provide me a bit more informations about lookback?
It should be the timeframe considered when we use our strategy, right?
So in this case we have an Indicator which uses two periods: 260 and 40.
In this case the lookback of 504 is okay, but a lookback of 304 would also have been ok, right? Since the longest dated period is 260...
So in this case either using 300, or 261 or 500 is fine as long as the longest period back in time used is 260, right?
-
@magenta-grimer Hi, the lookback period in the backtester function is expressed in calendar days, and the indicators are expressed in trading days. So as far as the lookback period is long enough to include all indicator needed periods, all choices are fine.
If the longest period needed for an indicator is 10 trading days (2 weeks), a lookback period of (for example) 20, 50 or 100 for the backtester function will deliver the same results. The shorter the better for efficiency.