#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


-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 4669 bytes
Desc: not available
URL: 
<http://lists.racket-lang.org/archive/dev/attachments/20100524/a4b5fc05/attachment.p7s>

Reply via email to