Gamestudio Links
Zorro Links
Newest Posts
Script filename
by AndrewAMD. 08/24/19 18:52
Any Old Timers Still Around?
by pyramide. 08/24/19 18:23
Oanda FIFO issue?
by AndrewAMD. 08/24/19 12:10
IG plugin initial release
by Dalla. 08/24/19 06:06
Tutorial for Vector Graphics
by Dooley. 08/23/19 22:32
Issue with dataParse function
by byakuren81. 08/23/19 21:57
Multiplayer subscription
by Truth. 08/23/19 20:08
candle pattern on weekly bars
by AndrewAMD. 08/23/19 13:20
AUM Magazine
Latest Screens
The Space Between
Pogostuck: Rage With Your Friends
Worst Case Z
AckCon'18 - Lotter vs the World 2 - Preview Release
Who's Online Now
8 registered members (AndrewAMD, pyramide, 3run, MatPed, byakuren81, Realspawn, 2 invisible), 646 guests, and 7 spiders.
Key: Admin, Global Mod, Mod
Newest Members
Ysbail, trader4321, GorgonzolaBYTE, Southqvist, tawin
18272 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Unexpected behaviour with two loops over multiple assets #477900
08/12/19 23:18
08/12/19 23:18
Joined: Oct 2018
Posts: 23
J
JamesHH Offline OP
Newbie
JamesHH  Offline OP
Newbie
J

Joined: Oct 2018
Posts: 23
I need to loop twice over my assets to code a particular strategy, because the decision to enter short or long depends on the ranking of signals over the assets.

So, in the first loop an ML model is called to get estimated probabilities:

char* symbol;
int i = 0;
while(asset(symbol = loop(Assets))) {
Spread = RollLong = RollShort = Commission = Slippage = 0;

var signal = adviseLong(NEURAL, target[0], features, LookBack);
signals[i++] = signal;
}

Here I found that loop(Assets) and for(listed_assets) have different behaviour (I guess this is an example of "special parameter handling by loop"?), so I stick with the "standard" choice of loop(Assets).

Then the signal rankings are determined:

sortRank(ranks_01, signals, NumAssetsListed);

And a second loop decides whether to go long or short depending on the ranking:

i = 0;
for(listed_assets) {
asset(Asset);

int rank = ranks[i++];

... enterLong() or enterShort() if the rank is high or low enough, respectively ...
}

This works perfectly when I tried it with up to 50 assets. However, when I test with my full asset list of 448 symbols, the second loop does not work anymore. It makes calls to enterShort() but no short trades are taken.

Am I doing something wrong here?


Last edited by JamesHH; 08/12/19 23:29.
Re: Unexpected behaviour with two loops over multiple assets [Re: JamesHH] #477906
08/13/19 15:19
08/13/19 15:19
Joined: Jul 2000
Posts: 26,996
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 26,996
Frankfurt
Probably yes, but not with the loops. They look ok.

Re: Unexpected behaviour with two loops over multiple assets [Re: JamesHH] #477916
08/13/19 20:56
08/13/19 20:56
Joined: Oct 2018
Posts: 23
J
JamesHH Offline OP
Newbie
JamesHH  Offline OP
Newbie
J

Joined: Oct 2018
Posts: 23
Below is a complete MRE, except for the asset data. When run with just the first 50 assets, everything works fine. But when the full asset list is used only long positions are entered. The printf output confirms that enterShort() is being called even though no short positions are actually taken. Is there a problem with the MRE script?


#include <r.h>

vars signals, ranks_01;

/// m-period simple return, at t steps back in time
var simple_returns(int t, int m) {
return priceClose(t) / priceClose(t + m) - 1;
}

