Gamestudio Links
Zorro Links
Newest Posts
Data from CSV not parsed correctly
by EternallyCurious. 04/18/24 10:45
StartWeek not working as it should
by Zheka. 04/18/24 10:11
folder management functions
by VoroneTZ. 04/17/24 06:52
lookback setting performance issue
by 7th_zorro. 04/16/24 03:08
zorro 64bit command line support
by 7th_zorro. 04/15/24 09:36
Zorro FIX plugin - Experimental
by flink. 04/14/24 07:48
Zorro FIX plugin - Experimental
by flink. 04/14/24 07:46
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
4 registered members (ozgur, EternallyCurious, howardR, 1 invisible), 623 guests, and 0 spiders.
Key: Admin, Global Mod, Mod
Newest Members
EternallyCurious, 11honza11, ccorrea, sakolin, rajesh7827
19046 Registered Users
Previous Thread
Next Thread
Print Thread
Rating: 5
Page 2 of 3 1 2 3
Re: Backtesting with T1 data and variable spread [Re: CaptainChezza] #463721
12/22/16 15:11
12/22/16 15:11
Joined: May 2016
Posts: 180
Prague
pcz Offline OP
Member
pcz  Offline OP
Member

Joined: May 2016
Posts: 180
Prague
Originally Posted By: CaptainChezza
Is FXCM T1 data that reliable, or is it worth using duka.


I don't know. I use Dukas because I'm used to them. Also because I know that the results obtained on their data correlate well with our broker's data. Last but not least they provide long enough history.

Originally Posted By: CaptainChezza

Futher, I'm definitely a noob with this, but where do you include in the your py script the csv file name?


I'm using new scripts now. I'll link them in the following post and explain how to use them. After that you can ask if you have any more questions.

Re: Backtesting with T1 data and variable spread [Re: pcz] #463722
12/22/16 16:17
12/22/16 16:17
Joined: May 2016
Posts: 180
Prague
pcz Offline OP
Member
pcz  Offline OP
Member

Joined: May 2016
Posts: 180
Prague
The new scripts are intended for batch conversion so you can run it on multiple files exported using Tick Downloader with no additional user input. It's more convenient because sometimes the conversion of multiple symbols can take hours or even days. Again I'm using Cygwin to run it. You must have python installed. You can check by running 'which python' command. If it doesn't return a python path, something is wrong.


How to use it - the short version

1. Save conversion bash script and python script into a folder. Edit history_path and zorro_path variables in convert.sh file and set them accordingly. The first variable is the path to the folder containing .csv files with tick data (exported using Tick Downloader).
2. Save T1 data conversion and T6 data conversion scripts in Zorro/Strategy folder and modify the basePath variable. It should be set to the same path as history_path in convert.sh but in Windows path notation style.
3. Run ./convert -p x, where x is the desired period of the converted data in minutes. -p 0 will produce T1 data, -p 1 will produce M1 T6 data with spread stored in fVal variable; higher periods don't work yet.


How to use it - the long version

The first file is a conversion bash script. It's important to edit it and set these two variables correctly: history_path and zorro_path. The first is a path of the folder containing tick data .csv files exported using Tick Downloader (by default they have names like EURUSD_tick.csv etc.). It shouldn't contain any other files otherwise unexpected things might happen laugh Folders are fine. The second variable is a path of the folder containing Zorro executable.

In the same folder as the previously mentioned script you should put this python script used for data preprocessing. It will be called automatically.

Then there are two Zorro strategies, one used for T1 data conversion and one for T6 data conversion. They belong to Zorro/Strategy folder. You have to edit them and set basePath variable correctly (should be the same folder as the previously mentioned history_path but in Windows notation style).

You can run the bash script for example like this:
Code:
./convert.sh -p 0


The first parameter is the desired period of the converted data. If you set it to 0 the conversion script will produce tick data in T1 format. If #define SPREAD directive is defined in the strategy file, two files will be created - one for ask and one for bid prices.

If you set -p to 1 it will produce M1 data in T6 format. Spread for opening price is stored in fVal variable. Higher periods don't work yet laugh

