To apply backtest only to some symbols randomly selected

#1
How to apply backtest only to some symbols randomly selected

Dear all,
I have a huge symbols database and I would backtest my Trading Systems using only some symbols randomly selected.
e.g. using their name: symbols name that start with 'B' and 'W' letters
How I can check for the first letter of the name symbol?

Anyway, any other solution to randomly select symbols are welcome.

thank you

Cippo
 
Last edited:

mastermind007

Well-Known Member
#2
Re: How to apply backtest only to some symbols randomly selected

Dear all,
I have a huge symbols database and I would backtest my Trading Systems using only some symbols randomly selected.
e.g. using their name: symbols name that start with 'B' and 'W' letters
How I can check for the first letter of the name symbol?

Anyway, any other solution to randomly select symbols are welcome.

thank you

Cippo
Solution 1)
You can edit the AFL and add in the Filter clause following
((StrLeft(Name(), 1) == "B") AND (StrRight(Name(), 1) == "W"))
Solution 2)
Add your randomly selected symbols to a watch list and then run backtest with global Filter set to the watch list.

You can add symbols to the watch list either manually or import from a text file in which one symbol is written down on one line ...

Second solution is lot more flexible..
 

mehtaka

Active Member
#4
hello,
Can we add few custom dates for backtesting? Right now we can add only one FROM and TO date in Automatic analysis window.
Suppose we want to back test between more FROM and TO dates, how to code the same in afl?
 

mastermind007

Well-Known Member
#6
hello,
Can we add few custom dates for backtesting? Right now we can add only one FROM and TO date in Automatic analysis window.
Suppose we want to back test between more FROM and TO dates, how to code the same in afl?
Test Date range ONE: From D1 To D2
Test Date range TWO: From D3 To D4

Run back testing for D1 to D4;

In the afl, exclude away the range D2 to D3 using filter and Ami's date arithmetic functions. You may also need to use the deDateTime plugin ....

Coding this thing may get fairly involved and its not possible to give correct answer in 1 or 2 minutes ...
 

mehtaka

Active Member
#7
Test Date range ONE: From D1 To D2
Test Date range TWO: From D3 To D4

Run back testing for D1 to D4;

In the afl, exclude away the range D2 to D3 using filter and Ami's date arithmetic functions. You may also need to use the deDateTime plugin ....

Coding this thing may get fairly involved and its not possible to give correct answer in 1 or 2 minutes ...
I still couldnt get, how to do it, i am very weak in coding part.

the purpose of involving multiple dates is to do the backtest contract wise at one go.
 

NJ23

Well-Known Member
#8
--------------------------
 
#9
I still couldnt get, how to do it, i am very weak in coding part.

the purpose of involving multiple dates is to do the backtest contract wise at one go.
I had the same need: running backtest between several "From-To" Ranges.
Following Mastermind suggestions, althought not totally, I carried out the following script:

From1="01/01/2005";
To1="31/12/2005";
DateFrom1=(StrToNum(StrRight(From1, 4))-1900)*10000+ StrToNum(StrMid(From1, 3, 2))*100 + StrToNum(StrLeft(From1, 2));
DateTo1=(StrToNum(StrRight(To1, 4))-1900)*10000+ StrToNum(StrMid(To1, 3, 2))*100 + StrToNum(StrLeft(To1, 2));
InRange1= DateNum() >= DateFrom1 AND DateNum() <= DateTo1;

From2="01/01/2013";
To2="12/12/2013";
DateFrom2=(StrToNum(StrRight(From2, 4))-1900)*10000+ StrToNum(StrMid(From2, 3, 2))*100 + StrToNum(StrLeft(From2, 2));
DateTo2=(StrToNum(StrRight(To2, 4))-1900)*10000+ StrToNum(StrMid(To2, 3, 2))*100 + StrToNum(StrLeft(To2, 2));
InRange2= DateNum() >= DateFrom2 AND DateNum() <= DateTo2;

InRange= InRange1 OR InRange2;


You have to change the 2 From-To Range periods as you like and then add InRange condition to your buy conditions:
buy= InRange and yourcondition1 and your condition2 and ...

of course if you need a third, fourth ... 'From-to' range period, you have just to copy the following script several time replacing "2" with 3 ... 4 ...

From2="01/01/2013";
To2="12/12/2013";
DateFrom2=(StrToNum(StrRight(From2, 4))-1900)*10000+ StrToNum(StrMid(From2, 3, 2))*100 + StrToNum(StrLeft(From2, 2));
DateTo2=(StrToNum(StrRight(To2, 4))-1900)*10000+ StrToNum(StrMid(To2, 3, 2))*100 + StrToNum(StrLeft(To2, 2));
InRange2= DateNum() >= DateFrom2 AND DateNum() <= DateTo2;


and dont forget to add inrange3 ... inrange4 to the last instruction
InRange= InRange1 OR InRange2 or Inrange3 ...;

Hope it helps
 

mehtaka

Active Member
#10
I had the same need: running backtest between several "From-To" Ranges.
Following Mastermind suggestions, althought not totally, I carried out the following script:

From1="01/01/2005";
To1="31/12/2005";
DateFrom1=(StrToNum(StrRight(From1, 4))-1900)*10000+ StrToNum(StrMid(From1, 3, 2))*100 + StrToNum(StrLeft(From1, 2));
DateTo1=(StrToNum(StrRight(To1, 4))-1900)*10000+ StrToNum(StrMid(To1, 3, 2))*100 + StrToNum(StrLeft(To1, 2));
InRange1= DateNum() >= DateFrom1 AND DateNum() <= DateTo1;

From2="01/01/2013";
To2="12/12/2013";
DateFrom2=(StrToNum(StrRight(From2, 4))-1900)*10000+ StrToNum(StrMid(From2, 3, 2))*100 + StrToNum(StrLeft(From2, 2));
DateTo2=(StrToNum(StrRight(To2, 4))-1900)*10000+ StrToNum(StrMid(To2, 3, 2))*100 + StrToNum(StrLeft(To2, 2));
InRange2= DateNum() >= DateFrom2 AND DateNum() <= DateTo2;

InRange= InRange1 OR InRange2;


You have to change the 2 From-To Range periods as you like and then add InRange condition to your buy conditions:
buy= InRange and yourcondition1 and your condition2 and ...

of course if you need a third, fourth ... 'From-to' range period, you have just to copy the following script several time replacing "2" with 3 ... 4 ...

From2="01/01/2013";
To2="12/12/2013";
DateFrom2=(StrToNum(StrRight(From2, 4))-1900)*10000+ StrToNum(StrMid(From2, 3, 2))*100 + StrToNum(StrLeft(From2, 2));
DateTo2=(StrToNum(StrRight(To2, 4))-1900)*10000+ StrToNum(StrMid(To2, 3, 2))*100 + StrToNum(StrLeft(To2, 2));
InRange2= DateNum() >= DateFrom2 AND DateNum() <= DateTo2;


and dont forget to add inrange3 ... inrange4 to the last instruction
InRange= InRange1 OR InRange2 or Inrange3 ...;

Hope it helps
certainly will try out this, update you soon.
 

Similar threads