Gamestudio Links
Zorro Links
Newest Posts
Trading Journey
by howardR. 04/24/24 20:04
M1 Oversampling
by Petra. 04/24/24 10:34
Zorro FIX plugin - Experimental
by flink. 04/21/24 07:12
Data from CSV not parsed correctly
by EternallyCurious. 04/20/24 21:39
Scripts not found
by juergen_wue. 04/20/24 18:51
zorro 64bit command line support
by 7th_zorro. 04/20/24 10:06
StartWeek not working as it should
by jcl. 04/20/24 08:38
folder management functions
by VoroneTZ. 04/17/24 06:52
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
2 registered members (Ayumi, AndrewAMD), 770 guests, and 4 spiders.
Key: Admin, Global Mod, Mod
Newest Members
Mega_Rod, EternallyCurious, howardR, 11honza11, ccorrea
19048 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Zorro: problem overriding the objective() function #446639
10/24/14 12:26
10/24/14 12:26
Joined: Oct 2014
Posts: 42
DEVON
S
scotpip Offline OP
Newbie
scotpip  Offline OP
Newbie
S

Joined: Oct 2014
Posts: 42
DEVON
Hi

No response on the Zorro Scripts forum, so would very much appreciate your help.

Trying to optimise on a different measure of P/L from the default.

In run() I calculate my P/L and place the running total in a file-scope variable (I've checked it holds the correct value).

In the same file I've placed an objective() function that simply returns the P/L value in the file-scope variable.

But the optimiser doesn't seem to be using this value, and the red Objective bar in the result charts is blank. Printing to the console seems to be disabled during backtesting so it's hard to figure out the issue.

Schematically, my code looks like this:

Code:
var pl;

run(){
   ... calculate pl
   pl += myVal;
}

var objective(){
   return pl;
}




The docs are a bit vague. What am I overlooking?

Quote:

The performance is calculated in the objective function in include\default.c. This function can be replaced by any user provided function in the script that is named objective. This way, other performance values can be used for optimizing parameters, for instance the profit/drawdown ratio, or the gross profit, or the Sharpe ratio

Re: Zorro: problem overriding the objective() function [Re: scotpip] #446641
10/24/14 12:51
10/24/14 12:51
Joined: Jul 2000
Posts: 27,982
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,982
Frankfurt
That should be easy. You need not even accumulate the PL, the total profit is WinTotal. For printing to the console, use printf() or print() in a backtest. You can also write variables to a file. Without knowing your script I can't say why your objective function does not work.

Re: Zorro: problem overriding the objective() function [Re: jcl] #446647
10/24/14 16:47
10/24/14 16:47
Joined: Oct 2014
Posts: 42
DEVON
S
scotpip Offline OP
Newbie
scotpip  Offline OP
Newbie
S

Joined: Oct 2014
Posts: 42
DEVON
Hi

Thanks for getting back.

As I say, I'm measuring the profit another way (for backtesting a Binary Options strategy), which I do in run().

The code I posted is pretty much all there is to it - the objective() function is a 1 liner that returns the value from the file-level global, as shown.

Code:
var objective(){
   return myVal;
}



Where would I begin to look for the issue?

(Sorry - when I said printing is disabled I meant during training, not during backtesting.)

Last edited by scotpip; 10/24/14 19:14.
Re: Zorro: problem overriding the objective() function [Re: scotpip] #446682
10/27/14 20:13
10/27/14 20:13
Joined: Oct 2014
Posts: 42
DEVON
S
scotpip Offline OP
Newbie
scotpip  Offline OP
Newbie
S

Joined: Oct 2014
Posts: 42
DEVON
Well, I've solved this with a bit of a hack, by editing the objective() function in default.c and calling in the value from there. For some reason it seems that Zorro wasn't using the value returned from the objective() function in my run() file.

I'd still like to get this working properly if possible, so I'd appreciate any suggestions you can offer.


Code:
var objective()
{
	if(IS_BINARY_TEST == 1)
	{
		return getPL();
	}
	else
	{
		if(!NumWinTotal && !NumLossTotal) return 0.;
		var wFac = 1./sqrt(1.+NumWinTotal); 
		var lFac = 1./sqrt(1.+NumLossTotal);
		var win = WinTotal, loss = LossTotal;
		// remove single outliers
		if(NumWinTotal > 2) win -= (NumWinTotal-2)*WinMaxTotal/NumWinTotal;
		if(NumLossTotal > 2) loss -= (NumLossTotal-2)*LossMaxTotal/NumLossTotal;
		// return PRR
		return (1.-wFac)/(1.+lFac)*(1.+win)/(1.+loss);
	}
}


Re: Zorro: problem overriding the objective() function [Re: scotpip] #446693
10/28/14 13:01
10/28/14 13:01
Joined: Jul 2000
Posts: 27,982
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,982
Frankfurt
If two lite-C functions have the same name and parameters, the last one is used. So I can't say from your description why your objective function does not work as it should, but if you post your complete script here, I can look over it. Maybe the problem is already visible in the code. If your script is top secret, you can replace your trade algo with some dummy algorithm for testing.


Moderated by  old_bill, Tobias 

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