SAFeTRADE 431 posts msg #117350  Ignore SAFeTRADE 
12/13/2013 2:29:09 PM
How would I code the following. I have started using already available code from Kevin. Not being a math
GURU I am stymied at this point. Anyone?
In order to calculate the number of standard deviations that a stock moves in the latest session, we use the following formula:
Today's price movement in terms of number of 20day standard deviations = ln (latest close/previous close) / ((20day historical volatility/100)/square root of 252))
In this formula we are simply comparing the latest price change to the standard deviation of the price returns over the last 20 sessions. We are using the "price return" for the daily change because this is how historical volatility is calculated. A "price return" is simply the natural log of the latest close divided by the previous close. Historical volatility is the measure that we use for the comparison in the denominator of our equation because historical volatility is simply defined as the standard deviation of the price returns, factored up to an annualized number. Since historical volatility is typically expressed as an annualized number, we need to reduce it to a daily figure for our daily "What’s Hot" calculation by dividing it by the square root of 252 (i.e., the approximate number of trading days in a year).
Let's look at an example. A123 Systems (ticker: AONE) on the close of Friday, May 14, 2010 had the following input figures: 5/10/2010 close was $11.46, 5/09/2010 close was $10.33, and the 20day historical volatility on 5/10/2010 was 66.69%. Let calculate how many standard deviations A123 Systems moved on 5/10/2010:
Ln (11.46/10.33) / ((66.69/100)/square root of 252) = 2.47
SET{PRICERATIO, CLOSE / close 1 day ago}
SET{RATIOSTD20, CSTDDEV(PRICERATIO,20)}
set{std20, priceratio / RATIOSTD20}
symlist(spy)
add column priceratio
add column ratiostd20
add column std20
