Zorro: problem overriding the objective() function

Posted By: scotpip

Zorro: problem overriding the objective() function - 10/24/14 12:26

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
Posted By: jcl

Re: Zorro: problem overriding the objective() function - 10/24/14 12:51

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.
Posted By: scotpip

Re: Zorro: problem overriding the objective() function - 10/24/14 16:47

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.)
Posted By: scotpip

Re: Zorro: problem overriding the objective() function - 10/27/14 20:13

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);
	}
}

Posted By: jcl

Re: Zorro: problem overriding the objective() function - 10/28/14 13:01

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.
© 2024 lite-C Forums