Rolling averages
Now that we can see the up-to-date stock price for a given company, it makes sense to display a rolling average of the past, say, five stock prices. In a real scenario, this would provide an objective view of a company's share trend in the stock market.
Let's extend our program to accommodate this new requirement.
First, we'll need to modify our namespace definition:
(ns stock-market-monitor.core (:require [seesaw.core :refer :all]) (:import (java.util.concurrent ScheduledThreadPoolExecutor TimeUnit) (clojure.lang PersistentQueue)))
The only change is a new import clause, for Clojure's PersistentQueue
class. We will be using that later.
We'll also need a new label to display the current running average:
(def running-avg-label (label "Running average: -")) (config! main-frame :content (border-panel :north price-label :center running-avg-label :border 5))
Next...