mirror of
https://github.com/wassname/pandas-ta.git
synced 2026-06-27 16:10:07 +08:00
Add 2 TI : Heikin-Ashi and supertrend
This commit is contained in:
@@ -0,0 +1,667 @@
|
|||||||
|
{
|
||||||
|
"cells": [
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": 23,
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [],
|
||||||
|
"source": [
|
||||||
|
"import pandas_ta as ta"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": 2,
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [],
|
||||||
|
"source": [
|
||||||
|
"import pandas as pd"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": 3,
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [],
|
||||||
|
"source": [
|
||||||
|
"df = pd.read_csv('/virt/admin/Fic_entree/Dwx-NDXH8.csv', sep=',', header=None)"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": 4,
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [
|
||||||
|
{
|
||||||
|
"data": {
|
||||||
|
"text/html": [
|
||||||
|
"<div>\n",
|
||||||
|
"<style scoped>\n",
|
||||||
|
" .dataframe tbody tr th:only-of-type {\n",
|
||||||
|
" vertical-align: middle;\n",
|
||||||
|
" }\n",
|
||||||
|
"\n",
|
||||||
|
" .dataframe tbody tr th {\n",
|
||||||
|
" vertical-align: top;\n",
|
||||||
|
" }\n",
|
||||||
|
"\n",
|
||||||
|
" .dataframe thead th {\n",
|
||||||
|
" text-align: right;\n",
|
||||||
|
" }\n",
|
||||||
|
"</style>\n",
|
||||||
|
"<table border=\"1\" class=\"dataframe\">\n",
|
||||||
|
" <thead>\n",
|
||||||
|
" <tr style=\"text-align: right;\">\n",
|
||||||
|
" <th></th>\n",
|
||||||
|
" <th>0</th>\n",
|
||||||
|
" <th>1</th>\n",
|
||||||
|
" <th>2</th>\n",
|
||||||
|
" <th>3</th>\n",
|
||||||
|
" <th>4</th>\n",
|
||||||
|
" <th>5</th>\n",
|
||||||
|
" <th>6</th>\n",
|
||||||
|
" </tr>\n",
|
||||||
|
" </thead>\n",
|
||||||
|
" <tbody>\n",
|
||||||
|
" <tr>\n",
|
||||||
|
" <th>0</th>\n",
|
||||||
|
" <td>2017.04.20</td>\n",
|
||||||
|
" <td>00:00</td>\n",
|
||||||
|
" <td>5395.3</td>\n",
|
||||||
|
" <td>5455.3</td>\n",
|
||||||
|
" <td>5393.3</td>\n",
|
||||||
|
" <td>5401.5</td>\n",
|
||||||
|
" <td>34502</td>\n",
|
||||||
|
" </tr>\n",
|
||||||
|
" <tr>\n",
|
||||||
|
" <th>1</th>\n",
|
||||||
|
" <td>2017.04.20</td>\n",
|
||||||
|
" <td>08:00</td>\n",
|
||||||
|
" <td>5401.8</td>\n",
|
||||||
|
" <td>5421.5</td>\n",
|
||||||
|
" <td>5399.8</td>\n",
|
||||||
|
" <td>5418.8</td>\n",
|
||||||
|
" <td>7241</td>\n",
|
||||||
|
" </tr>\n",
|
||||||
|
" <tr>\n",
|
||||||
|
" <th>2</th>\n",
|
||||||
|
" <td>2017.04.20</td>\n",
|
||||||
|
" <td>16:00</td>\n",
|
||||||
|
" <td>5418.5</td>\n",
|
||||||
|
" <td>5455.3</td>\n",
|
||||||
|
" <td>5412.0</td>\n",
|
||||||
|
" <td>5444.3</td>\n",
|
||||||
|
" <td>21038</td>\n",
|
||||||
|
" </tr>\n",
|
||||||
|
" <tr>\n",
|
||||||
|
" <th>3</th>\n",
|
||||||
|
" <td>2017.04.21</td>\n",
|
||||||
|
" <td>00:00</td>\n",
|
||||||
|
" <td>5442.8</td>\n",
|
||||||
|
" <td>5450.0</td>\n",
|
||||||
|
" <td>5442.5</td>\n",
|
||||||
|
" <td>5448.5</td>\n",
|
||||||
|
" <td>2181</td>\n",
|
||||||
|
" </tr>\n",
|
||||||
|
" <tr>\n",
|
||||||
|
" <th>4</th>\n",
|
||||||
|
" <td>2017.04.21</td>\n",
|
||||||
|
" <td>08:00</td>\n",
|
||||||
|
" <td>5448.4</td>\n",
|
||||||
|
" <td>5455.3</td>\n",
|
||||||
|
" <td>5447.8</td>\n",
|
||||||
|
" <td>5448.5</td>\n",
|
||||||
|
" <td>7406</td>\n",
|
||||||
|
" </tr>\n",
|
||||||
|
" <tr>\n",
|
||||||
|
" <th>...</th>\n",
|
||||||
|
" <td>...</td>\n",
|
||||||
|
" <td>...</td>\n",
|
||||||
|
" <td>...</td>\n",
|
||||||
|
" <td>...</td>\n",
|
||||||
|
" <td>...</td>\n",
|
||||||
|
" <td>...</td>\n",
|
||||||
|
" <td>...</td>\n",
|
||||||
|
" </tr>\n",
|
||||||
|
" <tr>\n",
|
||||||
|
" <th>2387</th>\n",
|
||||||
|
" <td>2020.05.26</td>\n",
|
||||||
|
" <td>00:00</td>\n",
|
||||||
|
" <td>9532.4</td>\n",
|
||||||
|
" <td>9597.8</td>\n",
|
||||||
|
" <td>9509.8</td>\n",
|
||||||
|
" <td>9587.6</td>\n",
|
||||||
|
" <td>15120</td>\n",
|
||||||
|
" </tr>\n",
|
||||||
|
" <tr>\n",
|
||||||
|
" <th>2388</th>\n",
|
||||||
|
" <td>2020.05.26</td>\n",
|
||||||
|
" <td>08:00</td>\n",
|
||||||
|
" <td>9587.8</td>\n",
|
||||||
|
" <td>9609.1</td>\n",
|
||||||
|
" <td>9542.5</td>\n",
|
||||||
|
" <td>9555.6</td>\n",
|
||||||
|
" <td>31628</td>\n",
|
||||||
|
" </tr>\n",
|
||||||
|
" <tr>\n",
|
||||||
|
" <th>2389</th>\n",
|
||||||
|
" <td>2020.05.26</td>\n",
|
||||||
|
" <td>16:00</td>\n",
|
||||||
|
" <td>9556.1</td>\n",
|
||||||
|
" <td>9574.8</td>\n",
|
||||||
|
" <td>9378.1</td>\n",
|
||||||
|
" <td>9417.3</td>\n",
|
||||||
|
" <td>73867</td>\n",
|
||||||
|
" </tr>\n",
|
||||||
|
" <tr>\n",
|
||||||
|
" <th>2390</th>\n",
|
||||||
|
" <td>2020.05.27</td>\n",
|
||||||
|
" <td>00:00</td>\n",
|
||||||
|
" <td>9413.5</td>\n",
|
||||||
|
" <td>9500.5</td>\n",
|
||||||
|
" <td>9380.7</td>\n",
|
||||||
|
" <td>9487.5</td>\n",
|
||||||
|
" <td>20104</td>\n",
|
||||||
|
" </tr>\n",
|
||||||
|
" <tr>\n",
|
||||||
|
" <th>2391</th>\n",
|
||||||
|
" <td>2020.05.27</td>\n",
|
||||||
|
" <td>08:00</td>\n",
|
||||||
|
" <td>9487.2</td>\n",
|
||||||
|
" <td>9513.0</td>\n",
|
||||||
|
" <td>9391.7</td>\n",
|
||||||
|
" <td>9395.5</td>\n",
|
||||||
|
" <td>33445</td>\n",
|
||||||
|
" </tr>\n",
|
||||||
|
" </tbody>\n",
|
||||||
|
"</table>\n",
|
||||||
|
"<p>2392 rows × 7 columns</p>\n",
|
||||||
|
"</div>"
|
||||||
|
],
|
||||||
|
"text/plain": [
|
||||||
|
" 0 1 2 3 4 5 6\n",
|
||||||
|
"0 2017.04.20 00:00 5395.3 5455.3 5393.3 5401.5 34502\n",
|
||||||
|
"1 2017.04.20 08:00 5401.8 5421.5 5399.8 5418.8 7241\n",
|
||||||
|
"2 2017.04.20 16:00 5418.5 5455.3 5412.0 5444.3 21038\n",
|
||||||
|
"3 2017.04.21 00:00 5442.8 5450.0 5442.5 5448.5 2181\n",
|
||||||
|
"4 2017.04.21 08:00 5448.4 5455.3 5447.8 5448.5 7406\n",
|
||||||
|
"... ... ... ... ... ... ... ...\n",
|
||||||
|
"2387 2020.05.26 00:00 9532.4 9597.8 9509.8 9587.6 15120\n",
|
||||||
|
"2388 2020.05.26 08:00 9587.8 9609.1 9542.5 9555.6 31628\n",
|
||||||
|
"2389 2020.05.26 16:00 9556.1 9574.8 9378.1 9417.3 73867\n",
|
||||||
|
"2390 2020.05.27 00:00 9413.5 9500.5 9380.7 9487.5 20104\n",
|
||||||
|
"2391 2020.05.27 08:00 9487.2 9513.0 9391.7 9395.5 33445\n",
|
||||||
|
"\n",
|
||||||
|
"[2392 rows x 7 columns]"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"execution_count": 4,
|
||||||
|
"metadata": {},
|
||||||
|
"output_type": "execute_result"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"source": [
|
||||||
|
"df"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": 5,
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [],
|
||||||
|
"source": [
|
||||||
|
"df.columns=['date', 'time', 'open', 'high', 'low', 'close', 'ticks']"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": 18,
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [
|
||||||
|
{
|
||||||
|
"data": {
|
||||||
|
"text/html": [
|
||||||
|
"<div>\n",
|
||||||
|
"<style scoped>\n",
|
||||||
|
" .dataframe tbody tr th:only-of-type {\n",
|
||||||
|
" vertical-align: middle;\n",
|
||||||
|
" }\n",
|
||||||
|
"\n",
|
||||||
|
" .dataframe tbody tr th {\n",
|
||||||
|
" vertical-align: top;\n",
|
||||||
|
" }\n",
|
||||||
|
"\n",
|
||||||
|
" .dataframe thead th {\n",
|
||||||
|
" text-align: right;\n",
|
||||||
|
" }\n",
|
||||||
|
"</style>\n",
|
||||||
|
"<table border=\"1\" class=\"dataframe\">\n",
|
||||||
|
" <thead>\n",
|
||||||
|
" <tr style=\"text-align: right;\">\n",
|
||||||
|
" <th></th>\n",
|
||||||
|
" <th>STOCHFk_14</th>\n",
|
||||||
|
" <th>STOCHFd_3</th>\n",
|
||||||
|
" <th>STOCHk_3</th>\n",
|
||||||
|
" <th>STOCHd_3</th>\n",
|
||||||
|
" </tr>\n",
|
||||||
|
" </thead>\n",
|
||||||
|
" <tbody>\n",
|
||||||
|
" <tr>\n",
|
||||||
|
" <th>0</th>\n",
|
||||||
|
" <td>NaN</td>\n",
|
||||||
|
" <td>NaN</td>\n",
|
||||||
|
" <td>NaN</td>\n",
|
||||||
|
" <td>NaN</td>\n",
|
||||||
|
" </tr>\n",
|
||||||
|
" <tr>\n",
|
||||||
|
" <th>1</th>\n",
|
||||||
|
" <td>NaN</td>\n",
|
||||||
|
" <td>NaN</td>\n",
|
||||||
|
" <td>NaN</td>\n",
|
||||||
|
" <td>NaN</td>\n",
|
||||||
|
" </tr>\n",
|
||||||
|
" <tr>\n",
|
||||||
|
" <th>2</th>\n",
|
||||||
|
" <td>82.258065</td>\n",
|
||||||
|
" <td>NaN</td>\n",
|
||||||
|
" <td>NaN</td>\n",
|
||||||
|
" <td>NaN</td>\n",
|
||||||
|
" </tr>\n",
|
||||||
|
" <tr>\n",
|
||||||
|
" <th>3</th>\n",
|
||||||
|
" <td>87.747748</td>\n",
|
||||||
|
" <td>NaN</td>\n",
|
||||||
|
" <td>NaN</td>\n",
|
||||||
|
" <td>NaN</td>\n",
|
||||||
|
" </tr>\n",
|
||||||
|
" <tr>\n",
|
||||||
|
" <th>4</th>\n",
|
||||||
|
" <td>84.295612</td>\n",
|
||||||
|
" <td>84.767141</td>\n",
|
||||||
|
" <td>84.767141</td>\n",
|
||||||
|
" <td>NaN</td>\n",
|
||||||
|
" </tr>\n",
|
||||||
|
" <tr>\n",
|
||||||
|
" <th>...</th>\n",
|
||||||
|
" <td>...</td>\n",
|
||||||
|
" <td>...</td>\n",
|
||||||
|
" <td>...</td>\n",
|
||||||
|
" <td>...</td>\n",
|
||||||
|
" </tr>\n",
|
||||||
|
" <tr>\n",
|
||||||
|
" <th>2387</th>\n",
|
||||||
|
" <td>93.098782</td>\n",
|
||||||
|
" <td>95.820450</td>\n",
|
||||||
|
" <td>95.820450</td>\n",
|
||||||
|
" <td>96.319133</td>\n",
|
||||||
|
" </tr>\n",
|
||||||
|
" <tr>\n",
|
||||||
|
" <th>2388</th>\n",
|
||||||
|
" <td>46.122860</td>\n",
|
||||||
|
" <td>78.475307</td>\n",
|
||||||
|
" <td>78.475307</td>\n",
|
||||||
|
" <td>90.117018</td>\n",
|
||||||
|
" </tr>\n",
|
||||||
|
" <tr>\n",
|
||||||
|
" <th>2389</th>\n",
|
||||||
|
" <td>16.969697</td>\n",
|
||||||
|
" <td>52.063780</td>\n",
|
||||||
|
" <td>52.063780</td>\n",
|
||||||
|
" <td>75.453179</td>\n",
|
||||||
|
" </tr>\n",
|
||||||
|
" <tr>\n",
|
||||||
|
" <th>2390</th>\n",
|
||||||
|
" <td>47.359307</td>\n",
|
||||||
|
" <td>36.817288</td>\n",
|
||||||
|
" <td>36.817288</td>\n",
|
||||||
|
" <td>55.785458</td>\n",
|
||||||
|
" </tr>\n",
|
||||||
|
" <tr>\n",
|
||||||
|
" <th>2391</th>\n",
|
||||||
|
" <td>8.845958</td>\n",
|
||||||
|
" <td>24.391654</td>\n",
|
||||||
|
" <td>24.391654</td>\n",
|
||||||
|
" <td>37.757574</td>\n",
|
||||||
|
" </tr>\n",
|
||||||
|
" </tbody>\n",
|
||||||
|
"</table>\n",
|
||||||
|
"<p>2392 rows × 4 columns</p>\n",
|
||||||
|
"</div>"
|
||||||
|
],
|
||||||
|
"text/plain": [
|
||||||
|
" STOCHFk_14 STOCHFd_3 STOCHk_3 STOCHd_3\n",
|
||||||
|
"0 NaN NaN NaN NaN\n",
|
||||||
|
"1 NaN NaN NaN NaN\n",
|
||||||
|
"2 82.258065 NaN NaN NaN\n",
|
||||||
|
"3 87.747748 NaN NaN NaN\n",
|
||||||
|
"4 84.295612 84.767141 84.767141 NaN\n",
|
||||||
|
"... ... ... ... ...\n",
|
||||||
|
"2387 93.098782 95.820450 95.820450 96.319133\n",
|
||||||
|
"2388 46.122860 78.475307 78.475307 90.117018\n",
|
||||||
|
"2389 16.969697 52.063780 52.063780 75.453179\n",
|
||||||
|
"2390 47.359307 36.817288 36.817288 55.785458\n",
|
||||||
|
"2391 8.845958 24.391654 24.391654 37.757574\n",
|
||||||
|
"\n",
|
||||||
|
"[2392 rows x 4 columns]"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"execution_count": 18,
|
||||||
|
"metadata": {},
|
||||||
|
"output_type": "execute_result"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"source": [
|
||||||
|
"df.ta.stoch(df['high'], df['low'], df['close'], 14,3,3, append = True)"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": 19,
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [
|
||||||
|
{
|
||||||
|
"data": {
|
||||||
|
"text/plain": [
|
||||||
|
"Index(['date', 'time', 'open', 'high', 'low', 'close', 'ticks', 'STOCHFk_14',\n",
|
||||||
|
" 'STOCHFd_3', 'STOCHk_3', 'STOCHd_3'],\n",
|
||||||
|
" dtype='object')"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"execution_count": 19,
|
||||||
|
"metadata": {},
|
||||||
|
"output_type": "execute_result"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"source": [
|
||||||
|
"df.columns"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": 20,
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [
|
||||||
|
{
|
||||||
|
"data": {
|
||||||
|
"text/html": [
|
||||||
|
"<div>\n",
|
||||||
|
"<style scoped>\n",
|
||||||
|
" .dataframe tbody tr th:only-of-type {\n",
|
||||||
|
" vertical-align: middle;\n",
|
||||||
|
" }\n",
|
||||||
|
"\n",
|
||||||
|
" .dataframe tbody tr th {\n",
|
||||||
|
" vertical-align: top;\n",
|
||||||
|
" }\n",
|
||||||
|
"\n",
|
||||||
|
" .dataframe thead th {\n",
|
||||||
|
" text-align: right;\n",
|
||||||
|
" }\n",
|
||||||
|
"</style>\n",
|
||||||
|
"<table border=\"1\" class=\"dataframe\">\n",
|
||||||
|
" <thead>\n",
|
||||||
|
" <tr style=\"text-align: right;\">\n",
|
||||||
|
" <th></th>\n",
|
||||||
|
" <th>date</th>\n",
|
||||||
|
" <th>time</th>\n",
|
||||||
|
" <th>open</th>\n",
|
||||||
|
" <th>high</th>\n",
|
||||||
|
" <th>low</th>\n",
|
||||||
|
" <th>close</th>\n",
|
||||||
|
" <th>ticks</th>\n",
|
||||||
|
" <th>STOCHFk_14</th>\n",
|
||||||
|
" <th>STOCHFd_3</th>\n",
|
||||||
|
" <th>STOCHk_3</th>\n",
|
||||||
|
" <th>STOCHd_3</th>\n",
|
||||||
|
" </tr>\n",
|
||||||
|
" </thead>\n",
|
||||||
|
" <tbody>\n",
|
||||||
|
" <tr>\n",
|
||||||
|
" <th>0</th>\n",
|
||||||
|
" <td>2017.04.20</td>\n",
|
||||||
|
" <td>00:00</td>\n",
|
||||||
|
" <td>5395.3</td>\n",
|
||||||
|
" <td>5455.3</td>\n",
|
||||||
|
" <td>5393.3</td>\n",
|
||||||
|
" <td>5401.5</td>\n",
|
||||||
|
" <td>34502</td>\n",
|
||||||
|
" <td>NaN</td>\n",
|
||||||
|
" <td>NaN</td>\n",
|
||||||
|
" <td>NaN</td>\n",
|
||||||
|
" <td>NaN</td>\n",
|
||||||
|
" </tr>\n",
|
||||||
|
" <tr>\n",
|
||||||
|
" <th>1</th>\n",
|
||||||
|
" <td>2017.04.20</td>\n",
|
||||||
|
" <td>08:00</td>\n",
|
||||||
|
" <td>5401.8</td>\n",
|
||||||
|
" <td>5421.5</td>\n",
|
||||||
|
" <td>5399.8</td>\n",
|
||||||
|
" <td>5418.8</td>\n",
|
||||||
|
" <td>7241</td>\n",
|
||||||
|
" <td>NaN</td>\n",
|
||||||
|
" <td>NaN</td>\n",
|
||||||
|
" <td>NaN</td>\n",
|
||||||
|
" <td>NaN</td>\n",
|
||||||
|
" </tr>\n",
|
||||||
|
" <tr>\n",
|
||||||
|
" <th>2</th>\n",
|
||||||
|
" <td>2017.04.20</td>\n",
|
||||||
|
" <td>16:00</td>\n",
|
||||||
|
" <td>5418.5</td>\n",
|
||||||
|
" <td>5455.3</td>\n",
|
||||||
|
" <td>5412.0</td>\n",
|
||||||
|
" <td>5444.3</td>\n",
|
||||||
|
" <td>21038</td>\n",
|
||||||
|
" <td>82.258065</td>\n",
|
||||||
|
" <td>NaN</td>\n",
|
||||||
|
" <td>NaN</td>\n",
|
||||||
|
" <td>NaN</td>\n",
|
||||||
|
" </tr>\n",
|
||||||
|
" <tr>\n",
|
||||||
|
" <th>3</th>\n",
|
||||||
|
" <td>2017.04.21</td>\n",
|
||||||
|
" <td>00:00</td>\n",
|
||||||
|
" <td>5442.8</td>\n",
|
||||||
|
" <td>5450.0</td>\n",
|
||||||
|
" <td>5442.5</td>\n",
|
||||||
|
" <td>5448.5</td>\n",
|
||||||
|
" <td>2181</td>\n",
|
||||||
|
" <td>87.747748</td>\n",
|
||||||
|
" <td>NaN</td>\n",
|
||||||
|
" <td>NaN</td>\n",
|
||||||
|
" <td>NaN</td>\n",
|
||||||
|
" </tr>\n",
|
||||||
|
" <tr>\n",
|
||||||
|
" <th>4</th>\n",
|
||||||
|
" <td>2017.04.21</td>\n",
|
||||||
|
" <td>08:00</td>\n",
|
||||||
|
" <td>5448.4</td>\n",
|
||||||
|
" <td>5455.3</td>\n",
|
||||||
|
" <td>5447.8</td>\n",
|
||||||
|
" <td>5448.5</td>\n",
|
||||||
|
" <td>7406</td>\n",
|
||||||
|
" <td>84.295612</td>\n",
|
||||||
|
" <td>84.767141</td>\n",
|
||||||
|
" <td>84.767141</td>\n",
|
||||||
|
" <td>NaN</td>\n",
|
||||||
|
" </tr>\n",
|
||||||
|
" <tr>\n",
|
||||||
|
" <th>...</th>\n",
|
||||||
|
" <td>...</td>\n",
|
||||||
|
" <td>...</td>\n",
|
||||||
|
" <td>...</td>\n",
|
||||||
|
" <td>...</td>\n",
|
||||||
|
" <td>...</td>\n",
|
||||||
|
" <td>...</td>\n",
|
||||||
|
" <td>...</td>\n",
|
||||||
|
" <td>...</td>\n",
|
||||||
|
" <td>...</td>\n",
|
||||||
|
" <td>...</td>\n",
|
||||||
|
" <td>...</td>\n",
|
||||||
|
" </tr>\n",
|
||||||
|
" <tr>\n",
|
||||||
|
" <th>2387</th>\n",
|
||||||
|
" <td>2020.05.26</td>\n",
|
||||||
|
" <td>00:00</td>\n",
|
||||||
|
" <td>9532.4</td>\n",
|
||||||
|
" <td>9597.8</td>\n",
|
||||||
|
" <td>9509.8</td>\n",
|
||||||
|
" <td>9587.6</td>\n",
|
||||||
|
" <td>15120</td>\n",
|
||||||
|
" <td>93.098782</td>\n",
|
||||||
|
" <td>95.820450</td>\n",
|
||||||
|
" <td>95.820450</td>\n",
|
||||||
|
" <td>96.319133</td>\n",
|
||||||
|
" </tr>\n",
|
||||||
|
" <tr>\n",
|
||||||
|
" <th>2388</th>\n",
|
||||||
|
" <td>2020.05.26</td>\n",
|
||||||
|
" <td>08:00</td>\n",
|
||||||
|
" <td>9587.8</td>\n",
|
||||||
|
" <td>9609.1</td>\n",
|
||||||
|
" <td>9542.5</td>\n",
|
||||||
|
" <td>9555.6</td>\n",
|
||||||
|
" <td>31628</td>\n",
|
||||||
|
" <td>46.122860</td>\n",
|
||||||
|
" <td>78.475307</td>\n",
|
||||||
|
" <td>78.475307</td>\n",
|
||||||
|
" <td>90.117018</td>\n",
|
||||||
|
" </tr>\n",
|
||||||
|
" <tr>\n",
|
||||||
|
" <th>2389</th>\n",
|
||||||
|
" <td>2020.05.26</td>\n",
|
||||||
|
" <td>16:00</td>\n",
|
||||||
|
" <td>9556.1</td>\n",
|
||||||
|
" <td>9574.8</td>\n",
|
||||||
|
" <td>9378.1</td>\n",
|
||||||
|
" <td>9417.3</td>\n",
|
||||||
|
" <td>73867</td>\n",
|
||||||
|
" <td>16.969697</td>\n",
|
||||||
|
" <td>52.063780</td>\n",
|
||||||
|
" <td>52.063780</td>\n",
|
||||||
|
" <td>75.453179</td>\n",
|
||||||
|
" </tr>\n",
|
||||||
|
" <tr>\n",
|
||||||
|
" <th>2390</th>\n",
|
||||||
|
" <td>2020.05.27</td>\n",
|
||||||
|
" <td>00:00</td>\n",
|
||||||
|
" <td>9413.5</td>\n",
|
||||||
|
" <td>9500.5</td>\n",
|
||||||
|
" <td>9380.7</td>\n",
|
||||||
|
" <td>9487.5</td>\n",
|
||||||
|
" <td>20104</td>\n",
|
||||||
|
" <td>47.359307</td>\n",
|
||||||
|
" <td>36.817288</td>\n",
|
||||||
|
" <td>36.817288</td>\n",
|
||||||
|
" <td>55.785458</td>\n",
|
||||||
|
" </tr>\n",
|
||||||
|
" <tr>\n",
|
||||||
|
" <th>2391</th>\n",
|
||||||
|
" <td>2020.05.27</td>\n",
|
||||||
|
" <td>08:00</td>\n",
|
||||||
|
" <td>9487.2</td>\n",
|
||||||
|
" <td>9513.0</td>\n",
|
||||||
|
" <td>9391.7</td>\n",
|
||||||
|
" <td>9395.5</td>\n",
|
||||||
|
" <td>33445</td>\n",
|
||||||
|
" <td>8.845958</td>\n",
|
||||||
|
" <td>24.391654</td>\n",
|
||||||
|
" <td>24.391654</td>\n",
|
||||||
|
" <td>37.757574</td>\n",
|
||||||
|
" </tr>\n",
|
||||||
|
" </tbody>\n",
|
||||||
|
"</table>\n",
|
||||||
|
"<p>2392 rows × 11 columns</p>\n",
|
||||||
|
"</div>"
|
||||||
|
],
|
||||||
|
"text/plain": [
|
||||||
|
" date time open high low close ticks STOCHFk_14 \\\n",
|
||||||
|
"0 2017.04.20 00:00 5395.3 5455.3 5393.3 5401.5 34502 NaN \n",
|
||||||
|
"1 2017.04.20 08:00 5401.8 5421.5 5399.8 5418.8 7241 NaN \n",
|
||||||
|
"2 2017.04.20 16:00 5418.5 5455.3 5412.0 5444.3 21038 82.258065 \n",
|
||||||
|
"3 2017.04.21 00:00 5442.8 5450.0 5442.5 5448.5 2181 87.747748 \n",
|
||||||
|
"4 2017.04.21 08:00 5448.4 5455.3 5447.8 5448.5 7406 84.295612 \n",
|
||||||
|
"... ... ... ... ... ... ... ... ... \n",
|
||||||
|
"2387 2020.05.26 00:00 9532.4 9597.8 9509.8 9587.6 15120 93.098782 \n",
|
||||||
|
"2388 2020.05.26 08:00 9587.8 9609.1 9542.5 9555.6 31628 46.122860 \n",
|
||||||
|
"2389 2020.05.26 16:00 9556.1 9574.8 9378.1 9417.3 73867 16.969697 \n",
|
||||||
|
"2390 2020.05.27 00:00 9413.5 9500.5 9380.7 9487.5 20104 47.359307 \n",
|
||||||
|
"2391 2020.05.27 08:00 9487.2 9513.0 9391.7 9395.5 33445 8.845958 \n",
|
||||||
|
"\n",
|
||||||
|
" STOCHFd_3 STOCHk_3 STOCHd_3 \n",
|
||||||
|
"0 NaN NaN NaN \n",
|
||||||
|
"1 NaN NaN NaN \n",
|
||||||
|
"2 NaN NaN NaN \n",
|
||||||
|
"3 NaN NaN NaN \n",
|
||||||
|
"4 84.767141 84.767141 NaN \n",
|
||||||
|
"... ... ... ... \n",
|
||||||
|
"2387 95.820450 95.820450 96.319133 \n",
|
||||||
|
"2388 78.475307 78.475307 90.117018 \n",
|
||||||
|
"2389 52.063780 52.063780 75.453179 \n",
|
||||||
|
"2390 36.817288 36.817288 55.785458 \n",
|
||||||
|
"2391 24.391654 24.391654 37.757574 \n",
|
||||||
|
"\n",
|
||||||
|
"[2392 rows x 11 columns]"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"execution_count": 20,
|
||||||
|
"metadata": {},
|
||||||
|
"output_type": "execute_result"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"source": [
|
||||||
|
"df"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": 24,
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [
|
||||||
|
{
|
||||||
|
"ename": "AttributeError",
|
||||||
|
"evalue": "module 'pandas_ta' has no attribute 'ha'",
|
||||||
|
"output_type": "error",
|
||||||
|
"traceback": [
|
||||||
|
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
|
||||||
|
"\u001b[0;31mAttributeError\u001b[0m Traceback (most recent call last)",
|
||||||
|
"\u001b[0;32m<ipython-input-24-c6639b8e7a6b>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mhelp\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mta\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mha\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m",
|
||||||
|
"\u001b[0;31mAttributeError\u001b[0m: module 'pandas_ta' has no attribute 'ha'"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"source": [
|
||||||
|
"help(ta.ha)"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": null,
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [],
|
||||||
|
"source": []
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"metadata": {
|
||||||
|
"kernelspec": {
|
||||||
|
"display_name": "Python 3",
|
||||||
|
"language": "python",
|
||||||
|
"name": "python3"
|
||||||
|
},
|
||||||
|
"language_info": {
|
||||||
|
"codemirror_mode": {
|
||||||
|
"name": "ipython",
|
||||||
|
"version": 3
|
||||||
|
},
|
||||||
|
"file_extension": ".py",
|
||||||
|
"mimetype": "text/x-python",
|
||||||
|
"name": "python",
|
||||||
|
"nbconvert_exporter": "python",
|
||||||
|
"pygments_lexer": "ipython3",
|
||||||
|
"version": "3.7.3"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"nbformat": 4,
|
||||||
|
"nbformat_minor": 4
|
||||||
|
}
|
||||||
@@ -881,6 +881,17 @@ class AnalysisIndicators(BasePandasObject):
|
|||||||
self._append(result, **kwargs)
|
self._append(result, **kwargs)
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
def ha(self, open=None, high=None, low=None, close=None, offset=None, **kwargs):
|
||||||
|
open = self._get_column(open, 'open')
|
||||||
|
high = self._get_column(high, 'high')
|
||||||
|
low = self._get_column(low, 'low')
|
||||||
|
close = self._get_column(close, 'close')
|
||||||
|
|
||||||
|
result = ha(open=open, high=high, low=low, close=close, offset=offset, **kwargs)
|
||||||
|
self._add_prefix_suffix(result, **kwargs)
|
||||||
|
self._append(result, **kwargs)
|
||||||
|
return result
|
||||||
|
|
||||||
def increasing(self, close=None, length=None, asint=True, offset=None, **kwargs):
|
def increasing(self, close=None, length=None, asint=True, offset=None, **kwargs):
|
||||||
close = self._get_column(close, 'close')
|
close = self._get_column(close, 'close')
|
||||||
|
|
||||||
@@ -939,6 +950,18 @@ class AnalysisIndicators(BasePandasObject):
|
|||||||
self._append(result, **kwargs)
|
self._append(result, **kwargs)
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
def supertrend(self, high=None, low=None, close=None, period=None, multiplier=None, mamode=None, drift=None,
|
||||||
|
offset=None, **kwargs):
|
||||||
|
high = self._get_column(high, 'high')
|
||||||
|
low = self._get_column(low, 'low')
|
||||||
|
close = self._get_column(close, 'close')
|
||||||
|
|
||||||
|
result = supertrend(high=high, low=low, close=close, period=period, multiplier=multiplier, mamode=mamode, drift=drift, offset=offset, **kwargs)
|
||||||
|
self._add_prefix_suffix(result, **kwargs)
|
||||||
|
self._append(result, **kwargs)
|
||||||
|
return result
|
||||||
|
|
||||||
|
|
||||||
def vortex(self, high=None, low=None, close=None, drift=None, offset=None, **kwargs):
|
def vortex(self, high=None, low=None, close=None, drift=None, offset=None, **kwargs):
|
||||||
high = self._get_column(high, 'high')
|
high = self._get_column(high, 'high')
|
||||||
low = self._get_column(low, 'low')
|
low = self._get_column(low, 'low')
|
||||||
|
|||||||
@@ -6,10 +6,12 @@ from .chop import chop
|
|||||||
from .cksp import cksp
|
from .cksp import cksp
|
||||||
from .decreasing import decreasing
|
from .decreasing import decreasing
|
||||||
from .dpo import dpo
|
from .dpo import dpo
|
||||||
|
from .ha import ha
|
||||||
from .increasing import increasing
|
from .increasing import increasing
|
||||||
from .linear_decay import linear_decay
|
from .linear_decay import linear_decay
|
||||||
from .long_run import long_run
|
from .long_run import long_run
|
||||||
from .psar import psar
|
from .psar import psar
|
||||||
from .qstick import qstick
|
from .qstick import qstick
|
||||||
from .short_run import short_run
|
from .short_run import short_run
|
||||||
|
from .supertrend import supertrend
|
||||||
from .vortex import vortex
|
from .vortex import vortex
|
||||||
@@ -1,11 +1,11 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
import numpy as np
|
import numpy as np
|
||||||
from pandas import DataFrame
|
from pandas import DataFrame
|
||||||
from ..utils import get_offset, verify_series
|
from pandas_ta.utils import get_offset, verify_series
|
||||||
|
|
||||||
|
|
||||||
def ha(open, high, low, close, offset=None, **kwargs):
|
def ha(open, high, low, close, offset=None, **kwargs):
|
||||||
# indicator : Heiken Ashi
|
# indicator : Heikin Ashi
|
||||||
# Validate Arguments
|
# Validate Arguments
|
||||||
open = verify_series(open)
|
open = verify_series(open)
|
||||||
high = verify_series(high)
|
high = verify_series(high)
|
||||||
@@ -13,32 +13,28 @@ def ha(open, high, low, close, offset=None, **kwargs):
|
|||||||
close = verify_series(close)
|
close = verify_series(close)
|
||||||
offset = get_offset(offset)
|
offset = get_offset(offset)
|
||||||
|
|
||||||
# Initialization of the ha_open serie
|
#calculate ha_close
|
||||||
|
ha_close = 0.25 * (open + high + low + close)
|
||||||
|
|
||||||
|
# Initialization of the ha_open array
|
||||||
ha_open = np.zeros(shape=(len(close)))
|
ha_open = np.zeros(shape=(len(close)))
|
||||||
|
|
||||||
# ha_open of the first element
|
# ha_open of the first element
|
||||||
ha_open[0] = 0.5 * (open[0] + close[0])
|
ha_open[0] = 0.5 * (open[0] + close[0])
|
||||||
|
|
||||||
# shift open and close series by one to calculate ha_open other elements
|
#calculate ha_open. Based on previous ha_open & ha_close
|
||||||
open_shifted = np.empty_like(open)
|
for i in range (1, len(close)):
|
||||||
open_shifted[:1] = np.nan
|
ha_open[i] = 0.5 * (ha_open[i-1] + ha_close[i-1])
|
||||||
open_shifted[1:] = open[:-1]
|
|
||||||
close_shifted = np.empty_like(close)
|
|
||||||
close_shifted[:1] = np.nan
|
|
||||||
close_shifted[1:] = close[:-1]
|
|
||||||
# Calculation of ha_open except first element
|
|
||||||
ha_open[1:] = 0.5 * (open_shifted[1:] + close_shifted[1:])
|
|
||||||
|
|
||||||
# calculation of ha_close, ha_high, ha_low
|
# calculation of ha_high & ha_low
|
||||||
ha_close = 0.25 * (open + high + low + close)
|
|
||||||
ha_high = np.maximum.reduce([high, ha_open, ha_close])
|
ha_high = np.maximum.reduce([high, ha_open, ha_close])
|
||||||
ha_low = np.minimum.reduce([low, ha_open, ha_close])
|
ha_low = np.minimum.reduce([low, ha_open, ha_close])
|
||||||
|
|
||||||
# Prepare DataFrame to return
|
# Prepare DataFrame to return
|
||||||
data = {'ha_open': ha_open, 'ha_high': ha_high, 'ha_low': ha_low, 'ha_close': ha_close}
|
data = {'ha_open': ha_open, 'ha_high': ha_high, 'ha_low': ha_low, 'ha_close': ha_close}
|
||||||
hadf = DataFrame(data)
|
hadf = DataFrame(data)
|
||||||
hadf.name = "Heiken-Ashi"
|
hadf.name = "Heikin-Ashi"
|
||||||
hadf.category = 'overlap'
|
hadf.category = 'trend'
|
||||||
|
|
||||||
# Apply offset if needed
|
# Apply offset if needed
|
||||||
if offset != 0:
|
if offset != 0:
|
||||||
@@ -55,7 +51,7 @@ def ha(open, high, low, close, offset=None, **kwargs):
|
|||||||
|
|
||||||
|
|
||||||
ha.__doc__ = \
|
ha.__doc__ = \
|
||||||
"""Heiken Ashi (HA)
|
"""Heikin Ashi (HA)
|
||||||
|
|
||||||
The Heikin-Ashi technique averages price data to create a Japanese candlestick chart that filters out market noise.
|
The Heikin-Ashi technique averages price data to create a Japanese candlestick chart that filters out market noise.
|
||||||
Heikin-Ashi charts, developed by Munehisa Homma in the 1700s,
|
Heikin-Ashi charts, developed by Munehisa Homma in the 1700s,
|
||||||
@@ -69,7 +65,7 @@ Sources:
|
|||||||
https://www.investopedia.com/terms/h/heikinashi.asp
|
https://www.investopedia.com/terms/h/heikinashi.asp
|
||||||
|
|
||||||
Calculation:
|
Calculation:
|
||||||
The Formula for the Heikin-Ashi Technique Is:
|
The Formula for the Heikin-Ashi technique is:
|
||||||
|
|
||||||
Heikin-Ashi Close=(Open0+High0+Low0+Close0)/4
|
Heikin-Ashi Close=(Open0+High0+Low0+Close0)/4
|
||||||
Heikin-Ashi Open=(HA Open−1+HA Close−1)/2
|
Heikin-Ashi Open=(HA Open−1+HA Close−1)/2
|
||||||
@@ -0,0 +1,101 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
import numpy as np
|
||||||
|
from pandas import DataFrame
|
||||||
|
from ..utils import get_offset, verify_series
|
||||||
|
from ..volatility import atr
|
||||||
|
|
||||||
|
def supertrend(high, low, close, period=None, multiplier=None, mamode=None, drift=None, offset=None, **kwargs):
|
||||||
|
# indicator : supertrend
|
||||||
|
# Validate Arguments
|
||||||
|
high = verify_series(high)
|
||||||
|
low = verify_series(low)
|
||||||
|
close = verify_series(close)
|
||||||
|
offset = get_offset(offset)
|
||||||
|
period = int(period) if period and period > 0 else 10
|
||||||
|
multiplier = float(multiplier) if multiplier and multiplier > 0 else 1.5
|
||||||
|
min_periods = int(kwargs['min_periods']) if 'min_periods' in kwargs and kwargs[
|
||||||
|
'min_periods'] is not None else period
|
||||||
|
|
||||||
|
st_updown = np.zeros(shape=(len(close)))
|
||||||
|
strend = np.zeros(shape=(len(close)))
|
||||||
|
|
||||||
|
# Bands initial calculation
|
||||||
|
midrange = 0.5 * (high + low)
|
||||||
|
distance = multiplier * atr(high, low, close, period, mamode, drift, offset, min_periods=min_periods)
|
||||||
|
lowerband = midrange - distance
|
||||||
|
upperband = midrange + distance
|
||||||
|
|
||||||
|
# final calculation loop
|
||||||
|
for i in range(1, len(close)):
|
||||||
|
if close[i] > upperband[i-1]:
|
||||||
|
st_updown[i] = 1
|
||||||
|
elif close[i] < lowerband[i-1]:
|
||||||
|
st_updown[i] = -1
|
||||||
|
else:
|
||||||
|
st_updown[i] = st_updown[i-1]
|
||||||
|
if st_updown[i] > 0 and lowerband[i] < lowerband[i-1]:
|
||||||
|
lowerband[i] = lowerband[i-1]
|
||||||
|
if st_updown[i] < 0 and upperband[i] > upperband[i-1]:
|
||||||
|
upperband[i] = upperband[i-1]
|
||||||
|
if st_updown[i] < 0 and st_updown[i-1] > 0:
|
||||||
|
upperband = midrange + distance
|
||||||
|
if st_updown[i] > 0 and st_updown[i-1] < 0:
|
||||||
|
lowerband = midrange - distance
|
||||||
|
if st_updown[i] < 0 :
|
||||||
|
strend[i] = upperband[i]
|
||||||
|
else:
|
||||||
|
strend[i] = lowerband[i]
|
||||||
|
|
||||||
|
|
||||||
|
# Prepare DataFrame to return
|
||||||
|
data = {f"supertrend_{period}_{multiplier}": strend, f"st_updown_{period}_{multiplier}": st_updown}
|
||||||
|
supertrend_df = DataFrame(data)
|
||||||
|
supertrend_df.name = f"supertrend_{period}_{multiplier}"
|
||||||
|
supertrend_df.category = 'trend'
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# Apply offset if needed
|
||||||
|
if offset != 0:
|
||||||
|
supertrend_df = supertrend_df.shift(offset)
|
||||||
|
|
||||||
|
# Handle fills
|
||||||
|
if 'fillna' in kwargs:
|
||||||
|
supertrend_df.fillna(kwargs['fillna'], inplace=True)
|
||||||
|
|
||||||
|
if 'fill_method' in kwargs:
|
||||||
|
supertrend_df.fillna(method=kwargs['fill_method'], inplace=True)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
return supertrend_df
|
||||||
|
|
||||||
|
supertrend.__doc__ = \
|
||||||
|
"""Supertrend (supertrend)
|
||||||
|
|
||||||
|
Supertrend is a trend indicator. It was created by Olivier Seban
|
||||||
|
|
||||||
|
Sources:
|
||||||
|
https://www.abcbourse.com/apprendre/11_le_supertrend.html
|
||||||
|
(in french, but many other can be found using a search engine)
|
||||||
|
|
||||||
|
Calculation:
|
||||||
|
Default Inputs:
|
||||||
|
period = 10
|
||||||
|
multiplier = 1.5
|
||||||
|
|
||||||
|
|
||||||
|
Args:
|
||||||
|
high (pd.Series): Series of 'high's
|
||||||
|
low (pd.Series): Series of 'low's
|
||||||
|
close (pd.Series): Series of 'close's
|
||||||
|
|
||||||
|
offset (int): How many periods to offset the result. Default: 0
|
||||||
|
|
||||||
|
Kwargs:
|
||||||
|
fillna (value, optional): pd.DataFrame.fillna(value)
|
||||||
|
fill_method (value, optional): Type of fill method
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
pd.DataFrame: supertrend, st_updown, slowk, slowd columns.
|
||||||
|
"""
|
||||||
Reference in New Issue
Block a user