During the last months at Lecrin Technologies, we have been studying some financial time series such as predict bitcoin price or different challenges proposed by Numer.ai, Two Sigma Investment or G-Research. Giving that said, we have decided to develop a technical analysis library in python using that is based in the "pandas" library. You can find the library at:
https://github.com/bukosabino/ta
This new library is oriented to do feature engineering from typical financial datasets that typically includes columns such as “timestamp”, “open”, “high”, “low”, “close” and “volume”. This library will be used by data scientifics that want to resolve machine learning problems using python technology stack for data science (pandas, scikit-learn, xgboost, lightgbm, keras, tensorflow, etc).
At this moment, these tools are getting good results to predict almost anything, but they are not working correctly when are used to face financial problems. They are not working correctly because the rows in the dataset only contain information about a specific period of time (e.g. 6 hours or one day) which is not sufficient to generate good predictions with the current models. To improve the predictions, we need to provide more information (features) to the dataset as the current models get better results when more information is provided.
Technical analysis is focused on providing new information from the past to forecast the direction of price. By adding the information generated by different indicators for the different variables (volume, volatility, trend, momentum, etc), we can improve the quality of the original dataset.
Now, we will explain two examples in detail:
Bollinger Bands:
The Bollinger Bands are used to analyze the volatility of the price for an asset in a specific period of time. There are 3 bands, the Middle Band (MB) is the average of the price in the last n periods, the Upper (UB) and Lower Bands (LB) are equal to the middle band, but adding and subtracting x times the standard deviation. The normal parameters that are being used are n = 20 periods and x = 2. So:
MB = SUM(n last close values) / n
UB = MB + (X * StdDev)
LB = MB - (X * StdDev)
In the library, the closing price variable is converted to 5 new features. Apart from the 3 Bollinger Bands, we generate another 2 indicators that will indicate when the closing value has a value higher than the Upper Bollinger Band or lower than the Lower Bollinger Band. Therefore, these two characteristics will be 0 except when the closing value get out of these bands, which will be 1.
If we take a look at the image, when the closing wave (blue) surpasses the upper or lower bands, there are sudden changes in the price, and it is usually a good idea to sell when it is higher than the Upper Band and to buy when it is lower than the Lower Band.
MACD
Moving Average Convergence Divergence is a trading indicator that focuses on exponential moving average (EMA). To calculate it we use:
MACD = EMA(n1, close) - EMA(n2, close)
MACD_Signal = EMA(n3, MACD)
MACD_Difference = MACD - MACD_Signal
The typical values for the variables are n1=12, n2=26 and n3=9, however other values can be substituted in the library depending on your trading style and goals.
The theory tells us that when the MACD curve (blue) is smaller than the MACD_Signal (orange) or when the MACD difference (green curve which represents the difference between MACD_Signal and MACD curve) has a value lower than 0, the price trend will be bearish. On the contrary, it indicates a price increase.
At this moment, the library has implemented 25 indicators and 46 features. The developer can set a lot of input parameters such as the size of windows, different constants or smart automatic fill Nans values generated in the methods.
We have uploaded a first stable version of the library to GitHub and it can be installed by using “pip”. The library is in continue development so we will be including more indicators, features, documentation, etc. Please, let us know about any comment, contribution or feedback.
Congratulations @dariolp! You received a personal award!
You can view your badges on your Steem Board and compare to others on the Steem Ranking
Vote for @Steemitboard as a witness to get one more award and increased upvotes!
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit