Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down on April 23, and its replacement, is already up and running.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: st: calculate volatility in different ways

From   Oliver Jones <>
Subject   Re: st: calculate volatility in different ways
Date   Tue, 26 Jul 2011 17:48:42 +0200

dose this help you?

********** Begin example ****************
sysuse sp500, clear
tsset date

rolling Var = r(Var), window(60) step(1): summarize open, d

list in 1/10
********** End example ****************


Am 25.07.2011 13:00, schrieb Nadine R:
Dear Statalisters!

I have a new problem: I want to calculate the volatility of some stock
returns using Equally Weighted Moving Averages and Exponential
Weighted Moving Averages in Stata 11.0. I have daily return data for
the stocks. I did not use the standard deviation measures as I need
the volatilities for different periods (if I could calculate the
60-day-volatilities for 10 years with this formula I would do it like

formula for Equally Weighted (for a 60-day-window: M=60):
variance at day t = 1/M * sum of the 60 preceding squared returns
variance at day 60 = 1/60 * Sum(from (return t=1)^2 to (return t=60)^2)
variance at day 61 = 1/60 * Sum(from (return t=2)^2 to (return t=61)^2)

I tried it with a formula like this:
generate var = 1/60 * sum((return[_n-60])^2 - (return[_n])^2)

where the "-" should indicate a "until/till" but Stata interpreted it
as a minus.

formula for the Exponential Weighted Moving Averages:
variance at day t = lambda*variance(t-1) + (1 - lambda)*squared return(t-1)

I tried it with a formula like this with lambda = 0.95 but it seems
that Stata does not calculate var(t=0) and then var(t=1) and therefore
the formula did not work:
generate var = 0.95*(var[_n-1]) + 0.05*return[_n]^2

Thanks for yur help.

Kind regards,

*   For searches and help try:

Universität Bielefeld
Fakultät für Wirtschaftswissenschaften
Lehrstuhl für Ökonometrie und Statistik
- -
Bielefeld University
Faculty of Business Administration and Economics
Chair of Econometrics and Statistics
- -
Raum / room:  V9-110
Tel / phone:  +49 (0)521 106 4871
*   For searches and help try:

© Copyright 1996–2015 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index