Thinking of predicting Stock Market Prices? I’m here to help with my Indicators Library for Python

Rinat Maksutov
3 min readNov 22, 2017

One of my colleagues once said, that the first thing that comes to mind for most people who realize that Artificial Neural Networks can be trained to predict some things, is “Hey! Let’s predict stock market prices and get rich!” He said this after I told him I’ve signed up for the Udacity’s Deep Learning Foundations course, and am planning to develop a model that does exactly that: tries to predict the stock prices.

I’ve spend several months developing the model, testing various network configurations, spent tons of money on AWS instances, and haven’t moved further than 60–70% accuracy on just predicting directions for the next day, let alone the actual movement value. It has been a great experience, although I realized that with the computing resources available to me this task is practically impossible to solve.

I will do a big post on this experience one day (and there are plenty of similar ones already, like this series by Alex Honchar), but today I want to share with you a by-product of this exercise: a Python library, which implements the most common stock market indicators.

In the vast majority of articles and tutorials on using Deep Learning for stock market prediction, only the OHLC values are used (which stand for Open, High, Low, Close), sometimes Volume is also taken into account. But the trading industry has quite a long history, and over this history, a wide range of derivative indicators have been developed, which are heavily used by traders and analysts.

My suggestion was that such indicators may greatly improve the accuracy of predictions by providing additional hints and patterns for the neural network. As it turned out, they actually were helpful, and in my case the accuracy increase was about 10% compared to just the OHLCV data.

I didn’t have time so far to open-source my entire project, make it human-readable and remove experimental and redundant code, but I can share the library, which implements 22 most common stock market indicators. Surprisingly, I couldn’t find anything similar at the time I was working on my project, so I had to implement them by myself.

Here’s the list of the implemented indicators:

  • Exponential moving average (EMA)
  • Moving Average Convergence/Divergence Oscillator (MACD)
  • Accumulation Distribution (A/D)
  • On Balance Volume (OBV)
  • Price-volume trend (PVT)
  • Average true range (ATR)
  • Bollinger Bands
  • Chaikin Oscillator
  • Typical Price
  • Ease of Movement
  • Mass Index
  • Average directional movement index
  • Money Flow Index (MFI)
  • Negative Volume Index (NVI)
  • Positive Volume Index (PVI)
  • Momentum
  • Relative Strenght Index (RSI)
  • Chaikin Volatility (CV)
  • William’s Accumulation/Distribution
  • William’s % R
  • TRIX
  • Ultimate Oscillator

It is small, simple to use, and relatively fast. There is some space for improvement, like you may wish to re-write the functions so that they return not the copy of the original DataFrame with a few new columns added, but only the required columns, or there may be some places where the calculations can be simplified using Pandas’ and NumPy’s tricks, but I’ll leave it up to those who will be using this library as a starting point.

The code is on GitHub, feel free to use, fork and develop it further.

Originally posted in my blog seigolonhcet.com. If you liked this post, consider following me on Twitter.

--

--

Rinat Maksutov

Technology consultant with experience in mobile and web development, artificial intelligence and systems architecture.