4.0

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

Historical Volatility

by Josiah Renfree

 

21 Jul 2009 (Updated 15 Oct 2010)

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

| Watch this File

File Information
Description

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.

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  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (3)
24 Sep 2010 Jose

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.

07 Oct 2010 David

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.

15 Oct 2010 Josiah Renfree

Hi David,

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

-Josiah

Please login to add a comment or rating.
Updates
15 Oct 2010

Fixed error in date handling

Tag Activity for this File
Tag Applied By Date/Time
historical volatility Josiah Renfree 22 Jul 2009 10:02:38
volatility Josiah Renfree 22 Jul 2009 10:02:38
stocks Josiah Renfree 22 Jul 2009 10:02:38
options Josiah Renfree 22 Jul 2009 10:02:38
derivatives Josiah Renfree 22 Jul 2009 10:02:38
finance Josiah Renfree 22 Jul 2009 10:02:38
historical volatility Prav 12 Jul 2011 10:53:39
derivatives Prav 12 Jul 2011 10:53:43
historical volatility Antonio 26 Jul 2011 11:28:31
historical volatility Mike 08 Aug 2011 11:01:40
historical volatility Belgacem 14 Dec 2011 10:39:46

Contact us at files@mathworks.com