Tracking Stocks Making New Highs
A Clojure project that tracks stocks that are making new yearly highs.
One of the better books that I have read on investing in the stock market especially from an Australian point of view, is Colin Nicholson’s Building Wealth Through Shares.
One of the central ideas to look for stocks that are starting to trend, Colin outlines that a good way to find these stocks is to look for those that are making new 52 week highs in price.
There are a few freely accessible locations to find this information.
- Australain Finacial Review share tables which are published daily in the evening.
- Sydney Morning Herald’s Markets site. This site has the advantage that new highs are updated throughout the day as trading occurs.
Now I only like to review this data once a week, typically on the weekend when I have some spare time to review the market action. My life is too busy to be worrying about trading decisions during the week. I was always wanting a way to get a weekly view of this daily information to enable me to narrow down the list of stocks to look at more quickly on the weekend. I especially was interested in stocks that were making several new highs during the week, this can indicate that a strong new trend is starting to take off.
I have previously manually tracked this information over the week. However I always felt this was a bit wrong, and given my ability to write code, I figured this should be an easy task to automate. I also wanted to use this to try out Clojure, which I have been experimenting with for some time now this year, yet never had a little product to do, until now.
I have been very happy with the experience of using Clojure to code up a little utility called New Highs that scrapes the data off the Sydney Morning Herald site and aggregates how many highs a stock has made throughout the week.
The ability to code a bit and then test things out in the REPL lead to very fast development. Whenever I found myself looking at using loop/recur I managed to rewrite it in terms of map or reduce. In the end there is no state, the structure of the application is that it reads data from disk and web, then transforms it though a series of functions until it writes the results back to disk and screen. Elegant code like this can be achieved very easily using the built in Clojure functions.
(defn number-of-highs
"Takes a list of stock codes. Returns a seq of [stock-code count] in order of count"
[shares]
(sort-by last (frequencies shares)))
I have been very please with my experiences in Clojure from this little task. The code was fast to write and very compact. Using the Cursive plugin for IntelliJ was great too.
Once I finished reading the book, Web Development With Clojure I think I will put a simple web UI on the data that my New High app is creating. Also I’m implementing a weekly trading algorithm based on one of Nick Radge’s books. More on that when I get the code up on Github.