sub group backtesting

Posted By: 7th_zorro

sub group backtesting - 09/22/21 04:39

Hello.

Does series() function must be called every assets even if some assets does not traded some period of time?

For example,

If I want trade 1,000 assets, I want to test every year with different asset group.

But zorro forced to calculate all assets even though the assets does not trade that specific year.

As a result, backtesting time increased unrealistically.

How to avoid this problem?

I want to test different sub group at every years.
Posted By: Grant

Re: sub group backtesting - 09/22/21 08:37

You can run the series() function after a condition like: if(priceClose() > 0)... etc
Posted By: 7th_zorro

Re: sub group backtesting - 09/22/21 08:44

No, That's not work.
It causes error while training or some other calculation like bolinger band.
Can't select sub assets group, always must calculate all assets.
Posted By: Grant

Re: sub group backtesting - 09/22/21 13:46

So, first you need to calculate the trading signals for all assets, correct? 1,000 assets is obviously a lot for a back test.

Maybe you can post your code to see which parts can be streamlined?
Posted By: 7th_zorro

Re: sub group backtesting - 09/22/21 23:20

Suppose I have 1,000 assets in assets list.
What I want to do is to calculate the trading signals for only different 100 assets in each year, not all assets.
Definitly while(asset(loop(Assets))) is not the right solution. Because it loops all assets.
Picking sub assets in while loop cause error. (don't know why, maybe someone can explain this? I suspect all assets need sync.)
How can I solve this?


Posted By: Grant

Re: sub group backtesting - 09/23/21 07:08

What might work, is hardcoding your list of assets by working with a loop & switch-statement.
Something like:

Code
int i;

function run()
	{
	if(is(INITRUN))
		{
		asset("A");
		asset("B");
		asset("C");
		}

	for(i = 0; 1<= 2; i++)
		{
		switch(i)
			{
			case 0:
				asset("A");
				break;
			case 1:
				asset("B");
				break;
			case 2:
				asset("C");
				break;
			}
		}
		quit();
	}	



You can use a spreadsheet to convert your asset list into code.
Posted By: 7th_zorro

Re: sub group backtesting - 09/23/21 11:21

This cause the following error. What's wrong in this codes?
"Error 041: Wrong series usage!"

Code
function run() 
{
	BarPeriod = 1440;

	if(is(INITRUN))
	{
		History = ........;
		assetList(......, 0);
		
		asset("A");
		asset("B");
		asset("C");
	}

	if(dow() == 1)
	{
		asset("A");
		vars price = series(priceClose());
	}
	else if(dow() == 2)
	{
		asset("B");
		vars price = series(priceClose());
	}
	else if(dow() == 3)
	{
		asset("C");
		vars price = series(priceClose());
	}
	else if(dow() == 4)
	{
		asset("A");
		vars price1 = series(priceClose());

		asset("B");
		vars price2 = series(priceClose());

		asset("C");
		vars price3 = series(priceClose());
	}
}
Posted By: AndrewAMD

Re: sub group backtesting - 09/23/21 13:35

Never bury series calls in an if else statement! You must call series() the exact same number of times every time run is called.

Here, run might call series 0, 1, or 3 times, which is wrong.
Posted By: 7th_zorro

Re: sub group backtesting - 09/23/21 13:43

So, my question is how to handle assets with sub-groups if I have 1,000 assets?
Need to calculate every assets at every bar even though some of them only used?
Posted By: Grant

Re: sub group backtesting - 09/24/21 23:00

Do you know in advance which assets you want to run during specified periods? If so, then I would suggest to run those blocks between date a & b, c & d, e & f, etc... By doing so there are no gaps like Andrew mentioned.
Posted By: 7th_zorro

Re: sub group backtesting - 09/25/21 01:46

Yes, I aleady know what assets to trade.
Backtesting the whole assets take forever.
What do you mean "run those blocks between date"?
How can we divide it into blocks?

Code
                   ... 2001 2002 2003 2004 2005 2006  2007 2008 2009 2010 ...
asset 1       --------------                  ------------       ---------------       

asset 2       -------------            -------------          -----------------

asset 3                           ---------                                   -------------
.
.
.
asset 1,000                        ---------------------           ------



Posted By: Grant

Re: sub group backtesting - 09/25/21 09:25

With a block I mean a group of assets, 100 in your case. So the idea is to change the 'dow()' condition in your script by a time/date condition, for example like:

Code
if(year(Bar) == 2001)
{	
asset("A");
vars price1 = series(priceClose());
asset("B");
vars price2 = series(priceClose());
asset("C");
vars price3 = series(priceClose());
}
else if(year(Bar) == 2002)
//Call another block, etc..
Posted By: 7th_zorro

Re: sub group backtesting - 09/25/21 12:09

As mentioned above, that codes doesn't work because series function is buried.
Posted By: Grant

Re: sub group backtesting - 09/25/21 12:23

I haven't tested it myself, but if it's impossible to call the series() function only during specified periods, then there's probably no way to speed your process up.
Posted By: 7th_zorro

Re: sub group backtesting - 09/25/21 13:00

Zorro won't give up. This is basic function. There must be a way.
Posted By: AndrewAMD

Re: sub group backtesting - 09/25/21 13:11

Originally Posted by 7th_zorro
So, my question is how to handle assets with sub-groups if I have 1,000 assets?
Need to calculate every assets at every bar even though some of them only used?
Depends on your strategy. At 1,000 assets, I'd start to become more concerned about scalability problems, especially while running a 32-bit Zorro instance.

That aside, create every possible needed series needed for every asset in every run call. You can make an array of series, like this (pseudocode):

vars Prices[NUMBER_OF_ASSETS];
vars EMAs[NUMBER_OF_ASSETS];

for every asset{
Prices[ASSET_NUMBER] = series(price());
EMAs[ASSET_NUMBER] = series(EMA(Prices[ASSET_NUMBER],14));
}

Then your trading logic comes after this loop. You can retrieve the series by an assigned asset number, from 0 through (NUMBER_OF_ASSETS - 1).

Like this:

vars aPrice = Prices[ASSET_NUMBER];
vars aEMA = EMAs[ASSET_NUMBER];
© 2024 lite-C Forums