File Exchange

image thumbnail

Historical Volatility

version 1.1 (2.2 KB) by

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

14 Downloads

Updated

View License

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.

Comments and Ratings (3)

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.

-Josiah

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.

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.

Updates

1.1

Fixed error in date handling

MATLAB Release
MATLAB 7.0.1 (R14SP1)
Acknowledgements

Inspired by: hist_stock_data(start_date, end_date, varargin)

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

» Watch video