Chapter 3. Developing the Simple Moving Average

We can think of humans as a symbolic species. By this, I mean that we use a number of characters and scripts to represent abstract things. These symbols are used by us to communicate with each other, our outside world, and our abstract thoughts. Symbolic representation is used in written language, math, and music notation. Dolphins or monkeys, while very intelligent, do not by themselves use any written symbols to communicate with each other. I'm not mentioning this simply as a philosophical musing. I think this is directly useful to consider when reaching for ideas on how to fully capture and represent our data.

In this chapter, we'll cover the following topics:

  • Translating requirements to data input
  • Knowing the target data output
  • Reasoning an equation needed to achieve our output
  • Understanding Vars and bindings
  • Working with lazy sequences
  • Implementing a Simple Moving Average(SMA) equation
  • Destructuring

Perception and representation

A big part of building working systems is the ability to correctly and fully abstract the problem we're trying to solve. In our case, this abstraction means quantifying all the input data that a problem involves, knowing the precise result data we need, and any processes or transformations that affect these inputs to get your desired output. This is what I'll describe as fully perceiving a problem. Let's take Clojure data structures, functions, and FP approaches as a way of representing our problem and solving it.

We ultimately need to gauge how close our perception and representations are to actual stock price data. However, for now, we have an infinite stream of price and time points. Apart from this stream of data, we want to calculate a moving average of prices. So, an average is just the sum of a collection of things divided by the length of the collection. This sounds easy enough. However, the moving qualifier only means that the average is calculated at each tick increment of price/time data.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.140.197.136