Created
October 29, 2012 03:02
-
-
Save guilespi/3971246 to your computer and use it in GitHub Desktop.
Running the QSTK tutorial in clojure
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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