From my computational finance class today, a function that computes (log)mean 
and (log)stdev for the last 20 years of a stock:

#lang racket

(require net/url (planet williams/science/statistics))
(define (ticker->url t) (format 
"http://ichart.finance.yahoo.com/table.csv?s=~a&a=04&b=24&c=1990&d=04&e=24&f=2010&g=d&ignore=.csv";
 t))

(define (pair-from-ticker ticker)
  (let* ([prices 
          (map (lambda (l) (string->number (seventh (regexp-split #rx"," l))))
               (rest (port->lines (get-pure-port (string->url (ticker->url 
ticker))))))]
         [logdiffs (list->vector (for/list ([p1 (in-list (rest prices))]
                                            [p2 (in-list prices)])
                                   (log (/ p2 p1))))])
    (vector (standard-deviation logdiffs)
            (mean logdiffs))))

(map pair-from-ticker '("T" "IBM"))


... bummer about the long url.

I'm about to combine this with a web-scraper to get the last 20 years of data 
for every member of the S&P that's been around for 20 years, but that *really* 
won't fit in the box.

John


Attachment: smime.p7s
Description: S/MIME cryptographic signature

_________________________________________________
  For list-related administrative tasks:
  http://list.cs.brown.edu/mailman/listinfo/plt-dev

Reply via email to