Database Reference
In-Depth Information
Working with time series data with
Incanter Zoo
Data that includes a regular timestamp, or time series data, is very common. Stock prices
and weather are just two examples of this. These datasets track values that change over the
course of seconds, hours, days, weeks, months, or even years.
Incanter includes a namespace ( incanter.zoo ) that makes working with time series data
very easy. We can use that to compute running averages and to map other functions over a
moving window of the data.
For this, we'll take a look at some stock data for IBM. You can get this from a
number of sources, but I downloaded a decade's worth of data from Google Finance
( http://www.google.com/finance ). You can download the same data from
http://www.ericrochester.com/clj-data-analysis/data/ibm.csv .
Getting ready
First, we need to list the dependencies we'll need in our Leiningen project.clj ile. Notice
that incanter-zoo has been included as a separate dependency since it's not distributed
with the core Incanter packages:
(defproject statim "0.1.0"
:dependencies [[org.clojure/clojure "1.6.0"]
[incanter "1.5.5"]
[incanter/incanter-zoo "1.5.5"]])
We'll need to require those namespaces in our script or REPL:
(require '[incanter.core :as i]
'incanter.io
'[incanter.zoo :as zoo]
'[clj-time.format :as tf])
We'll also need the data I mentioned in the introduction to this recipe. I've downloaded mine
to a ile named data/ibm.csv , and I'll bind that to the name data-file :
(def data-file "data/ibm.csv")
 
Search WWH ::




Custom Search