Gamestudio Links
Zorro Links
Newest Posts
Blobsculptor tools and objects download here
by NeoDumont. 03/28/24 03:01
Issue with Multi-Core WFO Training
by aliswee. 03/24/24 20:20
Why Zorro supports up to 72 cores?
by Edgar_Herrera. 03/23/24 21:41
Zorro Trader GPT
by TipmyPip. 03/06/24 09:27
VSCode instead of SED
by 3run. 03/01/24 19:06
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
2 registered members (Imhotep, opm), 785 guests, and 4 spiders.
Key: Admin, Global Mod, Mod
Newest Members
sakolin, rajesh7827, juergen_wue, NITRO_FOREVER, jack0roses
19043 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 1 of 2 1 2
SIGNALS file not being generated #477515
07/03/19 21:36
07/03/19 21:36
Joined: Oct 2018
Posts: 72
J
JamesHH Offline OP
Junior Member
JamesHH  Offline OP
Junior Member
J

Joined: Oct 2018
Posts: 72
When I set PEEK, and define a series that peeks ahead (for the target variable of course), then in some cases adviseLong with SIGNALS does not generate the signals file.

For example, in the following script (also attached) the median return one bar ahead over all assets is calculated in the variable cross_section_median. No signal files are output. However,
if I comment out the definition of cross_section_median then I get a signals file for each asset.

Is this a bug?


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

/// cross-section median of m-period simple returns, at s steps ahead
var median_cross_section_returns(int s, int m) {
vars cross_section = malloc(NumAssetsListed * sizeof(var));

int i = 0;
while(asset(loop(Assets))) {
cross_section[i++] = simple_returns(-s, m);
}

var result = Median(cross_section, NumAssetsListed);

free(cross_section);

return result;
}

function run()
{
StartDate = 19900101;
EndDate = 19931231;
BarPeriod = 1440;
LookBack = 240;

NumWFOCycles = 1;
DataSplit = 75;

assetList("Assets.2.1993.csv");
set(RULES+PEEK);
Spread = RollLong = RollShort = Commission = Slippage = 0;
LifeTime = 1;
if(Train) Hedge = 2;

//vars next_return = series(simple_returns(-1, 1));
vars cross_section_median = series(median_cross_section_returns(1, 1));

char* symbol;
while(asset(symbol = loop(Assets))) {
adviseLong(SIGNALS, 0, simple_returns(1, 1), simple_returns(2, 1), simple_returns(3, 1));
enterLong();
}
}

Attached Files
script.c (0 downloads)
Last edited by JamesHH; 07/03/19 21:38.
Re: SIGNALS file not being generated [Re: JamesHH] #477518
07/04/19 06:39
07/04/19 06:39
Joined: Jul 2000
Posts: 27,977
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,977
Frankfurt
This code will probably eat all available memory and then crash.

Re: SIGNALS file not being generated [Re: jcl] #477527
07/04/19 14:22
07/04/19 14:22
Joined: Oct 2018
Posts: 72
J
JamesHH Offline OP
Junior Member
JamesHH  Offline OP
Junior Member
J

Joined: Oct 2018
Posts: 72
No, it won't even start. If I run it with NEURAL instead of SIGNALS, the code exits before neural.init() is called.

So, what is the proper way to calculate the cross section median of the returns one bar ahead?

Re: SIGNALS file not being generated [Re: JamesHH] #477530
07/04/19 14:55
07/04/19 14:55
Joined: Jul 2000
Posts: 27,977
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,977
Frankfurt
I don't know, but run it in test mode and check the log - there you can proably see why it does not train. Also, better remove the malloc. Functions like malloc are resource heavy. You normally use them only at initialization, not at any bar.

Re: SIGNALS file not being generated [Re: JamesHH] #477536
07/04/19 18:21
07/04/19 18:21
Joined: May 2015
Posts: 390
Czech Republic
G
Grat Offline
Senior Member
Grat  Offline
Senior Member
G

Joined: May 2015
Posts: 390
Czech Republic
you are have data for symbol between 1990 and 1993?

StartDate = 19900101;
EndDate = 19931231;

Re: SIGNALS file not being generated [Re: Grat] #477556
07/05/19 21:16
07/05/19 21:16
Joined: Oct 2018
Posts: 72
J
JamesHH Offline OP
Junior Member
JamesHH  Offline OP
Junior Member
J

Joined: Oct 2018
Posts: 72
Originally Posted by Grat
you are have data for symbol between 1990 and 1993?

StartDate = 19900101;
EndDate = 19931231;


Yes. Of course, backtests on that data are not very meaningful for future trading laugh

Re: SIGNALS file not being generated [Re: jcl] #477557
07/05/19 21:25
07/05/19 21:25
Joined: Oct 2018
Posts: 72
J
JamesHH Offline OP
Junior Member
JamesHH  Offline OP
Junior Member
J

