PasteRack.org
Paste # 46080
2019-11-29 22:57:22

Fork as a new paste.

Paste viewed 533 times.


Embed:

Plot historical variance and implied volatility

#lang racket/base

(require db
         plot)

(define dbc (postgresql-connect #:user "user" #:password "password" #:database "local"))

(define hv-current (query-rows dbc "
select
  extract(epoch from \"date\"::timestamp),
  hv_current
from
  oic.volatility_history
where
  act_symbol = 'SPY';
"))

(define iv-current (query-rows dbc "
select
  extract(epoch from \"date\"::timestamp),
  iv_current
from
  oic.volatility_history
where
  act_symbol = 'SPY';
"))

(parameterize ([plot-x-ticks (date-ticks)])
  (plot-file (list (tick-grid)
              (lines hv-current #:color 'red)
              (lines iv-current #:color 'blue))
             "vol-history.png"
             'png
        #:width 800
        #:height 800))