StockFetcher Forums · General Discussion · Backtesting<< 1 2 >>Post Follow-up
rrochon
117 posts
msg #32435
Ignore rrochon
6/25/2004 8:52:49 PM

Is there a way to backtest a filter for a particular period of time? I know that the number of days can be changed, but how would I backtest a filter for 1/1/04 to 3/31/04, for example?

Some filters work better when the general market is going up, so it would be handy to be able to backtest a filter, like Muddy's, during a time when the SP500 or the Vectorvest Composite was trending up, as compared with the last 68 days.

Dick


robdavis
69 posts
msg #32730
Ignore robdavis
8/1/2004 4:04:53 PM

Always there is a way. I'm concerned about speed, efficiency, and accuracy. I've spent many days and nights with a paper, pen, handheld calculator, and historical charts, and recorded hundreds of numbers in the process, but there must be a better way!

Choose your time periods well. You want to view worst case scenarios. You want to choose periods of down trends if your filter is based on long positions. To find particularly "bad" periods, view historical charts of the S&P 500 index, and see exactly when the market for the S&P 500 stocks was particularly "bad".

The SF's standard (and flash) charts do display individual stocks' 1-week, 1-month, etc. performances, but A) how do you back date those charts, and B) how do you change the number of days?

Sometimes I think the best way is a (slow, but accurate and realistic) research based on a combination of paper, pen, handheld calculator, and a bunch of online historical charts... in the process one can record hundreds of numbers, but there must be a better, faster, and more efficient way! Guys, is there a better way?




cegis
235 posts
msg #32740
Ignore cegis
8/2/2004 9:45:24 AM

Of course you can do this! <G>

Assuming (because I don't feel like counting the exact number of trading days) that there's 65 days between 1/1 and 3/31, your filter might look like this:

Fetcher[
set{rtn1,price / price 65 days ago}
set{rtn2,rtn - 1}
set{rtn,rtn2 * 100}

price 65 days ago is between 3 and 4

add column rtn

offset 03/31/04
]



The object here is to "run the filter" for the 1/1 date, by using the 65 days ago plus the date offset. So in this case, my filter "price is between 3 and 4" needed to change to "price 65 days ago between 3 and 4". You'll need to change all of the indicators used for filtering to include "65 days ago" (or adjusted accordingly, if your filter already uses the "days ago" phrase).

Then, we "look forward" to 3/31 (by using the offset date) to determine what the return would have been. The three set{} commands calculate that return as a percentage, and the "add column" displays the results in the list of matching stocks.

Does this answer your question?

HTH,

C


cegis
235 posts
msg #32741
Ignore cegis
8/2/2004 10:10:40 AM

Oops, that sample filter should read

Fetcher[
set{rtn1,price / price 65 days ago}
set{rtn2,rtn1 - 1}
set{rtn,rtn2 * 100}

price 65 days ago is between 3 and 4

add column rtn

offset 03/31/04
]



(The second set{} had a typo...)

Sorry 'bout that.

C


tim.jones
4 posts
msg #32750
Ignore tim.jones
8/2/2004 11:52:14 PM

I have a script that will do this for you. Just specify the date range and the program will grab specific stockfetcher matches for the begin date and show the performance for that filter between those two dates (program determines actual trading days for you). It shows performance for individual stocks and then shows number positive, negative, unch similiar to way stockfetcher shows (though not as nice looking :)) I grab actual data for a particular stock from yahoo. Right now it only works for 2004. Probably will add 2003 and 2002 once I find out holidays for those years. If anyone is interested email me at tgjones47@hotmail.com. You will need to install Python on your system ...not a big deal.


rrochon
117 posts
msg #32987
Ignore rrochon
8/25/2004 5:51:57 PM

Cegis,

Maybe I am not reading it correctly, or you didn't understand what I was asking. The filter you designed shows a list of stocks and what the results were to date.

As an example, suppose I want to run a backtest on Muddy's filter from 6/30/04 to 8/12/04, when the QQQ went down 13%. How would I do this?

Dick


nikoschopen
2,824 posts
msg #33009
Ignore nikoschopen
8/26/2004 9:58:55 PM

