Navigation

    Quantiacs Community

    • Register
    • Login
    • Search
    • Categories
    • News
    • Recent
    • Tags
    • Popular
    • Users
    • Groups

    Help in developing a strategy

    Strategy help
    2
    9
    673
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • magenta.grimer
      magenta.grimer last edited by

      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"

      magenta.grimer 1 Reply Last reply Reply Quote 0
      • magenta.grimer
        magenta.grimer @magenta.grimer last edited by

        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?

        magenta.grimer support 2 Replies Last reply Reply Quote 0
        • magenta.grimer
          magenta.grimer @magenta.grimer last edited by

          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...

          support 2 Replies Last reply Reply Quote 0
          • support
            support @magenta.grimer last edited by

            @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".

            1 Reply Last reply Reply Quote 0
            • support
              support @magenta.grimer last edited by

              @magenta-grimer The backtest starts in 1990 and can be set using the instruction:

              settings['beginInSample'] = '19900101'
              
              1 Reply Last reply Reply Quote 0
              • support
                support @magenta.grimer last edited by

                @magenta-grimer RSI is ok, you can read (one) definition here:

                RSI

                You can also test more than 2 parameters at once.

                magenta.grimer 1 Reply Last reply Reply Quote 0
                • magenta.grimer
                  magenta.grimer @support last edited by

                  @support fantastic answers! Really on target and appropriate! I couldn't be more satisfied!

                  magenta.grimer 1 Reply Last reply Reply Quote 1
                  • magenta.grimer
                    magenta.grimer @magenta.grimer last edited by

                    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?

                    support 1 Reply Last reply Reply Quote 0
                    • support
                      support @magenta.grimer last edited by

                      @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.

                      1 Reply Last reply Reply Quote 0
                      • First post
                        Last post
                      Powered by NodeBB | Contributors
                      • Documentation
                      • About
                      • Career
                      • My account
                      • Privacy policy
                      • Terms and Conditions
                      • Cookies policy
                      Home
                      Copyright © 2014 - 2021 Quantiacs LLC.
                      Powered by NodeBB | Contributors