You can use T1 export script to check the converted T1 prices. For T6 you can use the script included in Zorro.

The whole thing has been tested but not very thoroughly, it's an ongoing work. So if you find a bug please let me know.


How it works

The bash script loads list of files in history_path folder. Then it loops through them and calls python script with given parameters on each of them.

The python script reverses the line order of each file, splits them by year and for periods greater than 0 it converts the tick data to OHLC with opening price spread stored in the last column.

After that the bash script takes over again and loads the list of newly split files. It stores the first and the last available year together with each symbol. After that it calls Zorro with these arguments to convert the .csv files to .t1 or .t6 files depending on the chosen period.


Some final warnings

- Don't trust the scripts unless you check the converted data yourself
- Don't use special distributions of Python (e.g. Anaconda) in Cygwin for this task. It might complicate things.
- Don't use periods higher than 1
- Timestamps can be shifted using -s parameter but it works only for T6 data

EDIT: T6 Zorro script fixed (wrong variable names)

Last edited by pcz; 12/23/16 16:22.
Re: Backtesting with T1 data and variable spread [Re: pcz] #464368
02/07/17 15:06
02/07/17 15:06
Joined: May 2016
Posts: 180
Prague
pcz Offline OP
Member
pcz  Offline OP
Member

Joined: May 2016
Posts: 180
Prague
I simplified everything. I even tried to do the tick conversion using only Zorro but the implementation was slow so I'll stick with the combination of Python and Zorro. I've also tried two new approaches which do not use the 'tac' command. They are slower but if you want to run the script on Windows without using Cygwin, it might help.

The Bash script and Python script are now merged into one: convert.py (it made sense to make it like this from the beginning but I wasn't that proficient in Python)

The two Zorro scripts for T1 and T6 data were also merged: ConvertData.c

The usage is similar, you can find more info here - you can skip directly to the "Usage" section.

After the initial setup it's possible to convert all .csv data for various assets to T1 and T6 formats (containing spread) using just one command. But please note the assets have to be present in AssetsFix file.

Re: Backtesting with T1 data and variable spread [Re: pcz] #464610
03/01/17 11:07
03/01/17 11:07
Joined: Apr 2014
Posts: 482
Sydney, Australia
B
boatman Offline
Senior Member
boatman  Offline
Senior Member
B

Joined: Apr 2014
Posts: 482
Sydney, Australia
Thanks pcz, this looks really useful.

Re: Backtesting with T1 data and variable spread [Re: boatman] #465021
03/27/17 12:12
03/27/17 12:12
Joined: May 2016
Posts: 180
Prague
pcz Offline OP
Member
pcz  Offline OP
Member

Joined: May 2016
Posts: 180
Prague
I've made some small modifications to the scripts and nothing changes regarding T1 data but I recommend re-creating all T6 data from scratch. There are two reasons for that:
  • The previous version of the conversion script stored opening tick spread in fVal variable while Zorro uses the previous bar's closing price for trade entry. So now the closing tick spread is stored instead.
  • The timestamps of T6 minute bars are now shifted by a minute. My understanding of the issue is that because FXCM's opening / closing prices are overlapping the candles' minute boundaries Zorro uses closing price of H:M:00 candle for entry / exit at the time H:M:00 while with T1 data it uses the previous candle (M-1). Therefore with (non-overlapping) data from other sources the trade entries / exits are up to 60 seconds late which is unnecessary and in certain situations it can create big differences in test results. For more information see this thread: Why are T1 and T6 results so different? (no SL/PT/Slippage...)

If you use the FXCM data downloaded from Zorro's website I recommend re-creating the T6 files as well either using Zorro's T1 data or using tick data downloaded from FXCM.

The good news is that with these changes you should be able to achieve exactly the same test results using T1 and T6 data if you enter / exit at the end of M1 (or higher period). If you use stop loss, profit targets or something like that the results might still differ.

Here's the modified Python script: convert.py
Plus the modified Zorro script: ConvertData.c

Re: Backtesting with T1 data and variable spread [Re: pcz] #466771
07/01/17 19:01
07/01/17 19:01
Joined: Jun 2017
Posts: 78
B
BobbyT Offline
Junior Member
BobbyT  Offline
Junior Member
B

Joined: Jun 2017
Posts: 78
Hi pcz,

I am having some problems with the scripts. Specifically, the zorro script seems to be the problem. Tick files are successfully reversed by the python script, zorro is opened, the ConvertData script is called and then Cygwin just hangs.
I tried letting it run overnight but it did not complete.

Can we attach images here somehow so I can post a screenshot of cygwin?

Regardless, this is the output in the cygwin terminal:
$ python convert.py
Period: [0, 1], Time shift: 0, Price to use: ask
convert_all_files
E:/FxData_tickstory/AUDCHF_tick.csv
Reversing file lines...
E:/FxData_tickstory/AUDCHF_2017.csv
D:/Users/BobTewilliger/Zorro/Zorro.exe ConvertData -run -i 2017 -i 2017 -a AUD/CHF -d TCK
E:/FxData_tickstory/AUDCHF_2017.csv
D:/Users/BobTewilliger/Zorro/Zorro.exe ConvertData -run -i 2017 -i 2017 -a AUD/CHF

I'm running windows 7, 6700k, 16gb ram (so it shouldn't be a memory issue). Python v3.6, most recent cygwin (downloaded week beginning 26th June), Zorro v1.58. I've been testing the scripts on the past months worth of data for efficiency reasons though using a year or twos worth of data results in the same thing, it just hangs.

