Software for standard Deviation

heres python getting from google.


import math,urllib

def logret (r):
logr=[]
for x in range(1,len(r)):
sret = math.log(r[x]/r[x-1])
logr.append(sret)
return logr

def sd(x):
mean = sum(x)/float(len(x))
return math.sqrt(sum([(x-mean)**2 for x in x])/(len(x)-1))

csv='http://finance.google.com/finance/historical?q=NASDAQ:CSCO&histperiod=weekly&output=csv'
c=urllib.urlopen(csv)
close = [ i.split(',')[4] for i in urllib.urlopen(csv).readlines() ]
close.pop(0)
close = map(float,close)
sd(logret(close))
 
I usually get std dev from ToS but to exercise the Excel skills I downloaded the closing prices for WMT for the last year, plugged it into Excel 2007, and calculated the std dev for a year's worth of data. Then ran another formula for std dev for first 2 days, then first 3 days, etc. (=stdev($x$1:x255).

Question I have is how to best account for the passage of time? ToS clearly shows the std dev enlarging as the number of days increases on the probability graph.

Also, is there an easy formula to give more weight to more recent volatility, similar to an exponential moving average?

Might be time for me to take a statistics 101 refresher course
:(

Thanks
Thetaseller
 
Quote from jasonc:

i was wondering if people use certain software to calculate a stocks standard deviation over a certain time frame. If so what is it. thanks
Bollinger bands?

They directly measure Std Deviation, and are easily available and free.
 
Quote from theta636:

...Question I have is how to best account for the passage of time? ToS clearly shows the std dev enlarging as the number of days increases on the probability graph...

St.deviation increases with the square root of time, so if you have 1-day st. dev you multiply it by the square root of 252 (or any other number you like to use to annualize the data).

Also, just a reminder for anyone trying to do it manually in Excel - st. dev is based on daily returns not prices.

Quote from crgarcia:

Bollinger bands?

They directly measure Std Deviation, and are easily available and free.

Bollinger bands are based on a moving average not the actual price.
 
Quote from MTE:

Also, just a reminder for anyone trying to do it manually in Excel - st. dev is based on daily returns not prices.

More precisely, prices are assumed to be lognormally distributed, and returns are assumed normally distributed. This makes sense when you understand that the x-axis in a normal distribution runs from negative infinity to positive infinity. In a lognormal distribution, the x-axis runs from zero to positive infinty. The price of a financial asset can't be a negative number, therefore a lognormal curve is the most accurate description for prices, and a normal curve for returns.

That is why you need to do ln(b/(b-a)) on the prices first, and take the stdev of that value. The stdev function in Excel uses a normal distribution.
 
Quote from MTE:

St.deviation increases with the square root of time, so if you have 1-day st. dev you multiply it by the square root of 252 (or any other number you like to use to annualize the data).

Also, just a reminder for anyone trying to do it manually in Excel - st. dev is based on daily returns not prices.


MTE - Thanks for the response. So if I have 6 years worth of historical daily prices, I determine the daily st.dev. based on the daily price change and then graph that out for X number of days into the future using the square root of X, square root of X -1, etc. Think I can do that.
Should I determine the st.dev. on 6 years worth of data? Obviously (?) more data is better but it is intuitive that more recent data should have a greater impact. Is there a formula to take this into account or do I just pick some number for "n"?

Panzerman - thanks for the clarification (That is why you need to do ln(b/(b-a)) on the prices first, and take the stdev of that value. The stdev function in Excel uses a normal distribution.) I'll plug that into the spreadsheet.

Nonprophet - thanks for the gummy site..now I'm going to be up all night reading about poker software:D

Crunching the numbers and getting my arms around the greeks isn't the easiest way to spend my time but it does keep me off the streets...

Theta
 
For those of you who like to crunch your own numbers, you might like this spreadsheet:
http://www.gummy-stuff.org/multi-stocks.htm

If you create something that guarantees a risk-free doubling of capital every month, don't forget to share your spreadsheet with the rest of us ... heck, some of us would be happy just to see a spreadsheet with multi-colored columns :p
 
Theta,

The square root method is just a way of converting standard deviation to various time frames, it's not a crystal ball!
 
Not to worry, I'm well aware of the lack of black boxes, secret option formulas, and crystal balls. Must admit that I was most bummed out about Santa. :eek:

Seems to me that options are more like roulette than craps. In roulette the house take doesn't change regardless of whether you bet on a column, a single number, or red or black. The risk/reward changes but the house take remains the same. Assuming one has no insight into future volatility or price change, Black-Scholes evens out the expected long term reward for a particular stock over a lengthy time period. (within reason, of course).

Craps has "sucker bets", roulette doesn't (except that any bet with a house advantage is a sucker bet, I know, I know). Any thoughts from the readership on whether you believe there are sucker bets in option strategies or does B-S even everything out in the long run?

Theta
 
Back
Top