View License

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video

Highlights from
Historical Volatility

4.0 | 1 rating Rate this file 19 Downloads (last 30 days) File Size: 2.2 KB File ID: #24811 Version: 1.1

Historical Volatility


Josiah Renfree (view profile)


21 Jul 2009 (Updated )

Calculates the annualized historical volatility for a stock over the previous N trading days.

| Watch this File

File Information

This program calculates the annualized historical volatility for one or more stocks over a user-specified number of N trading days. The program uses daily closing prices in the calculations. If not specified, the program defaults to N=20 previous trading days.

The user may supply either a single ticker symbol or a cell array of ticker symbols. Using the supplied N, the program will then calculate the historical volatility for each stock.

In order to run the program, the function 'hist_stock_data.m' must be downloaded and stored in the same directory. This function may be found in my MathWorks File Exchange.


Historical Stock Data Downloader inspired this file.

MATLAB release MATLAB 7.0.1 (R14SP1)
Other requirements This program downloads data from the Yahoo! finance service. Therefore, the user's computer must be connected to the Internet
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (3)
15 Oct 2010 Josiah Renfree

Josiah Renfree (view profile)

Hi David,

Thanks for pointing out the bug. I've made changes to the code now which should handle dates with days < 10.


Comment only
07 Oct 2010 David

David (view profile)

I think there is a bug in the code where the day has a leading zero. For instance, today, the "ddmmyyyy" is 07102010. When the for loop uses the str2double feature, I think the leading zero gets truncated such that when it is recast to a string, the data is of the form 7102010 instead of 07102010, and the hist_stock_data function does not handle this.

Comment only
24 Sep 2010 Patroklus

Nice work!
If you are using 2009b You will need to add the command: today=now to the first cell before the date variables are declared.

15 Oct 2010 1.1

Fixed error in date handling

Contact us