function run()
{
Script = "DeepLearn";
StartDate = 19930101;
EndDate = 19931231;
BarPeriod = 1440;
LookBack = 240;

NumWFOCycles = 1;
DataSplit = 75;

set(RULES+PEEK+LOGFILE);
LifeTime = 1;
if(Train) Hedge = 2;

if(is(INITRUN)) {
// All 448 assets
assetList("Assets.KDH.1993.csv");
// First 50 assets only
//assetList("Assets.50.1993.csv");
printf("\nNumAssetsListed: %d", NumAssetsListed);

signals = malloc(NumAssetsListed * sizeof(var));
ranks_01 = malloc(NumAssetsListed * sizeof(var));
}

vars target_returns = series(simple_returns(-1, 1));

char* symbol;
int i = 0;
while(asset(symbol = loop(Assets))) {
var signal = adviseLong(NEURAL, target_returns[0], simple_returns(0, 1), simple_returns(1, 1), simple_returns(2, 1));
signals[i++] = signal;
}

sortRank(ranks_01, signals, NumAssetsListed);

i = 0;
for(listed_assets) {
asset(Asset);

// Convert to an integer rank between 1 and NumAssetsListed
int rank = round(ranks_01[i++] * (NumAssetsListed - 1)) + 1;
//printf("\nrank: %d", rank);

if(rank == 1) {
printf("\nGoing short...");
enterShort();
}
if(rank == NumAssetsListed) {
printf("\nGoing long...");
enterLong();
}
}
}


Last edited by JamesHH; 08/13/19 20:57. Reason: typo
Re: Unexpected behaviour with two loops over multiple assets [Re: JamesHH] #477930
08/15/19 12:59
08/15/19 12:59
Joined: Jan 2019
Posts: 63
berlin
L
laz Offline
Junior Member
laz  Offline
Junior Member
L

Joined: Jan 2019
Posts: 63
berlin
This is just a guess, I have read something here, that could possibly fit.

You transfer here 448 parameters to a function (loop(Assets)), maybe jcl can clarify on whether this is still problematic or not?

I can not test your script, unfortunately I do not have so many assets or data from 1993.

Set Verbose higher, enable DIAG and debug deeper, use stepping for debugging with watch("!blabla"), look into the logfiles...

https://zorro-trader.com/manual/en/verbose.htm
http://manual.zorro-trader.com/watch.htm
https://zorro-trader.com/manual/en/trouble.htm

Zorro "normally" gives you a hint what goes wrong...

Last edited by laz; 08/15/19 13:15.
Re: Unexpected behaviour with two loops over multiple assets [Re: laz] #477941
08/16/19 18:39
08/16/19 18:39
Joined: Oct 2018
Posts: 23
J
JamesHH Offline OP
Newbie
JamesHH  Offline OP
Newbie
J

Joined: Oct 2018
Posts: 23
Thanks for your input.

Yes, that is very interesting. If too many parameters for the "Chinese compiler" is still an issue, I wonder if using MSVC with Zorro S could fix the problem? But yes, we need clarification from jcl or one of the Zorro engineers.

I could include data if it would help, but probably I should be making a support request if it comes to that.

So I set Verbose = 7 | DIAG as in the first suggestion, and there is something strange in the logs:

-----
[480: Thu 93-09-30 15:40] 31.16/31.16\30.71/30.84 -0.0100
Going short...
[43851610::S] Skipped (outside bars 481..543)
Going long...
[46069010::L] Skipped (outside bars 481..543)
End of lookback period

[481: Fri 93-10-01 15:40] 30.84/31.03\30.77/30.90 -0.0100
Going short...
[74763310::S] Skipped (outside bars 481..480)
Going long...
TRD: 64 MB allocated
[23331110::L8101] Long 1@30.24 at 15:40:00
Com 0.0100 Mrg 15.13 Net 0
Units 1.0000 MTotal 0.00 MCost 15.1250 PCost 0.01000 Opn 481
-----

In the first bar after the lookback period, bar 481, we can see that the short position is skipped because it is outside the range 481..480. This looks like a bug in Zorro to me, but I'm just a newbie at Zorro.


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