Skip to content

Instantly share code, notes, and snippets.

@guilespi
Created October 29, 2012 03:02
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save guilespi/3971246 to your computer and use it in GitHub Desktop.
Save guilespi/3971246 to your computer and use it in GitHub Desktop.
Running the QSTK tutorial in clojure
(defn run
[]
(let [symbols ["AAPL","GLD","GOOG","$SPX","XOM"]
start-day (date-time 2012 1 1)
end-day (date-time 2012 12 31)
time-of-day (hours 16)
timestamps (get-NYSE-days start-day end-day time-of-day)
symbols-data (read-symbols-data "Yahoo" symbols)
adj-close-data (incanter.core/to-dataset
(get-data timestamps symbols (keyword "Adj Close") symbols-data time-of-day))]
(do
;;first chart of the tutorial
(incanter.core/view (multi-series-chart {:series symbols
:x-label "Date"
:y-label "Adjusted Close"
:title "Adjusted close data"
:data adj-close-data}))
;;second chart of the tutorial
(incanter.core/view (multi-series-chart {:series symbols
:x-label "Date"
:y-label "Adjusted Close"
:title "Normalized close data"
:data (normalize adj-close-data)}))
;;daily returns
(incanter.core/view (multi-series-chart {:series symbols
:x-label "Date"
:y-label "Return"
:title "Daily Returns"
:data (daily-rets adj-close-data)}))
;;quotes comparison with scatter plot
(incanter.core/view (incanter.charts/scatter-plot
"AAPL" "GOOG"
:x-label "AAPL"
:y-label "GOOG"
:legend true
:data (normalize adj-close-data)
)))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment