Dukascopy
 
 
Wiki JStore Search Login

JFOREX-2675 Java code optimization in indicators
 Post subject: JFOREX-2675 Java code optimization in indicators Post rating: 0   New post Posted: Sat 22 Jan, 2011, 09:54 

User rating: 0
Joined: Thu 19 Aug, 2010, 13:53
Posts: 62
The Java code in indicators should be optimized for memory allocation and computing speed. This will increase the automated strategies backtests and efficiency.
For example, I think the code for Alligator indicator and maybe others should be like below:

    public IndicatorResult calculate(int startIndex, int endIndex) {
        //calculating startIndex taking into account lookback value
        if (startIndex - getLookback() < 0) {
            startIndex -= startIndex - getLookback();
        }

        if (startIndex > endIndex) {
            return new IndicatorResult(0, 0);
        }

        /* no need - save memory allocation space and computing time
        double[] jawSma = new double[endIndex - startIndex + 2 + getLookback()];
        double[] teethSma = new double[endIndex - startIndex + 2 + getLookback()];
        double[] lipsSma = new double[endIndex - startIndex + 2 + getLookback()];
         */
       
        int aOutLen = endIndex - startIndex + 1;
       
        jawSmmaIndicator.setInputParameter(0, inputs[0]);
        teethSmmaIndicator.setInputParameter(0, inputs[0]);
        lipsSmmaIndicator.setInputParameter(0, inputs[0]);

        // we already have output buffers; no need jawSma,etc
        jawSmmaIndicator.setOutputParameter(0, outputs[0]);//jawSma);
        teethSmmaIndicator.setOutputParameter(0, outputs[1]);//teethSma);
        lipsSmmaIndicator.setOutputParameter(0, outputs[2]); //lipsSma);

        IndicatorResult dJawSmaResult = jawSmmaIndicator.calculate(startIndex/* - 1*/, endIndex);
        IndicatorResult dTeethSmaResult = teethSmmaIndicator.calculate(startIndex/* - 1*/, endIndex);
        IndicatorResult dLipsSmaResult = lipsSmmaIndicator.calculate(startIndex/* - 1*/, endIndex);

        // checks
        if(!(dJawSmaResult.getNumberOfElements() == aOutLen && dTeethSmaResult.getNumberOfElements() == aOutLen &&
              dLipsSmaResult.getNumberOfElements() == aOutLen))
           throw new ArrayStoreException("Better Alligator : number of elements in outputs buffers do not match.");
       
        /* save computing time; outputs already computed above
        int i, k;
        for (i = 1, k = dJawSmaResult.getNumberOfElements(); i < k; i++) {
            outputs[0][i - 1] = jawSma[i];
        }
        for (i = 1, k = dTeethSmaResult.getNumberOfElements(); i < k; i++) {
            outputs[1][i - 1] = teethSma[i];
        }
        for (i = 1, k = dLipsSmaResult.getNumberOfElements(); i < k; i++) {
            outputs[2][i - 1] = lipsSma[i];
        }       

        return new IndicatorResult(startIndex, i - 1);
        */
       
        return new IndicatorResult(startIndex, aOutLen);
    }


 
 Post subject: Re: JFOREX-2675 Java code optimization in indicators Post rating: 0   New post Posted: Mon 28 Feb, 2011, 13:22 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
Back-testing results have indicated only a small difference in performance. Alligator indicator did have some redundant code which has been refactored and optimized.


 

Jump to:  

  © 1998-2025 Dukascopy® Bank SA
On-line Currency forex trading with Swiss Forex Broker - ECN Forex Brokerage,
Managed Forex Accounts, introducing forex brokers, Currency Forex Data Feed and News
Currency Forex Trading Platform provided on-line by Dukascopy.com