{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"pygments_lexer":"ipython3","nbconvert_exporter":"python","version":"3.6.4","file_extension":".py","codemirror_mode":{"name":"ipython","version":3},"name":"python","mimetype":"text/x-python"}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"markdown","source":"# Technical Analysis and Pattern Recognition:\n\nmod version: jhtalib a Dutch application\n\nJHTA-Lib is used by trading python developers requiring to perform technical analysis of time-series such as market data. It includes 250 indicators such as ADX, MACD, RSI, Autocorrelation, Stochastic, Bollinger Bands, and has Candlestick pattern recognition. Since JHTALib does come with a standard python package, the installation is easy. In this notebook, Just pip install and import the talib library. Finally, we will load the features dataframe to pyspark for all of the models which use pre-identified patterns available in JHTALib.\n\nImportant Links:\n* JHTA-Lib statified base:\n* TA-Lib Python Wrapper documentation: <a href=\"https://github.com/joosthoeks/jhtalib\" target=\"_blank\">here</a>\n* TA-Lib Website: <a href=\"https://www.ta-lib.org/\" target=\"_blank\">here</a>\n How to install talib in python: \n* All Tech Indicators: <a href=\"https://www.programcreek.com/python/index/7769/talib\" target=\"_blank\">here</a>\n\n* Using abstract API: <a href=\"https://mrjbq7.github.io/ta-lib/abstract.html\" target=\"_blank\">here</a>\n","metadata":{}},{"cell_type":"code","source":"url = 'https://launchpad.net/~mario-mariomedina/+archive/ubuntu/talib/+files'\next = '0.4.0-oneiric1_amd64.deb -qO'\n!wget $url/libta-lib0_$ext libta.deb\n!wget $url/ta-lib0-dev_$ext ta.deb\n!dpkg -i libta.deb ta.deb\n!pip install TA-Lib\n!git clone https://github.com/joosthoeks/jhTAlib.git\n%cd '../jhTAlib'\nimport jhtalib as jhta\n%cd '../'\n!rm -rf ./jhTAlib/","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# loading libraries\nimport pandas as pd\nimport talib\nfrom talib import abstract","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# loading dataset and converting the price column names to lowercase so abstract API can recognize the input\ndf = pd.read_csv('../input/g-research-crypto-forecasting/train.csv')\ndf.rename(columns={'Open': 'open', 'High': 'high','Low': 'low','Close': 'close', 'Volume': 'volume'}, inplace= True)\ndf.head()","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"If you're already familiar with using the function API, you should feel right at home using the abstract API. Every function takes the same input. In this notebook we focus on the Pattern Recognition. Candlestick patterns can be a great way of deciding if and when we should open or close a trade. For example, if we get a ‘hammer’ candlestick, this is usually a bullish sign. Paired with a moving average, this can be a powerful strategy. ","metadata":{}},{"cell_type":"code","source":"# talib library has many categories of indicators, feel free to add more indicator groups to your features.\ntalib.get_function_groups().keys()","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# list of all indicators\ntalib.get_function_groups()","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# due to the limitations of kaggle notebook, let's choose the first 1000 rows of data\ndf_debug = df.iloc[:1000,:]\ndf_debug.shape","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# all Pattern Recognition indicators start with CDL\nall_indicators = [method for method in dir(abstract) if method.startswith('CDL')]","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"all_indicators","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_indicator = pd.DataFrame()\nfor indicator in all_indicators:\n    df_indicator[str(indicator)] = getattr(abstract, indicator)(df_debug)","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_indicator","metadata":{"trusted":true},"execution_count":null,"outputs":[]}]}