Joined: Oct 2018
Posts: 72
Originally Posted by jcl
I don't know, but run it in test mode and check the log - there you can proably see why it does not train. Also, better remove the malloc. Functions like malloc are resource heavy. You normally use them only at initialization, not at any bar.


Thanks for the tip on malloc.

It turns out the problem was the way I was using the loop function. I was looping once to calculate the indicator, and then trying to loop again. However, following the manual which suggests using either for(listed_assets), for(used_assets) or a for-loop, I get some unexpected results:

1. for(listed_assets) produces the SIGNALS files correctly (one for each symbol), but it give me the error: "Error 015: invalid advise signal[0] at bar 251"
2. for(used_assets) gives the same SIGNALS files and no error.
3. the for-loop results in each signal repeated twice in the SIGNALS files.

Any insights on why I am seeing this, or what the correct approach is here? Here is the test code for this issue:

/// 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()
{
StartDate = 19900101;
EndDate = 19931231;
BarPeriod = 1440;
LookBack = 240;

NumWFOCycles = 1;
DataSplit = 75;

assetList("Assets.2.1993.csv");
set(RULES+PEEK);
Spread = RollLong = RollShort = Commission = Slippage = 0;
LifeTime = 1;
if(Train) Hedge = 2;

// This initialize the assets
while(asset(loop(Assets))) {
}

char* symbol;
int i;
// #1:
//for(listed_assets) {
// #2:
for(used_assets) {
// #3:
//for (i = 0; symbol = Assets[i]; i++) {
adviseLong(SIGNALS, 0, simple_returns(1, 1), simple_returns(2, 1), simple_returns(3, 1));
enterLong();
}
}

Re: SIGNALS file not being generated [Re: JamesHH] #477558
07/06/19 07:32
07/06/19 07:32
Joined: Sep 2003
Posts: 929
Spirit Offline

Moderator
Spirit  Offline

Moderator

Joined: Sep 2003
Posts: 929
I think its the other way round, you must use loop() for the advise calls. I dont understand why you use 2 loops. Invalid signal probably means you divide by zero.

https://manual.zorro-project.com/loop.htm

Re: SIGNALS file not being generated [Re: Spirit] #477560
07/06/19 19:24
07/06/19 19:24
Joined: Oct 2018
Posts: 72
J
JamesHH Offline OP
Junior Member
JamesHH  Offline OP
Junior Member
J

Joined: Oct 2018
Posts: 72
Originally Posted by Spirit
I think its the other way round, you must use loop() for the advise calls. I dont understand why you use 2 loops. Invalid signal probably means you divide by zero.

https://manual.zorro-project.com/loop.htm


I will try the other way around. Of course I read the manual (as I mentioned previously), but these function calls are not fully defined.

As for two loops, I don't see how else this could possibly be done? I need an indicator which is calculated over all assets, so presumably I need a loop to define the indicator. The indicator must be defined before the advise calls which are done in a second loop.

Thanks, I will check if divide by zero could be happening, but I still don't understand the difference between for(listed_assets) and for(used_assets) after reading the manual.

Re: SIGNALS file not being generated [Re: JamesHH] #477562
07/07/19 06:09
07/07/19 06:09
Joined: Oct 2018
Posts: 72
J
JamesHH Offline OP
Junior Member
JamesHH  Offline OP
Junior Member
J

Joined: Oct 2018
Posts: 72
After making the corrections shown below everything is fine.

I used loop() for the advise calls as Spirit suggested. Though I'm not sure it's necessary, it is obviously better code. The main thing though was that I needed to explicitly call asset() in the for(listed_assets) loop:


vars cross_section;

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

/// cross-section median of m-period simple returns, at s steps ahead
var median_cross_section_returns(int s, int m) {
int i = 0;
string current = Asset; // save the current asset
for(listed_assets) {
asset(Asset);
cross_section[i++] = simple_returns(-s, m);
}
asset(current); // restore the current asset

return Median(cross_section, NumAssetsListed);
}

function run()
{
StartDate = 19900101;
EndDate = 19931231;
BarPeriod = 1440;
LookBack = 240;

NumWFOCycles = 1;
DataSplit = 75;

set(RULES+PEEK);
Spread = RollLong = RollShort = Commission = Slippage = 0;
LifeTime = 1;
if(Train) Hedge = 2;

char* symbol;
while(asset(symbol = loop(Assets))) {
adviseLong(SIGNALS, median_cross_section_returns(1, 1), simple_returns(0, 1), simple_returns(1, 1), simple_returns(2, 1));
enterLong();
}
}

function main()
{
assetList("Assets.2.1993.csv");
cross_section = malloc(NumAssetsListed * sizeof(var));
}

Page 1 of 2 1 2

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