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

Reasoning about the equation needed to achieve our output

Our simple moving average equation will operate for an infinite input stream of ticks. We'll pick a starting point anywhere in the infinite input stream, pick a size n that we'd like to average, take the previous n (including the current) ticks, and apply our average equation.

Nominally, our equation will be similar to (/ price-sum (count ticks-within-window)).

Here, price-sum, as the name implies, is the sum of all the prices with our chosen average range, and ticks-within-window is the collection of ticks we want to include in our calculations.

The important part is that this equation has to be applied at each increment of the tick window. To get an average, therefore, we have to use the ...

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