StockFetcher Forums · General Discussion · Question for experienced coder<< >>Post Follow-up
313 posts
msg #117350
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 20-day standard deviations = ln (latest close/previous close) / ((20-day 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 20-day 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{std20, priceratio / RATIOSTD20}


add column priceratio
add column ratiostd20
add column std20

3,845 posts
msg #117351
Ignore Kevin_in_GA
12/13/2013 3:59:44 PM

What about this?

set{pricediff, close - close 1 day ago}
set{priceSD, cstddev(close,20)}

set{movement, pricediff / priceSD}

add column movement {movement in SD}


If all you are looking for is to determine the number of SD a stock moved today, then it is simply the ratio of the absolute price change to the SD of the price (here set at 20 days).

In this case today the SPY moved 0.25 SD. Is that what you are looking for?

313 posts
msg #117352
12/13/2013 4:18:32 PM

Yes, Kevin I think so. What about the square root as it relates to the annual. Thank you.


StockFetcher Forums · General Discussion · Question for experienced coder<< >>Post Follow-up

*** Disclaimer *** 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. does not recommend particular securities., 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