Installing TA-Lib for Python on x64
Following my completion of Andrew Ng’s Deep Learning Specialization, I am on a quest to create a model that predicts stock prices using a Recursive Neural Network (RNN) model. Part of that quest includes installing ta-lib for additional features. I built my model using a recursive neural network architecture followed by a dense layer with some batch normalization to speed up optimization. I used relu activations for their speed, though I had a brief detour exploring the use of the swish activation function. My network is damn simple, and most of my work has been spent on data manipulation.
I trust my model and data pipeline now, because after a few epochs of training it tells me that it can’t guess the direction of the stock market better than a coin flip. It gets it wrong 50% of the time, right on the money! I don’t think the problem is the density of my model, I think it’s the lack of features I’m feeding into it. Right now it gets 14 days of open, high, low, close, and volume values and I ask it to predict what the 3 day simple moving average close price will be in two days (with the simple moving average centered on those two days). I asked it to predict the average rather than the actual close price because I wanted to set it up for success by making it easier. I believe my model when it tells me that you can’t accurately forecast that value with these features.
My next step is additional features. Staying with my purely technical approach, I think Bollinger bands, 100-SMA, RSI, and MACD are valid things to try out. To that end, I need a library I can use to add that data with reasonable performance given the size of my data set (17 million examples of 14-day sequences). For Python, the choice is ta-lib.
Now that I’m done rambling, here’s exactly what installing ta-lib on my x64 computer looks like.
- Get the library source from https://www.ta-lib.org/hdr_dw.html. Select the msvc version. As of this writing, the latest is 0.4.
- Unzip the library so that c:\ta-lib has the readme.txt and the c, dotnet, etc directories. pip will look for this later.
- Get build tools for Visual Studio: https://visualstudio.microsoft.com/downloads/#build-tools-for-visual-studio-2017
- When launching the installer, select Individual Components and pick VC++2015.3 v14.00 (v140) toolset for desktop and Windows Universal CRT SDK. You’ll also need the Windows SDK. I installed the latest Windows 10 SDK, and the Windows 8.1 SDK.
- Open a fresh command prompt (so that it has the new PATH environment with the build tools in it) and go to c:\ta-lib\c\make\cdr\win32\msvc
- Execute “nmake”
- pip install msgpack
%comspec% /k "C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat" amd64 8.1
- pip install TA-Lib
If you’re lucky, smart, and beautiful, you’ll have TA-Lib installed and working. Try it out with the example code in the ta-lib github:
import numpy import talib close = numpy.random.random(100)
output = talib.SMA(close)
Now it’s up to you to feed these features into a model! However – keep in mind that you’re feeding the same data, just with slightly different conversions. Add features that you think make sense – do not shotgun it or you’ll run into the problem of multiple comparisons.
Do you need help building your model? Reach out!
Leave a Reply