Average daily range of a universe of stocks
Author: jimcrist
Creation Date: 5/8/2010 3:55 PM
profile picture

jimcrist

#1
I'm trying to do some research. I'd like to calculate the average daily range (High-Low) for a data set over time (daily) and then output the dates and average ranges to a .csv file. I can create a dataseries with the range for one stock. But averaging in all the stocks in a data set is stumping me...thanks!
CODE:
Please log in to see this code.

profile picture

Eugene

#2
Perhaps we'll even stick it in the Wiki FAQ someday. It's really easy if you follow this code pattern:

Multiple Symbol Examples?
Percent of stocks above 200d moving average

Run this code on a single symbol (not in portfolio backtest mode), it will correctly do the rest:
CODE:
Please log in to see this code.
profile picture

Cone

#3
Sidenote: Index Manager (Index-Lab) is coming in the summer release.
profile picture

jimcrist

#4
Thanks...works great! BTW, in case you do stick it in the wiki, technically, this is just an average range calculation. I guess we reserve the term Average True Range for the Wilder approach.
profile picture

Kefirich

#5
Hi,

I have a similar task, but instead of the average daily range of the set I need an average daily range of each given Symbol in the Dataset. In other words, I have a set of 14 Symbols in a set, each symbol is different, time period is almost the same for everyone. I want to have a table with all the symbols and their average daily ranges (see below).

Symbol 1 - Average daily range = X (Where X is the Sum of Daily ranges (High - Low) divided by the number of days)
Symbol 2 - Average daily range = Y
Symbol 3 - Average daily range = Z

Dates are not important.

I would really appreciate if some one could suggest a solution. I just started to code and things are a lit complicated for me.

Thanks.
profile picture

Eugene

#6
Hi Anton,
At first glance this seems to be what you're looking for:

CODE:
Please log in to see this code.
profile picture

Kefirich

#7
Hi Eugene,

Thanks. It works, but results are not the same compared to Ecxel. I took two symbols from the set and calculated the average in Excel (time period is the same). The results are 50-100% different. Any ideas why it happens?

Regards,
Anton
profile picture

Eugene

#8
Sorry Anton, I have little idea as to what may be wrong with your Excel calculation.
profile picture

Kefirich

#9
Eugene,

I was saying that the code perfomed the wrong calculation, not Excel. I double checked with ATR and it showed that Excel was correct. My question was what could be wrong in the code.
profile picture

Eugene

#10
Anton,

And I was implying that I've double checked my code and the output was correct. This discussion is going nowhere without providing facts.
This website uses cookies to improve your experience. We'll assume you're ok with that, but you can opt-out if you wish (Read more).