Cheers,
BobbyT

Last edited by BobbyT; 07/01/17 19:04.
Re: Backtesting with T1 data and variable spread [Re: BobbyT] #466772
07/01/17 19:08
07/01/17 19:08
Joined: Jun 2017
Posts: 78
B
BobbyT Offline
Junior Member
BobbyT  Offline
Junior Member
B

Joined: Jun 2017
Posts: 78
Please disregard the above message. The scripts have magically completed following another attempt (in which I did nothing different, so, weird).

A new problem has arisen though. There are no new t1/t6 files for the tested symbol in zorro/history. This is where ConvertData is meant to save the converted right?

Cheers,
BobbyT

PS: just ran a test again with the past months worth of data on a single symbol. It seems to be hanging again. Am I right in thinking this shouldn't be taking more than 30minutes to convert 1 months worth of data for a single symbol?

Last edited by BobbyT; 07/01/17 19:24.
Re: Backtesting with T1 data and variable spread [Re: BobbyT] #466781
07/02/17 10:58
07/02/17 10:58
Joined: Jul 2017
Posts: 3
S
Smile Offline
Guest
Smile  Offline
Guest
S

Joined: Jul 2017
Posts: 3
PCZ , hello.
when you finish your *.t1 and *s.t1 files, during backtesting, the sell / stop sell order,
which price will be trade? is it ask(in t1 file) - spread(in assets file) ?

the *s.t1 file, how to show its useful?

Last edited by Smile; 07/02/17 11:01.
Re: Backtesting with T1 data and variable spread [Re: Smile] #466782
07/02/17 15:51
07/02/17 15:51
Joined: Jun 2017
Posts: 78
B
BobbyT Offline
Junior Member
BobbyT  Offline
Junior Member
B

Joined: Jun 2017
Posts: 78
So, a little update.

After adding copious print statements to everything there seems to be an issue with the way the zorro script is called. I have no idea what it is as I'm in way over my head here (interfacing two unfamiliar languages/platforms).

But I can say that calling either convert.sh/ConvertT6.c or convert.py/ConvertData.c separately gets the job done (although the t6 files are saved to the tick directory and not zorro/history). At this stage I will be using the 2-part script process as the combined bash/python script locks cygwin from any further operations whereas convert.sh terminates properly and frees up the cygwin terminal.

Cheers,
BobbyT

Re: Backtesting with T1 data and variable spread [Re: BobbyT] #466800
07/03/17 09:41
07/03/17 09:41
Joined: Jul 2000
Posts: 27,978
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,978
Frankfurt
Check if Zorro is not started _before_ the convert.py script has finished. Otherwise the source file does not exist yet, or can not be accessed since another program is writing into it.

Page 2 of 3 1 2 3

Moderated by  Petra 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1