O'Reilly logo

Clojure for Finance by Timothy Washington

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

A third refactor of the analytic functions

We'll refactor simple-moving-average, exponential-moving-average, and bollinger-band at the same time. At each point, we need to take the reduce block of code and change it to a lazy version that fits a function's process criteria:

(defn simple-moving-average [options tick-window tick-list] (let [start-index tick-window {input-key :input output-key :output etal-keys :etal :or {input-key :last-trade-price output-key :last-trade-price-average etal-keys [:last-trade-price :last-trade-time]}} options] (map (fn [ech] (let [tsum (reduce (fn [rr ee] (let [ltprice (:last-trade-price ee)] (+ ltprice rr))) 0 ech) taverage (/ tsum (count ech))] (merge (zipmap etal-keys (map #(% (last ech)) etal-keys)) {output-key ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required