Dukascopy
 
 
Wiki JStore Search Login

Attention! Read the forum rules carefully before posting a topic.

    Try to find an answer in Wiki before asking a question.
    Submit programming questions in this forum only.
    Off topics are strictly forbidden.

Any topics which do not satisfy these rules will be deleted.

faster strategy tester
 Post subject: faster strategy tester Post rating: 0   New post Posted: Wed 03 Nov, 2010, 00:27 

User rating: 0
Joined: Tue 28 Sep, 2010, 09:41
Posts: 18
Hello,

I would like to post my idea how to make the strategyTester in JForex faster.

I will describe an example how I mean that..:
When user is testing his strategies in JForex he has to select instrument(s), and timeframe of the historical data.
Imagine user is testing some scalping strategy, which is doing the main loginc and calculations and decisions on close of every hour.
So the main logic needs to be calculated just at the end of every hour. And also the used indicators values are from 1Hour timeframes.
So in this case user can run the strategyTester on 1Hour historical data. The test will run fast!

Fast test is good, but we also need the test accurate! So everytime during the test, when strategy will open some position, the strategyTester will switch to Tick timeframe until the position will be closed - this will make the simulation accurate and valueable.


So the point is: Users has strategies, which are sufficient when they are simulated on 1Hour timeframe of historical data.
I mean lot of strategies where all the used indicators and values are calculated just once per hour, at the end of hour.
But the users NEED to have the results of the tests accurate.
So the solution is: Run the strategy in timeframe which user will choose (in this case 1Hour) and everytime when there will be any position created in the simulation, switch the simulation into Tick timeframe (it will make the results of the test accurate) until the position will close. Right after then swich the simulation again to the user's choosen timeframe (it will make the simulation fast).

Could you please implement the strategyTester like that?
Thank you


 
 Post subject: Re: faster strategy tester Post rating: 0   New post Posted: Wed 03 Nov, 2010, 10:18 
User avatar

User rating: 3
Joined: Wed 18 May, 2011, 16:25
Posts: 331
Location: SwitzerlandSwitzerland
Hi ZOOinek,

why don't you simply implement this tick-filter yourself?
Run the backtesting on ticks.
In onTick test for open trades. If there is an open trade, process the tick, otherwise skip the processing.
In onBar check for the 1H bar and perform your trade-entry conditions.

Best, RR.


 
 Post subject: Re: faster strategy tester Post rating: 0   New post Posted: Wed 03 Nov, 2010, 10:25 
User avatar

User rating: 3
Joined: Wed 18 May, 2011, 16:25
Posts: 331
Location: SwitzerlandSwitzerland
in addition, this should also help to speed up your backtesting:
https://www.dukascopy.com/swiss/english/forex/jforex/forum/viewtopic.php?f=5&t=24099


 
 Post subject: Re: faster strategy tester Post rating: 0   New post Posted: Wed 03 Nov, 2010, 13:56 

User rating: 0
Joined: Tue 28 Sep, 2010, 09:41
Posts: 18
Hello,

thanks for your suggestions but I am afraid I already did it before, and it is still very slow.

My strategy is based on multi-instrument indicators from GBPUSD and EURUSD. (For example correlation is one of them).
Strategy calculates correlation index between GBPUSD and EURUSD, on 1Hour timeframe.
Based on the calculated values strategy decide if to open some position.

So the code of my strategy, has no application logic implemented in onTick() method. Because strategy dont need react on every tick. So the onTick() method is empty!
I implemented all the calculations and decisions into this:

public void onBar(Instrument instrument, Period period, IBar askBar, IBar bidBar) throws JFException {
    if (instrument==Instrument.EURUSD && period.equals(Period.createCustomPeriod(Unit.Minute, 60))) {
        ...calculate the correlation index with this indicator https://files.lorencsoftware.cz/200000072-19d941ad37/LS_I_DirectionalCorrelation_vs_GBPUSD.java ...
        ... decide if open position...
        ... engine...opening position etc...
    }
}



So my strategy is waiting for close of every 1Hour bar and then is calculating and doing everythig.
If the correlations at the end of hour are good, strategy will open position and set StopLoss and TakeProfit.