I'm new to logical operators, and would like some clarification in everyday language. For instance, in the first set you're dividing today's price by price 65 days ago. But why is today's price necessary when in fact Dick wants a date-specific result in the past? Also suppose that today's price is less than price 65 days ago, which would return a result less than 1, and plugging this into your second set, which would return a negative number result...and I would think this wouldn't fetch any stock, provided that y


nikoschopen
2,824 posts
msg #33010
Ignore nikoschopen
8/26/2004 10:06:33 PM

Allow me to repeat...

I'm new to logical operators, and would like some clarification in everyday language. For instance, in the first set you're dividing today's price by price 65 days ago. But why is today's price necessary when in fact Dick wants a date-specific result in the past? Also suppose that today's price is less than price 65 days ago, which would return a result less than 1, and plugging this into your second set, which would return a negative number. How would StockFetcher be able to interpret this? Would it screen only the positive results, or both? Would you need to specify the parameters further in order to quantify the result for only that particular set of rules? Sorry if this sounds too trivial...but more questions to come later.


robdavis
69 posts
msg #33021
Ignore robdavis
8/27/2004 2:54:25 PM

Nikoschopen,


I suggest you try it. Because it will work. And because C (cegis) knows his stuff. And because one learns by doing.


But, if you *really* want lots of details, here are the most important details...


1) "set{rtn1,price / price 65 days ago}" means we're defining a brand new variable we call rtn1; here rtn1 = close / close 65 days ago. The trick is, thanks to "offset 03/31/04", this "price" is NOT the most recent (8/26/04) EOD close, but that of 3/31/04. And, thanks to "offset 03/31/04", the "price 65 days ago" is not an EOD close in 5/04, but one in December 2003.


2) "set{rtn2,rtn1 - 1}" means we're defining another brand new variable we call rtn2; here rtn2 = rtn1 - 1. If rtn2 is negative, there's no problem. SF's code does not "discriminate" too much. If rtn2 is negative, no problem. A signed value will be displayed in the rtn column. If rtn2 is positive, no problem there either. An unsigned value will be displayed in the rtn column.


3) "set{rtn,rtn2 * 100}" means we're defining another brand new variable we call rtn; here rtn = rtn2 * 100.


4) "price 65 days ago is between 3 and 4" is self explanatory.


5) "add column rtn" is also self explanatory.


6) "offset 03/31/04" means time offset is about 100 days; the whole back testing is pushed back in time, as if today's date was 3/31/04. In other words, it back tests the filter to 3/31/04.


I suggest you start experimenting, and just DO it. Because it is fun. And also because one learns by doing.


I hope this helps.


Rob


robdavis
69 posts
msg #33022
Ignore robdavis
8/27/2004 3:16:40 PM

Dick,

Suppose you wrote a very simple filter, like...
Fetcher[
Price is between 3 and 4
]


and you wanted to back test it between 6/30/04 and 8/12/04.

Then, using C's sample back tester, all you'd need is...
Fetcher[
set{rtn1,price / price 30 days ago}
set{rtn2,rtn1 - 1}
set{rtn,rtn2 * 100}
price 30 days ago is between 3 and 4
add column rtn
offset 08/12/04
]


Please note it's 30 days, because from 6/30/04 to 8/12/04 there were 30 trading days.

I hope this helps.

Rob



StockFetcher Forums · General Discussion · Backtesting<< 1 2 >>Post Follow-up

*** Disclaimer *** StockFetcher.com does not endorse or suggest any of the securities which are returned in any of the searches or filters. They are provided purely for informational and research purposes. StockFetcher.com does not recommend particular securities. StockFetcher.com, Vestyl Software, L.L.C. and involved content providers shall not be liable for any errors or delays in the content, or for any actions taken based on the content.


Copyright 2016 - Vestyl Software L.L.C.Terms of Service | License | Questions or comments? Contact Us
EOD Data sources: DDFPlus & CSI Data Quotes delayed during active market hours. Delay times are at least 15 mins for NASDAQ, 20 mins for NYSE and Amex. Delayed intraday data provided by DDFPlus