StockFetcher Forums · General Discussion · Question for experienced coder<< >>Post Follow-up
SAFeTRADE
644 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 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{RATIOSTD20, CSTDDEV(PRICERATIO,20)}
set{std20, priceratio / RATIOSTD20}

symlist(spy)

add column priceratio
add column ratiostd20
add column std20


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

What about this?

Fetcher[
symlist(SPY)
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?

SAFeTRADE
644 posts
msg #117352
Ignore SAFeTRADE
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.

Clarence

StockFetcher Forums · General Discussion · Question for experienced coder<< >>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 2022 - 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


This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.