But when I am testing this strategy on 1Hour historical data, the closePrices of the positions are not correct with the TakeProfits and StopLosses... as you know - it is not accurate.
So I need to test it on Tick data.

And yes, strategy is not doing anything after onTick. Strategy is calculating only after 1Hour bar.
But still the backtest is slow it takes something around 6hours!
It is because even strategy is not reacting on the ticks inside of 1Hour bar, the ticks are simulated and this takes some time.
There is no code for the ticks, but they are simulated and that makes the backtest slow.

It would be perfect like this.
Strategy tester will simulate ONLY 1Hour bars.
At the end of this bar my strategy has the calculations - the correlation index and the is decides if to open position.
After new position is open, strategyTester will simulate every tick (this will make the simulation results accurate).
After position is closed (StopLoss or TakeProfit), strategyTester will simulate againg just 1Hour bars.


So you know what I mean...
Yes you are right with your idea - do not calculate any application logic at every tick, when it is not needed for the strategy.
But I am saying also to NOT SIMULATE every tick in the strategyTester, when it is not needed.


 
 Post subject: Re: faster strategy tester Post rating: 0   New post Posted: Thu 04 Nov, 2010, 09:12 
User avatar

User rating: 3
Joined: Wed 18 May, 2011, 16:25
Posts: 331
Location: SwitzerlandSwitzerland
Hi ZOOinek,

ok, I understand.
I'm wondering why your backtesting is so slow.

If you run an empty strategy (no onBar-code, no onTick-code, ...) with messages, visual mode, equity, P/L and balance switched off, how long will it take to process your complete backtesting period?

Visual mode, equity, p/l, balance or messages may slowdown your backtesting significantly. We have everything switched off and log all we need for later analysis of the runs to files and databases.

If you have visual mode on, do you have indicators added to your charts while running the backtesting? If so, remove them, they might also slow down your run significantly.

Also, see how much percent of the processing time of the strategy is used up by your onBar-logic by including a timer-variable that adds up all onBar processing times.

Last but not least, do you have the "Show Java Memory heap" switched on? At the end of the run, when you click on the garbage collection icon, how much ram does the client free up and how much is still used at the end? If you can't free up most of the ram, a memory leakage problem would be the cause for the slow backtesting.

Best, RR.


 
 Post subject: Re: faster strategy tester Post rating: 0   New post Posted: Fri 05 Nov, 2010, 15:28 

User rating: 0
Joined: Tue 28 Sep, 2010, 09:41
Posts: 18
Hello
so here is some news...

Now the backtest of my strategy, which is working with two instruments tesed on data from 2007.05.01 till 2010.10.31 take 1hour 30minutes. I think its good.
I have optimized the test to reach so short time required to test:
- no calculations in onTick method, everthing is in onBar method
- onBar method has filters, every calculations are accessable just for needed instrument and period
- I dont use VisualMode (this is unfortunately very time consuming for backtests - but that is understable)
- the calculation time of onBar method is just few milliseconds

So now the tests of my strategy takes almoust the same time like test of empty strategy.


But now - great idea how to make it really much more faster.
I thing that the re-displaying the infos in the progressBar (see picture to understand what I mean) is taking very long time.
There should be possible to set-up in JForex preferences to NOT REFRESH the informations in the progressBar in strategyTester.
Because there is thousands of changes per second and the re-displaying them is slowing whole simulation.

To prove my idea, take a look at this example.

package test;

import java.util.Date;

public class Main {

    public static void main(String[] args) {
        long startTime = 0;
        long endTime = 0;
        long difference = 0;
        int i = 0;
        for (i = 0; i<Integer.MAX_VALUE; i++) {
            if (i==0) {
                startTime = new Date().getTime();
            }
            System.out.println(i);  // TRY TO DELETE THIS ROW, IT WILL BE MUCH MUCH MORE FASTER !!!
            endTime = new Date().getTime();
            difference = endTime - startTime;
            if (difference>5000) {
                break;
            }
        }
        System.out.println(i);
    }

}

This is very simple java program, which simulates the iteration - cycles.
This program will tell you, how many cycles can do in 5seconds and DISPLAY number of current cycle in every cycle.
Try to run that program and you will see it can do more than 40thousands of cycles in 5 seconds. (results from my pc)

