{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Example use of pandas_ta\n", "* Simple imports" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "import pandas as pd\n", "import matplotlib.pyplot as plt\n", "\n", "import pandas_ta as ta\n", "from alphaVantageAPI.alphavantage import AlphaVantage # pip install alphaVantage-api\n", "e = pd.DataFrame()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Help on Indicators (post an [issue](https://github.com/twopirllc/pandas-ta/issues) if the indicator doc needs updating)" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "pandas.ta - Technical Analysis Indicators\n", "Total Indicators: 72\n", "Abbreviations:\n", " accbands, ad, adosc, adx, ao, apo, aroon, atr, bbands, bop, cci, cmf, cmo, coppock, decreasing, dema, donchian, dpo, efi, ema, eom, fwma, hl2, hlc3, hma, ichimoku, increasing, kc, kst, kurtosis, linreg, log_return, macd, mad, massi, median, mfi, midpoint, midprice, mom, natr, nvi, obv, ohlc4, percent_return, ppo, pvol, pvt, pwma, quantile, rma, roc, rsi, skew, sma, stdev, stoch, t3, tema, trima, trix, true_range, tsi, uo, variance, vortex, vp, vwap, vwma, willr, wma, zscore\n", "Help on function accbands in module pandas_ta.volatility:\n", "\n", "accbands(high, low, close, length=None, c=None, drift=None, mamode=None, offset=None, **kwargs)\n", " Acceleration Bands (ACCBANDS)\n", " \n", " Acceleration Bands created by Price Headley plots upper and lower envelope\n", " bands around a simple moving average.\n", " \n", " Sources:\n", " https://www.tradingtechnologies.com/help/x-study/technical-indicator-definitions/acceleration-bands-abands/\n", " \n", " Calculation:\n", " Default Inputs:\n", " length=10, c=4\n", " EMA = Exponential Moving Average\n", " SMA = Simple Moving Average\n", " HL_RATIO = c * (high - low) / (high + low)\n", " LOW = low * (1 - HL_RATIO)\n", " HIGH = high * (1 + HL_RATIO)\n", " \n", " if 'ema':\n", " LOWER = EMA(LOW, length)\n", " MID = EMA(close, length)\n", " UPPER = EMA(HIGH, length)\n", " else:\n", " LOWER = SMA(LOW, length)\n", " MID = SMA(close, length)\n", " UPPER = SMA(HIGH, length)\n", " \n", " Args:\n", " high (pd.Series): Series of 'high's\n", " low (pd.Series): Series of 'low's\n", " close (pd.Series): Series of 'close's\n", " length (int): It's period. Default: 10\n", " c (int): Multiplier. Default: 4\n", " mamode (str): Two options: None or 'ema'. Default: 'ema'\n", " drift (int): The difference period. Default: 1\n", " offset (int): How many periods to offset the result. Default: 0\n", " \n", " Kwargs:\n", " fillna (value, optional): pd.DataFrame.fillna(value)\n", " fill_method (value, optional): Type of fill method\n", " \n", " Returns:\n", " pd.DataFrame: lower, mid, upper columns.\n", "\n" ] } ], "source": [ "e.ta.indicators()\n", "help(ta.accbands)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Load Daily EUR.USD from [AlphaVantage](http://www.alphavantage.com) and clean it up a little" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Shape: (100, 14)\n" ] }, { "data": { "text/html": [ "
| \n", " | open | \n", "high | \n", "low | \n", "close | \n", "-4 | \n", "-3 | \n", "-2 | \n", "-1 | \n", "0 | \n", "1 | \n", "2 | \n", "3 | \n", "4 | \n", "
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| date | \n", "\n", " | \n", " | \n", " | \n", " | \n", " | \n", " | \n", " | \n", " | \n", " | \n", " | \n", " | \n", " | \n", " |
| 2018-12-05 | \n", "1.1340 | \n", "1.1361 | \n", "1.1310 | \n", "1.1347 | \n", "-4 | \n", "-3 | \n", "-2 | \n", "-1 | \n", "0 | \n", "1 | \n", "2 | \n", "3 | \n", "4 | \n", "
| 2018-12-06 | \n", "1.1348 | \n", "1.1413 | \n", "1.1320 | \n", "1.1377 | \n", "-4 | \n", "-3 | \n", "-2 | \n", "-1 | \n", "0 | \n", "1 | \n", "2 | \n", "3 | \n", "4 | \n", "
| 2018-12-07 | \n", "1.1377 | \n", "1.1424 | \n", "1.1359 | \n", "1.1389 | \n", "-4 | \n", "-3 | \n", "-2 | \n", "-1 | \n", "0 | \n", "1 | \n", "2 | \n", "3 | \n", "4 | \n", "
| 2018-12-09 | \n", "1.1395 | \n", "1.1402 | \n", "1.1380 | \n", "1.1398 | \n", "-4 | \n", "-3 | \n", "-2 | \n", "-1 | \n", "0 | \n", "1 | \n", "2 | \n", "3 | \n", "4 | \n", "
| 2018-12-10 | \n", "1.1398 | \n", "1.1443 | \n", "1.1348 | \n", "1.1350 | \n", "-4 | \n", "-3 | \n", "-2 | \n", "-1 | \n", "0 | \n", "1 | \n", "2 | \n", "3 | \n", "4 | \n", "