Gamestudio Links
Zorro Links
Newest Posts
Sam Foster Sound | Experienced Game Composer for Hire
by titanicpiano14. 03/20/23 17:51
Strange error messages in for-loops
by AndrewAMD. 03/20/23 16:21
How can convert mdl7 with UV's?
by l1ve10. 03/20/23 16:13
Asset list - Market Column
by MatPed. 03/20/23 08:44
working with Futures
by logomon. 03/18/23 23:21
AUM Magazine
Latest Screens
SHADOW (2014)
DEAD TASTE
Tactics of World War I
Hecknex World
Who's Online Now
5 registered members (AndrewAMD, YesNotes, paulk, titanicpiano14, l1ve10), 1,389 guests, and 3 spiders.
Key: Admin, Global Mod, Mod
Newest Members
YesNotes, DonQuijote, cokibor, stilrz, unatrader
18906 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
working with Futures #486032
06/02/22 11:25
06/02/22 11:25
Joined: May 2022
Posts: 2
London
L
logomon Offline OP
Guest
logomon  Offline OP
Guest
L

Joined: May 2022
Posts: 2
London
I am interested to try testing and trading Zorro on Futures (via Interactive Brokers).
I have looked around the code examples, and the manual page for the contract functions, which give some nice examples of the functionality for options.

However, I can see that the way of working with futures must be slightly different - e.g. in the example AssetsIB.csv, it looks like each futures contract expiry must be specified as a separate asset (e.g. Jul wheat and Dec wheat).
So this is different from the options case, where we specify an underlying and IB will return the full chain/surface in one shot.
I.e. we cannot equivalently obtain the "chain" of e.g. wheat futures for all future months, and must query each contract individually?

Is there any canonical example of how to work with futures, in a strategy that may need to "roll" from one contract to the next as expiry approaches?
Is it true that we must "manually" add into the AssetsIB the name of each specific contract that we need - so that to backtest a wheat strategy we add every monthly contract name for the backtest period?

Likewise, is there any example for parsing the historical Futures price data from csv (as obtained from e.g. barchart.com), into the .t8 format (this is recommended better than .t6 for Futures?).
I can see the nice example for options but suspect the Futures case is not identical. If we already must treat each contract separately, is there any advantage to using .t8?


Massive thanks for the amazing tool that is Zorro - I'm sure there are very smart ways to do the above, so asking now before I try to reinvent the wheel!

Re: working with Futures [Re: logomon] #486039
06/03/22 06:31
06/03/22 06:31
Joined: Jul 2000
Posts: 27,933
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,933
Frankfurt
The examples are mostly for options chains, but work similar for chains of futures. Sometimes it's a bit tricky to find the correct underlying symbol especially with commodities. For rolling, simply buy a new position at expiration.

CSV formats are all different, so the conversion to .t8 must be individually adapted. We have a service for that, but you can normally also program it yourself. Use dataParse() with an adapted format string.

Re: working with Futures [Re: logomon] #487128
01/25/23 11:07
01/25/23 11:07
Joined: Jan 2023
Posts: 15
Q
qin Offline
Newbie
qin  Offline
Newbie
Q

Joined: Jan 2023
Posts: 15
do we need only add commodity undelyings in the AssetsIB.csv? Or do we add all contracts in the csv?

Re: working with Futures [Re: logomon] #487328
03/18/23 23:21
03/18/23 23:21
Joined: May 2022
Posts: 2
London
L
logomon Offline OP
Guest
logomon  Offline OP
Guest
L

Joined: May 2022
Posts: 2
London
I am revisiting my efforts to set up a futures trading script, and getting some unexpected behaviour - I wonder if anyone can give me a hint? :

When running a backtest I get a strange inconsistency between the entry/exit prices announced in the log at the point the trade is opened/closed, and the values that end up in the final results.

E.g. for first trade of the run, testtrades.csv shows:
Name,Type,Asset,ID,Lots,Open,Close,Entry,Exit,Profit,Roll,ExitType
MyStrategy,Short,LH-FUT-19980715-,38709,250,1998-07-09 16:30,1998-07-10 16:30,53.22,53.22,-0.63,0.00,Reverse

i.e. identical entry and exit prices!

However, the relevant log messages do show the trade was entered and exited at two different prices:
[LH-FUT::SF38709] Short 1941@53.22 Bid 53.22 at 16:30:00 Thu
Com 4.85 Mrg 41331301 Net 0
...
[LH-FUT::SF38709] Cover % 250@52.32: -0.63 at 23:00:00 Wed
Opn 53.22 Cls 53.22 Spr 0.0 Slp -3272789.75 Rol 0.00 Com 4.23 Lif 1 Net -1941


So even though the log recognises entry @ 53.22 and exit @ 52.32, the "Opn" and "Cls" prices that ultimately get recorded are identical, and indeed the stats, chart etc all reflect this (i.e. the only pnl I see is cumulative commissions).

I am calling contractUpdate for every asset on each run(), is there something more I need to do to propagate the correct prices?


Moderated by  Petra 

Powered by UBB.threads™ PHP Forum Software 7.7.1