Software for standard Deviation

Discussion in 'Options' started by jasonc, Oct 11, 2007.

  1. rosy2

    rosy2

    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))
     
    #11     Oct 13, 2007
  2. theta636

    theta636

    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
     
    #12     Oct 13, 2007
  3. Bollinger bands?

    They directly measure Std Deviation, and are easily available and free.
     
    #13     Oct 13, 2007
  4. MTE

    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.

    Bollinger bands are based on a moving average not the actual price.
     
    #14     Oct 14, 2007
  5. you know gummy ?
     
    #15     Oct 14, 2007
  6. panzerman

    panzerman

    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.
     
    #16     Oct 14, 2007
    beginner66 likes this.
  7. theta636

    theta636

     
    #17     Oct 14, 2007
  8. theta636

    theta636

    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
     
    #18     Oct 14, 2007
  9. MTE

    MTE

    Theta,

    The square root method is just a way of converting standard deviation to various time frames, it's not a crystal ball!
     
    #19     Oct 15, 2007
  10. theta636

    theta636

    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
     
    #20     Oct 15, 2007