And now the point: remove the row which is displaying the new information every cycle and run the program.
You will see it can make more than 100milions of cycles in the 5 seconds!!!

So that means, that the re-displaying of the informations per every cycle, is very time consuming for program.
If it will be possible to disable the refreshing in the progressBar of StrategyTester, lot of users will have much more faster simulations.

Is it possible to implement this feature into JForex? To give the users opportunity to disable the refreshing of progressBar in StrategyTester..?

Thank you
Have a nice day
ZOOinek


Attachments:
pic0.jpg [60.76 KiB]
Downloaded 517 times
DISCLAIMER: Dukascopy Bank SA's waiver of responsability - Documents, data or information available on this webpage may be posted by third parties without Dukascopy Bank SA being obliged to make any control on their content. Anyone accessing this webpage and downloading or otherwise making use of any document, data or information found on this webpage shall do it on his/her own risks without any recourse against Dukascopy Bank SA in relation thereto or for any consequences arising to him/her or any third party from the use and/or reliance on any document, data or information found on this webpage.
 
 Post subject: Re: faster strategy tester Post rating: 0   New post Posted: Sat 06 Nov, 2010, 10:55 
User avatar

User rating: 3
Joined: Wed 18 May, 2011, 16:25
Posts: 331
Location: SwitzerlandSwitzerland
Hi ZOOinek,

great to hear you could speed up your backtesting significantly!

Yes, every output is slowing down the process.
As far as I understand, DukasCopy is only updating the historical tester's progress bar every so often. In earlier versions it was updated on the 30 minutes, now it is about every 5-10minutes or so.
I'm not sure if that is really dragging the performance significantly.

But for sure DukasCopy could perform an internal benchmark tests with updating the progress bar switched on and off, just to see the effect. Should it have any significant effect, it might be useful to add a parameter for setting the update-intervals of the progress bar and time-to-finish fields.

Best, RR.


 
 Post subject: Re: faster strategy tester Post rating: 0   New post Posted: Sat 06 Nov, 2010, 13:17 

User rating: 0
Joined: Tue 28 Sep, 2010, 09:41
Posts: 18
RoadRunner wrote:
As far as I understand, DukasCopy is only updating the historical tester's progress bar every so often. In earlier versions it was updated on the 30 minutes, now it is about every 5-10minutes or so.


I dont understand what you mean..? :)
I was talking about the refreshing the text in the inside bar.
"Running, yyyy.mm.dd hh:mm Eq:xxxx UoL: xx%"

When you are running your backtest the text of date (yyyy.mm.dd hh:mm) is refreshing many times per second, because it is informing you which date and time is simulating by the StrategyTester.
And this re-displaying (re-drawing) of the output is very very time-consuming for program. Even much more you can think.

Thats the same like my example program posted in previous post.
You see that when program is drawing some output to the screen in every cycle, there is just 40thousand of cycles per 5 seconds.
But when you disable the drawing the output to screen in every cycle, after 5 seconds it can go throught 100milions of cycles per 5 seconds.

The re-drawing of the text information in the JProgressBar is the problem, really try it.

I suggest to implement new feature into JForex - to allow users to enable/disable text in the JProgressBar in StrategyTester.


Btw. RoadRunner you are from Dukascopy support or development or you are user..?


 
 Post subject: Re: faster strategy tester Post rating: 0   New post Posted: Mon 08 Nov, 2010, 08:27 
User avatar

User rating: 3
Joined: Wed 18 May, 2011, 16:25
Posts: 331
Location: SwitzerlandSwitzerland
Hi ZOOinek,

Sorry, I was a bit quick with my answer the last time. I've had another look. You are right, the text inside the progress bar is now updating a lot more often compared to earlier versions. In earlier versions DK updated the text only on the half hour bar, but meanwhile it's very frequently.

Yes, I think that update frequency is not needed and could get reduced drastically to not use up too much time.
Either including an update period that could be set by the user or setting the update frequence back to the half hour bar would both sound good to me.

Best, RR.

PS: No, I'm not from DK. ;)
We are a team developing our own strategies.


 

Jump to:  

cron
  © 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