mirror of
https://github.com/aguru-venkata-saisantosh-patnaik/Forex-Quantitative-Trading-Strategy-Development.git
synced 2026-08-07 15:57:48 +00:00
9123 lines
1.4 MiB
Plaintext
9123 lines
1.4 MiB
Plaintext
|
|
{
|
|||
|
|
"cells": [
|
|||
|
|
{
|
|||
|
|
"cell_type": "markdown",
|
|||
|
|
"metadata": {},
|
|||
|
|
"source": [
|
|||
|
|
"# Reading given data"
|
|||
|
|
]
|
|||
|
|
},
|
|||
|
|
{
|
|||
|
|
"cell_type": "code",
|
|||
|
|
"execution_count": 1,
|
|||
|
|
"metadata": {
|
|||
|
|
"colab": {
|
|||
|
|
"base_uri": "https://localhost:8080/",
|
|||
|
|
"height": 424
|
|||
|
|
},
|
|||
|
|
"id": "RlMur3_ELMtB",
|
|||
|
|
"outputId": "e63f3eaf-88cc-428d-dbd5-cacde139ae8c"
|
|||
|
|
},
|
|||
|
|
"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>Open</th>\n",
|
|||
|
|
" <th>High</th>\n",
|
|||
|
|
" <th>Low</th>\n",
|
|||
|
|
" <th>Close</th>\n",
|
|||
|
|
" <th>Volume</th>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" </thead>\n",
|
|||
|
|
" <tbody>\n",
|
|||
|
|
" <tr>\n",
|
|||
|
|
" <th>0</th>\n",
|
|||
|
|
" <td>2004-12-31 20:00:00</td>\n",
|
|||
|
|
" <td>1.35460</td>\n",
|
|||
|
|
" <td>1.35860</td>\n",
|
|||
|
|
" <td>1.35370</td>\n",
|
|||
|
|
" <td>1.35710</td>\n",
|
|||
|
|
" <td>409.0</td>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" <tr>\n",
|
|||
|
|
" <th>1</th>\n",
|
|||
|
|
" <td>2004-12-31 21:00:00</td>\n",
|
|||
|
|
" <td>1.35720</td>\n",
|
|||
|
|
" <td>1.35850</td>\n",
|
|||
|
|
" <td>1.35600</td>\n",
|
|||
|
|
" <td>1.35650</td>\n",
|
|||
|
|
" <td>304.0</td>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" <tr>\n",
|
|||
|
|
" <th>2</th>\n",
|
|||
|
|
" <td>2004-12-31 22:00:00</td>\n",
|
|||
|
|
" <td>1.35660</td>\n",
|
|||
|
|
" <td>1.35710</td>\n",
|
|||
|
|
" <td>1.35520</td>\n",
|
|||
|
|
" <td>1.35540</td>\n",
|
|||
|
|
" <td>272.0</td>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" <tr>\n",
|
|||
|
|
" <th>3</th>\n",
|
|||
|
|
" <td>2004-12-31 23:00:00</td>\n",
|
|||
|
|
" <td>1.35540</td>\n",
|
|||
|
|
" <td>1.35630</td>\n",
|
|||
|
|
" <td>1.35520</td>\n",
|
|||
|
|
" <td>1.35620</td>\n",
|
|||
|
|
" <td>84.0</td>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" <tr>\n",
|
|||
|
|
" <th>4</th>\n",
|
|||
|
|
" <td>2005-01-03 01:00:00</td>\n",
|
|||
|
|
" <td>1.35790</td>\n",
|
|||
|
|
" <td>1.35810</td>\n",
|
|||
|
|
" <td>1.35390</td>\n",
|
|||
|
|
" <td>1.35470</td>\n",
|
|||
|
|
" <td>318.0</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",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" <tr>\n",
|
|||
|
|
" <th>126570</th>\n",
|
|||
|
|
" <td>2025-08-04 07:00:00</td>\n",
|
|||
|
|
" <td>1.15793</td>\n",
|
|||
|
|
" <td>1.15855</td>\n",
|
|||
|
|
" <td>1.15741</td>\n",
|
|||
|
|
" <td>1.15748</td>\n",
|
|||
|
|
" <td>1245.0</td>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" <tr>\n",
|
|||
|
|
" <th>126571</th>\n",
|
|||
|
|
" <td>2025-08-04 08:00:00</td>\n",
|
|||
|
|
" <td>1.15748</td>\n",
|
|||
|
|
" <td>1.15824</td>\n",
|
|||
|
|
" <td>1.15668</td>\n",
|
|||
|
|
" <td>1.15706</td>\n",
|
|||
|
|
" <td>1925.0</td>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" <tr>\n",
|
|||
|
|
" <th>126572</th>\n",
|
|||
|
|
" <td>2025-08-04 09:00:00</td>\n",
|
|||
|
|
" <td>1.15707</td>\n",
|
|||
|
|
" <td>1.15834</td>\n",
|
|||
|
|
" <td>1.15630</td>\n",
|
|||
|
|
" <td>1.15718</td>\n",
|
|||
|
|
" <td>3556.0</td>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" <tr>\n",
|
|||
|
|
" <th>126573</th>\n",
|
|||
|
|
" <td>2025-08-04 10:00:00</td>\n",
|
|||
|
|
" <td>1.15719</td>\n",
|
|||
|
|
" <td>1.15787</td>\n",
|
|||
|
|
" <td>1.15506</td>\n",
|
|||
|
|
" <td>1.15636</td>\n",
|
|||
|
|
" <td>3699.0</td>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" <tr>\n",
|
|||
|
|
" <th>126574</th>\n",
|
|||
|
|
" <td>2025-08-04 11:00:00</td>\n",
|
|||
|
|
" <td>1.15637</td>\n",
|
|||
|
|
" <td>1.15654</td>\n",
|
|||
|
|
" <td>1.15495</td>\n",
|
|||
|
|
" <td>1.15544</td>\n",
|
|||
|
|
" <td>2637.0</td>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" </tbody>\n",
|
|||
|
|
"</table>\n",
|
|||
|
|
"<p>126575 rows × 6 columns</p>\n",
|
|||
|
|
"</div>"
|
|||
|
|
],
|
|||
|
|
"text/plain": [
|
|||
|
|
" Date Open High Low Close Volume\n",
|
|||
|
|
"0 2004-12-31 20:00:00 1.35460 1.35860 1.35370 1.35710 409.0\n",
|
|||
|
|
"1 2004-12-31 21:00:00 1.35720 1.35850 1.35600 1.35650 304.0\n",
|
|||
|
|
"2 2004-12-31 22:00:00 1.35660 1.35710 1.35520 1.35540 272.0\n",
|
|||
|
|
"3 2004-12-31 23:00:00 1.35540 1.35630 1.35520 1.35620 84.0\n",
|
|||
|
|
"4 2005-01-03 01:00:00 1.35790 1.35810 1.35390 1.35470 318.0\n",
|
|||
|
|
"... ... ... ... ... ... ...\n",
|
|||
|
|
"126570 2025-08-04 07:00:00 1.15793 1.15855 1.15741 1.15748 1245.0\n",
|
|||
|
|
"126571 2025-08-04 08:00:00 1.15748 1.15824 1.15668 1.15706 1925.0\n",
|
|||
|
|
"126572 2025-08-04 09:00:00 1.15707 1.15834 1.15630 1.15718 3556.0\n",
|
|||
|
|
"126573 2025-08-04 10:00:00 1.15719 1.15787 1.15506 1.15636 3699.0\n",
|
|||
|
|
"126574 2025-08-04 11:00:00 1.15637 1.15654 1.15495 1.15544 2637.0\n",
|
|||
|
|
"\n",
|
|||
|
|
"[126575 rows x 6 columns]"
|
|||
|
|
]
|
|||
|
|
},
|
|||
|
|
"execution_count": 1,
|
|||
|
|
"metadata": {},
|
|||
|
|
"output_type": "execute_result"
|
|||
|
|
}
|
|||
|
|
],
|
|||
|
|
"source": [
|
|||
|
|
"import pandas as pd\n",
|
|||
|
|
"df = pd.read_csv('data.csv')\n",
|
|||
|
|
"df\n"
|
|||
|
|
]
|
|||
|
|
},
|
|||
|
|
{
|
|||
|
|
"cell_type": "markdown",
|
|||
|
|
"metadata": {
|
|||
|
|
"id": "Dds9bbs-Lf4V"
|
|||
|
|
},
|
|||
|
|
"source": [
|
|||
|
|
"# Making Features for the Model"
|
|||
|
|
]
|
|||
|
|
},
|
|||
|
|
{
|
|||
|
|
"cell_type": "markdown",
|
|||
|
|
"metadata": {
|
|||
|
|
"id": "mlyVnjaPLkOP"
|
|||
|
|
},
|
|||
|
|
"source": [
|
|||
|
|
"## Session Labeling (Asian, NY, London) (Ordinal Encoding)\n",
|
|||
|
|
"\n",
|
|||
|
|
"* The label is 0 when none of the sessions are trading in a given time\n",
|
|||
|
|
"* The label is 1 when only 1 session is trading in a given time\n",
|
|||
|
|
"* The label is 2 when only 2 sessions are trading in a given time\n",
|
|||
|
|
"* The label is 3 when all 3 sessions are trading in a given time"
|
|||
|
|
]
|
|||
|
|
},
|
|||
|
|
{
|
|||
|
|
"cell_type": "code",
|
|||
|
|
"execution_count": 2,
|
|||
|
|
"metadata": {
|
|||
|
|
"colab": {
|
|||
|
|
"base_uri": "https://localhost:8080/",
|
|||
|
|
"height": 424
|
|||
|
|
},
|
|||
|
|
"id": "QLIgfSAWLZ13",
|
|||
|
|
"outputId": "57032e3f-2c30-4699-8f4d-9f412195b8c1"
|
|||
|
|
},
|
|||
|
|
"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>Open</th>\n",
|
|||
|
|
" <th>High</th>\n",
|
|||
|
|
" <th>Low</th>\n",
|
|||
|
|
" <th>Close</th>\n",
|
|||
|
|
" <th>Volume</th>\n",
|
|||
|
|
" <th>Hour</th>\n",
|
|||
|
|
" <th>Session</th>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" </thead>\n",
|
|||
|
|
" <tbody>\n",
|
|||
|
|
" <tr>\n",
|
|||
|
|
" <th>0</th>\n",
|
|||
|
|
" <td>2004-12-31 20:00:00</td>\n",
|
|||
|
|
" <td>1.35460</td>\n",
|
|||
|
|
" <td>1.35860</td>\n",
|
|||
|
|
" <td>1.35370</td>\n",
|
|||
|
|
" <td>1.35710</td>\n",
|
|||
|
|
" <td>409.0</td>\n",
|
|||
|
|
" <td>20</td>\n",
|
|||
|
|
" <td>1</td>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" <tr>\n",
|
|||
|
|
" <th>1</th>\n",
|
|||
|
|
" <td>2004-12-31 21:00:00</td>\n",
|
|||
|
|
" <td>1.35720</td>\n",
|
|||
|
|
" <td>1.35850</td>\n",
|
|||
|
|
" <td>1.35600</td>\n",
|
|||
|
|
" <td>1.35650</td>\n",
|
|||
|
|
" <td>304.0</td>\n",
|
|||
|
|
" <td>21</td>\n",
|
|||
|
|
" <td>1</td>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" <tr>\n",
|
|||
|
|
" <th>2</th>\n",
|
|||
|
|
" <td>2004-12-31 22:00:00</td>\n",
|
|||
|
|
" <td>1.35660</td>\n",
|
|||
|
|
" <td>1.35710</td>\n",
|
|||
|
|
" <td>1.35520</td>\n",
|
|||
|
|
" <td>1.35540</td>\n",
|
|||
|
|
" <td>272.0</td>\n",
|
|||
|
|
" <td>22</td>\n",
|
|||
|
|
" <td>0</td>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" <tr>\n",
|
|||
|
|
" <th>3</th>\n",
|
|||
|
|
" <td>2004-12-31 23:00:00</td>\n",
|
|||
|
|
" <td>1.35540</td>\n",
|
|||
|
|
" <td>1.35630</td>\n",
|
|||
|
|
" <td>1.35520</td>\n",
|
|||
|
|
" <td>1.35620</td>\n",
|
|||
|
|
" <td>84.0</td>\n",
|
|||
|
|
" <td>23</td>\n",
|
|||
|
|
" <td>0</td>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" <tr>\n",
|
|||
|
|
" <th>4</th>\n",
|
|||
|
|
" <td>2005-01-03 01:00:00</td>\n",
|
|||
|
|
" <td>1.35790</td>\n",
|
|||
|
|
" <td>1.35810</td>\n",
|
|||
|
|
" <td>1.35390</td>\n",
|
|||
|
|
" <td>1.35470</td>\n",
|
|||
|
|
" <td>318.0</td>\n",
|
|||
|
|
" <td>1</td>\n",
|
|||
|
|
" <td>1</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",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" <tr>\n",
|
|||
|
|
" <th>126570</th>\n",
|
|||
|
|
" <td>2025-08-04 07:00:00</td>\n",
|
|||
|
|
" <td>1.15793</td>\n",
|
|||
|
|
" <td>1.15855</td>\n",
|
|||
|
|
" <td>1.15741</td>\n",
|
|||
|
|
" <td>1.15748</td>\n",
|
|||
|
|
" <td>1245.0</td>\n",
|
|||
|
|
" <td>7</td>\n",
|
|||
|
|
" <td>1</td>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" <tr>\n",
|
|||
|
|
" <th>126571</th>\n",
|
|||
|
|
" <td>2025-08-04 08:00:00</td>\n",
|
|||
|
|
" <td>1.15748</td>\n",
|
|||
|
|
" <td>1.15824</td>\n",
|
|||
|
|
" <td>1.15668</td>\n",
|
|||
|
|
" <td>1.15706</td>\n",
|
|||
|
|
" <td>1925.0</td>\n",
|
|||
|
|
" <td>8</td>\n",
|
|||
|
|
" <td>2</td>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" <tr>\n",
|
|||
|
|
" <th>126572</th>\n",
|
|||
|
|
" <td>2025-08-04 09:00:00</td>\n",
|
|||
|
|
" <td>1.15707</td>\n",
|
|||
|
|
" <td>1.15834</td>\n",
|
|||
|
|
" <td>1.15630</td>\n",
|
|||
|
|
" <td>1.15718</td>\n",
|
|||
|
|
" <td>3556.0</td>\n",
|
|||
|
|
" <td>9</td>\n",
|
|||
|
|
" <td>1</td>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" <tr>\n",
|
|||
|
|
" <th>126573</th>\n",
|
|||
|
|
" <td>2025-08-04 10:00:00</td>\n",
|
|||
|
|
" <td>1.15719</td>\n",
|
|||
|
|
" <td>1.15787</td>\n",
|
|||
|
|
" <td>1.15506</td>\n",
|
|||
|
|
" <td>1.15636</td>\n",
|
|||
|
|
" <td>3699.0</td>\n",
|
|||
|
|
" <td>10</td>\n",
|
|||
|
|
" <td>1</td>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" <tr>\n",
|
|||
|
|
" <th>126574</th>\n",
|
|||
|
|
" <td>2025-08-04 11:00:00</td>\n",
|
|||
|
|
" <td>1.15637</td>\n",
|
|||
|
|
" <td>1.15654</td>\n",
|
|||
|
|
" <td>1.15495</td>\n",
|
|||
|
|
" <td>1.15544</td>\n",
|
|||
|
|
" <td>2637.0</td>\n",
|
|||
|
|
" <td>11</td>\n",
|
|||
|
|
" <td>1</td>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" </tbody>\n",
|
|||
|
|
"</table>\n",
|
|||
|
|
"<p>126575 rows × 8 columns</p>\n",
|
|||
|
|
"</div>"
|
|||
|
|
],
|
|||
|
|
"text/plain": [
|
|||
|
|
" Date Open High Low Close Volume Hour \\\n",
|
|||
|
|
"0 2004-12-31 20:00:00 1.35460 1.35860 1.35370 1.35710 409.0 20 \n",
|
|||
|
|
"1 2004-12-31 21:00:00 1.35720 1.35850 1.35600 1.35650 304.0 21 \n",
|
|||
|
|
"2 2004-12-31 22:00:00 1.35660 1.35710 1.35520 1.35540 272.0 22 \n",
|
|||
|
|
"3 2004-12-31 23:00:00 1.35540 1.35630 1.35520 1.35620 84.0 23 \n",
|
|||
|
|
"4 2005-01-03 01:00:00 1.35790 1.35810 1.35390 1.35470 318.0 1 \n",
|
|||
|
|
"... ... ... ... ... ... ... ... \n",
|
|||
|
|
"126570 2025-08-04 07:00:00 1.15793 1.15855 1.15741 1.15748 1245.0 7 \n",
|
|||
|
|
"126571 2025-08-04 08:00:00 1.15748 1.15824 1.15668 1.15706 1925.0 8 \n",
|
|||
|
|
"126572 2025-08-04 09:00:00 1.15707 1.15834 1.15630 1.15718 3556.0 9 \n",
|
|||
|
|
"126573 2025-08-04 10:00:00 1.15719 1.15787 1.15506 1.15636 3699.0 10 \n",
|
|||
|
|
"126574 2025-08-04 11:00:00 1.15637 1.15654 1.15495 1.15544 2637.0 11 \n",
|
|||
|
|
"\n",
|
|||
|
|
" Session \n",
|
|||
|
|
"0 1 \n",
|
|||
|
|
"1 1 \n",
|
|||
|
|
"2 0 \n",
|
|||
|
|
"3 0 \n",
|
|||
|
|
"4 1 \n",
|
|||
|
|
"... ... \n",
|
|||
|
|
"126570 1 \n",
|
|||
|
|
"126571 2 \n",
|
|||
|
|
"126572 1 \n",
|
|||
|
|
"126573 1 \n",
|
|||
|
|
"126574 1 \n",
|
|||
|
|
"\n",
|
|||
|
|
"[126575 rows x 8 columns]"
|
|||
|
|
]
|
|||
|
|
},
|
|||
|
|
"execution_count": 2,
|
|||
|
|
"metadata": {},
|
|||
|
|
"output_type": "execute_result"
|
|||
|
|
}
|
|||
|
|
],
|
|||
|
|
"source": [
|
|||
|
|
"df['Date'] = pd.to_datetime(df['Date'])\n",
|
|||
|
|
"\n",
|
|||
|
|
"# Extract time\n",
|
|||
|
|
"df['Hour'] = df['Date'].dt.hour\n",
|
|||
|
|
"\n",
|
|||
|
|
"def label_hour(h):\n",
|
|||
|
|
" if 0 <= h < 8:\n",
|
|||
|
|
" return 1\n",
|
|||
|
|
" elif 8 <= h < 9:\n",
|
|||
|
|
" return 2\n",
|
|||
|
|
" elif 9 <= h < 13:\n",
|
|||
|
|
" return 1\n",
|
|||
|
|
" elif 13 <= h < 17:\n",
|
|||
|
|
" return 2\n",
|
|||
|
|
" elif 17 <= h < 22:\n",
|
|||
|
|
" return 1\n",
|
|||
|
|
" elif 22 <= h <= 23:\n",
|
|||
|
|
" return 0\n",
|
|||
|
|
"\n",
|
|||
|
|
"df['Session'] = df['Hour'].apply(label_hour)\n",
|
|||
|
|
"\n",
|
|||
|
|
"df"
|
|||
|
|
]
|
|||
|
|
},
|
|||
|
|
{
|
|||
|
|
"cell_type": "markdown",
|
|||
|
|
"metadata": {
|
|||
|
|
"id": "TljgWYOkMYbi"
|
|||
|
|
},
|
|||
|
|
"source": [
|
|||
|
|
"## Labeling Quarter (Ordinal Encoding)\n",
|
|||
|
|
"\n",
|
|||
|
|
"* 1 for April, May, June\n",
|
|||
|
|
"* 2 for July, August, Spetember\n",
|
|||
|
|
"* 3 for October, November, December\n",
|
|||
|
|
"* 4 for January, Febrauary, March"
|
|||
|
|
]
|
|||
|
|
},
|
|||
|
|
{
|
|||
|
|
"cell_type": "code",
|
|||
|
|
"execution_count": 3,
|
|||
|
|
"metadata": {
|
|||
|
|
"colab": {
|
|||
|
|
"base_uri": "https://localhost:8080/"
|
|||
|
|
},
|
|||
|
|
"id": "zO2xcjh7MPzM",
|
|||
|
|
"outputId": "18ff470a-2562-48f7-f4e6-eb7e09c08885"
|
|||
|
|
},
|
|||
|
|
"outputs": [
|
|||
|
|
{
|
|||
|
|
"name": "stdout",
|
|||
|
|
"output_type": "stream",
|
|||
|
|
"text": [
|
|||
|
|
" Date Open High Low Close Volume Hour \\\n",
|
|||
|
|
"0 2004-12-31 20:00:00 1.35460 1.35860 1.35370 1.35710 409.0 20 \n",
|
|||
|
|
"1 2004-12-31 21:00:00 1.35720 1.35850 1.35600 1.35650 304.0 21 \n",
|
|||
|
|
"2 2004-12-31 22:00:00 1.35660 1.35710 1.35520 1.35540 272.0 22 \n",
|
|||
|
|
"3 2004-12-31 23:00:00 1.35540 1.35630 1.35520 1.35620 84.0 23 \n",
|
|||
|
|
"4 2005-01-03 01:00:00 1.35790 1.35810 1.35390 1.35470 318.0 1 \n",
|
|||
|
|
"... ... ... ... ... ... ... ... \n",
|
|||
|
|
"126570 2025-08-04 07:00:00 1.15793 1.15855 1.15741 1.15748 1245.0 7 \n",
|
|||
|
|
"126571 2025-08-04 08:00:00 1.15748 1.15824 1.15668 1.15706 1925.0 8 \n",
|
|||
|
|
"126572 2025-08-04 09:00:00 1.15707 1.15834 1.15630 1.15718 3556.0 9 \n",
|
|||
|
|
"126573 2025-08-04 10:00:00 1.15719 1.15787 1.15506 1.15636 3699.0 10 \n",
|
|||
|
|
"126574 2025-08-04 11:00:00 1.15637 1.15654 1.15495 1.15544 2637.0 11 \n",
|
|||
|
|
"\n",
|
|||
|
|
" Session Month Quarter \n",
|
|||
|
|
"0 1 12 4 \n",
|
|||
|
|
"1 1 12 4 \n",
|
|||
|
|
"2 0 12 4 \n",
|
|||
|
|
"3 0 12 4 \n",
|
|||
|
|
"4 1 1 1 \n",
|
|||
|
|
"... ... ... ... \n",
|
|||
|
|
"126570 1 8 3 \n",
|
|||
|
|
"126571 2 8 3 \n",
|
|||
|
|
"126572 1 8 3 \n",
|
|||
|
|
"126573 1 8 3 \n",
|
|||
|
|
"126574 1 8 3 \n",
|
|||
|
|
"\n",
|
|||
|
|
"[126575 rows x 10 columns]\n"
|
|||
|
|
]
|
|||
|
|
}
|
|||
|
|
],
|
|||
|
|
"source": [
|
|||
|
|
"df['Month'] = df['Date'].dt.month\n",
|
|||
|
|
"\n",
|
|||
|
|
"# Function to assign quarter labels\n",
|
|||
|
|
"def label_quarter(m):\n",
|
|||
|
|
" if 1 <= m <= 3:\n",
|
|||
|
|
" return 1\n",
|
|||
|
|
" elif 4 <= m <= 6:\n",
|
|||
|
|
" return 2\n",
|
|||
|
|
" elif 7 <= m <= 9:\n",
|
|||
|
|
" return 3\n",
|
|||
|
|
" elif 10 <= m <= 12:\n",
|
|||
|
|
" return 4\n",
|
|||
|
|
"\n",
|
|||
|
|
"# Apply function\n",
|
|||
|
|
"df['Quarter'] = df['Month'].apply(label_quarter)\n",
|
|||
|
|
"\n",
|
|||
|
|
"print(df)"
|
|||
|
|
]
|
|||
|
|
},
|
|||
|
|
{
|
|||
|
|
"cell_type": "markdown",
|
|||
|
|
"metadata": {
|
|||
|
|
"id": "AdeG3Dk9NNiP"
|
|||
|
|
},
|
|||
|
|
"source": [
|
|||
|
|
"## Capturing the cyclic nature of Months, Date(1,2,...,31), Day of Week (Mon, Tue, Wed,...,Sun), Hour of the day (0,1,2,3,...,23)\n",
|
|||
|
|
"\n",
|
|||
|
|
"* Applying sine transformation to the above mentioned fields so that the machine understands that december is closer to january than to June and other details hidden in DateTime in a similar fashion.\n",
|
|||
|
|
"* Truncating the values upto 5 decimal points because the OHLCV is of the precision upto 5 decimal points"
|
|||
|
|
]
|
|||
|
|
},
|
|||
|
|
{
|
|||
|
|
"cell_type": "code",
|
|||
|
|
"execution_count": 4,
|
|||
|
|
"metadata": {
|
|||
|
|
"colab": {
|
|||
|
|
"base_uri": "https://localhost:8080/"
|
|||
|
|
},
|
|||
|
|
"id": "GAwVGdAzMurb",
|
|||
|
|
"outputId": "5bdaad6f-efaa-454f-de09-cae01d39fad0"
|
|||
|
|
},
|
|||
|
|
"outputs": [
|
|||
|
|
{
|
|||
|
|
"name": "stdout",
|
|||
|
|
"output_type": "stream",
|
|||
|
|
"text": [
|
|||
|
|
" Date Open High Low Close Volume Hour \\\n",
|
|||
|
|
"0 2004-12-31 20:00:00 1.35460 1.35860 1.35370 1.35710 409.0 20 \n",
|
|||
|
|
"1 2004-12-31 21:00:00 1.35720 1.35850 1.35600 1.35650 304.0 21 \n",
|
|||
|
|
"2 2004-12-31 22:00:00 1.35660 1.35710 1.35520 1.35540 272.0 22 \n",
|
|||
|
|
"3 2004-12-31 23:00:00 1.35540 1.35630 1.35520 1.35620 84.0 23 \n",
|
|||
|
|
"4 2005-01-03 01:00:00 1.35790 1.35810 1.35390 1.35470 318.0 1 \n",
|
|||
|
|
"... ... ... ... ... ... ... ... \n",
|
|||
|
|
"126570 2025-08-04 07:00:00 1.15793 1.15855 1.15741 1.15748 1245.0 7 \n",
|
|||
|
|
"126571 2025-08-04 08:00:00 1.15748 1.15824 1.15668 1.15706 1925.0 8 \n",
|
|||
|
|
"126572 2025-08-04 09:00:00 1.15707 1.15834 1.15630 1.15718 3556.0 9 \n",
|
|||
|
|
"126573 2025-08-04 10:00:00 1.15719 1.15787 1.15506 1.15636 3699.0 10 \n",
|
|||
|
|
"126574 2025-08-04 11:00:00 1.15637 1.15654 1.15495 1.15544 2637.0 11 \n",
|
|||
|
|
"\n",
|
|||
|
|
" Session Month Quarter Month_sin \n",
|
|||
|
|
"0 1 12 4 -0.00000 \n",
|
|||
|
|
"1 1 12 4 -0.00000 \n",
|
|||
|
|
"2 0 12 4 -0.00000 \n",
|
|||
|
|
"3 0 12 4 -0.00000 \n",
|
|||
|
|
"4 1 1 1 0.50000 \n",
|
|||
|
|
"... ... ... ... ... \n",
|
|||
|
|
"126570 1 8 3 -0.86603 \n",
|
|||
|
|
"126571 2 8 3 -0.86603 \n",
|
|||
|
|
"126572 1 8 3 -0.86603 \n",
|
|||
|
|
"126573 1 8 3 -0.86603 \n",
|
|||
|
|
"126574 1 8 3 -0.86603 \n",
|
|||
|
|
"\n",
|
|||
|
|
"[126575 rows x 11 columns]\n"
|
|||
|
|
]
|
|||
|
|
}
|
|||
|
|
],
|
|||
|
|
"source": [
|
|||
|
|
"import numpy as np\n",
|
|||
|
|
"\n",
|
|||
|
|
"# Apply sine transformation (cyclical encoding)\n",
|
|||
|
|
"df['Month_sin'] = np.round(np.sin(2 * np.pi * df['Month'] / 12),5)\n",
|
|||
|
|
"\n",
|
|||
|
|
"print(df)"
|
|||
|
|
]
|
|||
|
|
},
|
|||
|
|
{
|
|||
|
|
"cell_type": "code",
|
|||
|
|
"execution_count": 5,
|
|||
|
|
"metadata": {
|
|||
|
|
"colab": {
|
|||
|
|
"base_uri": "https://localhost:8080/"
|
|||
|
|
},
|
|||
|
|
"id": "j9rjsyofNtYj",
|
|||
|
|
"outputId": "96b4c886-a6c3-4778-b449-c4cf465b8e87"
|
|||
|
|
},
|
|||
|
|
"outputs": [
|
|||
|
|
{
|
|||
|
|
"name": "stdout",
|
|||
|
|
"output_type": "stream",
|
|||
|
|
"text": [
|
|||
|
|
" Date Open High Low Close Volume Hour \\\n",
|
|||
|
|
"0 2004-12-31 20:00:00 1.35460 1.35860 1.35370 1.35710 409.0 20 \n",
|
|||
|
|
"1 2004-12-31 21:00:00 1.35720 1.35850 1.35600 1.35650 304.0 21 \n",
|
|||
|
|
"2 2004-12-31 22:00:00 1.35660 1.35710 1.35520 1.35540 272.0 22 \n",
|
|||
|
|
"3 2004-12-31 23:00:00 1.35540 1.35630 1.35520 1.35620 84.0 23 \n",
|
|||
|
|
"4 2005-01-03 01:00:00 1.35790 1.35810 1.35390 1.35470 318.0 1 \n",
|
|||
|
|
"... ... ... ... ... ... ... ... \n",
|
|||
|
|
"126570 2025-08-04 07:00:00 1.15793 1.15855 1.15741 1.15748 1245.0 7 \n",
|
|||
|
|
"126571 2025-08-04 08:00:00 1.15748 1.15824 1.15668 1.15706 1925.0 8 \n",
|
|||
|
|
"126572 2025-08-04 09:00:00 1.15707 1.15834 1.15630 1.15718 3556.0 9 \n",
|
|||
|
|
"126573 2025-08-04 10:00:00 1.15719 1.15787 1.15506 1.15636 3699.0 10 \n",
|
|||
|
|
"126574 2025-08-04 11:00:00 1.15637 1.15654 1.15495 1.15544 2637.0 11 \n",
|
|||
|
|
"\n",
|
|||
|
|
" Session Month Quarter Month_sin Hour_sin \n",
|
|||
|
|
"0 1 12 4 -0.00000 -0.86603 \n",
|
|||
|
|
"1 1 12 4 -0.00000 -0.70711 \n",
|
|||
|
|
"2 0 12 4 -0.00000 -0.50000 \n",
|
|||
|
|
"3 0 12 4 -0.00000 -0.25882 \n",
|
|||
|
|
"4 1 1 1 0.50000 0.25882 \n",
|
|||
|
|
"... ... ... ... ... ... \n",
|
|||
|
|
"126570 1 8 3 -0.86603 0.96593 \n",
|
|||
|
|
"126571 2 8 3 -0.86603 0.86603 \n",
|
|||
|
|
"126572 1 8 3 -0.86603 0.70711 \n",
|
|||
|
|
"126573 1 8 3 -0.86603 0.50000 \n",
|
|||
|
|
"126574 1 8 3 -0.86603 0.25882 \n",
|
|||
|
|
"\n",
|
|||
|
|
"[126575 rows x 12 columns]\n"
|
|||
|
|
]
|
|||
|
|
}
|
|||
|
|
],
|
|||
|
|
"source": [
|
|||
|
|
"# Apply sine transformation and round to 5 decimals\n",
|
|||
|
|
"df['Hour_sin'] = np.round(np.sin(2 * np.pi * df['Hour'] / 24), 5)\n",
|
|||
|
|
"\n",
|
|||
|
|
"print(df)"
|
|||
|
|
]
|
|||
|
|
},
|
|||
|
|
{
|
|||
|
|
"cell_type": "code",
|
|||
|
|
"execution_count": 6,
|
|||
|
|
"metadata": {
|
|||
|
|
"colab": {
|
|||
|
|
"base_uri": "https://localhost:8080/"
|
|||
|
|
},
|
|||
|
|
"id": "ZJCsFhVrOjIc",
|
|||
|
|
"outputId": "23685120-b1a2-457e-dd9a-b5c00bf8185a"
|
|||
|
|
},
|
|||
|
|
"outputs": [
|
|||
|
|
{
|
|||
|
|
"name": "stdout",
|
|||
|
|
"output_type": "stream",
|
|||
|
|
"text": [
|
|||
|
|
" Date Open High Low Close Volume Hour \\\n",
|
|||
|
|
"0 2004-12-31 20:00:00 1.35460 1.35860 1.35370 1.35710 409.0 20 \n",
|
|||
|
|
"1 2004-12-31 21:00:00 1.35720 1.35850 1.35600 1.35650 304.0 21 \n",
|
|||
|
|
"2 2004-12-31 22:00:00 1.35660 1.35710 1.35520 1.35540 272.0 22 \n",
|
|||
|
|
"3 2004-12-31 23:00:00 1.35540 1.35630 1.35520 1.35620 84.0 23 \n",
|
|||
|
|
"4 2005-01-03 01:00:00 1.35790 1.35810 1.35390 1.35470 318.0 1 \n",
|
|||
|
|
"... ... ... ... ... ... ... ... \n",
|
|||
|
|
"126570 2025-08-04 07:00:00 1.15793 1.15855 1.15741 1.15748 1245.0 7 \n",
|
|||
|
|
"126571 2025-08-04 08:00:00 1.15748 1.15824 1.15668 1.15706 1925.0 8 \n",
|
|||
|
|
"126572 2025-08-04 09:00:00 1.15707 1.15834 1.15630 1.15718 3556.0 9 \n",
|
|||
|
|
"126573 2025-08-04 10:00:00 1.15719 1.15787 1.15506 1.15636 3699.0 10 \n",
|
|||
|
|
"126574 2025-08-04 11:00:00 1.15637 1.15654 1.15495 1.15544 2637.0 11 \n",
|
|||
|
|
"\n",
|
|||
|
|
" Session Month Quarter Month_sin Hour_sin Day Date_sin \n",
|
|||
|
|
"0 1 12 4 -0.00000 -0.86603 31 0.20791 \n",
|
|||
|
|
"1 1 12 4 -0.00000 -0.70711 31 0.20791 \n",
|
|||
|
|
"2 0 12 4 -0.00000 -0.50000 31 0.20791 \n",
|
|||
|
|
"3 0 12 4 -0.00000 -0.25882 31 0.20791 \n",
|
|||
|
|
"4 1 1 1 0.50000 0.25882 3 0.58779 \n",
|
|||
|
|
"... ... ... ... ... ... ... ... \n",
|
|||
|
|
"126570 1 8 3 -0.86603 0.96593 4 0.74314 \n",
|
|||
|
|
"126571 2 8 3 -0.86603 0.86603 4 0.74314 \n",
|
|||
|
|
"126572 1 8 3 -0.86603 0.70711 4 0.74314 \n",
|
|||
|
|
"126573 1 8 3 -0.86603 0.50000 4 0.74314 \n",
|
|||
|
|
"126574 1 8 3 -0.86603 0.25882 4 0.74314 \n",
|
|||
|
|
"\n",
|
|||
|
|
"[126575 rows x 14 columns]\n"
|
|||
|
|
]
|
|||
|
|
}
|
|||
|
|
],
|
|||
|
|
"source": [
|
|||
|
|
"# Ensure Date column is datetime type\n",
|
|||
|
|
"df[\"Date\"] = pd.to_datetime(df[\"Date\"])\n",
|
|||
|
|
"\n",
|
|||
|
|
"# Extract only the day number (1–31)\n",
|
|||
|
|
"df[\"Day\"] = df[\"Date\"].dt.day\n",
|
|||
|
|
"\n",
|
|||
|
|
"\n",
|
|||
|
|
"# Apply sine transformation and round to 5 decimals\n",
|
|||
|
|
"df['Date_sin'] = np.round(np.sin(2 * np.pi * df['Day'] / 30), 5)\n",
|
|||
|
|
"\n",
|
|||
|
|
"print(df)\n",
|
|||
|
|
"\n",
|
|||
|
|
"\n"
|
|||
|
|
]
|
|||
|
|
},
|
|||
|
|
{
|
|||
|
|
"cell_type": "code",
|
|||
|
|
"execution_count": 7,
|
|||
|
|
"metadata": {
|
|||
|
|
"colab": {
|
|||
|
|
"base_uri": "https://localhost:8080/",
|
|||
|
|
"height": 424
|
|||
|
|
},
|
|||
|
|
"id": "ZCNbAVrhPHE6",
|
|||
|
|
"outputId": "ef6a6bd9-3794-43c2-d07d-36fccd5cc88a"
|
|||
|
|
},
|
|||
|
|
"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>Open</th>\n",
|
|||
|
|
" <th>High</th>\n",
|
|||
|
|
" <th>Low</th>\n",
|
|||
|
|
" <th>Close</th>\n",
|
|||
|
|
" <th>Volume</th>\n",
|
|||
|
|
" <th>Hour</th>\n",
|
|||
|
|
" <th>Session</th>\n",
|
|||
|
|
" <th>Month</th>\n",
|
|||
|
|
" <th>Quarter</th>\n",
|
|||
|
|
" <th>Month_sin</th>\n",
|
|||
|
|
" <th>Hour_sin</th>\n",
|
|||
|
|
" <th>Day</th>\n",
|
|||
|
|
" <th>Date_sin</th>\n",
|
|||
|
|
" <th>DOW</th>\n",
|
|||
|
|
" <th>DOW_sin</th>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" </thead>\n",
|
|||
|
|
" <tbody>\n",
|
|||
|
|
" <tr>\n",
|
|||
|
|
" <th>0</th>\n",
|
|||
|
|
" <td>2004-12-31 20:00:00</td>\n",
|
|||
|
|
" <td>1.35460</td>\n",
|
|||
|
|
" <td>1.35860</td>\n",
|
|||
|
|
" <td>1.35370</td>\n",
|
|||
|
|
" <td>1.35710</td>\n",
|
|||
|
|
" <td>409.0</td>\n",
|
|||
|
|
" <td>20</td>\n",
|
|||
|
|
" <td>1</td>\n",
|
|||
|
|
" <td>12</td>\n",
|
|||
|
|
" <td>4</td>\n",
|
|||
|
|
" <td>-0.00000</td>\n",
|
|||
|
|
" <td>-0.86603</td>\n",
|
|||
|
|
" <td>31</td>\n",
|
|||
|
|
" <td>0.20791</td>\n",
|
|||
|
|
" <td>4</td>\n",
|
|||
|
|
" <td>-0.433884</td>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" <tr>\n",
|
|||
|
|
" <th>1</th>\n",
|
|||
|
|
" <td>2004-12-31 21:00:00</td>\n",
|
|||
|
|
" <td>1.35720</td>\n",
|
|||
|
|
" <td>1.35850</td>\n",
|
|||
|
|
" <td>1.35600</td>\n",
|
|||
|
|
" <td>1.35650</td>\n",
|
|||
|
|
" <td>304.0</td>\n",
|
|||
|
|
" <td>21</td>\n",
|
|||
|
|
" <td>1</td>\n",
|
|||
|
|
" <td>12</td>\n",
|
|||
|
|
" <td>4</td>\n",
|
|||
|
|
" <td>-0.00000</td>\n",
|
|||
|
|
" <td>-0.70711</td>\n",
|
|||
|
|
" <td>31</td>\n",
|
|||
|
|
" <td>0.20791</td>\n",
|
|||
|
|
" <td>4</td>\n",
|
|||
|
|
" <td>-0.433884</td>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" <tr>\n",
|
|||
|
|
" <th>2</th>\n",
|
|||
|
|
" <td>2004-12-31 22:00:00</td>\n",
|
|||
|
|
" <td>1.35660</td>\n",
|
|||
|
|
" <td>1.35710</td>\n",
|
|||
|
|
" <td>1.35520</td>\n",
|
|||
|
|
" <td>1.35540</td>\n",
|
|||
|
|
" <td>272.0</td>\n",
|
|||
|
|
" <td>22</td>\n",
|
|||
|
|
" <td>0</td>\n",
|
|||
|
|
" <td>12</td>\n",
|
|||
|
|
" <td>4</td>\n",
|
|||
|
|
" <td>-0.00000</td>\n",
|
|||
|
|
" <td>-0.50000</td>\n",
|
|||
|
|
" <td>31</td>\n",
|
|||
|
|
" <td>0.20791</td>\n",
|
|||
|
|
" <td>4</td>\n",
|
|||
|
|
" <td>-0.433884</td>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" <tr>\n",
|
|||
|
|
" <th>3</th>\n",
|
|||
|
|
" <td>2004-12-31 23:00:00</td>\n",
|
|||
|
|
" <td>1.35540</td>\n",
|
|||
|
|
" <td>1.35630</td>\n",
|
|||
|
|
" <td>1.35520</td>\n",
|
|||
|
|
" <td>1.35620</td>\n",
|
|||
|
|
" <td>84.0</td>\n",
|
|||
|
|
" <td>23</td>\n",
|
|||
|
|
" <td>0</td>\n",
|
|||
|
|
" <td>12</td>\n",
|
|||
|
|
" <td>4</td>\n",
|
|||
|
|
" <td>-0.00000</td>\n",
|
|||
|
|
" <td>-0.25882</td>\n",
|
|||
|
|
" <td>31</td>\n",
|
|||
|
|
" <td>0.20791</td>\n",
|
|||
|
|
" <td>4</td>\n",
|
|||
|
|
" <td>-0.433884</td>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" <tr>\n",
|
|||
|
|
" <th>4</th>\n",
|
|||
|
|
" <td>2005-01-03 01:00:00</td>\n",
|
|||
|
|
" <td>1.35790</td>\n",
|
|||
|
|
" <td>1.35810</td>\n",
|
|||
|
|
" <td>1.35390</td>\n",
|
|||
|
|
" <td>1.35470</td>\n",
|
|||
|
|
" <td>318.0</td>\n",
|
|||
|
|
" <td>1</td>\n",
|
|||
|
|
" <td>1</td>\n",
|
|||
|
|
" <td>1</td>\n",
|
|||
|
|
" <td>1</td>\n",
|
|||
|
|
" <td>0.50000</td>\n",
|
|||
|
|
" <td>0.25882</td>\n",
|
|||
|
|
" <td>3</td>\n",
|
|||
|
|
" <td>0.58779</td>\n",
|
|||
|
|
" <td>0</td>\n",
|
|||
|
|
" <td>0.000000</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",
|
|||
|
|
" <td>...</td>\n",
|
|||
|
|
" <td>...</td>\n",
|
|||
|
|
" <td>...</td>\n",
|
|||
|
|
" <td>...</td>\n",
|
|||
|
|
" <td>...</td>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" <tr>\n",
|
|||
|
|
" <th>126570</th>\n",
|
|||
|
|
" <td>2025-08-04 07:00:00</td>\n",
|
|||
|
|
" <td>1.15793</td>\n",
|
|||
|
|
" <td>1.15855</td>\n",
|
|||
|
|
" <td>1.15741</td>\n",
|
|||
|
|
" <td>1.15748</td>\n",
|
|||
|
|
" <td>1245.0</td>\n",
|
|||
|
|
" <td>7</td>\n",
|
|||
|
|
" <td>1</td>\n",
|
|||
|
|
" <td>8</td>\n",
|
|||
|
|
" <td>3</td>\n",
|
|||
|
|
" <td>-0.86603</td>\n",
|
|||
|
|
" <td>0.96593</td>\n",
|
|||
|
|
" <td>4</td>\n",
|
|||
|
|
" <td>0.74314</td>\n",
|
|||
|
|
" <td>0</td>\n",
|
|||
|
|
" <td>0.000000</td>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" <tr>\n",
|
|||
|
|
" <th>126571</th>\n",
|
|||
|
|
" <td>2025-08-04 08:00:00</td>\n",
|
|||
|
|
" <td>1.15748</td>\n",
|
|||
|
|
" <td>1.15824</td>\n",
|
|||
|
|
" <td>1.15668</td>\n",
|
|||
|
|
" <td>1.15706</td>\n",
|
|||
|
|
" <td>1925.0</td>\n",
|
|||
|
|
" <td>8</td>\n",
|
|||
|
|
" <td>2</td>\n",
|
|||
|
|
" <td>8</td>\n",
|
|||
|
|
" <td>3</td>\n",
|
|||
|
|
" <td>-0.86603</td>\n",
|
|||
|
|
" <td>0.86603</td>\n",
|
|||
|
|
" <td>4</td>\n",
|
|||
|
|
" <td>0.74314</td>\n",
|
|||
|
|
" <td>0</td>\n",
|
|||
|
|
" <td>0.000000</td>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" <tr>\n",
|
|||
|
|
" <th>126572</th>\n",
|
|||
|
|
" <td>2025-08-04 09:00:00</td>\n",
|
|||
|
|
" <td>1.15707</td>\n",
|
|||
|
|
" <td>1.15834</td>\n",
|
|||
|
|
" <td>1.15630</td>\n",
|
|||
|
|
" <td>1.15718</td>\n",
|
|||
|
|
" <td>3556.0</td>\n",
|
|||
|
|
" <td>9</td>\n",
|
|||
|
|
" <td>1</td>\n",
|
|||
|
|
" <td>8</td>\n",
|
|||
|
|
" <td>3</td>\n",
|
|||
|
|
" <td>-0.86603</td>\n",
|
|||
|
|
" <td>0.70711</td>\n",
|
|||
|
|
" <td>4</td>\n",
|
|||
|
|
" <td>0.74314</td>\n",
|
|||
|
|
" <td>0</td>\n",
|
|||
|
|
" <td>0.000000</td>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" <tr>\n",
|
|||
|
|
" <th>126573</th>\n",
|
|||
|
|
" <td>2025-08-04 10:00:00</td>\n",
|
|||
|
|
" <td>1.15719</td>\n",
|
|||
|
|
" <td>1.15787</td>\n",
|
|||
|
|
" <td>1.15506</td>\n",
|
|||
|
|
" <td>1.15636</td>\n",
|
|||
|
|
" <td>3699.0</td>\n",
|
|||
|
|
" <td>10</td>\n",
|
|||
|
|
" <td>1</td>\n",
|
|||
|
|
" <td>8</td>\n",
|
|||
|
|
" <td>3</td>\n",
|
|||
|
|
" <td>-0.86603</td>\n",
|
|||
|
|
" <td>0.50000</td>\n",
|
|||
|
|
" <td>4</td>\n",
|
|||
|
|
" <td>0.74314</td>\n",
|
|||
|
|
" <td>0</td>\n",
|
|||
|
|
" <td>0.000000</td>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" <tr>\n",
|
|||
|
|
" <th>126574</th>\n",
|
|||
|
|
" <td>2025-08-04 11:00:00</td>\n",
|
|||
|
|
" <td>1.15637</td>\n",
|
|||
|
|
" <td>1.15654</td>\n",
|
|||
|
|
" <td>1.15495</td>\n",
|
|||
|
|
" <td>1.15544</td>\n",
|
|||
|
|
" <td>2637.0</td>\n",
|
|||
|
|
" <td>11</td>\n",
|
|||
|
|
" <td>1</td>\n",
|
|||
|
|
" <td>8</td>\n",
|
|||
|
|
" <td>3</td>\n",
|
|||
|
|
" <td>-0.86603</td>\n",
|
|||
|
|
" <td>0.25882</td>\n",
|
|||
|
|
" <td>4</td>\n",
|
|||
|
|
" <td>0.74314</td>\n",
|
|||
|
|
" <td>0</td>\n",
|
|||
|
|
" <td>0.000000</td>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" </tbody>\n",
|
|||
|
|
"</table>\n",
|
|||
|
|
"<p>126575 rows × 16 columns</p>\n",
|
|||
|
|
"</div>"
|
|||
|
|
],
|
|||
|
|
"text/plain": [
|
|||
|
|
" Date Open High Low Close Volume Hour \\\n",
|
|||
|
|
"0 2004-12-31 20:00:00 1.35460 1.35860 1.35370 1.35710 409.0 20 \n",
|
|||
|
|
"1 2004-12-31 21:00:00 1.35720 1.35850 1.35600 1.35650 304.0 21 \n",
|
|||
|
|
"2 2004-12-31 22:00:00 1.35660 1.35710 1.35520 1.35540 272.0 22 \n",
|
|||
|
|
"3 2004-12-31 23:00:00 1.35540 1.35630 1.35520 1.35620 84.0 23 \n",
|
|||
|
|
"4 2005-01-03 01:00:00 1.35790 1.35810 1.35390 1.35470 318.0 1 \n",
|
|||
|
|
"... ... ... ... ... ... ... ... \n",
|
|||
|
|
"126570 2025-08-04 07:00:00 1.15793 1.15855 1.15741 1.15748 1245.0 7 \n",
|
|||
|
|
"126571 2025-08-04 08:00:00 1.15748 1.15824 1.15668 1.15706 1925.0 8 \n",
|
|||
|
|
"126572 2025-08-04 09:00:00 1.15707 1.15834 1.15630 1.15718 3556.0 9 \n",
|
|||
|
|
"126573 2025-08-04 10:00:00 1.15719 1.15787 1.15506 1.15636 3699.0 10 \n",
|
|||
|
|
"126574 2025-08-04 11:00:00 1.15637 1.15654 1.15495 1.15544 2637.0 11 \n",
|
|||
|
|
"\n",
|
|||
|
|
" Session Month Quarter Month_sin Hour_sin Day Date_sin DOW \\\n",
|
|||
|
|
"0 1 12 4 -0.00000 -0.86603 31 0.20791 4 \n",
|
|||
|
|
"1 1 12 4 -0.00000 -0.70711 31 0.20791 4 \n",
|
|||
|
|
"2 0 12 4 -0.00000 -0.50000 31 0.20791 4 \n",
|
|||
|
|
"3 0 12 4 -0.00000 -0.25882 31 0.20791 4 \n",
|
|||
|
|
"4 1 1 1 0.50000 0.25882 3 0.58779 0 \n",
|
|||
|
|
"... ... ... ... ... ... ... ... ... \n",
|
|||
|
|
"126570 1 8 3 -0.86603 0.96593 4 0.74314 0 \n",
|
|||
|
|
"126571 2 8 3 -0.86603 0.86603 4 0.74314 0 \n",
|
|||
|
|
"126572 1 8 3 -0.86603 0.70711 4 0.74314 0 \n",
|
|||
|
|
"126573 1 8 3 -0.86603 0.50000 4 0.74314 0 \n",
|
|||
|
|
"126574 1 8 3 -0.86603 0.25882 4 0.74314 0 \n",
|
|||
|
|
"\n",
|
|||
|
|
" DOW_sin \n",
|
|||
|
|
"0 -0.433884 \n",
|
|||
|
|
"1 -0.433884 \n",
|
|||
|
|
"2 -0.433884 \n",
|
|||
|
|
"3 -0.433884 \n",
|
|||
|
|
"4 0.000000 \n",
|
|||
|
|
"... ... \n",
|
|||
|
|
"126570 0.000000 \n",
|
|||
|
|
"126571 0.000000 \n",
|
|||
|
|
"126572 0.000000 \n",
|
|||
|
|
"126573 0.000000 \n",
|
|||
|
|
"126574 0.000000 \n",
|
|||
|
|
"\n",
|
|||
|
|
"[126575 rows x 16 columns]"
|
|||
|
|
]
|
|||
|
|
},
|
|||
|
|
"execution_count": 7,
|
|||
|
|
"metadata": {},
|
|||
|
|
"output_type": "execute_result"
|
|||
|
|
}
|
|||
|
|
],
|
|||
|
|
"source": [
|
|||
|
|
"# make sure Date is datetime\n",
|
|||
|
|
"df[\"Date\"] = pd.to_datetime(df[\"Date\"])\n",
|
|||
|
|
"\n",
|
|||
|
|
"# get day of week (Monday=0, Sunday=6)\n",
|
|||
|
|
"df[\"DOW\"] = df[\"Date\"].dt.weekday\n",
|
|||
|
|
"\n",
|
|||
|
|
"# sine transformation (map 1–7 into a circle)\n",
|
|||
|
|
"df[\"DOW_sin\"] = np.sin(2 * np.pi * df[\"DOW\"] / 7)\n",
|
|||
|
|
"\n",
|
|||
|
|
"df\n"
|
|||
|
|
]
|
|||
|
|
},
|
|||
|
|
{
|
|||
|
|
"cell_type": "code",
|
|||
|
|
"execution_count": 8,
|
|||
|
|
"metadata": {
|
|||
|
|
"colab": {
|
|||
|
|
"base_uri": "https://localhost:8080/",
|
|||
|
|
"height": 424
|
|||
|
|
},
|
|||
|
|
"id": "P46xfd-tTdbP",
|
|||
|
|
"outputId": "b94c3546-a576-4f07-f569-2e683064cede"
|
|||
|
|
},
|
|||
|
|
"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>Open</th>\n",
|
|||
|
|
" <th>High</th>\n",
|
|||
|
|
" <th>Low</th>\n",
|
|||
|
|
" <th>Close</th>\n",
|
|||
|
|
" <th>Volume</th>\n",
|
|||
|
|
" <th>Session</th>\n",
|
|||
|
|
" <th>Quarter</th>\n",
|
|||
|
|
" <th>Month_sin</th>\n",
|
|||
|
|
" <th>Hour_sin</th>\n",
|
|||
|
|
" <th>Date_sin</th>\n",
|
|||
|
|
" <th>DOW_sin</th>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" </thead>\n",
|
|||
|
|
" <tbody>\n",
|
|||
|
|
" <tr>\n",
|
|||
|
|
" <th>0</th>\n",
|
|||
|
|
" <td>2004-12-31 20:00:00</td>\n",
|
|||
|
|
" <td>1.35460</td>\n",
|
|||
|
|
" <td>1.35860</td>\n",
|
|||
|
|
" <td>1.35370</td>\n",
|
|||
|
|
" <td>1.35710</td>\n",
|
|||
|
|
" <td>409.0</td>\n",
|
|||
|
|
" <td>1</td>\n",
|
|||
|
|
" <td>4</td>\n",
|
|||
|
|
" <td>-0.00000</td>\n",
|
|||
|
|
" <td>-0.86603</td>\n",
|
|||
|
|
" <td>0.20791</td>\n",
|
|||
|
|
" <td>-0.433884</td>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" <tr>\n",
|
|||
|
|
" <th>1</th>\n",
|
|||
|
|
" <td>2004-12-31 21:00:00</td>\n",
|
|||
|
|
" <td>1.35720</td>\n",
|
|||
|
|
" <td>1.35850</td>\n",
|
|||
|
|
" <td>1.35600</td>\n",
|
|||
|
|
" <td>1.35650</td>\n",
|
|||
|
|
" <td>304.0</td>\n",
|
|||
|
|
" <td>1</td>\n",
|
|||
|
|
" <td>4</td>\n",
|
|||
|
|
" <td>-0.00000</td>\n",
|
|||
|
|
" <td>-0.70711</td>\n",
|
|||
|
|
" <td>0.20791</td>\n",
|
|||
|
|
" <td>-0.433884</td>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" <tr>\n",
|
|||
|
|
" <th>2</th>\n",
|
|||
|
|
" <td>2004-12-31 22:00:00</td>\n",
|
|||
|
|
" <td>1.35660</td>\n",
|
|||
|
|
" <td>1.35710</td>\n",
|
|||
|
|
" <td>1.35520</td>\n",
|
|||
|
|
" <td>1.35540</td>\n",
|
|||
|
|
" <td>272.0</td>\n",
|
|||
|
|
" <td>0</td>\n",
|
|||
|
|
" <td>4</td>\n",
|
|||
|
|
" <td>-0.00000</td>\n",
|
|||
|
|
" <td>-0.50000</td>\n",
|
|||
|
|
" <td>0.20791</td>\n",
|
|||
|
|
" <td>-0.433884</td>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" <tr>\n",
|
|||
|
|
" <th>3</th>\n",
|
|||
|
|
" <td>2004-12-31 23:00:00</td>\n",
|
|||
|
|
" <td>1.35540</td>\n",
|
|||
|
|
" <td>1.35630</td>\n",
|
|||
|
|
" <td>1.35520</td>\n",
|
|||
|
|
" <td>1.35620</td>\n",
|
|||
|
|
" <td>84.0</td>\n",
|
|||
|
|
" <td>0</td>\n",
|
|||
|
|
" <td>4</td>\n",
|
|||
|
|
" <td>-0.00000</td>\n",
|
|||
|
|
" <td>-0.25882</td>\n",
|
|||
|
|
" <td>0.20791</td>\n",
|
|||
|
|
" <td>-0.433884</td>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" <tr>\n",
|
|||
|
|
" <th>4</th>\n",
|
|||
|
|
" <td>2005-01-03 01:00:00</td>\n",
|
|||
|
|
" <td>1.35790</td>\n",
|
|||
|
|
" <td>1.35810</td>\n",
|
|||
|
|
" <td>1.35390</td>\n",
|
|||
|
|
" <td>1.35470</td>\n",
|
|||
|
|
" <td>318.0</td>\n",
|
|||
|
|
" <td>1</td>\n",
|
|||
|
|
" <td>1</td>\n",
|
|||
|
|
" <td>0.50000</td>\n",
|
|||
|
|
" <td>0.25882</td>\n",
|
|||
|
|
" <td>0.58779</td>\n",
|
|||
|
|
" <td>0.000000</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",
|
|||
|
|
" <td>...</td>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" <tr>\n",
|
|||
|
|
" <th>126570</th>\n",
|
|||
|
|
" <td>2025-08-04 07:00:00</td>\n",
|
|||
|
|
" <td>1.15793</td>\n",
|
|||
|
|
" <td>1.15855</td>\n",
|
|||
|
|
" <td>1.15741</td>\n",
|
|||
|
|
" <td>1.15748</td>\n",
|
|||
|
|
" <td>1245.0</td>\n",
|
|||
|
|
" <td>1</td>\n",
|
|||
|
|
" <td>3</td>\n",
|
|||
|
|
" <td>-0.86603</td>\n",
|
|||
|
|
" <td>0.96593</td>\n",
|
|||
|
|
" <td>0.74314</td>\n",
|
|||
|
|
" <td>0.000000</td>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" <tr>\n",
|
|||
|
|
" <th>126571</th>\n",
|
|||
|
|
" <td>2025-08-04 08:00:00</td>\n",
|
|||
|
|
" <td>1.15748</td>\n",
|
|||
|
|
" <td>1.15824</td>\n",
|
|||
|
|
" <td>1.15668</td>\n",
|
|||
|
|
" <td>1.15706</td>\n",
|
|||
|
|
" <td>1925.0</td>\n",
|
|||
|
|
" <td>2</td>\n",
|
|||
|
|
" <td>3</td>\n",
|
|||
|
|
" <td>-0.86603</td>\n",
|
|||
|
|
" <td>0.86603</td>\n",
|
|||
|
|
" <td>0.74314</td>\n",
|
|||
|
|
" <td>0.000000</td>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" <tr>\n",
|
|||
|
|
" <th>126572</th>\n",
|
|||
|
|
" <td>2025-08-04 09:00:00</td>\n",
|
|||
|
|
" <td>1.15707</td>\n",
|
|||
|
|
" <td>1.15834</td>\n",
|
|||
|
|
" <td>1.15630</td>\n",
|
|||
|
|
" <td>1.15718</td>\n",
|
|||
|
|
" <td>3556.0</td>\n",
|
|||
|
|
" <td>1</td>\n",
|
|||
|
|
" <td>3</td>\n",
|
|||
|
|
" <td>-0.86603</td>\n",
|
|||
|
|
" <td>0.70711</td>\n",
|
|||
|
|
" <td>0.74314</td>\n",
|
|||
|
|
" <td>0.000000</td>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" <tr>\n",
|
|||
|
|
" <th>126573</th>\n",
|
|||
|
|
" <td>2025-08-04 10:00:00</td>\n",
|
|||
|
|
" <td>1.15719</td>\n",
|
|||
|
|
" <td>1.15787</td>\n",
|
|||
|
|
" <td>1.15506</td>\n",
|
|||
|
|
" <td>1.15636</td>\n",
|
|||
|
|
" <td>3699.0</td>\n",
|
|||
|
|
" <td>1</td>\n",
|
|||
|
|
" <td>3</td>\n",
|
|||
|
|
" <td>-0.86603</td>\n",
|
|||
|
|
" <td>0.50000</td>\n",
|
|||
|
|
" <td>0.74314</td>\n",
|
|||
|
|
" <td>0.000000</td>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" <tr>\n",
|
|||
|
|
" <th>126574</th>\n",
|
|||
|
|
" <td>2025-08-04 11:00:00</td>\n",
|
|||
|
|
" <td>1.15637</td>\n",
|
|||
|
|
" <td>1.15654</td>\n",
|
|||
|
|
" <td>1.15495</td>\n",
|
|||
|
|
" <td>1.15544</td>\n",
|
|||
|
|
" <td>2637.0</td>\n",
|
|||
|
|
" <td>1</td>\n",
|
|||
|
|
" <td>3</td>\n",
|
|||
|
|
" <td>-0.86603</td>\n",
|
|||
|
|
" <td>0.25882</td>\n",
|
|||
|
|
" <td>0.74314</td>\n",
|
|||
|
|
" <td>0.000000</td>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" </tbody>\n",
|
|||
|
|
"</table>\n",
|
|||
|
|
"<p>126575 rows × 12 columns</p>\n",
|
|||
|
|
"</div>"
|
|||
|
|
],
|
|||
|
|
"text/plain": [
|
|||
|
|
" Date Open High Low Close Volume \\\n",
|
|||
|
|
"0 2004-12-31 20:00:00 1.35460 1.35860 1.35370 1.35710 409.0 \n",
|
|||
|
|
"1 2004-12-31 21:00:00 1.35720 1.35850 1.35600 1.35650 304.0 \n",
|
|||
|
|
"2 2004-12-31 22:00:00 1.35660 1.35710 1.35520 1.35540 272.0 \n",
|
|||
|
|
"3 2004-12-31 23:00:00 1.35540 1.35630 1.35520 1.35620 84.0 \n",
|
|||
|
|
"4 2005-01-03 01:00:00 1.35790 1.35810 1.35390 1.35470 318.0 \n",
|
|||
|
|
"... ... ... ... ... ... ... \n",
|
|||
|
|
"126570 2025-08-04 07:00:00 1.15793 1.15855 1.15741 1.15748 1245.0 \n",
|
|||
|
|
"126571 2025-08-04 08:00:00 1.15748 1.15824 1.15668 1.15706 1925.0 \n",
|
|||
|
|
"126572 2025-08-04 09:00:00 1.15707 1.15834 1.15630 1.15718 3556.0 \n",
|
|||
|
|
"126573 2025-08-04 10:00:00 1.15719 1.15787 1.15506 1.15636 3699.0 \n",
|
|||
|
|
"126574 2025-08-04 11:00:00 1.15637 1.15654 1.15495 1.15544 2637.0 \n",
|
|||
|
|
"\n",
|
|||
|
|
" Session Quarter Month_sin Hour_sin Date_sin DOW_sin \n",
|
|||
|
|
"0 1 4 -0.00000 -0.86603 0.20791 -0.433884 \n",
|
|||
|
|
"1 1 4 -0.00000 -0.70711 0.20791 -0.433884 \n",
|
|||
|
|
"2 0 4 -0.00000 -0.50000 0.20791 -0.433884 \n",
|
|||
|
|
"3 0 4 -0.00000 -0.25882 0.20791 -0.433884 \n",
|
|||
|
|
"4 1 1 0.50000 0.25882 0.58779 0.000000 \n",
|
|||
|
|
"... ... ... ... ... ... ... \n",
|
|||
|
|
"126570 1 3 -0.86603 0.96593 0.74314 0.000000 \n",
|
|||
|
|
"126571 2 3 -0.86603 0.86603 0.74314 0.000000 \n",
|
|||
|
|
"126572 1 3 -0.86603 0.70711 0.74314 0.000000 \n",
|
|||
|
|
"126573 1 3 -0.86603 0.50000 0.74314 0.000000 \n",
|
|||
|
|
"126574 1 3 -0.86603 0.25882 0.74314 0.000000 \n",
|
|||
|
|
"\n",
|
|||
|
|
"[126575 rows x 12 columns]"
|
|||
|
|
]
|
|||
|
|
},
|
|||
|
|
"execution_count": 8,
|
|||
|
|
"metadata": {},
|
|||
|
|
"output_type": "execute_result"
|
|||
|
|
}
|
|||
|
|
],
|
|||
|
|
"source": [
|
|||
|
|
"df = df.drop([\"Hour\", \"Month\", \"Day\", \"DOW\"], axis=1)\n",
|
|||
|
|
"df"
|
|||
|
|
]
|
|||
|
|
},
|
|||
|
|
{
|
|||
|
|
"cell_type": "markdown",
|
|||
|
|
"metadata": {
|
|||
|
|
"id": "OjEVy_bnUSi8"
|
|||
|
|
},
|
|||
|
|
"source": [
|
|||
|
|
"## Using Alternate Data as features\n",
|
|||
|
|
"\n",
|
|||
|
|
"### Interest Rate Differential of Yield-Par curve of 2Yr and 10Yr US Treasuary Bonds\n",
|
|||
|
|
"\n",
|
|||
|
|
"* US has been selected because the data provided during the assignment did not contain any explicit mention of the currency pair. So, as a backup plan, US has been choosen because of the dependency of almost all currency pairs on it due to its importance as the primary global trading currency\n",
|
|||
|
|
"\n",
|
|||
|
|
"The data for this has been taken from : \"https://home.treasury.gov/resource-center/data-chart-center/interest-rates/TextView?type=daily_treasury_yield_curve&field_tdr_date_value_month=202508\""
|
|||
|
|
]
|
|||
|
|
},
|
|||
|
|
{
|
|||
|
|
"cell_type": "code",
|
|||
|
|
"execution_count": 9,
|
|||
|
|
"metadata": {
|
|||
|
|
"colab": {
|
|||
|
|
"base_uri": "https://localhost:8080/",
|
|||
|
|
"height": 424
|
|||
|
|
},
|
|||
|
|
"id": "aa43BXfRUHxw",
|
|||
|
|
"outputId": "4b94663a-c506-49e8-ba49-583a3cebfea1"
|
|||
|
|
},
|
|||
|
|
"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>1 Mo</th>\n",
|
|||
|
|
" <th>2 Mo</th>\n",
|
|||
|
|
" <th>3 Mo</th>\n",
|
|||
|
|
" <th>4 Mo</th>\n",
|
|||
|
|
" <th>6 Mo</th>\n",
|
|||
|
|
" <th>1 Yr</th>\n",
|
|||
|
|
" <th>2 Yr</th>\n",
|
|||
|
|
" <th>3 Yr</th>\n",
|
|||
|
|
" <th>5 Yr</th>\n",
|
|||
|
|
" <th>7 Yr</th>\n",
|
|||
|
|
" <th>10 Yr</th>\n",
|
|||
|
|
" <th>20 Yr</th>\n",
|
|||
|
|
" <th>30 Yr</th>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" </thead>\n",
|
|||
|
|
" <tbody>\n",
|
|||
|
|
" <tr>\n",
|
|||
|
|
" <th>0</th>\n",
|
|||
|
|
" <td>12/31/24</td>\n",
|
|||
|
|
" <td>4.40</td>\n",
|
|||
|
|
" <td>4.39</td>\n",
|
|||
|
|
" <td>4.37</td>\n",
|
|||
|
|
" <td>4.32</td>\n",
|
|||
|
|
" <td>4.24</td>\n",
|
|||
|
|
" <td>4.16</td>\n",
|
|||
|
|
" <td>4.25</td>\n",
|
|||
|
|
" <td>4.27</td>\n",
|
|||
|
|
" <td>4.38</td>\n",
|
|||
|
|
" <td>4.48</td>\n",
|
|||
|
|
" <td>4.58</td>\n",
|
|||
|
|
" <td>4.86</td>\n",
|
|||
|
|
" <td>4.78</td>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" <tr>\n",
|
|||
|
|
" <th>1</th>\n",
|
|||
|
|
" <td>12/30/24</td>\n",
|
|||
|
|
" <td>4.43</td>\n",
|
|||
|
|
" <td>4.42</td>\n",
|
|||
|
|
" <td>4.37</td>\n",
|
|||
|
|
" <td>4.33</td>\n",
|
|||
|
|
" <td>4.25</td>\n",
|
|||
|
|
" <td>4.17</td>\n",
|
|||
|
|
" <td>4.24</td>\n",
|
|||
|
|
" <td>4.29</td>\n",
|
|||
|
|
" <td>4.37</td>\n",
|
|||
|
|
" <td>4.46</td>\n",
|
|||
|
|
" <td>4.55</td>\n",
|
|||
|
|
" <td>4.84</td>\n",
|
|||
|
|
" <td>4.77</td>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" <tr>\n",
|
|||
|
|
" <th>2</th>\n",
|
|||
|
|
" <td>12/27/24</td>\n",
|
|||
|
|
" <td>4.44</td>\n",
|
|||
|
|
" <td>4.43</td>\n",
|
|||
|
|
" <td>4.31</td>\n",
|
|||
|
|
" <td>4.35</td>\n",
|
|||
|
|
" <td>4.29</td>\n",
|
|||
|
|
" <td>4.20</td>\n",
|
|||
|
|
" <td>4.31</td>\n",
|
|||
|
|
" <td>4.36</td>\n",
|
|||
|
|
" <td>4.45</td>\n",
|
|||
|
|
" <td>4.53</td>\n",
|
|||
|
|
" <td>4.62</td>\n",
|
|||
|
|
" <td>4.89</td>\n",
|
|||
|
|
" <td>4.82</td>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" <tr>\n",
|
|||
|
|
" <th>3</th>\n",
|
|||
|
|
" <td>12/26/24</td>\n",
|
|||
|
|
" <td>4.45</td>\n",
|
|||
|
|
" <td>4.45</td>\n",
|
|||
|
|
" <td>4.35</td>\n",
|
|||
|
|
" <td>4.37</td>\n",
|
|||
|
|
" <td>4.31</td>\n",
|
|||
|
|
" <td>4.23</td>\n",
|
|||
|
|
" <td>4.30</td>\n",
|
|||
|
|
" <td>4.35</td>\n",
|
|||
|
|
" <td>4.42</td>\n",
|
|||
|
|
" <td>4.49</td>\n",
|
|||
|
|
" <td>4.58</td>\n",
|
|||
|
|
" <td>4.83</td>\n",
|
|||
|
|
" <td>4.76</td>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" <tr>\n",
|
|||
|
|
" <th>4</th>\n",
|
|||
|
|
" <td>12/24/24</td>\n",
|
|||
|
|
" <td>4.44</td>\n",
|
|||
|
|
" <td>4.44</td>\n",
|
|||
|
|
" <td>4.40</td>\n",
|
|||
|
|
" <td>4.38</td>\n",
|
|||
|
|
" <td>4.30</td>\n",
|
|||
|
|
" <td>4.24</td>\n",
|
|||
|
|
" <td>4.29</td>\n",
|
|||
|
|
" <td>4.36</td>\n",
|
|||
|
|
" <td>4.43</td>\n",
|
|||
|
|
" <td>4.52</td>\n",
|
|||
|
|
" <td>4.59</td>\n",
|
|||
|
|
" <td>4.84</td>\n",
|
|||
|
|
" <td>4.76</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",
|
|||
|
|
" <td>...</td>\n",
|
|||
|
|
" <td>...</td>\n",
|
|||
|
|
" <td>...</td>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" <tr>\n",
|
|||
|
|
" <th>8752</th>\n",
|
|||
|
|
" <td>1/8/90</td>\n",
|
|||
|
|
" <td>NaN</td>\n",
|
|||
|
|
" <td>NaN</td>\n",
|
|||
|
|
" <td>7.79</td>\n",
|
|||
|
|
" <td>NaN</td>\n",
|
|||
|
|
" <td>7.88</td>\n",
|
|||
|
|
" <td>7.81</td>\n",
|
|||
|
|
" <td>7.90</td>\n",
|
|||
|
|
" <td>7.95</td>\n",
|
|||
|
|
" <td>7.92</td>\n",
|
|||
|
|
" <td>8.05</td>\n",
|
|||
|
|
" <td>8.02</td>\n",
|
|||
|
|
" <td>NaN</td>\n",
|
|||
|
|
" <td>8.09</td>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" <tr>\n",
|
|||
|
|
" <th>8753</th>\n",
|
|||
|
|
" <td>1/5/90</td>\n",
|
|||
|
|
" <td>NaN</td>\n",
|
|||
|
|
" <td>NaN</td>\n",
|
|||
|
|
" <td>7.79</td>\n",
|
|||
|
|
" <td>NaN</td>\n",
|
|||
|
|
" <td>7.85</td>\n",
|
|||
|
|
" <td>7.79</td>\n",
|
|||
|
|
" <td>7.90</td>\n",
|
|||
|
|
" <td>7.94</td>\n",
|
|||
|
|
" <td>7.92</td>\n",
|
|||
|
|
" <td>8.03</td>\n",
|
|||
|
|
" <td>7.99</td>\n",
|
|||
|
|
" <td>NaN</td>\n",
|
|||
|
|
" <td>8.06</td>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" <tr>\n",
|
|||
|
|
" <th>8754</th>\n",
|
|||
|
|
" <td>1/4/90</td>\n",
|
|||
|
|
" <td>NaN</td>\n",
|
|||
|
|
" <td>NaN</td>\n",
|
|||
|
|
" <td>7.84</td>\n",
|
|||
|
|
" <td>NaN</td>\n",
|
|||
|
|
" <td>7.90</td>\n",
|
|||
|
|
" <td>7.82</td>\n",
|
|||
|
|
" <td>7.92</td>\n",
|
|||
|
|
" <td>7.93</td>\n",
|
|||
|
|
" <td>7.91</td>\n",
|
|||
|
|
" <td>8.02</td>\n",
|
|||
|
|
" <td>7.98</td>\n",
|
|||
|
|
" <td>NaN</td>\n",
|
|||
|
|
" <td>8.04</td>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" <tr>\n",
|
|||
|
|
" <th>8755</th>\n",
|
|||
|
|
" <td>1/3/90</td>\n",
|
|||
|
|
" <td>NaN</td>\n",
|
|||
|
|
" <td>NaN</td>\n",
|
|||
|
|
" <td>7.89</td>\n",
|
|||
|
|
" <td>NaN</td>\n",
|
|||
|
|
" <td>7.94</td>\n",
|
|||
|
|
" <td>7.85</td>\n",
|
|||
|
|
" <td>7.94</td>\n",
|
|||
|
|
" <td>7.96</td>\n",
|
|||
|
|
" <td>7.92</td>\n",
|
|||
|
|
" <td>8.04</td>\n",
|
|||
|
|
" <td>7.99</td>\n",
|
|||
|
|
" <td>NaN</td>\n",
|
|||
|
|
" <td>8.04</td>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" <tr>\n",
|
|||
|
|
" <th>8756</th>\n",
|
|||
|
|
" <td>1/2/90</td>\n",
|
|||
|
|
" <td>NaN</td>\n",
|
|||
|
|
" <td>NaN</td>\n",
|
|||
|
|
" <td>7.83</td>\n",
|
|||
|
|
" <td>NaN</td>\n",
|
|||
|
|
" <td>7.89</td>\n",
|
|||
|
|
" <td>7.81</td>\n",
|
|||
|
|
" <td>7.87</td>\n",
|
|||
|
|
" <td>7.90</td>\n",
|
|||
|
|
" <td>7.87</td>\n",
|
|||
|
|
" <td>7.98</td>\n",
|
|||
|
|
" <td>7.94</td>\n",
|
|||
|
|
" <td>NaN</td>\n",
|
|||
|
|
" <td>8.00</td>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" </tbody>\n",
|
|||
|
|
"</table>\n",
|
|||
|
|
"<p>8757 rows × 14 columns</p>\n",
|
|||
|
|
"</div>"
|
|||
|
|
],
|
|||
|
|
"text/plain": [
|
|||
|
|
" Date 1 Mo 2 Mo 3 Mo 4 Mo 6 Mo 1 Yr 2 Yr 3 Yr 5 Yr 7 Yr \\\n",
|
|||
|
|
"0 12/31/24 4.40 4.39 4.37 4.32 4.24 4.16 4.25 4.27 4.38 4.48 \n",
|
|||
|
|
"1 12/30/24 4.43 4.42 4.37 4.33 4.25 4.17 4.24 4.29 4.37 4.46 \n",
|
|||
|
|
"2 12/27/24 4.44 4.43 4.31 4.35 4.29 4.20 4.31 4.36 4.45 4.53 \n",
|
|||
|
|
"3 12/26/24 4.45 4.45 4.35 4.37 4.31 4.23 4.30 4.35 4.42 4.49 \n",
|
|||
|
|
"4 12/24/24 4.44 4.44 4.40 4.38 4.30 4.24 4.29 4.36 4.43 4.52 \n",
|
|||
|
|
"... ... ... ... ... ... ... ... ... ... ... ... \n",
|
|||
|
|
"8752 1/8/90 NaN NaN 7.79 NaN 7.88 7.81 7.90 7.95 7.92 8.05 \n",
|
|||
|
|
"8753 1/5/90 NaN NaN 7.79 NaN 7.85 7.79 7.90 7.94 7.92 8.03 \n",
|
|||
|
|
"8754 1/4/90 NaN NaN 7.84 NaN 7.90 7.82 7.92 7.93 7.91 8.02 \n",
|
|||
|
|
"8755 1/3/90 NaN NaN 7.89 NaN 7.94 7.85 7.94 7.96 7.92 8.04 \n",
|
|||
|
|
"8756 1/2/90 NaN NaN 7.83 NaN 7.89 7.81 7.87 7.90 7.87 7.98 \n",
|
|||
|
|
"\n",
|
|||
|
|
" 10 Yr 20 Yr 30 Yr \n",
|
|||
|
|
"0 4.58 4.86 4.78 \n",
|
|||
|
|
"1 4.55 4.84 4.77 \n",
|
|||
|
|
"2 4.62 4.89 4.82 \n",
|
|||
|
|
"3 4.58 4.83 4.76 \n",
|
|||
|
|
"4 4.59 4.84 4.76 \n",
|
|||
|
|
"... ... ... ... \n",
|
|||
|
|
"8752 8.02 NaN 8.09 \n",
|
|||
|
|
"8753 7.99 NaN 8.06 \n",
|
|||
|
|
"8754 7.98 NaN 8.04 \n",
|
|||
|
|
"8755 7.99 NaN 8.04 \n",
|
|||
|
|
"8756 7.94 NaN 8.00 \n",
|
|||
|
|
"\n",
|
|||
|
|
"[8757 rows x 14 columns]"
|
|||
|
|
]
|
|||
|
|
},
|
|||
|
|
"execution_count": 9,
|
|||
|
|
"metadata": {},
|
|||
|
|
"output_type": "execute_result"
|
|||
|
|
}
|
|||
|
|
],
|
|||
|
|
"source": [
|
|||
|
|
"rate_df = pd.read_csv('interest_rates.csv')\n",
|
|||
|
|
"rate_df"
|
|||
|
|
]
|
|||
|
|
},
|
|||
|
|
{
|
|||
|
|
"cell_type": "code",
|
|||
|
|
"execution_count": 10,
|
|||
|
|
"metadata": {
|
|||
|
|
"colab": {
|
|||
|
|
"base_uri": "https://localhost:8080/",
|
|||
|
|
"height": 424
|
|||
|
|
},
|
|||
|
|
"id": "9timicWWVNkh",
|
|||
|
|
"outputId": "ea843e32-0649-4954-dd50-545e9f9b0a41"
|
|||
|
|
},
|
|||
|
|
"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>Open</th>\n",
|
|||
|
|
" <th>High</th>\n",
|
|||
|
|
" <th>Low</th>\n",
|
|||
|
|
" <th>Close</th>\n",
|
|||
|
|
" <th>Volume</th>\n",
|
|||
|
|
" <th>Session</th>\n",
|
|||
|
|
" <th>Quarter</th>\n",
|
|||
|
|
" <th>Month_sin</th>\n",
|
|||
|
|
" <th>Hour_sin</th>\n",
|
|||
|
|
" <th>Date_sin</th>\n",
|
|||
|
|
" <th>DOW_sin</th>\n",
|
|||
|
|
" <th>DateTime</th>\n",
|
|||
|
|
" <th>Diff_10Y_2Y</th>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" </thead>\n",
|
|||
|
|
" <tbody>\n",
|
|||
|
|
" <tr>\n",
|
|||
|
|
" <th>0</th>\n",
|
|||
|
|
" <td>1.35460</td>\n",
|
|||
|
|
" <td>1.35860</td>\n",
|
|||
|
|
" <td>1.35370</td>\n",
|
|||
|
|
" <td>1.35710</td>\n",
|
|||
|
|
" <td>409.0</td>\n",
|
|||
|
|
" <td>1</td>\n",
|
|||
|
|
" <td>4</td>\n",
|
|||
|
|
" <td>-0.0</td>\n",
|
|||
|
|
" <td>-0.86603</td>\n",
|
|||
|
|
" <td>0.20791</td>\n",
|
|||
|
|
" <td>-0.433884</td>\n",
|
|||
|
|
" <td>2004-12-31 20:00:00</td>\n",
|
|||
|
|
" <td>0.048333</td>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" <tr>\n",
|
|||
|
|
" <th>1</th>\n",
|
|||
|
|
" <td>1.35720</td>\n",
|
|||
|
|
" <td>1.35850</td>\n",
|
|||
|
|
" <td>1.35600</td>\n",
|
|||
|
|
" <td>1.35650</td>\n",
|
|||
|
|
" <td>304.0</td>\n",
|
|||
|
|
" <td>1</td>\n",
|
|||
|
|
" <td>4</td>\n",
|
|||
|
|
" <td>-0.0</td>\n",
|
|||
|
|
" <td>-0.70711</td>\n",
|
|||
|
|
" <td>0.20791</td>\n",
|
|||
|
|
" <td>-0.433884</td>\n",
|
|||
|
|
" <td>2004-12-31 21:00:00</td>\n",
|
|||
|
|
" <td>0.048333</td>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" <tr>\n",
|
|||
|
|
" <th>2</th>\n",
|
|||
|
|
" <td>1.35660</td>\n",
|
|||
|
|
" <td>1.35710</td>\n",
|
|||
|
|
" <td>1.35520</td>\n",
|
|||
|
|
" <td>1.35540</td>\n",
|
|||
|
|
" <td>272.0</td>\n",
|
|||
|
|
" <td>0</td>\n",
|
|||
|
|
" <td>4</td>\n",
|
|||
|
|
" <td>-0.0</td>\n",
|
|||
|
|
" <td>-0.50000</td>\n",
|
|||
|
|
" <td>0.20791</td>\n",
|
|||
|
|
" <td>-0.433884</td>\n",
|
|||
|
|
" <td>2004-12-31 22:00:00</td>\n",
|
|||
|
|
" <td>0.048333</td>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" <tr>\n",
|
|||
|
|
" <th>3</th>\n",
|
|||
|
|
" <td>1.35540</td>\n",
|
|||
|
|
" <td>1.35630</td>\n",
|
|||
|
|
" <td>1.35520</td>\n",
|
|||
|
|
" <td>1.35620</td>\n",
|
|||
|
|
" <td>84.0</td>\n",
|
|||
|
|
" <td>0</td>\n",
|
|||
|
|
" <td>4</td>\n",
|
|||
|
|
" <td>-0.0</td>\n",
|
|||
|
|
" <td>-0.25882</td>\n",
|
|||
|
|
" <td>0.20791</td>\n",
|
|||
|
|
" <td>-0.433884</td>\n",
|
|||
|
|
" <td>2004-12-31 23:00:00</td>\n",
|
|||
|
|
" <td>0.048333</td>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" <tr>\n",
|
|||
|
|
" <th>4</th>\n",
|
|||
|
|
" <td>1.35790</td>\n",
|
|||
|
|
" <td>1.35810</td>\n",
|
|||
|
|
" <td>1.35390</td>\n",
|
|||
|
|
" <td>1.35470</td>\n",
|
|||
|
|
" <td>318.0</td>\n",
|
|||
|
|
" <td>1</td>\n",
|
|||
|
|
" <td>1</td>\n",
|
|||
|
|
" <td>0.5</td>\n",
|
|||
|
|
" <td>0.25882</td>\n",
|
|||
|
|
" <td>0.58779</td>\n",
|
|||
|
|
" <td>0.000000</td>\n",
|
|||
|
|
" <td>2005-01-03 01:00:00</td>\n",
|
|||
|
|
" <td>0.047083</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",
|
|||
|
|
" <td>...</td>\n",
|
|||
|
|
" <td>...</td>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" <tr>\n",
|
|||
|
|
" <th>122928</th>\n",
|
|||
|
|
" <td>1.03502</td>\n",
|
|||
|
|
" <td>1.03548</td>\n",
|
|||
|
|
" <td>1.03438</td>\n",
|
|||
|
|
" <td>1.03490</td>\n",
|
|||
|
|
" <td>2323.0</td>\n",
|
|||
|
|
" <td>1</td>\n",
|
|||
|
|
" <td>4</td>\n",
|
|||
|
|
" <td>-0.0</td>\n",
|
|||
|
|
" <td>-0.96593</td>\n",
|
|||
|
|
" <td>0.20791</td>\n",
|
|||
|
|
" <td>0.781831</td>\n",
|
|||
|
|
" <td>2024-12-31 19:00:00</td>\n",
|
|||
|
|
" <td>0.013750</td>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" <tr>\n",
|
|||
|
|
" <th>122929</th>\n",
|
|||
|
|
" <td>1.03489</td>\n",
|
|||
|
|
" <td>1.03566</td>\n",
|
|||
|
|
" <td>1.03455</td>\n",
|
|||
|
|
" <td>1.03529</td>\n",
|
|||
|
|
" <td>1900.0</td>\n",
|
|||
|
|
" <td>1</td>\n",
|
|||
|
|
" <td>4</td>\n",
|
|||
|
|
" <td>-0.0</td>\n",
|
|||
|
|
" <td>-0.86603</td>\n",
|
|||
|
|
" <td>0.20791</td>\n",
|
|||
|
|
" <td>0.781831</td>\n",
|
|||
|
|
" <td>2024-12-31 20:00:00</td>\n",
|
|||
|
|
" <td>0.013750</td>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" <tr>\n",
|
|||
|
|
" <th>122930</th>\n",
|
|||
|
|
" <td>1.03526</td>\n",
|
|||
|
|
" <td>1.03645</td>\n",
|
|||
|
|
" <td>1.03516</td>\n",
|
|||
|
|
" <td>1.03547</td>\n",
|
|||
|
|
" <td>1445.0</td>\n",
|
|||
|
|
" <td>1</td>\n",
|
|||
|
|
" <td>4</td>\n",
|
|||
|
|
" <td>-0.0</td>\n",
|
|||
|
|
" <td>-0.70711</td>\n",
|
|||
|
|
" <td>0.20791</td>\n",
|
|||
|
|
" <td>0.781831</td>\n",
|
|||
|
|
" <td>2024-12-31 21:00:00</td>\n",
|
|||
|
|
" <td>0.013750</td>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" <tr>\n",
|
|||
|
|
" <th>122931</th>\n",
|
|||
|
|
" <td>1.03547</td>\n",
|
|||
|
|
" <td>1.03631</td>\n",
|
|||
|
|
" <td>1.03544</td>\n",
|
|||
|
|
" <td>1.03582</td>\n",
|
|||
|
|
" <td>1208.0</td>\n",
|
|||
|
|
" <td>0</td>\n",
|
|||
|
|
" <td>4</td>\n",
|
|||
|
|
" <td>-0.0</td>\n",
|
|||
|
|
" <td>-0.50000</td>\n",
|
|||
|
|
" <td>0.20791</td>\n",
|
|||
|
|
" <td>0.781831</td>\n",
|
|||
|
|
" <td>2024-12-31 22:00:00</td>\n",
|
|||
|
|
" <td>0.013750</td>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" <tr>\n",
|
|||
|
|
" <th>122932</th>\n",
|
|||
|
|
" <td>1.03585</td>\n",
|
|||
|
|
" <td>1.03608</td>\n",
|
|||
|
|
" <td>1.03489</td>\n",
|
|||
|
|
" <td>1.03493</td>\n",
|
|||
|
|
" <td>616.0</td>\n",
|
|||
|
|
" <td>0</td>\n",
|
|||
|
|
" <td>4</td>\n",
|
|||
|
|
" <td>-0.0</td>\n",
|
|||
|
|
" <td>-0.25882</td>\n",
|
|||
|
|
" <td>0.20791</td>\n",
|
|||
|
|
" <td>0.781831</td>\n",
|
|||
|
|
" <td>2024-12-31 23:00:00</td>\n",
|
|||
|
|
" <td>0.013750</td>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" </tbody>\n",
|
|||
|
|
"</table>\n",
|
|||
|
|
"<p>118632 rows × 13 columns</p>\n",
|
|||
|
|
"</div>"
|
|||
|
|
],
|
|||
|
|
"text/plain": [
|
|||
|
|
" Open High Low Close Volume Session Quarter \\\n",
|
|||
|
|
"0 1.35460 1.35860 1.35370 1.35710 409.0 1 4 \n",
|
|||
|
|
"1 1.35720 1.35850 1.35600 1.35650 304.0 1 4 \n",
|
|||
|
|
"2 1.35660 1.35710 1.35520 1.35540 272.0 0 4 \n",
|
|||
|
|
"3 1.35540 1.35630 1.35520 1.35620 84.0 0 4 \n",
|
|||
|
|
"4 1.35790 1.35810 1.35390 1.35470 318.0 1 1 \n",
|
|||
|
|
"... ... ... ... ... ... ... ... \n",
|
|||
|
|
"122928 1.03502 1.03548 1.03438 1.03490 2323.0 1 4 \n",
|
|||
|
|
"122929 1.03489 1.03566 1.03455 1.03529 1900.0 1 4 \n",
|
|||
|
|
"122930 1.03526 1.03645 1.03516 1.03547 1445.0 1 4 \n",
|
|||
|
|
"122931 1.03547 1.03631 1.03544 1.03582 1208.0 0 4 \n",
|
|||
|
|
"122932 1.03585 1.03608 1.03489 1.03493 616.0 0 4 \n",
|
|||
|
|
"\n",
|
|||
|
|
" Month_sin Hour_sin Date_sin DOW_sin DateTime \\\n",
|
|||
|
|
"0 -0.0 -0.86603 0.20791 -0.433884 2004-12-31 20:00:00 \n",
|
|||
|
|
"1 -0.0 -0.70711 0.20791 -0.433884 2004-12-31 21:00:00 \n",
|
|||
|
|
"2 -0.0 -0.50000 0.20791 -0.433884 2004-12-31 22:00:00 \n",
|
|||
|
|
"3 -0.0 -0.25882 0.20791 -0.433884 2004-12-31 23:00:00 \n",
|
|||
|
|
"4 0.5 0.25882 0.58779 0.000000 2005-01-03 01:00:00 \n",
|
|||
|
|
"... ... ... ... ... ... \n",
|
|||
|
|
"122928 -0.0 -0.96593 0.20791 0.781831 2024-12-31 19:00:00 \n",
|
|||
|
|
"122929 -0.0 -0.86603 0.20791 0.781831 2024-12-31 20:00:00 \n",
|
|||
|
|
"122930 -0.0 -0.70711 0.20791 0.781831 2024-12-31 21:00:00 \n",
|
|||
|
|
"122931 -0.0 -0.50000 0.20791 0.781831 2024-12-31 22:00:00 \n",
|
|||
|
|
"122932 -0.0 -0.25882 0.20791 0.781831 2024-12-31 23:00:00 \n",
|
|||
|
|
"\n",
|
|||
|
|
" Diff_10Y_2Y \n",
|
|||
|
|
"0 0.048333 \n",
|
|||
|
|
"1 0.048333 \n",
|
|||
|
|
"2 0.048333 \n",
|
|||
|
|
"3 0.048333 \n",
|
|||
|
|
"4 0.047083 \n",
|
|||
|
|
"... ... \n",
|
|||
|
|
"122928 0.013750 \n",
|
|||
|
|
"122929 0.013750 \n",
|
|||
|
|
"122930 0.013750 \n",
|
|||
|
|
"122931 0.013750 \n",
|
|||
|
|
"122932 0.013750 \n",
|
|||
|
|
"\n",
|
|||
|
|
"[118632 rows x 13 columns]"
|
|||
|
|
]
|
|||
|
|
},
|
|||
|
|
"execution_count": 10,
|
|||
|
|
"metadata": {},
|
|||
|
|
"output_type": "execute_result"
|
|||
|
|
}
|
|||
|
|
],
|
|||
|
|
"source": [
|
|||
|
|
"import pandas as pd\n",
|
|||
|
|
"\n",
|
|||
|
|
"# Convert Date to datetime\n",
|
|||
|
|
"rate_df['Date'] = pd.to_datetime(rate_df['Date'], format='%m/%d/%y', errors='coerce')\n",
|
|||
|
|
"\n",
|
|||
|
|
"# Create interest rate differential column (10 Yr - 2 Yr)\n",
|
|||
|
|
"rate_df['Diff_10Y_2Y'] = (rate_df['10 Yr'] - rate_df['2 Yr'])/24\n",
|
|||
|
|
"\n",
|
|||
|
|
"# keep a copy of original datetime\n",
|
|||
|
|
"df['DateTime'] = df['Date']\n",
|
|||
|
|
"\n",
|
|||
|
|
"# extract just the date (without time) for merging\n",
|
|||
|
|
"df['Date'] = df['Date'].dt.date\n",
|
|||
|
|
"rate_df['Date'] = rate_df['Date'].dt.date\n",
|
|||
|
|
"\n",
|
|||
|
|
"# merge on just the date\n",
|
|||
|
|
"merged = pd.merge(df, rate_df, on='Date', how='left')\n",
|
|||
|
|
"\n",
|
|||
|
|
"# restore datetime with hours\n",
|
|||
|
|
"merged['Date'] = merged['DateTime']\n",
|
|||
|
|
"merged = merged.drop(columns=['Date'])\n",
|
|||
|
|
"\n",
|
|||
|
|
"df = merged\n",
|
|||
|
|
"\n",
|
|||
|
|
"df = df.drop(columns=['1 Mo', '2 Mo', '3 Mo', '4 Mo', '6 Mo', '1 Yr', '2 Yr', '3 Yr', '5 Yr', '7 Yr', '10 Yr', '20 Yr', '30 Yr'])\n",
|
|||
|
|
"\n",
|
|||
|
|
"df = df.dropna()\n",
|
|||
|
|
"\n",
|
|||
|
|
"df\n"
|
|||
|
|
]
|
|||
|
|
},
|
|||
|
|
{
|
|||
|
|
"cell_type": "markdown",
|
|||
|
|
"metadata": {
|
|||
|
|
"id": "dqhkZF0OXUww"
|
|||
|
|
},
|
|||
|
|
"source": [
|
|||
|
|
"### Oil and Gold\n",
|
|||
|
|
"\n",
|
|||
|
|
"* It is often seen that the currency values changes majorly when major global trading commodities such as oil and Gold change.\n",
|
|||
|
|
"* They can be seen as a leading indicator of volume and change in price for the forex trading pairs.\n",
|
|||
|
|
"\n",
|
|||
|
|
"The data for Gold has been taken from : \"https://www.kaggle.com/datasets/novandraanugrah/xauusd-gold-price-historical-data-2004-2024\"\n",
|
|||
|
|
"\n",
|
|||
|
|
"The data for oil has been taken from : \"https://finance.yahoo.com/quote/CL%3DF/history/?guccounter=1&guce_referrer=aHR0cHM6Ly93d3cuZ29vZ2xlLmNvbS8&guce_referrer_sig=AQAAAHBu3O2YAG4BmOqSpxUDAQmwfsfej5nBk9-VmpIWBpBNgHZ1tYYoD_v3BTwELQ3cousJCEKhSI3XsDuRq6vgSSFUHkx4tDVdKSnRKkPws55F1t8K4QRVCnjfk9AGgPfoaR9Yaxt6TvQATiAjAZwx17brwzdzjm01jDiV98-3sGo6\""
|
|||
|
|
]
|
|||
|
|
},
|
|||
|
|
{
|
|||
|
|
"cell_type": "code",
|
|||
|
|
"execution_count": 11,
|
|||
|
|
"metadata": {
|
|||
|
|
"colab": {
|
|||
|
|
"base_uri": "https://localhost:8080/",
|
|||
|
|
"height": 424
|
|||
|
|
},
|
|||
|
|
"id": "3zTFOYjqVq0w",
|
|||
|
|
"outputId": "f81d7a32-dcb6-426b-ed97-4550ec3f6470"
|
|||
|
|
},
|
|||
|
|
"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>Oil_Volume</th>\n",
|
|||
|
|
" <th>Oil_Close</th>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" </thead>\n",
|
|||
|
|
" <tbody>\n",
|
|||
|
|
" <tr>\n",
|
|||
|
|
" <th>0</th>\n",
|
|||
|
|
" <td>Aug 21, 2025</td>\n",
|
|||
|
|
" <td>196698</td>\n",
|
|||
|
|
" <td>63.50</td>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" <tr>\n",
|
|||
|
|
" <th>1</th>\n",
|
|||
|
|
" <td>Aug 20, 2025</td>\n",
|
|||
|
|
" <td>99484</td>\n",
|
|||
|
|
" <td>63.21</td>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" <tr>\n",
|
|||
|
|
" <th>2</th>\n",
|
|||
|
|
" <td>Aug 19, 2025</td>\n",
|
|||
|
|
" <td>99484</td>\n",
|
|||
|
|
" <td>62.35</td>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" <tr>\n",
|
|||
|
|
" <th>3</th>\n",
|
|||
|
|
" <td>Aug 18, 2025</td>\n",
|
|||
|
|
" <td>95113</td>\n",
|
|||
|
|
" <td>63.42</td>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" <tr>\n",
|
|||
|
|
" <th>4</th>\n",
|
|||
|
|
" <td>Aug 15, 2025</td>\n",
|
|||
|
|
" <td>197390</td>\n",
|
|||
|
|
" <td>62.80</td>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" <tr>\n",
|
|||
|
|
" <th>...</th>\n",
|
|||
|
|
" <td>...</td>\n",
|
|||
|
|
" <td>...</td>\n",
|
|||
|
|
" <td>...</td>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" <tr>\n",
|
|||
|
|
" <th>6271</th>\n",
|
|||
|
|
" <td>Aug 29, 2000</td>\n",
|
|||
|
|
" <td>49131</td>\n",
|
|||
|
|
" <td>32.72</td>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" <tr>\n",
|
|||
|
|
" <th>6272</th>\n",
|
|||
|
|
" <td>Aug 28, 2000</td>\n",
|
|||
|
|
" <td>46770</td>\n",
|
|||
|
|
" <td>32.87</td>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" <tr>\n",
|
|||
|
|
" <th>6273</th>\n",
|
|||
|
|
" <td>Aug 25, 2000</td>\n",
|
|||
|
|
" <td>44601</td>\n",
|
|||
|
|
" <td>32.05</td>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" <tr>\n",
|
|||
|
|
" <th>6274</th>\n",
|
|||
|
|
" <td>Aug 24, 2000</td>\n",
|
|||
|
|
" <td>72978</td>\n",
|
|||
|
|
" <td>31.63</td>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" <tr>\n",
|
|||
|
|
" <th>6275</th>\n",
|
|||
|
|
" <td>Aug 23, 2000</td>\n",
|
|||
|
|
" <td>79385</td>\n",
|
|||
|
|
" <td>32.05</td>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" </tbody>\n",
|
|||
|
|
"</table>\n",
|
|||
|
|
"<p>6276 rows × 3 columns</p>\n",
|
|||
|
|
"</div>"
|
|||
|
|
],
|
|||
|
|
"text/plain": [
|
|||
|
|
" Date Oil_Volume Oil_Close\n",
|
|||
|
|
"0 Aug 21, 2025 196698 63.50\n",
|
|||
|
|
"1 Aug 20, 2025 99484 63.21\n",
|
|||
|
|
"2 Aug 19, 2025 99484 62.35\n",
|
|||
|
|
"3 Aug 18, 2025 95113 63.42\n",
|
|||
|
|
"4 Aug 15, 2025 197390 62.80\n",
|
|||
|
|
"... ... ... ...\n",
|
|||
|
|
"6271 Aug 29, 2000 49131 32.72\n",
|
|||
|
|
"6272 Aug 28, 2000 46770 32.87\n",
|
|||
|
|
"6273 Aug 25, 2000 44601 32.05\n",
|
|||
|
|
"6274 Aug 24, 2000 72978 31.63\n",
|
|||
|
|
"6275 Aug 23, 2000 79385 32.05\n",
|
|||
|
|
"\n",
|
|||
|
|
"[6276 rows x 3 columns]"
|
|||
|
|
]
|
|||
|
|
},
|
|||
|
|
"execution_count": 11,
|
|||
|
|
"metadata": {},
|
|||
|
|
"output_type": "execute_result"
|
|||
|
|
}
|
|||
|
|
],
|
|||
|
|
"source": [
|
|||
|
|
"oil_df = pd.read_csv('oil.csv')\n",
|
|||
|
|
"oil_df = oil_df.rename(columns={\n",
|
|||
|
|
" \"Volume\": \"Oil_Volume\",\n",
|
|||
|
|
" \"Adj Close\": \"Oil_Close\"\n",
|
|||
|
|
"})\n",
|
|||
|
|
"\n",
|
|||
|
|
"\n",
|
|||
|
|
"oil_df"
|
|||
|
|
]
|
|||
|
|
},
|
|||
|
|
{
|
|||
|
|
"cell_type": "code",
|
|||
|
|
"execution_count": 12,
|
|||
|
|
"metadata": {
|
|||
|
|
"colab": {
|
|||
|
|
"base_uri": "https://localhost:8080/",
|
|||
|
|
"height": 898
|
|||
|
|
},
|
|||
|
|
"id": "zCFvrZJTY0Gz",
|
|||
|
|
"outputId": "11eb17e6-b5b5-4885-873e-c91acd61f6f1"
|
|||
|
|
},
|
|||
|
|
"outputs": [
|
|||
|
|
{
|
|||
|
|
"name": "stderr",
|
|||
|
|
"output_type": "stream",
|
|||
|
|
"text": [
|
|||
|
|
"/var/folders/l_/j4rfg9014yvd4jfvv441w26r0000gn/T/ipykernel_16708/2363661686.py:16: SettingWithCopyWarning: \n",
|
|||
|
|
"A value is trying to be set on a copy of a slice from a DataFrame.\n",
|
|||
|
|
"Try using .loc[row_indexer,col_indexer] = value instead\n",
|
|||
|
|
"\n",
|
|||
|
|
"See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n",
|
|||
|
|
" df['Oil_Volume'] = (df['Oil_Volume']/24)\n"
|
|||
|
|
]
|
|||
|
|
},
|
|||
|
|
{
|
|||
|
|
"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>Open</th>\n",
|
|||
|
|
" <th>High</th>\n",
|
|||
|
|
" <th>Low</th>\n",
|
|||
|
|
" <th>Close</th>\n",
|
|||
|
|
" <th>Volume</th>\n",
|
|||
|
|
" <th>Session</th>\n",
|
|||
|
|
" <th>Quarter</th>\n",
|
|||
|
|
" <th>Month_sin</th>\n",
|
|||
|
|
" <th>Hour_sin</th>\n",
|
|||
|
|
" <th>Date_sin</th>\n",
|
|||
|
|
" <th>DOW_sin</th>\n",
|
|||
|
|
" <th>DateTime</th>\n",
|
|||
|
|
" <th>Diff_10Y_2Y</th>\n",
|
|||
|
|
" <th>Oil_Volume</th>\n",
|
|||
|
|
" <th>Oil_Close</th>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" </thead>\n",
|
|||
|
|
" <tbody>\n",
|
|||
|
|
" <tr>\n",
|
|||
|
|
" <th>4</th>\n",
|
|||
|
|
" <td>1.35790</td>\n",
|
|||
|
|
" <td>1.35810</td>\n",
|
|||
|
|
" <td>1.35390</td>\n",
|
|||
|
|
" <td>1.35470</td>\n",
|
|||
|
|
" <td>318.0</td>\n",
|
|||
|
|
" <td>1</td>\n",
|
|||
|
|
" <td>1</td>\n",
|
|||
|
|
" <td>0.5</td>\n",
|
|||
|
|
" <td>0.25882</td>\n",
|
|||
|
|
" <td>0.58779</td>\n",
|
|||
|
|
" <td>0.000000</td>\n",
|
|||
|
|
" <td>2005-01-03 01:00:00</td>\n",
|
|||
|
|
" <td>0.047083</td>\n",
|
|||
|
|
" <td>2895.166667</td>\n",
|
|||
|
|
" <td>42.12</td>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" <tr>\n",
|
|||
|
|
" <th>5</th>\n",
|
|||
|
|
" <td>1.35460</td>\n",
|
|||
|
|
" <td>1.35510</td>\n",
|
|||
|
|
" <td>1.35290</td>\n",
|
|||
|
|
" <td>1.35380</td>\n",
|
|||
|
|
" <td>338.0</td>\n",
|
|||
|
|
" <td>1</td>\n",
|
|||
|
|
" <td>1</td>\n",
|
|||
|
|
" <td>0.5</td>\n",
|
|||
|
|
" <td>0.50000</td>\n",
|
|||
|
|
" <td>0.58779</td>\n",
|
|||
|
|
" <td>0.000000</td>\n",
|
|||
|
|
" <td>2005-01-03 02:00:00</td>\n",
|
|||
|
|
" <td>0.047083</td>\n",
|
|||
|
|
" <td>2895.166667</td>\n",
|
|||
|
|
" <td>42.12</td>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" <tr>\n",
|
|||
|
|
" <th>6</th>\n",
|
|||
|
|
" <td>1.35390</td>\n",
|
|||
|
|
" <td>1.35390</td>\n",
|
|||
|
|
" <td>1.34980</td>\n",
|
|||
|
|
" <td>1.35040</td>\n",
|
|||
|
|
" <td>356.0</td>\n",
|
|||
|
|
" <td>1</td>\n",
|
|||
|
|
" <td>1</td>\n",
|
|||
|
|
" <td>0.5</td>\n",
|
|||
|
|
" <td>0.70711</td>\n",
|
|||
|
|
" <td>0.58779</td>\n",
|
|||
|
|
" <td>0.000000</td>\n",
|
|||
|
|
" <td>2005-01-03 03:00:00</td>\n",
|
|||
|
|
" <td>0.047083</td>\n",
|
|||
|
|
" <td>2895.166667</td>\n",
|
|||
|
|
" <td>42.12</td>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" <tr>\n",
|
|||
|
|
" <th>7</th>\n",
|
|||
|
|
" <td>1.35040</td>\n",
|
|||
|
|
" <td>1.35060</td>\n",
|
|||
|
|
" <td>1.33850</td>\n",
|
|||
|
|
" <td>1.33990</td>\n",
|
|||
|
|
" <td>545.0</td>\n",
|
|||
|
|
" <td>1</td>\n",
|
|||
|
|
" <td>1</td>\n",
|
|||
|
|
" <td>0.5</td>\n",
|
|||
|
|
" <td>0.86603</td>\n",
|
|||
|
|
" <td>0.58779</td>\n",
|
|||
|
|
" <td>0.000000</td>\n",
|
|||
|
|
" <td>2005-01-03 04:00:00</td>\n",
|
|||
|
|
" <td>0.047083</td>\n",
|
|||
|
|
" <td>2895.166667</td>\n",
|
|||
|
|
" <td>42.12</td>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" <tr>\n",
|
|||
|
|
" <th>8</th>\n",
|
|||
|
|
" <td>1.33990</td>\n",
|
|||
|
|
" <td>1.34450</td>\n",
|
|||
|
|
" <td>1.33990</td>\n",
|
|||
|
|
" <td>1.34430</td>\n",
|
|||
|
|
" <td>385.0</td>\n",
|
|||
|
|
" <td>1</td>\n",
|
|||
|
|
" <td>1</td>\n",
|
|||
|
|
" <td>0.5</td>\n",
|
|||
|
|
" <td>0.96593</td>\n",
|
|||
|
|
" <td>0.58779</td>\n",
|
|||
|
|
" <td>0.000000</td>\n",
|
|||
|
|
" <td>2005-01-03 05:00:00</td>\n",
|
|||
|
|
" <td>0.047083</td>\n",
|
|||
|
|
" <td>2895.166667</td>\n",
|
|||
|
|
" <td>42.12</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",
|
|||
|
|
" <td>...</td>\n",
|
|||
|
|
" <td>...</td>\n",
|
|||
|
|
" <td>...</td>\n",
|
|||
|
|
" <td>...</td>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" <tr>\n",
|
|||
|
|
" <th>118627</th>\n",
|
|||
|
|
" <td>1.03502</td>\n",
|
|||
|
|
" <td>1.03548</td>\n",
|
|||
|
|
" <td>1.03438</td>\n",
|
|||
|
|
" <td>1.03490</td>\n",
|
|||
|
|
" <td>2323.0</td>\n",
|
|||
|
|
" <td>1</td>\n",
|
|||
|
|
" <td>4</td>\n",
|
|||
|
|
" <td>-0.0</td>\n",
|
|||
|
|
" <td>-0.96593</td>\n",
|
|||
|
|
" <td>0.20791</td>\n",
|
|||
|
|
" <td>0.781831</td>\n",
|
|||
|
|
" <td>2024-12-31 19:00:00</td>\n",
|
|||
|
|
" <td>0.013750</td>\n",
|
|||
|
|
" <td>6298.125000</td>\n",
|
|||
|
|
" <td>71.72</td>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" <tr>\n",
|
|||
|
|
" <th>118628</th>\n",
|
|||
|
|
" <td>1.03489</td>\n",
|
|||
|
|
" <td>1.03566</td>\n",
|
|||
|
|
" <td>1.03455</td>\n",
|
|||
|
|
" <td>1.03529</td>\n",
|
|||
|
|
" <td>1900.0</td>\n",
|
|||
|
|
" <td>1</td>\n",
|
|||
|
|
" <td>4</td>\n",
|
|||
|
|
" <td>-0.0</td>\n",
|
|||
|
|
" <td>-0.86603</td>\n",
|
|||
|
|
" <td>0.20791</td>\n",
|
|||
|
|
" <td>0.781831</td>\n",
|
|||
|
|
" <td>2024-12-31 20:00:00</td>\n",
|
|||
|
|
" <td>0.013750</td>\n",
|
|||
|
|
" <td>6298.125000</td>\n",
|
|||
|
|
" <td>71.72</td>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" <tr>\n",
|
|||
|
|
" <th>118629</th>\n",
|
|||
|
|
" <td>1.03526</td>\n",
|
|||
|
|
" <td>1.03645</td>\n",
|
|||
|
|
" <td>1.03516</td>\n",
|
|||
|
|
" <td>1.03547</td>\n",
|
|||
|
|
" <td>1445.0</td>\n",
|
|||
|
|
" <td>1</td>\n",
|
|||
|
|
" <td>4</td>\n",
|
|||
|
|
" <td>-0.0</td>\n",
|
|||
|
|
" <td>-0.70711</td>\n",
|
|||
|
|
" <td>0.20791</td>\n",
|
|||
|
|
" <td>0.781831</td>\n",
|
|||
|
|
" <td>2024-12-31 21:00:00</td>\n",
|
|||
|
|
" <td>0.013750</td>\n",
|
|||
|
|
" <td>6298.125000</td>\n",
|
|||
|
|
" <td>71.72</td>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" <tr>\n",
|
|||
|
|
" <th>118630</th>\n",
|
|||
|
|
" <td>1.03547</td>\n",
|
|||
|
|
" <td>1.03631</td>\n",
|
|||
|
|
" <td>1.03544</td>\n",
|
|||
|
|
" <td>1.03582</td>\n",
|
|||
|
|
" <td>1208.0</td>\n",
|
|||
|
|
" <td>0</td>\n",
|
|||
|
|
" <td>4</td>\n",
|
|||
|
|
" <td>-0.0</td>\n",
|
|||
|
|
" <td>-0.50000</td>\n",
|
|||
|
|
" <td>0.20791</td>\n",
|
|||
|
|
" <td>0.781831</td>\n",
|
|||
|
|
" <td>2024-12-31 22:00:00</td>\n",
|
|||
|
|
" <td>0.013750</td>\n",
|
|||
|
|
" <td>6298.125000</td>\n",
|
|||
|
|
" <td>71.72</td>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" <tr>\n",
|
|||
|
|
" <th>118631</th>\n",
|
|||
|
|
" <td>1.03585</td>\n",
|
|||
|
|
" <td>1.03608</td>\n",
|
|||
|
|
" <td>1.03489</td>\n",
|
|||
|
|
" <td>1.03493</td>\n",
|
|||
|
|
" <td>616.0</td>\n",
|
|||
|
|
" <td>0</td>\n",
|
|||
|
|
" <td>4</td>\n",
|
|||
|
|
" <td>-0.0</td>\n",
|
|||
|
|
" <td>-0.25882</td>\n",
|
|||
|
|
" <td>0.20791</td>\n",
|
|||
|
|
" <td>0.781831</td>\n",
|
|||
|
|
" <td>2024-12-31 23:00:00</td>\n",
|
|||
|
|
" <td>0.013750</td>\n",
|
|||
|
|
" <td>6298.125000</td>\n",
|
|||
|
|
" <td>71.72</td>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" </tbody>\n",
|
|||
|
|
"</table>\n",
|
|||
|
|
"<p>118393 rows × 15 columns</p>\n",
|
|||
|
|
"</div>"
|
|||
|
|
],
|
|||
|
|
"text/plain": [
|
|||
|
|
" Open High Low Close Volume Session Quarter \\\n",
|
|||
|
|
"4 1.35790 1.35810 1.35390 1.35470 318.0 1 1 \n",
|
|||
|
|
"5 1.35460 1.35510 1.35290 1.35380 338.0 1 1 \n",
|
|||
|
|
"6 1.35390 1.35390 1.34980 1.35040 356.0 1 1 \n",
|
|||
|
|
"7 1.35040 1.35060 1.33850 1.33990 545.0 1 1 \n",
|
|||
|
|
"8 1.33990 1.34450 1.33990 1.34430 385.0 1 1 \n",
|
|||
|
|
"... ... ... ... ... ... ... ... \n",
|
|||
|
|
"118627 1.03502 1.03548 1.03438 1.03490 2323.0 1 4 \n",
|
|||
|
|
"118628 1.03489 1.03566 1.03455 1.03529 1900.0 1 4 \n",
|
|||
|
|
"118629 1.03526 1.03645 1.03516 1.03547 1445.0 1 4 \n",
|
|||
|
|
"118630 1.03547 1.03631 1.03544 1.03582 1208.0 0 4 \n",
|
|||
|
|
"118631 1.03585 1.03608 1.03489 1.03493 616.0 0 4 \n",
|
|||
|
|
"\n",
|
|||
|
|
" Month_sin Hour_sin Date_sin DOW_sin DateTime \\\n",
|
|||
|
|
"4 0.5 0.25882 0.58779 0.000000 2005-01-03 01:00:00 \n",
|
|||
|
|
"5 0.5 0.50000 0.58779 0.000000 2005-01-03 02:00:00 \n",
|
|||
|
|
"6 0.5 0.70711 0.58779 0.000000 2005-01-03 03:00:00 \n",
|
|||
|
|
"7 0.5 0.86603 0.58779 0.000000 2005-01-03 04:00:00 \n",
|
|||
|
|
"8 0.5 0.96593 0.58779 0.000000 2005-01-03 05:00:00 \n",
|
|||
|
|
"... ... ... ... ... ... \n",
|
|||
|
|
"118627 -0.0 -0.96593 0.20791 0.781831 2024-12-31 19:00:00 \n",
|
|||
|
|
"118628 -0.0 -0.86603 0.20791 0.781831 2024-12-31 20:00:00 \n",
|
|||
|
|
"118629 -0.0 -0.70711 0.20791 0.781831 2024-12-31 21:00:00 \n",
|
|||
|
|
"118630 -0.0 -0.50000 0.20791 0.781831 2024-12-31 22:00:00 \n",
|
|||
|
|
"118631 -0.0 -0.25882 0.20791 0.781831 2024-12-31 23:00:00 \n",
|
|||
|
|
"\n",
|
|||
|
|
" Diff_10Y_2Y Oil_Volume Oil_Close \n",
|
|||
|
|
"4 0.047083 2895.166667 42.12 \n",
|
|||
|
|
"5 0.047083 2895.166667 42.12 \n",
|
|||
|
|
"6 0.047083 2895.166667 42.12 \n",
|
|||
|
|
"7 0.047083 2895.166667 42.12 \n",
|
|||
|
|
"8 0.047083 2895.166667 42.12 \n",
|
|||
|
|
"... ... ... ... \n",
|
|||
|
|
"118627 0.013750 6298.125000 71.72 \n",
|
|||
|
|
"118628 0.013750 6298.125000 71.72 \n",
|
|||
|
|
"118629 0.013750 6298.125000 71.72 \n",
|
|||
|
|
"118630 0.013750 6298.125000 71.72 \n",
|
|||
|
|
"118631 0.013750 6298.125000 71.72 \n",
|
|||
|
|
"\n",
|
|||
|
|
"[118393 rows x 15 columns]"
|
|||
|
|
]
|
|||
|
|
},
|
|||
|
|
"execution_count": 12,
|
|||
|
|
"metadata": {},
|
|||
|
|
"output_type": "execute_result"
|
|||
|
|
}
|
|||
|
|
],
|
|||
|
|
"source": [
|
|||
|
|
"import pandas as pd\n",
|
|||
|
|
"\n",
|
|||
|
|
"# Convert both to datetime64[ns]\n",
|
|||
|
|
"oil_df['Date'] = pd.to_datetime(oil_df['Date'], errors='coerce')\n",
|
|||
|
|
"df['Date'] = pd.to_datetime(df['DateTime']).dt.normalize() # strips time, keeps dtype datetime64[ns]\n",
|
|||
|
|
"\n",
|
|||
|
|
"# Now merge\n",
|
|||
|
|
"newmerge = pd.merge(df, oil_df, on='Date', how='left')\n",
|
|||
|
|
"\n",
|
|||
|
|
"newmerge = newmerge.drop(columns=['Date'])\n",
|
|||
|
|
"\n",
|
|||
|
|
"df = newmerge\n",
|
|||
|
|
"\n",
|
|||
|
|
"df = df.dropna()\n",
|
|||
|
|
"\n",
|
|||
|
|
"df['Oil_Volume'] = (df['Oil_Volume']/24)\n",
|
|||
|
|
"\n",
|
|||
|
|
"df\n"
|
|||
|
|
]
|
|||
|
|
},
|
|||
|
|
{
|
|||
|
|
"cell_type": "code",
|
|||
|
|
"execution_count": 13,
|
|||
|
|
"metadata": {
|
|||
|
|
"colab": {
|
|||
|
|
"base_uri": "https://localhost:8080/",
|
|||
|
|
"height": 424
|
|||
|
|
},
|
|||
|
|
"id": "aQeTiaPtfGTx",
|
|||
|
|
"outputId": "06f350ab-55f2-46f0-847c-0f88c640df86"
|
|||
|
|
},
|
|||
|
|
"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>Open</th>\n",
|
|||
|
|
" <th>High</th>\n",
|
|||
|
|
" <th>Low</th>\n",
|
|||
|
|
" <th>Close</th>\n",
|
|||
|
|
" <th>Volume</th>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" </thead>\n",
|
|||
|
|
" <tbody>\n",
|
|||
|
|
" <tr>\n",
|
|||
|
|
" <th>0</th>\n",
|
|||
|
|
" <td>2004.06.11 07:00</td>\n",
|
|||
|
|
" <td>384.00</td>\n",
|
|||
|
|
" <td>384.30</td>\n",
|
|||
|
|
" <td>383.30</td>\n",
|
|||
|
|
" <td>383.80</td>\n",
|
|||
|
|
" <td>44</td>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" <tr>\n",
|
|||
|
|
" <th>1</th>\n",
|
|||
|
|
" <td>2004.06.11 08:00</td>\n",
|
|||
|
|
" <td>383.80</td>\n",
|
|||
|
|
" <td>384.30</td>\n",
|
|||
|
|
" <td>383.10</td>\n",
|
|||
|
|
" <td>383.10</td>\n",
|
|||
|
|
" <td>41</td>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" <tr>\n",
|
|||
|
|
" <th>2</th>\n",
|
|||
|
|
" <td>2004.06.11 09:00</td>\n",
|
|||
|
|
" <td>383.10</td>\n",
|
|||
|
|
" <td>384.10</td>\n",
|
|||
|
|
" <td>382.80</td>\n",
|
|||
|
|
" <td>383.10</td>\n",
|
|||
|
|
" <td>55</td>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" <tr>\n",
|
|||
|
|
" <th>3</th>\n",
|
|||
|
|
" <td>2004.06.11 10:00</td>\n",
|
|||
|
|
" <td>383.00</td>\n",
|
|||
|
|
" <td>383.80</td>\n",
|
|||
|
|
" <td>383.00</td>\n",
|
|||
|
|
" <td>383.60</td>\n",
|
|||
|
|
" <td>33</td>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" <tr>\n",
|
|||
|
|
" <th>4</th>\n",
|
|||
|
|
" <td>2004.06.11 11:00</td>\n",
|
|||
|
|
" <td>383.60</td>\n",
|
|||
|
|
" <td>383.80</td>\n",
|
|||
|
|
" <td>383.50</td>\n",
|
|||
|
|
" <td>383.60</td>\n",
|
|||
|
|
" <td>23</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",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" <tr>\n",
|
|||
|
|
" <th>122651</th>\n",
|
|||
|
|
" <td>2025.07.15 15:00</td>\n",
|
|||
|
|
" <td>3354.84</td>\n",
|
|||
|
|
" <td>3360.22</td>\n",
|
|||
|
|
" <td>3346.34</td>\n",
|
|||
|
|
" <td>3348.77</td>\n",
|
|||
|
|
" <td>55313</td>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" <tr>\n",
|
|||
|
|
" <th>122652</th>\n",
|
|||
|
|
" <td>2025.07.15 16:00</td>\n",
|
|||
|
|
" <td>3348.78</td>\n",
|
|||
|
|
" <td>3352.36</td>\n",
|
|||
|
|
" <td>3334.35</td>\n",
|
|||
|
|
" <td>3346.50</td>\n",
|
|||
|
|
" <td>79108</td>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" <tr>\n",
|
|||
|
|
" <th>122653</th>\n",
|
|||
|
|
" <td>2025.07.15 17:00</td>\n",
|
|||
|
|
" <td>3346.49</td>\n",
|
|||
|
|
" <td>3352.05</td>\n",
|
|||
|
|
" <td>3342.43</td>\n",
|
|||
|
|
" <td>3347.89</td>\n",
|
|||
|
|
" <td>54849</td>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" <tr>\n",
|
|||
|
|
" <th>122654</th>\n",
|
|||
|
|
" <td>2025.07.15 18:00</td>\n",
|
|||
|
|
" <td>3347.88</td>\n",
|
|||
|
|
" <td>3349.87</td>\n",
|
|||
|
|
" <td>3325.34</td>\n",
|
|||
|
|
" <td>3328.88</td>\n",
|
|||
|
|
" <td>63341</td>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" <tr>\n",
|
|||
|
|
" <th>122655</th>\n",
|
|||
|
|
" <td>2025.07.15 19:00</td>\n",
|
|||
|
|
" <td>3328.87</td>\n",
|
|||
|
|
" <td>3328.89</td>\n",
|
|||
|
|
" <td>3320.17</td>\n",
|
|||
|
|
" <td>3327.27</td>\n",
|
|||
|
|
" <td>36550</td>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" </tbody>\n",
|
|||
|
|
"</table>\n",
|
|||
|
|
"<p>122656 rows × 6 columns</p>\n",
|
|||
|
|
"</div>"
|
|||
|
|
],
|
|||
|
|
"text/plain": [
|
|||
|
|
" Date Open High Low Close Volume\n",
|
|||
|
|
"0 2004.06.11 07:00 384.00 384.30 383.30 383.80 44\n",
|
|||
|
|
"1 2004.06.11 08:00 383.80 384.30 383.10 383.10 41\n",
|
|||
|
|
"2 2004.06.11 09:00 383.10 384.10 382.80 383.10 55\n",
|
|||
|
|
"3 2004.06.11 10:00 383.00 383.80 383.00 383.60 33\n",
|
|||
|
|
"4 2004.06.11 11:00 383.60 383.80 383.50 383.60 23\n",
|
|||
|
|
"... ... ... ... ... ... ...\n",
|
|||
|
|
"122651 2025.07.15 15:00 3354.84 3360.22 3346.34 3348.77 55313\n",
|
|||
|
|
"122652 2025.07.15 16:00 3348.78 3352.36 3334.35 3346.50 79108\n",
|
|||
|
|
"122653 2025.07.15 17:00 3346.49 3352.05 3342.43 3347.89 54849\n",
|
|||
|
|
"122654 2025.07.15 18:00 3347.88 3349.87 3325.34 3328.88 63341\n",
|
|||
|
|
"122655 2025.07.15 19:00 3328.87 3328.89 3320.17 3327.27 36550\n",
|
|||
|
|
"\n",
|
|||
|
|
"[122656 rows x 6 columns]"
|
|||
|
|
]
|
|||
|
|
},
|
|||
|
|
"execution_count": 13,
|
|||
|
|
"metadata": {},
|
|||
|
|
"output_type": "execute_result"
|
|||
|
|
}
|
|||
|
|
],
|
|||
|
|
"source": [
|
|||
|
|
"gold_df = pd.read_csv('gold.csv', sep=\";\")\n",
|
|||
|
|
"gold_df"
|
|||
|
|
]
|
|||
|
|
},
|
|||
|
|
{
|
|||
|
|
"cell_type": "code",
|
|||
|
|
"execution_count": 14,
|
|||
|
|
"metadata": {
|
|||
|
|
"colab": {
|
|||
|
|
"base_uri": "https://localhost:8080/",
|
|||
|
|
"height": 791
|
|||
|
|
},
|
|||
|
|
"id": "pRr9VzVvgsCI",
|
|||
|
|
"outputId": "a573b200-5696-49b3-8a14-ff20938f32b6"
|
|||
|
|
},
|
|||
|
|
"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>Open</th>\n",
|
|||
|
|
" <th>High</th>\n",
|
|||
|
|
" <th>Low</th>\n",
|
|||
|
|
" <th>Close</th>\n",
|
|||
|
|
" <th>Volume</th>\n",
|
|||
|
|
" <th>Session</th>\n",
|
|||
|
|
" <th>Quarter</th>\n",
|
|||
|
|
" <th>Month_sin</th>\n",
|
|||
|
|
" <th>Hour_sin</th>\n",
|
|||
|
|
" <th>Date_sin</th>\n",
|
|||
|
|
" <th>DOW_sin</th>\n",
|
|||
|
|
" <th>DateTime</th>\n",
|
|||
|
|
" <th>Diff_10Y_2Y</th>\n",
|
|||
|
|
" <th>Oil_Volume</th>\n",
|
|||
|
|
" <th>Oil_Close</th>\n",
|
|||
|
|
" <th>Gold_Close</th>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" </thead>\n",
|
|||
|
|
" <tbody>\n",
|
|||
|
|
" <tr>\n",
|
|||
|
|
" <th>0</th>\n",
|
|||
|
|
" <td>1.35790</td>\n",
|
|||
|
|
" <td>1.35810</td>\n",
|
|||
|
|
" <td>1.35390</td>\n",
|
|||
|
|
" <td>1.35470</td>\n",
|
|||
|
|
" <td>318.0</td>\n",
|
|||
|
|
" <td>1</td>\n",
|
|||
|
|
" <td>1</td>\n",
|
|||
|
|
" <td>0.5</td>\n",
|
|||
|
|
" <td>0.25882</td>\n",
|
|||
|
|
" <td>0.58779</td>\n",
|
|||
|
|
" <td>0.000000</td>\n",
|
|||
|
|
" <td>2005-01-03 01:00:00</td>\n",
|
|||
|
|
" <td>0.047083</td>\n",
|
|||
|
|
" <td>2895.166667</td>\n",
|
|||
|
|
" <td>42.12</td>\n",
|
|||
|
|
" <td>435.60</td>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" <tr>\n",
|
|||
|
|
" <th>1</th>\n",
|
|||
|
|
" <td>1.35460</td>\n",
|
|||
|
|
" <td>1.35510</td>\n",
|
|||
|
|
" <td>1.35290</td>\n",
|
|||
|
|
" <td>1.35380</td>\n",
|
|||
|
|
" <td>338.0</td>\n",
|
|||
|
|
" <td>1</td>\n",
|
|||
|
|
" <td>1</td>\n",
|
|||
|
|
" <td>0.5</td>\n",
|
|||
|
|
" <td>0.50000</td>\n",
|
|||
|
|
" <td>0.58779</td>\n",
|
|||
|
|
" <td>0.000000</td>\n",
|
|||
|
|
" <td>2005-01-03 02:00:00</td>\n",
|
|||
|
|
" <td>0.047083</td>\n",
|
|||
|
|
" <td>2895.166667</td>\n",
|
|||
|
|
" <td>42.12</td>\n",
|
|||
|
|
" <td>435.50</td>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" <tr>\n",
|
|||
|
|
" <th>2</th>\n",
|
|||
|
|
" <td>1.35390</td>\n",
|
|||
|
|
" <td>1.35390</td>\n",
|
|||
|
|
" <td>1.34980</td>\n",
|
|||
|
|
" <td>1.35040</td>\n",
|
|||
|
|
" <td>356.0</td>\n",
|
|||
|
|
" <td>1</td>\n",
|
|||
|
|
" <td>1</td>\n",
|
|||
|
|
" <td>0.5</td>\n",
|
|||
|
|
" <td>0.70711</td>\n",
|
|||
|
|
" <td>0.58779</td>\n",
|
|||
|
|
" <td>0.000000</td>\n",
|
|||
|
|
" <td>2005-01-03 03:00:00</td>\n",
|
|||
|
|
" <td>0.047083</td>\n",
|
|||
|
|
" <td>2895.166667</td>\n",
|
|||
|
|
" <td>42.12</td>\n",
|
|||
|
|
" <td>435.00</td>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" <tr>\n",
|
|||
|
|
" <th>3</th>\n",
|
|||
|
|
" <td>1.35040</td>\n",
|
|||
|
|
" <td>1.35060</td>\n",
|
|||
|
|
" <td>1.33850</td>\n",
|
|||
|
|
" <td>1.33990</td>\n",
|
|||
|
|
" <td>545.0</td>\n",
|
|||
|
|
" <td>1</td>\n",
|
|||
|
|
" <td>1</td>\n",
|
|||
|
|
" <td>0.5</td>\n",
|
|||
|
|
" <td>0.86603</td>\n",
|
|||
|
|
" <td>0.58779</td>\n",
|
|||
|
|
" <td>0.000000</td>\n",
|
|||
|
|
" <td>2005-01-03 04:00:00</td>\n",
|
|||
|
|
" <td>0.047083</td>\n",
|
|||
|
|
" <td>2895.166667</td>\n",
|
|||
|
|
" <td>42.12</td>\n",
|
|||
|
|
" <td>433.60</td>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" <tr>\n",
|
|||
|
|
" <th>4</th>\n",
|
|||
|
|
" <td>1.33990</td>\n",
|
|||
|
|
" <td>1.34450</td>\n",
|
|||
|
|
" <td>1.33990</td>\n",
|
|||
|
|
" <td>1.34430</td>\n",
|
|||
|
|
" <td>385.0</td>\n",
|
|||
|
|
" <td>1</td>\n",
|
|||
|
|
" <td>1</td>\n",
|
|||
|
|
" <td>0.5</td>\n",
|
|||
|
|
" <td>0.96593</td>\n",
|
|||
|
|
" <td>0.58779</td>\n",
|
|||
|
|
" <td>0.000000</td>\n",
|
|||
|
|
" <td>2005-01-03 05:00:00</td>\n",
|
|||
|
|
" <td>0.047083</td>\n",
|
|||
|
|
" <td>2895.166667</td>\n",
|
|||
|
|
" <td>42.12</td>\n",
|
|||
|
|
" <td>433.60</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",
|
|||
|
|
" <td>...</td>\n",
|
|||
|
|
" <td>...</td>\n",
|
|||
|
|
" <td>...</td>\n",
|
|||
|
|
" <td>...</td>\n",
|
|||
|
|
" <td>...</td>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" <tr>\n",
|
|||
|
|
" <th>118388</th>\n",
|
|||
|
|
" <td>1.03502</td>\n",
|
|||
|
|
" <td>1.03548</td>\n",
|
|||
|
|
" <td>1.03438</td>\n",
|
|||
|
|
" <td>1.03490</td>\n",
|
|||
|
|
" <td>2323.0</td>\n",
|
|||
|
|
" <td>1</td>\n",
|
|||
|
|
" <td>4</td>\n",
|
|||
|
|
" <td>-0.0</td>\n",
|
|||
|
|
" <td>-0.96593</td>\n",
|
|||
|
|
" <td>0.20791</td>\n",
|
|||
|
|
" <td>0.781831</td>\n",
|
|||
|
|
" <td>2024-12-31 19:00:00</td>\n",
|
|||
|
|
" <td>0.013750</td>\n",
|
|||
|
|
" <td>6298.125000</td>\n",
|
|||
|
|
" <td>71.72</td>\n",
|
|||
|
|
" <td>2624.38</td>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" <tr>\n",
|
|||
|
|
" <th>118389</th>\n",
|
|||
|
|
" <td>1.03489</td>\n",
|
|||
|
|
" <td>1.03566</td>\n",
|
|||
|
|
" <td>1.03455</td>\n",
|
|||
|
|
" <td>1.03529</td>\n",
|
|||
|
|
" <td>1900.0</td>\n",
|
|||
|
|
" <td>1</td>\n",
|
|||
|
|
" <td>4</td>\n",
|
|||
|
|
" <td>-0.0</td>\n",
|
|||
|
|
" <td>-0.86603</td>\n",
|
|||
|
|
" <td>0.20791</td>\n",
|
|||
|
|
" <td>0.781831</td>\n",
|
|||
|
|
" <td>2024-12-31 20:00:00</td>\n",
|
|||
|
|
" <td>0.013750</td>\n",
|
|||
|
|
" <td>6298.125000</td>\n",
|
|||
|
|
" <td>71.72</td>\n",
|
|||
|
|
" <td>2624.81</td>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" <tr>\n",
|
|||
|
|
" <th>118390</th>\n",
|
|||
|
|
" <td>1.03526</td>\n",
|
|||
|
|
" <td>1.03645</td>\n",
|
|||
|
|
" <td>1.03516</td>\n",
|
|||
|
|
" <td>1.03547</td>\n",
|
|||
|
|
" <td>1445.0</td>\n",
|
|||
|
|
" <td>1</td>\n",
|
|||
|
|
" <td>4</td>\n",
|
|||
|
|
" <td>-0.0</td>\n",
|
|||
|
|
" <td>-0.70711</td>\n",
|
|||
|
|
" <td>0.20791</td>\n",
|
|||
|
|
" <td>0.781831</td>\n",
|
|||
|
|
" <td>2024-12-31 21:00:00</td>\n",
|
|||
|
|
" <td>0.013750</td>\n",
|
|||
|
|
" <td>6298.125000</td>\n",
|
|||
|
|
" <td>71.72</td>\n",
|
|||
|
|
" <td>2623.85</td>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" <tr>\n",
|
|||
|
|
" <th>118391</th>\n",
|
|||
|
|
" <td>1.03547</td>\n",
|
|||
|
|
" <td>1.03631</td>\n",
|
|||
|
|
" <td>1.03544</td>\n",
|
|||
|
|
" <td>1.03582</td>\n",
|
|||
|
|
" <td>1208.0</td>\n",
|
|||
|
|
" <td>0</td>\n",
|
|||
|
|
" <td>4</td>\n",
|
|||
|
|
" <td>-0.0</td>\n",
|
|||
|
|
" <td>-0.50000</td>\n",
|
|||
|
|
" <td>0.20791</td>\n",
|
|||
|
|
" <td>0.781831</td>\n",
|
|||
|
|
" <td>2024-12-31 22:00:00</td>\n",
|
|||
|
|
" <td>0.013750</td>\n",
|
|||
|
|
" <td>6298.125000</td>\n",
|
|||
|
|
" <td>71.72</td>\n",
|
|||
|
|
" <td>2623.36</td>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" <tr>\n",
|
|||
|
|
" <th>118392</th>\n",
|
|||
|
|
" <td>1.03585</td>\n",
|
|||
|
|
" <td>1.03608</td>\n",
|
|||
|
|
" <td>1.03489</td>\n",
|
|||
|
|
" <td>1.03493</td>\n",
|
|||
|
|
" <td>616.0</td>\n",
|
|||
|
|
" <td>0</td>\n",
|
|||
|
|
" <td>4</td>\n",
|
|||
|
|
" <td>-0.0</td>\n",
|
|||
|
|
" <td>-0.25882</td>\n",
|
|||
|
|
" <td>0.20791</td>\n",
|
|||
|
|
" <td>0.781831</td>\n",
|
|||
|
|
" <td>2024-12-31 23:00:00</td>\n",
|
|||
|
|
" <td>0.013750</td>\n",
|
|||
|
|
" <td>6298.125000</td>\n",
|
|||
|
|
" <td>71.72</td>\n",
|
|||
|
|
" <td>2624.61</td>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" </tbody>\n",
|
|||
|
|
"</table>\n",
|
|||
|
|
"<p>113016 rows × 16 columns</p>\n",
|
|||
|
|
"</div>"
|
|||
|
|
],
|
|||
|
|
"text/plain": [
|
|||
|
|
" Open High Low Close Volume Session Quarter \\\n",
|
|||
|
|
"0 1.35790 1.35810 1.35390 1.35470 318.0 1 1 \n",
|
|||
|
|
"1 1.35460 1.35510 1.35290 1.35380 338.0 1 1 \n",
|
|||
|
|
"2 1.35390 1.35390 1.34980 1.35040 356.0 1 1 \n",
|
|||
|
|
"3 1.35040 1.35060 1.33850 1.33990 545.0 1 1 \n",
|
|||
|
|
"4 1.33990 1.34450 1.33990 1.34430 385.0 1 1 \n",
|
|||
|
|
"... ... ... ... ... ... ... ... \n",
|
|||
|
|
"118388 1.03502 1.03548 1.03438 1.03490 2323.0 1 4 \n",
|
|||
|
|
"118389 1.03489 1.03566 1.03455 1.03529 1900.0 1 4 \n",
|
|||
|
|
"118390 1.03526 1.03645 1.03516 1.03547 1445.0 1 4 \n",
|
|||
|
|
"118391 1.03547 1.03631 1.03544 1.03582 1208.0 0 4 \n",
|
|||
|
|
"118392 1.03585 1.03608 1.03489 1.03493 616.0 0 4 \n",
|
|||
|
|
"\n",
|
|||
|
|
" Month_sin Hour_sin Date_sin DOW_sin DateTime \\\n",
|
|||
|
|
"0 0.5 0.25882 0.58779 0.000000 2005-01-03 01:00:00 \n",
|
|||
|
|
"1 0.5 0.50000 0.58779 0.000000 2005-01-03 02:00:00 \n",
|
|||
|
|
"2 0.5 0.70711 0.58779 0.000000 2005-01-03 03:00:00 \n",
|
|||
|
|
"3 0.5 0.86603 0.58779 0.000000 2005-01-03 04:00:00 \n",
|
|||
|
|
"4 0.5 0.96593 0.58779 0.000000 2005-01-03 05:00:00 \n",
|
|||
|
|
"... ... ... ... ... ... \n",
|
|||
|
|
"118388 -0.0 -0.96593 0.20791 0.781831 2024-12-31 19:00:00 \n",
|
|||
|
|
"118389 -0.0 -0.86603 0.20791 0.781831 2024-12-31 20:00:00 \n",
|
|||
|
|
"118390 -0.0 -0.70711 0.20791 0.781831 2024-12-31 21:00:00 \n",
|
|||
|
|
"118391 -0.0 -0.50000 0.20791 0.781831 2024-12-31 22:00:00 \n",
|
|||
|
|
"118392 -0.0 -0.25882 0.20791 0.781831 2024-12-31 23:00:00 \n",
|
|||
|
|
"\n",
|
|||
|
|
" Diff_10Y_2Y Oil_Volume Oil_Close Gold_Close \n",
|
|||
|
|
"0 0.047083 2895.166667 42.12 435.60 \n",
|
|||
|
|
"1 0.047083 2895.166667 42.12 435.50 \n",
|
|||
|
|
"2 0.047083 2895.166667 42.12 435.00 \n",
|
|||
|
|
"3 0.047083 2895.166667 42.12 433.60 \n",
|
|||
|
|
"4 0.047083 2895.166667 42.12 433.60 \n",
|
|||
|
|
"... ... ... ... ... \n",
|
|||
|
|
"118388 0.013750 6298.125000 71.72 2624.38 \n",
|
|||
|
|
"118389 0.013750 6298.125000 71.72 2624.81 \n",
|
|||
|
|
"118390 0.013750 6298.125000 71.72 2623.85 \n",
|
|||
|
|
"118391 0.013750 6298.125000 71.72 2623.36 \n",
|
|||
|
|
"118392 0.013750 6298.125000 71.72 2624.61 \n",
|
|||
|
|
"\n",
|
|||
|
|
"[113016 rows x 16 columns]"
|
|||
|
|
]
|
|||
|
|
},
|
|||
|
|
"execution_count": 14,
|
|||
|
|
"metadata": {},
|
|||
|
|
"output_type": "execute_result"
|
|||
|
|
}
|
|||
|
|
],
|
|||
|
|
"source": [
|
|||
|
|
"gold_df = gold_df.drop(columns=['Open', 'High', 'Low', 'Volume'])\n",
|
|||
|
|
"\n",
|
|||
|
|
"gold_df = gold_df.rename(columns={\n",
|
|||
|
|
" \"Close\": \"Gold_Close\",\n",
|
|||
|
|
" \"Date\":\"DateTime\"\n",
|
|||
|
|
"})\n",
|
|||
|
|
"\n",
|
|||
|
|
"# Convert gold_df['Date'] to proper datetime\n",
|
|||
|
|
"gold_df['DateTime'] = pd.to_datetime(gold_df['DateTime'], format=\"%Y.%m.%d %H:%M\", errors=\"coerce\")\n",
|
|||
|
|
"\n",
|
|||
|
|
"# Merge on DateOnly\n",
|
|||
|
|
"merged = pd.merge(df, gold_df, on='DateTime', how='left')\n",
|
|||
|
|
"\n",
|
|||
|
|
"df = merged\n",
|
|||
|
|
"\n",
|
|||
|
|
"df = df.dropna()\n",
|
|||
|
|
"\n",
|
|||
|
|
"df\n",
|
|||
|
|
"\n",
|
|||
|
|
"\n",
|
|||
|
|
"\n"
|
|||
|
|
]
|
|||
|
|
},
|
|||
|
|
{
|
|||
|
|
"cell_type": "markdown",
|
|||
|
|
"metadata": {
|
|||
|
|
"id": "MyqzbrPmjL4J"
|
|||
|
|
},
|
|||
|
|
"source": [
|
|||
|
|
"## Technical Indicators\n",
|
|||
|
|
"\n",
|
|||
|
|
"* I have chosen only bounded indicators because i do not want the machine to get confused.\n",
|
|||
|
|
"* All the chosen Indicators are selected keeping in mind that their primary function is to help understand the machine the nature of the market when combined with the previously made features.\n",
|
|||
|
|
"\n",
|
|||
|
|
"* The Features selected can be broadly classified into 3 categories:\n",
|
|||
|
|
"\n",
|
|||
|
|
" * Trend :\n",
|
|||
|
|
" * ADX - Average Directional Index (Strength Only)\n",
|
|||
|
|
" * CCI - Commodity Channel Index (Strength and Direction)\n",
|
|||
|
|
" \n",
|
|||
|
|
" * Momentum :\n",
|
|||
|
|
" * PPO - Percent Price Oscillator (Strength and Direction)\n",
|
|||
|
|
" * CMO - Chande Momentum Oscillator (Strength and Direction)\n",
|
|||
|
|
"\n",
|
|||
|
|
" * Volatility:\n",
|
|||
|
|
" * Chaikin Volatility (Intra-Bar)\n",
|
|||
|
|
" * Keltner Channel Width (Inter-Bar)\n",
|
|||
|
|
"\n",
|
|||
|
|
"* Here I am calculating them and then in order to find the most responsive lookback periods, graphs showing ACF (Auto-Correlation Function) and PACF (Partial Auto-Correlation Factor)\n",
|
|||
|
|
"\n",
|
|||
|
|
"* Based on ACF, PACF and standard lookback periods, we will calculate indicators for multiple lookback periods.\n",
|
|||
|
|
"\n",
|
|||
|
|
"* Based on all these indicators, new secondary indicators will be calculated from primary features to catch as micro market structures and repetitive macro market structures"
|
|||
|
|
]
|
|||
|
|
},
|
|||
|
|
{
|
|||
|
|
"cell_type": "code",
|
|||
|
|
"execution_count": 118,
|
|||
|
|
"metadata": {
|
|||
|
|
"colab": {
|
|||
|
|
"base_uri": "https://localhost:8080/",
|
|||
|
|
"height": 1000
|
|||
|
|
},
|
|||
|
|
"id": "2jBOM8xwhBg2",
|
|||
|
|
"outputId": "ddd7d7d6-7eb8-4317-fb44-539ed00c6232"
|
|||
|
|
},
|
|||
|
|
"outputs": [
|
|||
|
|
{
|
|||
|
|
"name": "stderr",
|
|||
|
|
"output_type": "stream",
|
|||
|
|
"text": [
|
|||
|
|
"/var/folders/l_/j4rfg9014yvd4jfvv441w26r0000gn/T/ipykernel_54914/3209065174.py:9: SettingWithCopyWarning: \n",
|
|||
|
|
"A value is trying to be set on a copy of a slice from a DataFrame.\n",
|
|||
|
|
"Try using .loc[row_indexer,col_indexer] = value instead\n",
|
|||
|
|
"\n",
|
|||
|
|
"See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n",
|
|||
|
|
" df['ADX_14'] = talib.ADX(df['High'], df['Low'], df['Close'], timeperiod=14)\n",
|
|||
|
|
"/var/folders/l_/j4rfg9014yvd4jfvv441w26r0000gn/T/ipykernel_54914/3209065174.py:10: SettingWithCopyWarning: \n",
|
|||
|
|
"A value is trying to be set on a copy of a slice from a DataFrame.\n",
|
|||
|
|
"Try using .loc[row_indexer,col_indexer] = value instead\n",
|
|||
|
|
"\n",
|
|||
|
|
"See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n",
|
|||
|
|
" df['CCI_14'] = talib.CCI(df['High'], df['Low'], df['Close'], timeperiod=14)\n",
|
|||
|
|
"/var/folders/l_/j4rfg9014yvd4jfvv441w26r0000gn/T/ipykernel_54914/3209065174.py:11: SettingWithCopyWarning: \n",
|
|||
|
|
"A value is trying to be set on a copy of a slice from a DataFrame.\n",
|
|||
|
|
"Try using .loc[row_indexer,col_indexer] = value instead\n",
|
|||
|
|
"\n",
|
|||
|
|
"See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n",
|
|||
|
|
" df['PPO_12_26'] = talib.PPO(df['Close'], fastperiod=12, slowperiod=26, matype=0)\n",
|
|||
|
|
"/var/folders/l_/j4rfg9014yvd4jfvv441w26r0000gn/T/ipykernel_54914/3209065174.py:12: SettingWithCopyWarning: \n",
|
|||
|
|
"A value is trying to be set on a copy of a slice from a DataFrame.\n",
|
|||
|
|
"Try using .loc[row_indexer,col_indexer] = value instead\n",
|
|||
|
|
"\n",
|
|||
|
|
"See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n",
|
|||
|
|
" df['CMO_14'] = talib.CMO(df['Close'], timeperiod=14)\n",
|
|||
|
|
"/var/folders/l_/j4rfg9014yvd4jfvv441w26r0000gn/T/ipykernel_54914/3209065174.py:13: SettingWithCopyWarning: \n",
|
|||
|
|
"A value is trying to be set on a copy of a slice from a DataFrame.\n",
|
|||
|
|
"Try using .loc[row_indexer,col_indexer] = value instead\n",
|
|||
|
|
"\n",
|
|||
|
|
"See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n",
|
|||
|
|
" df['ChaikinVol_3_10'] = talib.ADOSC(df['High'], df['Low'], df['Close'], df['Volume'], fastperiod=3, slowperiod=10)\n",
|
|||
|
|
"/var/folders/l_/j4rfg9014yvd4jfvv441w26r0000gn/T/ipykernel_54914/3209065174.py:14: SettingWithCopyWarning: \n",
|
|||
|
|
"A value is trying to be set on a copy of a slice from a DataFrame.\n",
|
|||
|
|
"Try using .loc[row_indexer,col_indexer] = value instead\n",
|
|||
|
|
"\n",
|
|||
|
|
"See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n",
|
|||
|
|
" df['KeltnerWidth_20'] = (talib.EMA(df['High'] - df['Low'], timeperiod=20) / talib.EMA(df['Close'], timeperiod=20))\n"
|
|||
|
|
]
|
|||
|
|
},
|
|||
|
|
{
|
|||
|
|
"data": {
|
|||
|
|
"image/png": "iVBORw0KGgoAAAANSUhEUgAABKUAAAHqCAYAAADVi/1VAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjguMCwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy81sbWrAAAACXBIWXMAAA9hAAAPYQGoP6dpAABcrklEQVR4nO3df1wVZfr/8feAgEhCJAoYiNSmlkSZlGK/17TcrK0I8FOZlbnrmltGfVM/1Wbtlku1qdVW1lr2a0uK3LaPZlEp5qolpmFuta5hQkGGISgSKsz3D+TIgcOBg8zAOef1fDzOA8/MPcN9MwgX19xz3YZpmqYAAAAAAAAAGwV0dQcAAAAAAADgf0hKAQAAAAAAwHYkpQAAAAAAAGA7klIAAAAAAACwHUkpAAAAAAAA2I6kFAAAAAAAAGxHUgoAAAAAAAC2IykFAAAAAAAA25GUAgAAAAAAgO1ISgFol8cff1yGYSgpKcltu2+++UbTp0/XoEGDFBoaql69emno0KG655579N133zna3XDDDTIMw+Xr//7v/zqlzwcOHNDUqVMVGxurwMBAnX766e067qqrrpJhGJo+fbrL/atWrXLqb3BwsPr27auzzz5bd999t7799tsWx9x0000KCQnRli1bWuz785//LMMw9M4777R7bFu3btW0adOUmpqqsLAwGYahVatWtXncDz/8oD59+sgwDL355pvt/nwAAMC1xYsXO8UFPXr0UFxcnG688Uan2KcRMdURxFQAenR1BwB4h+eff15Swy/uTz75RCNGjGjR5v/+7/80YcIERUVFafr06Ro2bJgMw9CWLVv0/PPPa9myZdq0aZOjfWhoqD766KMW5xkyZEin9Pnpp5/WwoUL9cQTT2j48OE65phj2jxm165djgDu1Vdf1aOPPqqePXu6bPvQQw/pwgsvVF1dnXbv3q1PPvlEzz//vObNm6fnnntO1157raPt/Pnz9eGHH2rSpEn65JNPFBQUJEnasmWL7rvvPt1www267LLL2j22goIC/eMf/9CwYcM0evTodgdft9xyS6vjAQAAHffCCy9oyJAhqqmp0erVqzV37lzl5+dry5YtCgsLc7QjpmqJmArwYyYAtGHDhg2mJPPSSy81JZlTpkxp0eabb74xw8LCzGHDhpl79uxpsb++vt7Mzc11vJ80aZIZFhZmab9vvvlmMzQ01KNjHnnkEaexvvrqqy3arFy50pRkvvHGGy327d692xw2bJjZo0cPs7Cw0GlfXl6eaRiG+Yc//ME0TdM8cOCAedppp5nx8fEuv2bu1NXVOf79xhtvmJLMlStXuj3mzTffNI855hjzxRdfbLX/AADAMy+88IIpydywYYPT9nvvvdeUZL7yyiuObcRUzoipAPD4HoA2LVq0SFLDlOhRo0bp9ddf1/79+53aPPbYY6qurtZTTz2liIiIFucwDENXXXVVp/Tn559/1uzZs5WYmKjg4GAdf/zxuuWWW7Rnzx6nz/e3v/1NNTU1jinhixcvbvPczz//vKKjo/Xiiy8qNDTUcTezvY477jgtXLhQhw4d0rx585z2XXTRRZo6daoeeughbdy4UXPmzNHnn3+uRYsWufyauRMQ4NmP759++km33HKLHnzwQQ0YMMCjYwEAgOdGjhwpSU6PoBFTtR8xFeAfSEoBcKumpkavvfaazjzzTCUlJemmm27S3r179cYbbzi1e//99xUdHe0IwNrr0KFDTq+6ujq37U3T1BVXXKFHH31UEydO1LJly5SVlaUXX3xRv/zlL1VbWytJWrdunX71q18pNDRU69at07p163TppZe6PffatWv15Zdf6vrrr1efPn2Ulpamjz76SEVFRR6N6cwzz1RsbKxWr17dYt8jjzyiAQMG6Oqrr1Z2dramTp2qMWPGeHT+jrj11luVmJjYak0HAADQuf773/9Kkvr27SuJmIqYCoArJKUAuPXmm2+qsrJSkydPliRlZmbqmGOOcdzpa7Rz504lJiZ6dO7q6moFBQU5vc4//3y3x7z//vt677339NBDD+mBBx7QmDFjdMcdd+j555/Xpk2b9NJLL0lquDvZt29fBQQEaOTIkY737jSO6aabbpIkTZ48WaZp6oUXXvBoXJI0YMAAff/99y22h4WF6U9/+pN27Nihvn376pFHHvH43J5atmyZcnJy9Nxzz3l8NxAAALRPXV2dDh06pH379mnZsmX605/+pN69e+vyyy+XRExFTAXAFf4nAXBr0aJFCg0N1YQJEyRJxxxzjNLT0/Xxxx9r27ZtR3Xu0NBQbdiwwenVPDBrrrGI5w033OC0PT09XWFhYfrwww871Jd9+/YpJydHo0aNchQFPf/883XiiSdq8eLFqq+v9+h8pmm63F5fX68nnnhCAQEB2rVrlz7//PMO9be9Kisr9dvf/lYzZ85sc5UfAADQcSNHjlRQUJB69+6t8ePHKyYmRu+++66io6MlEVMRUwFwhaQUgFb997//1erVq3XppZfKNE3t2bNHe/bs0dVXXy1JTrUBBgwY4PGU7ICAAKWkpDi9Bg8e7PaY3bt3q0ePHi3u0BmGoZiYGO3evdujPjRasmSJ9u3bp4yMDMc4KysrlZGRoeLiYuXl5Xl0vp07d6p///4ttj/66KNat26d/v73v+ukk07STTfdpJqamg71uT3uvvtuBQUFafr06Y5x7du3T5K0f/9+7dmzp9VgDwAAtN9LL72kDRs2aNOmTfr+++9VWFios88+WxIxFTEVgNaQlALQqueff16maerNN99UZGSk49VYR+DFF1901Cu4+OKL9cMPP2j9+vWW9qlPnz46dOiQfvzxR6ftpmmqrKxMUVFRHTpv493EGTNmOI117ty5Tvvb49NPP1VZWZkuuOACp+3//ve/9Yc//EHXX3+9MjMztXjxYv33v//V3Xff3aE+t8cXX3yhHTt2KCYmxjGmxmWSJ02apMjISFVWVlr2+QEA8Bcnn3yyUlJSdPrppys2NtZpHzEVMRUA10hKAXCprq5OL774ok488UStXLmyxeuOO+5QaWmp3n33XUnS7bffrrCwME2bNs3lL2TTNLV06dKj7tfo0aMlSa+88orT9tzcXFVXVzv2e+LLL7/UunXrlJaW5nKso0eP1ttvv92uO4Y//fSTpk6dqqCgIN1+++2O7YcOHdKkSZMUFRWlBQsWSGqY5p+VlaUFCxboX//6l8f9bo/58+e3GE/jCjZz5szRypUrdcwxx1jyuQEAADEVMRUAd3p0dQcAdE/vvvuuvv/+e2VnZ7e4OyVJSUlJevLJJ7Vo0SKNHz9eiYmJev3115WZmanTTz9d06dP17BhwyQ13M1qvEN45ZVXHlW/xowZo4svvlgzZ85UVVWVzj77bBUWFuq+++7TsGHDNHHiRI/P2XjH7q677tJZZ53VYv/evXv14Ycf6pVXXtFtt93m2L5t2zatX79e9fX12r17tz755BMtWrRIVVVVeumllzR06FBH27lz56qgoEDvvvuujj32WMf2P/7xj3rnnXd00003afPmzQoNDW1Xn/fv36/ly5dLkuNOan5+vsrLyxUWFqZx48ZJkk4//fRWzzF06FCX1xYAAHQeYqojiKkAtGACgAtXXHGFGRwcbO7atavVNhMmTDB79OhhlpWVObZt377dnDZtmvmLX/zCDAkJMUNDQ81TTjnFzMrKMouKihztJk2aZIaFhXWobzU1NebMmTPNhIQEMygoyIyNjTV/97vfmRUVFU7t2vM5Dhw4YPbr1888/fTTW21z6NAhMy4uzjz11FNN0zTNlStXmpIcrx49eph9+vQxU1NTzf/93/81d+zY4XT85s2bzaCgIHPKlCkuz79u3TozICDAvP3229sx+gZFRUVOfWj6SkhIcHtsY//feOONdn8+AADg2gsvvGBKMjds2OByPzHVEcRUAJozTJNqbAAAAAAAALAXNaUAAAAAAABgO2pKAUA3UldX53Y5YcMwFBgYaGOPAAAAvA8xFeAdmCkFAN3I6NGjFRQU1OrrxBNP7OouAgAAdHvEVIB3sDQptXr1al122WXq37+/DMPQP/7xjza
|
|||
|
|
"text/plain": [
|
|||
|
|
"<Figure size 1200x500 with 2 Axes>"
|
|||
|
|
]
|
|||
|
|
},
|
|||
|
|
"metadata": {},
|
|||
|
|
"output_type": "display_data"
|
|||
|
|
},
|
|||
|
|
{
|
|||
|
|
"data": {
|
|||
|
|
"image/png": "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
|
|||
|
|
"text/plain": [
|
|||
|
|
"<Figure size 1200x500 with 2 Axes>"
|
|||
|
|
]
|
|||
|
|
},
|
|||
|
|
"metadata": {},
|
|||
|
|
"output_type": "display_data"
|
|||
|
|
},
|
|||
|
|
{
|
|||
|
|
"data": {
|
|||
|
|
"image/png": "iVBORw0KGgoAAAANSUhEUgAABKUAAAHqCAYAAADVi/1VAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjguMCwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy81sbWrAAAACXBIWXMAAA9hAAAPYQGoP6dpAABfy0lEQVR4nO3df1yV9f3/8ecFCCIFQ1HAIGAtNUPKPOWPfmdaLtePmeBn5adauTnnltFuqdtaZp/N0VZpP5ebZb8+iY35bVtm0UrNj1phGv10zjChIMMIDBEV3t8/jCNHDkcOcl3n1+N+u53b4VzX+3qf95vrAC9e1/t6vy1jjBEAAAAAAADgoKhANwAAAAAAAACRh6QUAAAAAAAAHEdSCgAAAAAAAI4jKQUAAAAAAADHkZQCAAAAAACA40hKAQAAAAAAwHEkpQAAAAAAAOA4klIAAAAAAABwHEkpAAAAAAAAOI6kFBBh7r//flmWpdzcXJ/lPv74Y82cOVODBg1SfHy8+vTpo1NPPVW//vWv9emnn7rLXX/99bIsy+vjn//8Z4+0ef/+/Zo+fbrS09MVHR2t008/vdOyR7YnLi5OgwcP1h133KF9+/a5y82bN8+jXGxsrHJycnTzzTfrq6++6lDvxo0bNXnyZKWnpys2NlZpaWm6+uqrtWHDhm716cknn9SUKVM0ePBgRUVFKTs722u5V199VT/84Q81ZMgQJSQk6IQTTtAVV1yhTZs2+f2e/tZ14MAB3XvvvRo2bJji4+P1rW99S2PGjNH69ev9fm8AAILd0qVLPWKDmJgYZWRk6IYbbvCIfdoQUx1CTEVMBRyLmEA3AICzHnvsMUnS+++/rzfeeEMjR47sUOaf//ynpkyZopSUFM2cOVPDhw+XZVl699139dhjj+mFF17Q5s2b3eXj4+P16quvdqhnyJAhPdLmRx55RI8++qgeeOABjRgxQscdd5zP8u3bU1dXp2effVbz58/XRx99pOLiYo+yq1atUlJSkvbs2aOVK1dq0aJFevPNN7V+/XpZliVJeuCBBzRr1iydddZZuvvuu5WVlaWdO3fqoYce0jnnnKNFixZp5syZfvXpqaeeUk1Njc466yy1trbqwIEDnfZ99+7duvnmmzV06FB98cUXuueeezRq1Ci99NJLuuiii7r8nv7U1dLSoquuukrr1q3TbbfdpjFjxqixsVGbNm1SY2OjX30FACCUPP744xoyZIiampq0du1aLViwQGvWrNG7776rhIQEdzliKmIqYiqgBxgAEeOtt94yksxll11mJJlp06Z1KPPxxx+bhIQEM3z4cPPVV1912N/a2mpKSkrcr6+77jqTkJBga7tvuukmEx8f36WynbXn3HPPNZJMVVWVMcaYO+64w0gyX3zxhUe5qVOnGklm3bp1xhhj1q1bZ6KioszEiRPNgQMHPMoeOHDATJw40URFRbnLd1VLS4v768suu8xkZWV5Lff555932LZnzx6Tmppqxo4d69d7+lPXfffdZ6KiosyGDRv8eg8AAELV448/biSZt956y2P77bffbiSZp59+2r2NmIqYqqt1EVMBvnH7HhBBlixZIkn6/e9/rzFjxmjZsmXau3evR5l7771XjY2Nevjhh5WUlNShDsuy9P3vf79H2rNv3z7NnTtXOTk5io2N1QknnKCf/vSnHkO9LcvSX/7yFzU1NbmHhS9dutTv9xo1apQk6ZNPPvGr3IIFC2RZlh555BHFxHgOLo2JidHDDz8sy7L0+9//3q/2REV17dfvgAEDOmw77rjjNHToUFVWVvr1nv7UtWjRIp133nnu7wcAAJHKWwxBTEVM1dW6iKkA30hKARGiqalJzz77rM4880zl5ubqhz/8ofbs2aPnnnvOo9zLL7+s1NRUv/9wHjx40OPR0tLis7wxRldeeaX++Mc/aurUqXrhhRdUWFioJ554QhdddJGam5slSRs2bNB3v/tdxcfHa8OGDdqwYYMuu+wy/zov6T//+Y8kqX///l0u19LSotdee00ul0sZGRley2dmZmrEiBF69dVXj9rnnlJfX6+3335bp556qi11VVZWaseOHRo2bJh++ctfKjU1VTExMTr11FP1xBNPHPN7AgAQSo6MIYipiKm6WhcxFdAFgR6qBcAZTz75pJFk/vSnPxljDg0xPu6448y5557rUa53795m1KhRXa73uuuuM5I6PM4++2yfx61atcpIMnfffbfH9uLiYiPJLF682OM9ujqcva3sgQMHzIEDB8wXX3xhFi1aZCzLMmeeeaa7XNtQ85qaGnPgwAFTV1dnnn76aRMfH28yMzNNU1OTqampMZLMlClTfL5nQUGBkeR1KHdX+Bpq7s0111xjYmJiTFlZWbfe72h1bdiwwUgyiYmJZujQoWb58uXmpZdeMldffXWHcwMAQLhou31v48aN5sCBA2bPnj3mn//8p+nfv785/vjjTU1NjTGGmIqYqut1EVMBR8dE50CEWLJkieLj4zVlyhRJh4YYT548WY8//ri2bdumk08+udt1x8fHa+3atR7bjj/+eJ/HtE2aef3113tsnzx5sn74wx/qX//6l6ZNm9at9jQ2NqpXr17u15ZlacKECVq8eHGHsmlpaR6vzz77bC1evFi9e/dWfX19l97PGON+H7vdfvvteuaZZ9wTlNpRV2trq6RDtwKsXLlSWVlZkqRx48bJ5XJp/vz53T43AAAEuyNHNg0bNkyPPPKIUlNTJRFTEVN1vS5iKuDoSEoBEeA///mP1q5dq0mTJskY455f4Oqrr9bjjz+uxx57TAsWLJAknXjiiaqoqPCr/qioKLlcLr+O2b17t2JiYjoM/bYsS2lpadq9e7df9bXXPqCLi4tTVlaWEhMTvZZ95ZVXlJSUpF69eikjI0P9+vVz70tJSVGfPn2O+v3YsWOH+vTpo759+3a7zV1x55136n/+53/029/+1u+Vafypq+17MGTIEHfwJB06N5dccokWLFigXbt2eZ1PAQCAUPfkk0/qlFNOUUxMjFJTU5Wenu7eR0xFTOVPXcRUwNExpxQQAR577DEZY/TXv/5VycnJ7kfbPAJPPPGE+979Sy65RJ9//rk2btxoa5v69eungwcP6osvvvDYboxRTU2NUlJSul13W0Dncrk0bNiwToMnSTrttNPkcrl02mmneQRPkhQdHa0LL7xQZWVlqqqq8np8VVWVNm3apIsuukjR0dHdbvPR3HnnnZo3b57mzZunX/7yl7bWddJJJ6lPnz5ej227gtnVSUUBAAg1p5xyilwul04//XSPhJRETEVM5V9dxFTA0fETAIS5lpYWPfHEEzrppJP02muvdXjceuutqq6u1osvvihJuuWWW5SQkKAZM2Z4HWptjNGKFSuOuV1jx46VJD399NMe20tKStTY2OjeH2hz586VMUYzZszoMOlmS0uLfvKTn8gYo7lz59rWhrvuukvz5s3Tr3/9a91xxx221xUTE6MrrrhCH374oXbs2OHebozRqlWrdNJJJx1TgAsAQCgipjo2xFQ73NuJqYDDuH0PCHMvvviiPvvsMxUVFemCCy7osD83N1cPPviglixZookTJyonJ0fLli1TQUGBTj/9dM2cOVPDhw+XJH3wwQfuK4RXXXXVMbVr3LhxuuSSSzR79mw1NDTo7LPPVnl5ue644w4NHz5cU6dOPab6e8rZZ5+thQsXatasWTrnnHM0c+ZMnXjiidq5c6ceeughvfHGG1q4cKHGjBnjV70ffPCBPvjgA0lSTU2N9u7dq7/+9a+SpKFDh2ro0KGSpHvuuUe/+c1vdOmll+qyyy7rcLXVnxV9/Knrrrvu0osvvqhLL71U8+bNU2Jiov7yl7/onXfe0fLly/3qKwAA4YCY6tgQUxFTAV45O686AKddeeWVJjY21uzatavTMlOmTDExMTHuVWWMMWb79u1mxowZ5jvf+Y6Ji4sz8fHxZujQoaawsNBUVFS4y/mzisuRmpqazOzZs01WVpbp1auXSU9PNz/5yU9MXV2dR7nurBRzNG0rxXzxxRddqnfDhg3m6quvNqmpqSYmJsYMGDDAfP/73zf
|
|||
|
|
"text/plain": [
|
|||
|
|
"<Figure size 1200x500 with 2 Axes>"
|
|||
|
|
]
|
|||
|
|
},
|
|||
|
|
"metadata": {},
|
|||
|
|
"output_type": "display_data"
|
|||
|
|
},
|
|||
|
|
{
|
|||
|
|
"data": {
|
|||
|
|
"image/png": "iVBORw0KGgoAAAANSUhEUgAABKUAAAHqCAYAAADVi/1VAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjguMCwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy81sbWrAAAACXBIWXMAAA9hAAAPYQGoP6dpAABYMklEQVR4nO3dfVxUZf7/8ffhViSZUBRQCKlNrYgyKcXuMynLbl3RbfNbrbnbWlum/VK+W9vNfjejdk2rtXLXMrtTi9za1SzbFHPVEtMot1zXMLEgoxAUCRWu3x/GyMhwM8g5DDOv5+MxD5xzrjlzXRzEj++5znUsY4wRAAAAAAAA4KCQju4AAAAAAAAAgg+hFAAAAAAAABxHKAUAAAAAAADHEUoBAAAAAADAcYRSAAAAAAAAcByhFAAAAAAAABxHKAUAAAAAAADHEUoBAAAAAADAcYRSAAAAAAAAcByhFIBmPf7447IsS2lpac22++KLL3TbbbepX79+ioqKUteuXXXKKafonnvu0VdffeVud+ONN8qyLK+Pf/zjH+3S5/379+uWW25RYmKiQkNDdfrpp7f4mr///e+64oorFB8fr4iICHXv3l3Dhg3TSy+9pAMHDrjb1ff1xhtv9HqcBx980N1m+/btHvuMMXr55Zd10UUXKTY2VpGRkTr++ON16623qri4uE1jveeeezRy5Ej16dOn2X4d6frrr5dlWRo5cmSb3hcAgGA3b948jzomLCxMSUlJuummmzxqn3rUVNRUABoL6+gOAPBvzz77rCRp8+bN+uCDDzR48OBGbf7xj39o7NixiouL02233aaBAwfKsix98sknevbZZ7VkyRJt3LjR3T4qKkrvvfdeo+MMGDCgXfr81FNP6ZlnntETTzyhQYMG6ZhjjmmyrTFGv/jFLzRv3jxddtllmjFjhpKTk1VRUaEVK1Zo4sSJKisr0x133OF+Tbdu3fTqq6/qiSeeULdu3TyONW/ePMXExKiystLjferq6nTddddp4cKF+tnPfqZ58+bJ5XKpsLBQjz76qF5++WX94x//0Nlnn+3TWB977DGlp6fryiuvdJ+rlixZskR/+9vfFBMT49N7AQCAxp577jkNGDBA1dXVWrVqlaZPn678/Hx98sknio6OdrejpqKmAuCFAYAmrF+/3kgyl19+uZFkJkyY0KjNF198YaKjo83AgQPN7t27G+2vq6szeXl57uc33HCDiY6OtrXfN998s4mKimpV29zcXCPJPPDAA173l5SUmPfff9/9XJK5/vrrTVRUlJkzZ45H23fffdf9fZJkioqK3PseeughI8k8/PDDjd6jtLTUpKSkmPj4eFNeXt6qfterra11/zk6OtrccMMNzbbfvXu36dOnj5kxY4ZJSUkxl19+uU/vBwAADnnuueeMJLN+/XqP7ffee6+RZF588UX3NmoqaioA3nH5HoAmzZ07V5L08MMPa+jQoVqwYIH27dvn0WbGjBmqqqrS7Nmz5XK5Gh3Dsixde+217dKfH374QTk5OUpNTVVERIT69OmjW2+9Vbt37/Z4v7/+9a+qrq52T/meN2+e1+MdOHBAubm5GjBggO69916vbRISEnTOOed4bHO5XLrmmmsafYr27LPP6uyzz1a/fv08tu/fv1+PPvqoTjrpJN19992N3iM+Pl7Tp0/XN9984/6et1ZIiG+/xqdMmaLExETdfvvtPr0OAAC0zpAhQyRJX375pXsbNRU1FQDvCKUAeFVdXa1XXnlFZ555ptLS0vSLX/xCe/bs0auvvurR7p133lF8fLy7AGutgwcPejxqa2ubbW+M0dVXX60//vGPGjdunJYsWaLJkyfr+eef10UXXaSamhpJ0tq1a3XZZZcpKipKa9eu1dq1a3X55Zd7PWZBQYG+//57XXXVVbIsy6f+jx8/XuvWrdNnn30mSdq9e7def/11jR8/vlHbDRs2qLy8XFdeeWWT73PFFVcoJCREy5cv96kfvnj33Xc1f/58/fWvf1VoaKht7wMAQDD773//K0nq2bOnJGqqllBTAcGNUAqAV6+99poqKircBcGYMWN0zDHHNPrUaceOHUpNTfXp2FVVVQoPD/d4nH/++c2+5p133tHbb7+thx56SA8++KCGDx+uKVOm6Nlnn9XGjRs1f/58SYc+nezZs6dCQkI0ZMgQ93NvduzYIUk+91+SLrzwQqWmpro/2Xv55ZcVFham0aNHt+l9jjnmGPXs2dPdtr3t3btXEyZM0F133aXTTjvNlvcAACAY1dbW6uDBg9q7d6+WLFmi//u//1O3bt105ZVXSqKmagk1FRDcCKUAeDV37lxFRUVp7Nixkg79Az969Gi9//772rp161EdOyoqSuvXr/d4tDTFun4RzyPvhDJ69GhFR0frn//851H1yVf1d2V54YUXdPDgQc2dO1fZ2dnNLgDaEmOMz58utta0adMUHh6u3/3ud7YcHwCAYDVkyBCFh4erW7duGjlypBISEvTWW28pPj5eEjVVS6ipgOBGKAWgkf/+979atWqVLr/8chljtHv3bu3evVs//elPJcnjuv/jjjtORUVFPh0/JCREGRkZHo/+/fs3+5rvvvtOYWFhjT6hsyxLCQkJ+u6773zqQ33fJfnc/3o33XSTvv32Wz300EP66KOPvE4zb+37VFVVqaysTMnJyW3qS3M+/PBDzZ49W4888oh++OEH9/msq6vTwYMHtXv3bvdUfQAA4Jv58+dr/fr12rhxo77++msVFha67/xGTdU61FRA8CKUAtDIs88+K2OMXnvtNcXGxrof9esIPP/88+71Ci655BJ98803Wrduna196tGjhw4ePKhvv/3WY7sxRqWlpYqLi/P5mBkZGerevbveeOMNGWN8fn1ycrIuvvhiPfDAA+rfv7+GDh3qtd2gQYMUGxurN998s8n3efPNN1VXV6fhw4f73I+W/Pvf/5YxRtdcc43H+SwuLtbbb7+t2NhYPfXUU+3+vgAABIOTTjpJGRkZOv3005WYmOixj5qqdaipgOBFKAXAQ21trZ5//nmdcMIJWrFiRaPHlClTVFJSorfeekuSdOeddyo6OloTJ05URUVFo+MZY7R48eKj7tewYcMkSS+++KLH9ry8PFVVVbn3+yI8PFxTp07V559/rt///vde2+zatUv/+te/mjzGlClTdMUVVzR5pxlJioiI0P/7f/9Pn332mR599FGv75GTk6P4+HjdfPPNPo+jJZdeeqnXc1m/mOqKFSvcn9gCAID2QU3liZoKgDdhHd0BAP7lrbfe0tdff63c3FxdcMEFjfanpaXpySef1Ny5czVy5EilpqZqwYIFGjNmjE4//XTddtttGjhwoKRDnybVf0J4zTXXHFW/hg8frksuuURTp05VZWWlzj77bBUWFuq+++7TwIEDNW7cuDYdt76wue+++/Thhx/quuuuU3JysioqKrRq1SrNmTNHDzzwgHsa/pGysrKUlZXV4vtMnTpVH3/8sfvrmDFj5HK5VFhYqEcffVR79uzRP/7xD6+3gG5Ofn6++5PO2tpaffnll3rttdckSeeff7569uyphIQEJSQkNHptly5d1KNHD6/nGQAAHB1qKmoqAK1gAKCBq6++2kRERJhdu3Y12Wbs2LEmLCzMlJaWurdt27bNTJw40fzkJz8xkZGRJioqypx88slm8uTJpqioyN3uhhtuMNHR0W3qW3V1tZk6dapJSUkx4eHhJjEx0fz617825eXlHu3a8h5vvPGGufzyy03Pnj1NWFiYiY2NNRdeeKF5+umnTU1NjbudJHPrrbc2e6xHH33USPIYtzHG1NXVmZdeeslccMEF5thjjzUREREmNTXV/PrXvzZffvmlT/2td/755xtJXh8rVqxo9rUpKSnm8ssvb9P7AgAQ7J577jkjyaxfv97rfmoqaioALbOMacNFvwAAAAAAAMBRYE0pAAAAAAAAOI41pQDAzxhj3HfiaUpoaKgsy3KoRwAAAJ0PNRXg/5gpBQB+5vnnn1d4eHizj/z8/I7uJgAAgF+jpgL8n62h1KpVq3TFFVeod+/esixLf/vb31p8TX5+vgY
|
|||
|
|
"text/plain": [
|
|||
|
|
"<Figure size 1200x500 with 2 Axes>"
|
|||
|
|
]
|
|||
|
|
},
|
|||
|
|
"metadata": {},
|
|||
|
|
"output_type": "display_data"
|
|||
|
|
},
|
|||
|
|
{
|
|||
|
|
"data": {
|
|||
|
|
"image/png": "iVBORw0KGgoAAAANSUhEUgAABKUAAAHqCAYAAADVi/1VAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjguMCwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy81sbWrAAAACXBIWXMAAA9hAAAPYQGoP6dpAABaRElEQVR4nO3de1yUZf7/8fcNCCIJoShoELCVh0TKJBUrO5iYZduB9bBtbrnm5ra1GfVN/e62nb6tUbumHSzbtezooSV/bZtZuKuoqSWmUVaua5hQkFEIRgQK1+8PY3RkQAa574GZ1/PxmIfOfV9zzXXNzeHDe+65bssYYwQAAAAAAAA4KMjXAwAAAAAAAEDgIZQCAAAAAACA4wilAAAAAAAA4DhCKQAAAAAAADiOUAoAAAAAAACOI5QCAAAAAACA4wilAAAAAAAA4DhCKQAAAAAAADiOUAoAAAAAAACOI5QC2rFHH31UlmUpJSWl2XafffaZbr75ZvXp00fh4eHq0qWLBgwYoD/84Q/64osvXO2uv/56WZbl8fbPf/6zTcZcW1uradOmqVevXgoODtaZZ555zMe8/vrruvzyyxUbG6vQ0FB169ZNI0eO1EsvvaQDBw5Iknbv3i3LsvTnP/+5TcYpSWvWrJFlWVqzZo1r2/XXX68TTjjhmI+94IILdMEFF3j9nIMGDdJJJ52kurq6Jtucc845iomJUW1tbYv69DSPY6mqqtLEiRPVt29fde3aVRERERowYID+7//+T1VVVS3up8HcuXN19dVXKzk5WZZlNfva7N27V9dff71iYmLUpUsXpaen61//+pfXzwkACFyLFi1yq2NCQkIUHx+vyZMnu9U+DaipqKlagpoKcF6IrwcAoGnPPPOMJGn79u169913NXTo0EZt/vnPf2rixImKiYnRzTffrEGDBsmyLH344Yd65pln9MYbb2jr1q2u9uHh4fr3v//dqJ9+/fq1yZiffPJJLViwQI899pgGDx7cbDFijNGvfvUrLVq0SJdeeqnmzJmjhIQEVVRUaPXq1brppptUVlamW2+9tU3GdrSzzjpLGzdu1Omnn+71Y+fPn9+q55wyZYpuueUWvfXWW7r00ksb7f/Pf/6jDRs2aPr06QoNDW3Vc7TEgQMHZIxRVlaWkpOTFRQUpLVr1+q+++7TmjVrtGrVKq/6e+qppxQREaGLLrpIr7/+epPtampqNHLkSO3bt0/z5s1Tz5499cQTT+iSSy7RqlWrdP755x/v1AAAAeTZZ59Vv379VF1drbVr12r27NnKy8vThx9+qIiICFc7aipqKrtQUwHHyQBolzZv3mwkmcsuu8xIMlOnTm3U5rPPPjMRERFm0KBBZt++fY3219fXm5ycHNf96667zkRERNg67htuuMGEh4e3qG12draRZO69916P+0tKSsy6deuMMcYUFhYaSebhhx9us7F6Yvdr9O2335rOnTubzMxMj/tnzJhhJJmCgoIW97l69Wojyaxevfq4x3fnnXcaSWbXrl1ePa6urs71/wEDBpjzzz/fY7snnnjCSDIbNmxwbTtw4IA5/fTTzZAhQ1o1ZgBA4Hn22WeNJLN582a37XfddZeRZF588UXXNmoqaqqWoqYCnMfH94B2auHChZKkBx98UMOHD9eSJUv0/fffu7WZM2eOqqqqNH/+fEVFRTXqw7IsXX311W0ynh9++EGzZs1ScnKyQkNDddJJJ+m3v/2t9u3b5/Z8f/vb31RdXe06hX3RokUe+ztw4ICys7PVr18/3XXXXR7bxMXF6dxzz220fc6cOUpOTtYJJ5yg9PR0bdq0yW1/fn6+Jk6cqKSkJIWHhyspKUk///nP9fnnn7u1a+kp2u+8845iYmI0duxY12nYR59qfuSp8M2NLzo6WldddZVef/11ffPNN27PU1dXpxdeeEFnn322Bg4cKElav369Ro4cqa5du6pLly4aPny43njjjWbHezx69OghSQoJ8e5E2qCglv06Wb58ufr27av09HTXtpCQEF177bV67733PH7kAgCAlho2bJgkuf3Op6aippKoqYD2ilAKaIeqq6u1ePFinX322UpJSdGvfvUr7d+/X6+88opbu7fffluxsbGuAqylDh486HZr7rP40qFTwq+88kr9+c9/1qRJk/TGG28oKytLzz33nC666CLV1NRIkjZu3KhLL71U4eHh2rhxozZu3KjLLrvMY5/5+fn69ttvdcUVV8iyrBaP/YknnlBubq7mzp2rl156SVVVVbr00ktVUVHharN792717dtXc+fO1VtvvaXs7GyVlJTo7LPPVllZWYufS5KWLVumkSNHavz48XrttdfcPgrQ2vFNmTJFtbW1evHFF90e+9Zbb+nLL7/UlClTJEl5eXm66KKLVFFRoYULF2rx4sXq2rWrLr/8ci1dutSreTTFGKODBw+qsrJSK1eu1F/+8hf9/Oc/18knn9wm/R/to48+UmpqaqPtDdu2b99uy/MCAALDf//7X0mHAwFqqqZRU1FTAe2Cb0/UAuDJ888/bySZp556yhhjzP79+80JJ5xgzjvvPLd2nTt3NsOGDWtxv9ddd52R1Oh2zjnnNPu4lStXGknmoYcectu+dOlSI8k8/fTTbs/RklO1lyxZ4jbHY2k41XzgwIHm4MGDru3vvfeekWQWL17c5GMPHjxovvvuOxMREWHmzZvn2u7pFO0jx//ggw+a4OBgk52d3ajP888/3+10am/GV19fb5KTk01qaqpbn5mZmaZLly6moqLCGGPMsGHDTM+ePc3+/fvd5pKSkmLi4+NNfX19k/NoqcWLF7t9LUyePNkcOHDA636O1Nyp5p06dTI33nhjo+0bNmwwkszLL798XM8NAAgMDR/f27Rpkzlw4IDZv3+/+ec//2l69OhhunbtakpLS40x1FSeUFMdngs1FeB7nCkFtEMLFy5UeHi4Jk6cKEk64YQTNG7cOK1bt047d+48rr7Dw8O1efNmt1vDae1NaVjE8/rrr3fbPm7cOEVERDh6lY/LLrtMwcHBrvsN7wYdeRr5d999pxkzZujUU09VSEiIQkJCdMIJJ6iqqkqffPLJMZ/DGKMbb7xRd999t15++WXdeeedbTo+y7I0efJkFRQUaMuWLZKkb775Rq+//royMzMVGRmpqqoqvfvuu/rZz37mtrBpcHCwJk2apOLiYu3YsaPF42rK6NGjtXnzZv373//WAw88oJycHGVmZqq+vv64+25Kc+/ievMOLwAAw4YNU6dOndS1a1eNHTtWcXFxevPNNxUbGyuJmqo51FTUVEB7wNX3gHbmv//9r9auXavMzEwZY1zrC/zsZz/Ts88+q2eeeUazZ8+WJJ188skqLCz0qv+goCClpaV59ZhvvvlGISEhrlPhG1iWpbi4uEaf42+JhlOZvR1/9+7d3e6HhYVJOnR6foNrrrlG//rXv3TXXXfp7LPPVmRkpCzL0qWXXurWrim1tbVaunSpBgwYoDFjxrT5+CRp8uTJuueee/Tss89q8ODBeumll1RbW+s6zby8vFzGGPXq1avRc/Tu3VuSWvW6Hy06Otr19XDhhRfqlFNO0cSJE/Xaa6/pqquuOu7+j9a9e3eP4/72228lSd26dWvz5wQA+K/nn39e/fv3V0hIiGJjY91+b1JTNY+aipoKaA84UwpoZ5555hkZY/T3v/9d0dHRrlvDOgLPPfeca72C0aNH66uvvmq0KGVb6969uw4ePKivv/7abbsxRqWlpYqJifG6z7S0NHXr1k2vvfaajDFtNVRVVFTon//8p+68807NnDlTI0eOdC1y2fBL+ljCwsK0evVqFRUV6eKLL1Z5eXmbja9BfHy8MjIy9PLLL6umpkbPPvusTj31VI0YMULSocImKChIJSUljR775ZdfSlKrXvdjGTJkiKRDl1G2w8CBA/Xhhx822t6wLSUlxZbnBQD4p/79+ystLU1nnnlmo9CBmur4UFMdH2oqoGUIpYB2pK6uTs8995xOOeUUrV69utHt9ttvV0lJid58801J0m233aaIiAjddNNNbos+NjDGaPny5cc9rpEjR0pSo0Ukc3J
|
|||
|
|
"text/plain": [
|
|||
|
|
"<Figure size 1200x500 with 2 Axes>"
|
|||
|
|
]
|
|||
|
|
},
|
|||
|
|
"metadata": {},
|
|||
|
|
"output_type": "display_data"
|
|||
|
|
},
|
|||
|
|
{
|
|||
|
|
"data": {
|
|||
|
|
"image/png": "iVBORw0KGgoAAAANSUhEUgAABKUAAAHqCAYAAADVi/1VAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjguMCwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy81sbWrAAAACXBIWXMAAA9hAAAPYQGoP6dpAABeLklEQVR4nO3de1yUdd7/8fdwRhNSUcAkpDZPoabiAe1gmZhppzUPW5mW2e2alVm/zLtts7rvde0us8N22jTtqJWZ7Wombh5y1RLTtDLXEgULPAuKCArX7w+akWEGmAu5Lobh9Xw85oFzXd+55ntxzeBn3vO9vpfDMAxDAAAAAAAAgI2C6roDAAAAAAAAaHgIpQAAAAAAAGA7QikAAAAAAADYjlAKAAAAAAAAtiOUAgAAAAAAgO0IpQAAAAAAAGA7QikAAAAAAADYjlAKAAAAAAAAtiOUAgAAAAAAgO0IpQA/9cILL8jhcCg5ObnKdrt27dLEiRPVtm1bRUZGqlGjRrr44ov1pz/9Sb/88our3ZgxY+RwOLze/vnPf9ZKn4uLizV+/HjFx8crODhYl1xySaVtx4wZo3POOcdj+caNGxUTE6O2bdtqz549Pj/33Llz5XA4tHv3btey9957T7NmzTKxB7Xvo48+ksPh0IIFCzzWdenSRQ6HQ59//rnHugsvvFDdunWTJK1atUoOh0OrVq2q9vnGjBmjNm3auO6fOHFC06ZN8/rYadOmyeFw6ODBgz7vT2U+/vhj/eEPf9Dvfvc7RUZGqk2bNrr11lu1c+dOr+1XrFih1NRUNWrUSDExMRozZoz2799/1v0AAAQ+5//5zltISIhat26tO+64w632caKmoqaipgL8V0hddwCAd3PmzJEkff/99/rqq6/Uq1cvjzb//Oc/NXLkSMXExGjixInq2rWrHA6Htm3bpjlz5mjJkiXavHmzq31kZKS++OILj+20b9++Vvr8yiuv6LXXXtOLL76o7t27ey2QqrJy5UrdcMMNuvDCC/X555+rZcuWZ9Wf9957T999950mTZp0Vts5G/369ZPD4dDKlSs1YsQI1/LDhw9r27Ztaty4sVauXKmBAwe61u3du1e7du3S5MmTJUndunXT+vXr1bFjR9PPf+LECT3xxBOuvlhlxowZiouL06OPPqoLLrhA2dnZ+stf/qJu3bppw4YNuvjii11tV69erUGDBmnw4MFavHix9u/frylTpqh///7KyMhQeHi4Zf0EAASON998U+3bt1dhYaHWrFmj6dOna/Xq1a7/X52oqaipqKkA/0UoBfihjIwMffvttxo8eLCWLFmi2bNnexRQmZmZGjlypNq2bauVK1cqOjrate6qq67Sfffdp0WLFrk9JigoSL1797as3999950iIyM1ceJE049dvHixRowYoR49euif//yn2/7UV4WFhWrevLmSk5M9vlVbvXq1QkJCNHbsWK1cudJtnfP+lVdeKUmKioqy9LjVhn/84x8eBe9VV12lNm3a6LnnntMbb7zhWv7//t//U9u2bfXRRx8pJKTsv6GkpCT17dtXc+bM0R//+Edb+w4AqJ+Sk5OVkpIiqez/zJKSEj311FP65JNPdOutt0qipqKmoqYC/B2n7wF+aPbs2ZKkv/71r+rTp4/mz5+vEydOuLWZOXOmCgoK9PLLL3stNhwOh37/+9/XSn9OnjypqVOnKikpSWFhYTrvvPN0zz336OjRo27P98Ybb6iwsNA1hH3u3Lk+bf/tt9/WzTffrKuuukrLly/32J8VK1aof//+ioqKUqNGjdS3b1/961//qnKb/fr105IlS7Rnzx63YfWStHv3bjkcDj3zzDOaOXOmkpKSdM455yg1NVUbNmzw2FZGRoauv/56NWvWTBEREeratas++OADtzbOoe7Lly/XnXfeqRYtWqhRo0YqKirSlVdeqR07dignJ8fVftWqVerRo4euvfZabdq0SceOHXNbFxwcrMsuu8x139tQ87lz56pdu3YKDw9Xhw4d9NZbb7mt3717t1q0aCFJeuKJJ1y/gzFjxri127dvn/7whz8oOjpasbGxuvPOO5WXl1fl77cib9/AtmrVSq1bt1Z2drZr2S+//KKNGzdq1KhRruJJkvr06aO2bdt6FP0AAPjKGTaUP1WNmoqaipoK8G+EUoCfKSws1Pvvv68ePXooOTlZd955p44dO6YPP/zQrd3y5csVGxtr+tue06dPu91KSkqqbG8Yhm688UY988wzGjVqlJYsWaLJkydr3rx5uuqqq1RUVCRJWr9+va699lpFRkZq/fr1Wr9+vQYPHlxtf1544QWNHj1aN998sxYvXqzIyEi39e+8847S0tIUFRWlefPm6YMPPlCzZs00cODAKouol19+WX379lVcXJyrP+vXr3dr87e//U3p6emaNWuW3n33XRUUFOjaa691Kx5Wrlypvn376ujRo3r11Ve1ePFiXXLJJRoxYoTXAvHOO+9UaGio3n77bX300UcKDQ11fTtXvgBauXKlrrjiCvXt21cOh0Nffvml27pu3bpV+c3m3Llzdccdd6hDhw5auHCh/vSnP+mpp55yO5UgPj5ey5YtkySNHTvW9Tt47LHH3LY1dOhQtW3bVgsXLtQjjzyi9957Tw888EClz+2rXbt2ac+ePW7DzL/77jtJUufOnT3ad+7c2bUeAACzfvrpJ0lyhQfUVNRU1FRAPWAA8CtvvfWWIcl49dVXDcMwjGPHjhnnnHOOcdlll7m1i4iIMHr37u3zdkePHm1I8rj17du3ysctW7bMkGQ8/fTTbssXLFhgSDJef/11t+do3Lix6f5ceumlRklJiUebgoICo1mzZsZ1113ntrykpMTo0qWL0bNnT9eyN99805BkZGZmupYNHjzYSExM9NhuZmamIcno1KmTcfr0adfyr7/+2pBkvP/++65l7du3N7p27WqcOnXKbRtDhgwx4uPjXf12Pv/tt9/u8XyHDx82goKCjLvvvtswDMM4ePCg4XA4jGXLlhmGYRg9e/Y0HnroIcMwDCMrK8uQZDz88MOux69cudKQZKxcudK1/61atTK6detmlJaWutrt3r3bCA0NddvnAwcOGJKMxx9/3KNfjz/+uNdjO2HCBCMiIsJt22adOnXK6NevnxEVFWVkZWW5lr/77ruGJGP9+vUej7n77ruNsLCwGj8nAKBhcP6fu2HDBuPUqVPGsWPHjH/+859GixYtjCZNmhi5ubmGYVBTlUdNVYaaCvA/jJQC/Mzs2bMVGRmpkSNHSpLOOeccDRs2TF9++WWlV93wVWRkpDZu3Oh2cw5rr4zzW6KKw5OHDRumxo0bVzvku7r+DBgwQP/+97/16quveqxft26dDh8+rNGjR7t9E1laWqprrrlGGzduVEFBQY2ff/DgwQoODnbdd37T5Bz2/9NPP+nHH390zUtRvg/XXnutcnJytGPHDrdtDh061ON5mjZtqi5duri+1Vu9erWCg4PVt29fSdIVV1zhmvOg4twH3uzYsUO//vqrbrnlFtfweUlKTExUnz59TP0OJOn66693u9+5c2edPHmyxlduMQxDY8eO1Zdffqm33npLCQkJHm3K99uX5QAAVNS7d2+FhoaqSZMmGjJkiOLi4vTZZ58pNjZWEjVVedRU3lFTAXWPic4BP/LTTz9pzZo1Gjp0qAzDcM0vcPPNN+vNN9/UnDlzNH36dEnS+eefr8zMTFPbDwoKck0I6qtDhw4pJCTENRTeyeFwKC4uTocOHTK1vYr9+fTTT3XDDTfonnvukWEYuueee1zr9+3bJ6ls/ytz+PBhtyvsmNG8eXO3+84rlBQWFro9/0MPPaSHHnrI6zYqXvo3Pj7ea7srr7xSM2fO1K+//qqVK1e6XUnniiuu0LPPPqu8vDytXLlSISEhuvTSSyvtt/N3HhcX57EuLi7O7RLOvqju92CGYRi666679M4772jevHm64YYbvD6Xt9fN4cOH1axZM9PPCQBomN566y116NBBISEhio2Ndfs/mJqKmoqaipoK9QOhFOBH5syZI8Mw9NFHH+mjjz7yWD9v3jz9z//8j4KDgzV
|
|||
|
|
"text/plain": [
|
|||
|
|
"<Figure size 1200x500 with 2 Axes>"
|
|||
|
|
]
|
|||
|
|
},
|
|||
|
|
"metadata": {},
|
|||
|
|
"output_type": "display_data"
|
|||
|
|
}
|
|||
|
|
],
|
|||
|
|
"source": [
|
|||
|
|
"import pandas as pd\n",
|
|||
|
|
"import matplotlib.pyplot as plt\n",
|
|||
|
|
"from statsmodels.graphics.tsaplots import plot_acf, plot_pacf\n",
|
|||
|
|
"import talib\n",
|
|||
|
|
"\n",
|
|||
|
|
"# Example: df contains columns ['Open', 'High', 'Low', 'Close', 'Volume']\n",
|
|||
|
|
"\n",
|
|||
|
|
"# Compute indicators using TA-Lib\n",
|
|||
|
|
"df['ADX_14'] = talib.ADX(df['High'], df['Low'], df['Close'], timeperiod=14)\n",
|
|||
|
|
"df['CCI_14'] = talib.CCI(df['High'], df['Low'], df['Close'], timeperiod=14)\n",
|
|||
|
|
"df['PPO_12_26'] = talib.PPO(df['Close'], fastperiod=12, slowperiod=26, matype=0)\n",
|
|||
|
|
"df['CMO_14'] = talib.CMO(df['Close'], timeperiod=14)\n",
|
|||
|
|
"df['ChaikinVol_3_10'] = talib.ADOSC(df['High'], df['Low'], df['Close'], df['Volume'], fastperiod=3, slowperiod=10)\n",
|
|||
|
|
"df['KeltnerWidth_20'] = (talib.EMA(df['High'] - df['Low'], timeperiod=20) / talib.EMA(df['Close'], timeperiod=20))\n",
|
|||
|
|
"\n",
|
|||
|
|
"# Select only indicator columns\n",
|
|||
|
|
"indicators = ['ADX_14', 'CCI_14', 'PPO_12_26', 'CMO_14', 'ChaikinVol_3_10', 'KeltnerWidth_20']\n",
|
|||
|
|
"\n",
|
|||
|
|
"# Loop through each indicator and plot ACF + PACF\n",
|
|||
|
|
"for ind in indicators:\n",
|
|||
|
|
" plt.figure(figsize=(12, 5))\n",
|
|||
|
|
"\n",
|
|||
|
|
" plt.subplot(1, 2, 1)\n",
|
|||
|
|
" plot_acf(df[ind].dropna(), lags=40, ax=plt.gca())\n",
|
|||
|
|
" plt.title(f'ACF of {ind}')\n",
|
|||
|
|
"\n",
|
|||
|
|
" plt.subplot(1, 2, 2)\n",
|
|||
|
|
" plot_pacf(df[ind].dropna(), lags=40, ax=plt.gca(), method='ywm')\n",
|
|||
|
|
" plt.title(f'PACF of {ind}')\n",
|
|||
|
|
"\n",
|
|||
|
|
" plt.tight_layout()\n",
|
|||
|
|
" plt.show()\n"
|
|||
|
|
]
|
|||
|
|
},
|
|||
|
|
{
|
|||
|
|
"cell_type": "code",
|
|||
|
|
"execution_count": 119,
|
|||
|
|
"metadata": {
|
|||
|
|
"colab": {
|
|||
|
|
"base_uri": "https://localhost:8080/",
|
|||
|
|
"height": 444
|
|||
|
|
},
|
|||
|
|
"id": "kR6NuS-VxeuX",
|
|||
|
|
"outputId": "c58ceb4c-4b02-45b2-a2d2-adfb8bddd8eb"
|
|||
|
|
},
|
|||
|
|
"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>Open</th>\n",
|
|||
|
|
" <th>High</th>\n",
|
|||
|
|
" <th>Low</th>\n",
|
|||
|
|
" <th>Close</th>\n",
|
|||
|
|
" <th>Volume</th>\n",
|
|||
|
|
" <th>Session</th>\n",
|
|||
|
|
" <th>Quarter</th>\n",
|
|||
|
|
" <th>Month_sin</th>\n",
|
|||
|
|
" <th>Hour_sin</th>\n",
|
|||
|
|
" <th>Date_sin</th>\n",
|
|||
|
|
" <th>...</th>\n",
|
|||
|
|
" <th>Diff_10Y_2Y</th>\n",
|
|||
|
|
" <th>Oil_Volume</th>\n",
|
|||
|
|
" <th>Oil_Close</th>\n",
|
|||
|
|
" <th>Gold_Close</th>\n",
|
|||
|
|
" <th>ADX_14</th>\n",
|
|||
|
|
" <th>CCI_14</th>\n",
|
|||
|
|
" <th>PPO_12_26</th>\n",
|
|||
|
|
" <th>CMO_14</th>\n",
|
|||
|
|
" <th>ChaikinVol_3_10</th>\n",
|
|||
|
|
" <th>KeltnerWidth_20</th>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" </thead>\n",
|
|||
|
|
" <tbody>\n",
|
|||
|
|
" <tr>\n",
|
|||
|
|
" <th>0</th>\n",
|
|||
|
|
" <td>1.35790</td>\n",
|
|||
|
|
" <td>1.35810</td>\n",
|
|||
|
|
" <td>1.35390</td>\n",
|
|||
|
|
" <td>1.35470</td>\n",
|
|||
|
|
" <td>318.0</td>\n",
|
|||
|
|
" <td>1</td>\n",
|
|||
|
|
" <td>1</td>\n",
|
|||
|
|
" <td>0.5</td>\n",
|
|||
|
|
" <td>0.25882</td>\n",
|
|||
|
|
" <td>0.58779</td>\n",
|
|||
|
|
" <td>...</td>\n",
|
|||
|
|
" <td>0.047083</td>\n",
|
|||
|
|
" <td>2895.166667</td>\n",
|
|||
|
|
" <td>42.12</td>\n",
|
|||
|
|
" <td>435.60</td>\n",
|
|||
|
|
" <td>NaN</td>\n",
|
|||
|
|
" <td>NaN</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>1.35460</td>\n",
|
|||
|
|
" <td>1.35510</td>\n",
|
|||
|
|
" <td>1.35290</td>\n",
|
|||
|
|
" <td>1.35380</td>\n",
|
|||
|
|
" <td>338.0</td>\n",
|
|||
|
|
" <td>1</td>\n",
|
|||
|
|
" <td>1</td>\n",
|
|||
|
|
" <td>0.5</td>\n",
|
|||
|
|
" <td>0.50000</td>\n",
|
|||
|
|
" <td>0.58779</td>\n",
|
|||
|
|
" <td>...</td>\n",
|
|||
|
|
" <td>0.047083</td>\n",
|
|||
|
|
" <td>2895.166667</td>\n",
|
|||
|
|
" <td>42.12</td>\n",
|
|||
|
|
" <td>435.50</td>\n",
|
|||
|
|
" <td>NaN</td>\n",
|
|||
|
|
" <td>NaN</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>1.35390</td>\n",
|
|||
|
|
" <td>1.35390</td>\n",
|
|||
|
|
" <td>1.34980</td>\n",
|
|||
|
|
" <td>1.35040</td>\n",
|
|||
|
|
" <td>356.0</td>\n",
|
|||
|
|
" <td>1</td>\n",
|
|||
|
|
" <td>1</td>\n",
|
|||
|
|
" <td>0.5</td>\n",
|
|||
|
|
" <td>0.70711</td>\n",
|
|||
|
|
" <td>0.58779</td>\n",
|
|||
|
|
" <td>...</td>\n",
|
|||
|
|
" <td>0.047083</td>\n",
|
|||
|
|
" <td>2895.166667</td>\n",
|
|||
|
|
" <td>42.12</td>\n",
|
|||
|
|
" <td>435.00</td>\n",
|
|||
|
|
" <td>NaN</td>\n",
|
|||
|
|
" <td>NaN</td>\n",
|
|||
|
|
" <td>NaN</td>\n",
|
|||
|
|
" <td>NaN</td>\n",
|
|||
|
|
" <td>NaN</td>\n",
|
|||
|
|
" <td>NaN</td>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" <tr>\n",
|
|||
|
|
" <th>3</th>\n",
|
|||
|
|
" <td>1.35040</td>\n",
|
|||
|
|
" <td>1.35060</td>\n",
|
|||
|
|
" <td>1.33850</td>\n",
|
|||
|
|
" <td>1.33990</td>\n",
|
|||
|
|
" <td>545.0</td>\n",
|
|||
|
|
" <td>1</td>\n",
|
|||
|
|
" <td>1</td>\n",
|
|||
|
|
" <td>0.5</td>\n",
|
|||
|
|
" <td>0.86603</td>\n",
|
|||
|
|
" <td>0.58779</td>\n",
|
|||
|
|
" <td>...</td>\n",
|
|||
|
|
" <td>0.047083</td>\n",
|
|||
|
|
" <td>2895.166667</td>\n",
|
|||
|
|
" <td>42.12</td>\n",
|
|||
|
|
" <td>433.60</td>\n",
|
|||
|
|
" <td>NaN</td>\n",
|
|||
|
|
" <td>NaN</td>\n",
|
|||
|
|
" <td>NaN</td>\n",
|
|||
|
|
" <td>NaN</td>\n",
|
|||
|
|
" <td>NaN</td>\n",
|
|||
|
|
" <td>NaN</td>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" <tr>\n",
|
|||
|
|
" <th>4</th>\n",
|
|||
|
|
" <td>1.33990</td>\n",
|
|||
|
|
" <td>1.34450</td>\n",
|
|||
|
|
" <td>1.33990</td>\n",
|
|||
|
|
" <td>1.34430</td>\n",
|
|||
|
|
" <td>385.0</td>\n",
|
|||
|
|
" <td>1</td>\n",
|
|||
|
|
" <td>1</td>\n",
|
|||
|
|
" <td>0.5</td>\n",
|
|||
|
|
" <td>0.96593</td>\n",
|
|||
|
|
" <td>0.58779</td>\n",
|
|||
|
|
" <td>...</td>\n",
|
|||
|
|
" <td>0.047083</td>\n",
|
|||
|
|
" <td>2895.166667</td>\n",
|
|||
|
|
" <td>42.12</td>\n",
|
|||
|
|
" <td>433.60</td>\n",
|
|||
|
|
" <td>NaN</td>\n",
|
|||
|
|
" <td>NaN</td>\n",
|
|||
|
|
" <td>NaN</td>\n",
|
|||
|
|
" <td>NaN</td>\n",
|
|||
|
|
" <td>NaN</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",
|
|||
|
|
" <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>118388</th>\n",
|
|||
|
|
" <td>1.03502</td>\n",
|
|||
|
|
" <td>1.03548</td>\n",
|
|||
|
|
" <td>1.03438</td>\n",
|
|||
|
|
" <td>1.03490</td>\n",
|
|||
|
|
" <td>2323.0</td>\n",
|
|||
|
|
" <td>1</td>\n",
|
|||
|
|
" <td>4</td>\n",
|
|||
|
|
" <td>-0.0</td>\n",
|
|||
|
|
" <td>-0.96593</td>\n",
|
|||
|
|
" <td>0.20791</td>\n",
|
|||
|
|
" <td>...</td>\n",
|
|||
|
|
" <td>0.013750</td>\n",
|
|||
|
|
" <td>6298.125000</td>\n",
|
|||
|
|
" <td>71.72</td>\n",
|
|||
|
|
" <td>2624.38</td>\n",
|
|||
|
|
" <td>23.611404</td>\n",
|
|||
|
|
" <td>-160.337614</td>\n",
|
|||
|
|
" <td>-0.051720</td>\n",
|
|||
|
|
" <td>-49.033438</td>\n",
|
|||
|
|
" <td>-2699.177784</td>\n",
|
|||
|
|
" <td>0.001465</td>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" <tr>\n",
|
|||
|
|
" <th>118389</th>\n",
|
|||
|
|
" <td>1.03489</td>\n",
|
|||
|
|
" <td>1.03566</td>\n",
|
|||
|
|
" <td>1.03455</td>\n",
|
|||
|
|
" <td>1.03529</td>\n",
|
|||
|
|
" <td>1900.0</td>\n",
|
|||
|
|
" <td>1</td>\n",
|
|||
|
|
" <td>4</td>\n",
|
|||
|
|
" <td>-0.0</td>\n",
|
|||
|
|
" <td>-0.86603</td>\n",
|
|||
|
|
" <td>0.20791</td>\n",
|
|||
|
|
" <td>...</td>\n",
|
|||
|
|
" <td>0.013750</td>\n",
|
|||
|
|
" <td>6298.125000</td>\n",
|
|||
|
|
" <td>71.72</td>\n",
|
|||
|
|
" <td>2624.81</td>\n",
|
|||
|
|
" <td>25.551370</td>\n",
|
|||
|
|
" <td>-119.355906</td>\n",
|
|||
|
|
" <td>-0.082496</td>\n",
|
|||
|
|
" <td>-43.107288</td>\n",
|
|||
|
|
" <td>-2306.287257</td>\n",
|
|||
|
|
" <td>0.001427</td>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" <tr>\n",
|
|||
|
|
" <th>118390</th>\n",
|
|||
|
|
" <td>1.03526</td>\n",
|
|||
|
|
" <td>1.03645</td>\n",
|
|||
|
|
" <td>1.03516</td>\n",
|
|||
|
|
" <td>1.03547</td>\n",
|
|||
|
|
" <td>1445.0</td>\n",
|
|||
|
|
" <td>1</td>\n",
|
|||
|
|
" <td>4</td>\n",
|
|||
|
|
" <td>-0.0</td>\n",
|
|||
|
|
" <td>-0.70711</td>\n",
|
|||
|
|
" <td>0.20791</td>\n",
|
|||
|
|
" <td>...</td>\n",
|
|||
|
|
" <td>0.013750</td>\n",
|
|||
|
|
" <td>6298.125000</td>\n",
|
|||
|
|
" <td>71.72</td>\n",
|
|||
|
|
" <td>2623.85</td>\n",
|
|||
|
|
" <td>26.385304</td>\n",
|
|||
|
|
" <td>-85.267741</td>\n",
|
|||
|
|
" <td>-0.116771</td>\n",
|
|||
|
|
" <td>-40.333690</td>\n",
|
|||
|
|
" <td>-2174.693523</td>\n",
|
|||
|
|
" <td>0.001410</td>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" <tr>\n",
|
|||
|
|
" <th>118391</th>\n",
|
|||
|
|
" <td>1.03547</td>\n",
|
|||
|
|
" <td>1.03631</td>\n",
|
|||
|
|
" <td>1.03544</td>\n",
|
|||
|
|
" <td>1.03582</td>\n",
|
|||
|
|
" <td>1208.0</td>\n",
|
|||
|
|
" <td>0</td>\n",
|
|||
|
|
" <td>4</td>\n",
|
|||
|
|
" <td>-0.0</td>\n",
|
|||
|
|
" <td>-0.50000</td>\n",
|
|||
|
|
" <td>0.20791</td>\n",
|
|||
|
|
" <td>...</td>\n",
|
|||
|
|
" <td>0.013750</td>\n",
|
|||
|
|
" <td>6298.125000</td>\n",
|
|||
|
|
" <td>71.72</td>\n",
|
|||
|
|
" <td>2623.36</td>\n",
|
|||
|
|
" <td>27.159672</td>\n",
|
|||
|
|
" <td>-69.016843</td>\n",
|
|||
|
|
" <td>-0.151568</td>\n",
|
|||
|
|
" <td>-34.860425</td>\n",
|
|||
|
|
" <td>-1971.758013</td>\n",
|
|||
|
|
" <td>0.001356</td>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" <tr>\n",
|
|||
|
|
" <th>118392</th>\n",
|
|||
|
|
" <td>1.03585</td>\n",
|
|||
|
|
" <td>1.03608</td>\n",
|
|||
|
|
" <td>1.03489</td>\n",
|
|||
|
|
" <td>1.03493</td>\n",
|
|||
|
|
" <td>616.0</td>\n",
|
|||
|
|
" <td>0</td>\n",
|
|||
|
|
" <td>4</td>\n",
|
|||
|
|
" <td>-0.0</td>\n",
|
|||
|
|
" <td>-0.25882</td>\n",
|
|||
|
|
" <td>0.20791</td>\n",
|
|||
|
|
" <td>...</td>\n",
|
|||
|
|
" <td>0.013750</td>\n",
|
|||
|
|
" <td>6298.125000</td>\n",
|
|||
|
|
" <td>71.72</td>\n",
|
|||
|
|
" <td>2624.61</td>\n",
|
|||
|
|
" <td>28.181968</td>\n",
|
|||
|
|
" <td>-73.068540</td>\n",
|
|||
|
|
" <td>-0.186740</td>\n",
|
|||
|
|
" <td>-41.146290</td>\n",
|
|||
|
|
" <td>-1892.311742</td>\n",
|
|||
|
|
" <td>0.001336</td>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" </tbody>\n",
|
|||
|
|
"</table>\n",
|
|||
|
|
"<p>113016 rows × 22 columns</p>\n",
|
|||
|
|
"</div>"
|
|||
|
|
],
|
|||
|
|
"text/plain": [
|
|||
|
|
" Open High Low Close Volume Session Quarter \\\n",
|
|||
|
|
"0 1.35790 1.35810 1.35390 1.35470 318.0 1 1 \n",
|
|||
|
|
"1 1.35460 1.35510 1.35290 1.35380 338.0 1 1 \n",
|
|||
|
|
"2 1.35390 1.35390 1.34980 1.35040 356.0 1 1 \n",
|
|||
|
|
"3 1.35040 1.35060 1.33850 1.33990 545.0 1 1 \n",
|
|||
|
|
"4 1.33990 1.34450 1.33990 1.34430 385.0 1 1 \n",
|
|||
|
|
"... ... ... ... ... ... ... ... \n",
|
|||
|
|
"118388 1.03502 1.03548 1.03438 1.03490 2323.0 1 4 \n",
|
|||
|
|
"118389 1.03489 1.03566 1.03455 1.03529 1900.0 1 4 \n",
|
|||
|
|
"118390 1.03526 1.03645 1.03516 1.03547 1445.0 1 4 \n",
|
|||
|
|
"118391 1.03547 1.03631 1.03544 1.03582 1208.0 0 4 \n",
|
|||
|
|
"118392 1.03585 1.03608 1.03489 1.03493 616.0 0 4 \n",
|
|||
|
|
"\n",
|
|||
|
|
" Month_sin Hour_sin Date_sin ... Diff_10Y_2Y Oil_Volume \\\n",
|
|||
|
|
"0 0.5 0.25882 0.58779 ... 0.047083 2895.166667 \n",
|
|||
|
|
"1 0.5 0.50000 0.58779 ... 0.047083 2895.166667 \n",
|
|||
|
|
"2 0.5 0.70711 0.58779 ... 0.047083 2895.166667 \n",
|
|||
|
|
"3 0.5 0.86603 0.58779 ... 0.047083 2895.166667 \n",
|
|||
|
|
"4 0.5 0.96593 0.58779 ... 0.047083 2895.166667 \n",
|
|||
|
|
"... ... ... ... ... ... ... \n",
|
|||
|
|
"118388 -0.0 -0.96593 0.20791 ... 0.013750 6298.125000 \n",
|
|||
|
|
"118389 -0.0 -0.86603 0.20791 ... 0.013750 6298.125000 \n",
|
|||
|
|
"118390 -0.0 -0.70711 0.20791 ... 0.013750 6298.125000 \n",
|
|||
|
|
"118391 -0.0 -0.50000 0.20791 ... 0.013750 6298.125000 \n",
|
|||
|
|
"118392 -0.0 -0.25882 0.20791 ... 0.013750 6298.125000 \n",
|
|||
|
|
"\n",
|
|||
|
|
" Oil_Close Gold_Close ADX_14 CCI_14 PPO_12_26 CMO_14 \\\n",
|
|||
|
|
"0 42.12 435.60 NaN NaN NaN NaN \n",
|
|||
|
|
"1 42.12 435.50 NaN NaN NaN NaN \n",
|
|||
|
|
"2 42.12 435.00 NaN NaN NaN NaN \n",
|
|||
|
|
"3 42.12 433.60 NaN NaN NaN NaN \n",
|
|||
|
|
"4 42.12 433.60 NaN NaN NaN NaN \n",
|
|||
|
|
"... ... ... ... ... ... ... \n",
|
|||
|
|
"118388 71.72 2624.38 23.611404 -160.337614 -0.051720 -49.033438 \n",
|
|||
|
|
"118389 71.72 2624.81 25.551370 -119.355906 -0.082496 -43.107288 \n",
|
|||
|
|
"118390 71.72 2623.85 26.385304 -85.267741 -0.116771 -40.333690 \n",
|
|||
|
|
"118391 71.72 2623.36 27.159672 -69.016843 -0.151568 -34.860425 \n",
|
|||
|
|
"118392 71.72 2624.61 28.181968 -73.068540 -0.186740 -41.146290 \n",
|
|||
|
|
"\n",
|
|||
|
|
" ChaikinVol_3_10 KeltnerWidth_20 \n",
|
|||
|
|
"0 NaN NaN \n",
|
|||
|
|
"1 NaN NaN \n",
|
|||
|
|
"2 NaN NaN \n",
|
|||
|
|
"3 NaN NaN \n",
|
|||
|
|
"4 NaN NaN \n",
|
|||
|
|
"... ... ... \n",
|
|||
|
|
"118388 -2699.177784 0.001465 \n",
|
|||
|
|
"118389 -2306.287257 0.001427 \n",
|
|||
|
|
"118390 -2174.693523 0.001410 \n",
|
|||
|
|
"118391 -1971.758013 0.001356 \n",
|
|||
|
|
"118392 -1892.311742 0.001336 \n",
|
|||
|
|
"\n",
|
|||
|
|
"[113016 rows x 22 columns]"
|
|||
|
|
]
|
|||
|
|
},
|
|||
|
|
"execution_count": 119,
|
|||
|
|
"metadata": {},
|
|||
|
|
"output_type": "execute_result"
|
|||
|
|
}
|
|||
|
|
],
|
|||
|
|
"source": [
|
|||
|
|
"df"
|
|||
|
|
]
|
|||
|
|
},
|
|||
|
|
{
|
|||
|
|
"cell_type": "code",
|
|||
|
|
"execution_count": 120,
|
|||
|
|
"metadata": {
|
|||
|
|
"colab": {
|
|||
|
|
"base_uri": "https://localhost:8080/"
|
|||
|
|
},
|
|||
|
|
"id": "-oXlHPKm5btt",
|
|||
|
|
"outputId": "f89f8f33-3b6d-4f91-de95-a3e060a06d97"
|
|||
|
|
},
|
|||
|
|
"outputs": [
|
|||
|
|
{
|
|||
|
|
"name": "stderr",
|
|||
|
|
"output_type": "stream",
|
|||
|
|
"text": [
|
|||
|
|
"/var/folders/l_/j4rfg9014yvd4jfvv441w26r0000gn/T/ipykernel_54914/1728166818.py:1: SettingWithCopyWarning: \n",
|
|||
|
|
"A value is trying to be set on a copy of a slice from a DataFrame.\n",
|
|||
|
|
"Try using .loc[row_indexer,col_indexer] = value instead\n",
|
|||
|
|
"\n",
|
|||
|
|
"See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n",
|
|||
|
|
" df['ADX_2'] = talib.ADX(df['High'], df['Low'], df['Close'], timeperiod=2)\n",
|
|||
|
|
"/var/folders/l_/j4rfg9014yvd4jfvv441w26r0000gn/T/ipykernel_54914/1728166818.py:2: SettingWithCopyWarning: \n",
|
|||
|
|
"A value is trying to be set on a copy of a slice from a DataFrame.\n",
|
|||
|
|
"Try using .loc[row_indexer,col_indexer] = value instead\n",
|
|||
|
|
"\n",
|
|||
|
|
"See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n",
|
|||
|
|
" df['ADX_5'] = talib.ADX(df['High'], df['Low'], df['Close'], timeperiod=5)\n",
|
|||
|
|
"/var/folders/l_/j4rfg9014yvd4jfvv441w26r0000gn/T/ipykernel_54914/1728166818.py:3: SettingWithCopyWarning: \n",
|
|||
|
|
"A value is trying to be set on a copy of a slice from a DataFrame.\n",
|
|||
|
|
"Try using .loc[row_indexer,col_indexer] = value instead\n",
|
|||
|
|
"\n",
|
|||
|
|
"See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n",
|
|||
|
|
" df['CCI_2'] = talib.CCI(df['High'], df['Low'], df['Close'], timeperiod=2)\n",
|
|||
|
|
"/var/folders/l_/j4rfg9014yvd4jfvv441w26r0000gn/T/ipykernel_54914/1728166818.py:4: SettingWithCopyWarning: \n",
|
|||
|
|
"A value is trying to be set on a copy of a slice from a DataFrame.\n",
|
|||
|
|
"Try using .loc[row_indexer,col_indexer] = value instead\n",
|
|||
|
|
"\n",
|
|||
|
|
"See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n",
|
|||
|
|
" df['CCI_8'] = talib.CCI(df['High'], df['Low'], df['Close'], timeperiod=8)\n",
|
|||
|
|
"/var/folders/l_/j4rfg9014yvd4jfvv441w26r0000gn/T/ipykernel_54914/1728166818.py:5: SettingWithCopyWarning: \n",
|
|||
|
|
"A value is trying to be set on a copy of a slice from a DataFrame.\n",
|
|||
|
|
"Try using .loc[row_indexer,col_indexer] = value instead\n",
|
|||
|
|
"\n",
|
|||
|
|
"See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n",
|
|||
|
|
" df['CCI_20'] = talib.CCI(df['High'], df['Low'], df['Close'], timeperiod=20)\n",
|
|||
|
|
"/var/folders/l_/j4rfg9014yvd4jfvv441w26r0000gn/T/ipykernel_54914/1728166818.py:6: SettingWithCopyWarning: \n",
|
|||
|
|
"A value is trying to be set on a copy of a slice from a DataFrame.\n",
|
|||
|
|
"Try using .loc[row_indexer,col_indexer] = value instead\n",
|
|||
|
|
"\n",
|
|||
|
|
"See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n",
|
|||
|
|
" df['PPO_2_6'] = talib.PPO(df['Close'], fastperiod=2, slowperiod=6, matype=0)\n",
|
|||
|
|
"/var/folders/l_/j4rfg9014yvd4jfvv441w26r0000gn/T/ipykernel_54914/1728166818.py:7: SettingWithCopyWarning: \n",
|
|||
|
|
"A value is trying to be set on a copy of a slice from a DataFrame.\n",
|
|||
|
|
"Try using .loc[row_indexer,col_indexer] = value instead\n",
|
|||
|
|
"\n",
|
|||
|
|
"See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n",
|
|||
|
|
" df['CMO_2'] = talib.CMO(df['Close'], timeperiod=2)\n",
|
|||
|
|
"/var/folders/l_/j4rfg9014yvd4jfvv441w26r0000gn/T/ipykernel_54914/1728166818.py:8: SettingWithCopyWarning: \n",
|
|||
|
|
"A value is trying to be set on a copy of a slice from a DataFrame.\n",
|
|||
|
|
"Try using .loc[row_indexer,col_indexer] = value instead\n",
|
|||
|
|
"\n",
|
|||
|
|
"See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n",
|
|||
|
|
" df['CMO54'] = talib.CMO(df['Close'], timeperiod=5)\n",
|
|||
|
|
"/var/folders/l_/j4rfg9014yvd4jfvv441w26r0000gn/T/ipykernel_54914/1728166818.py:9: SettingWithCopyWarning: \n",
|
|||
|
|
"A value is trying to be set on a copy of a slice from a DataFrame.\n",
|
|||
|
|
"Try using .loc[row_indexer,col_indexer] = value instead\n",
|
|||
|
|
"\n",
|
|||
|
|
"See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n",
|
|||
|
|
" df['ChaikinVol_2_5'] = talib.ADOSC(df['High'], df['Low'], df['Close'], df['Volume'], fastperiod=2, slowperiod=5)\n",
|
|||
|
|
"/var/folders/l_/j4rfg9014yvd4jfvv441w26r0000gn/T/ipykernel_54914/1728166818.py:10: SettingWithCopyWarning: \n",
|
|||
|
|
"A value is trying to be set on a copy of a slice from a DataFrame.\n",
|
|||
|
|
"Try using .loc[row_indexer,col_indexer] = value instead\n",
|
|||
|
|
"\n",
|
|||
|
|
"See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n",
|
|||
|
|
" df['KeltnerWidth_2'] = (talib.EMA(df['High'] - df['Low'], timeperiod=2) / talib.EMA(df['Close'], timeperiod=2))\n",
|
|||
|
|
"/var/folders/l_/j4rfg9014yvd4jfvv441w26r0000gn/T/ipykernel_54914/1728166818.py:11: SettingWithCopyWarning: \n",
|
|||
|
|
"A value is trying to be set on a copy of a slice from a DataFrame.\n",
|
|||
|
|
"Try using .loc[row_indexer,col_indexer] = value instead\n",
|
|||
|
|
"\n",
|
|||
|
|
"See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n",
|
|||
|
|
" df['KeltnerWidth_15'] = (talib.EMA(df['High'] - df['Low'], timeperiod=15) / talib.EMA(df['Close'], timeperiod=15))\n",
|
|||
|
|
"/var/folders/l_/j4rfg9014yvd4jfvv441w26r0000gn/T/ipykernel_54914/1728166818.py:12: SettingWithCopyWarning: \n",
|
|||
|
|
"A value is trying to be set on a copy of a slice from a DataFrame.\n",
|
|||
|
|
"Try using .loc[row_indexer,col_indexer] = value instead\n",
|
|||
|
|
"\n",
|
|||
|
|
"See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n",
|
|||
|
|
" df['KeltnerWidth_24'] = (talib.EMA(df['High'] - df['Low'], timeperiod=24) / talib.EMA(df['Close'], timeperiod=24))\n"
|
|||
|
|
]
|
|||
|
|
}
|
|||
|
|
],
|
|||
|
|
"source": [
|
|||
|
|
"df['ADX_2'] = talib.ADX(df['High'], df['Low'], df['Close'], timeperiod=2)\n",
|
|||
|
|
"df['ADX_5'] = talib.ADX(df['High'], df['Low'], df['Close'], timeperiod=5)\n",
|
|||
|
|
"df['CCI_2'] = talib.CCI(df['High'], df['Low'], df['Close'], timeperiod=2)\n",
|
|||
|
|
"df['CCI_8'] = talib.CCI(df['High'], df['Low'], df['Close'], timeperiod=8)\n",
|
|||
|
|
"df['CCI_20'] = talib.CCI(df['High'], df['Low'], df['Close'], timeperiod=20)\n",
|
|||
|
|
"df['PPO_2_6'] = talib.PPO(df['Close'], fastperiod=2, slowperiod=6, matype=0)\n",
|
|||
|
|
"df['CMO_2'] = talib.CMO(df['Close'], timeperiod=2)\n",
|
|||
|
|
"df['CMO54'] = talib.CMO(df['Close'], timeperiod=5)\n",
|
|||
|
|
"df['ChaikinVol_2_5'] = talib.ADOSC(df['High'], df['Low'], df['Close'], df['Volume'], fastperiod=2, slowperiod=5)\n",
|
|||
|
|
"df['KeltnerWidth_2'] = (talib.EMA(df['High'] - df['Low'], timeperiod=2) / talib.EMA(df['Close'], timeperiod=2))\n",
|
|||
|
|
"df['KeltnerWidth_15'] = (talib.EMA(df['High'] - df['Low'], timeperiod=15) / talib.EMA(df['Close'], timeperiod=15))\n",
|
|||
|
|
"df['KeltnerWidth_24'] = (talib.EMA(df['High'] - df['Low'], timeperiod=24) / talib.EMA(df['Close'], timeperiod=24))"
|
|||
|
|
]
|
|||
|
|
},
|
|||
|
|
{
|
|||
|
|
"cell_type": "code",
|
|||
|
|
"execution_count": 121,
|
|||
|
|
"metadata": {
|
|||
|
|
"colab": {
|
|||
|
|
"base_uri": "https://localhost:8080/",
|
|||
|
|
"height": 444
|
|||
|
|
},
|
|||
|
|
"id": "G0IqqeYr6zo4",
|
|||
|
|
"outputId": "9c95e7d5-f43e-4232-d741-34cd44558b51"
|
|||
|
|
},
|
|||
|
|
"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>Open</th>\n",
|
|||
|
|
" <th>High</th>\n",
|
|||
|
|
" <th>Low</th>\n",
|
|||
|
|
" <th>Close</th>\n",
|
|||
|
|
" <th>Volume</th>\n",
|
|||
|
|
" <th>Session</th>\n",
|
|||
|
|
" <th>Quarter</th>\n",
|
|||
|
|
" <th>Month_sin</th>\n",
|
|||
|
|
" <th>Hour_sin</th>\n",
|
|||
|
|
" <th>Date_sin</th>\n",
|
|||
|
|
" <th>...</th>\n",
|
|||
|
|
" <th>CCI_2</th>\n",
|
|||
|
|
" <th>CCI_8</th>\n",
|
|||
|
|
" <th>CCI_20</th>\n",
|
|||
|
|
" <th>PPO_2_6</th>\n",
|
|||
|
|
" <th>CMO_2</th>\n",
|
|||
|
|
" <th>CMO54</th>\n",
|
|||
|
|
" <th>ChaikinVol_2_5</th>\n",
|
|||
|
|
" <th>KeltnerWidth_2</th>\n",
|
|||
|
|
" <th>KeltnerWidth_15</th>\n",
|
|||
|
|
" <th>KeltnerWidth_24</th>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" </thead>\n",
|
|||
|
|
" <tbody>\n",
|
|||
|
|
" <tr>\n",
|
|||
|
|
" <th>0</th>\n",
|
|||
|
|
" <td>1.35790</td>\n",
|
|||
|
|
" <td>1.35810</td>\n",
|
|||
|
|
" <td>1.35390</td>\n",
|
|||
|
|
" <td>1.35470</td>\n",
|
|||
|
|
" <td>318.0</td>\n",
|
|||
|
|
" <td>1</td>\n",
|
|||
|
|
" <td>1</td>\n",
|
|||
|
|
" <td>0.5</td>\n",
|
|||
|
|
" <td>0.25882</td>\n",
|
|||
|
|
" <td>0.58779</td>\n",
|
|||
|
|
" <td>...</td>\n",
|
|||
|
|
" <td>NaN</td>\n",
|
|||
|
|
" <td>NaN</td>\n",
|
|||
|
|
" <td>NaN</td>\n",
|
|||
|
|
" <td>NaN</td>\n",
|
|||
|
|
" <td>NaN</td>\n",
|
|||
|
|
" <td>NaN</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>1.35460</td>\n",
|
|||
|
|
" <td>1.35510</td>\n",
|
|||
|
|
" <td>1.35290</td>\n",
|
|||
|
|
" <td>1.35380</td>\n",
|
|||
|
|
" <td>338.0</td>\n",
|
|||
|
|
" <td>1</td>\n",
|
|||
|
|
" <td>1</td>\n",
|
|||
|
|
" <td>0.5</td>\n",
|
|||
|
|
" <td>0.50000</td>\n",
|
|||
|
|
" <td>0.58779</td>\n",
|
|||
|
|
" <td>...</td>\n",
|
|||
|
|
" <td>-66.666667</td>\n",
|
|||
|
|
" <td>NaN</td>\n",
|
|||
|
|
" <td>NaN</td>\n",
|
|||
|
|
" <td>NaN</td>\n",
|
|||
|
|
" <td>NaN</td>\n",
|
|||
|
|
" <td>NaN</td>\n",
|
|||
|
|
" <td>NaN</td>\n",
|
|||
|
|
" <td>0.002363</td>\n",
|
|||
|
|
" <td>NaN</td>\n",
|
|||
|
|
" <td>NaN</td>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" <tr>\n",
|
|||
|
|
" <th>2</th>\n",
|
|||
|
|
" <td>1.35390</td>\n",
|
|||
|
|
" <td>1.35390</td>\n",
|
|||
|
|
" <td>1.34980</td>\n",
|
|||
|
|
" <td>1.35040</td>\n",
|
|||
|
|
" <td>356.0</td>\n",
|
|||
|
|
" <td>1</td>\n",
|
|||
|
|
" <td>1</td>\n",
|
|||
|
|
" <td>0.5</td>\n",
|
|||
|
|
" <td>0.70711</td>\n",
|
|||
|
|
" <td>0.58779</td>\n",
|
|||
|
|
" <td>...</td>\n",
|
|||
|
|
" <td>-66.666667</td>\n",
|
|||
|
|
" <td>NaN</td>\n",
|
|||
|
|
" <td>NaN</td>\n",
|
|||
|
|
" <td>NaN</td>\n",
|
|||
|
|
" <td>-100.000000</td>\n",
|
|||
|
|
" <td>NaN</td>\n",
|
|||
|
|
" <td>NaN</td>\n",
|
|||
|
|
" <td>0.002811</td>\n",
|
|||
|
|
" <td>NaN</td>\n",
|
|||
|
|
" <td>NaN</td>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" <tr>\n",
|
|||
|
|
" <th>3</th>\n",
|
|||
|
|
" <td>1.35040</td>\n",
|
|||
|
|
" <td>1.35060</td>\n",
|
|||
|
|
" <td>1.33850</td>\n",
|
|||
|
|
" <td>1.33990</td>\n",
|
|||
|
|
" <td>545.0</td>\n",
|
|||
|
|
" <td>1</td>\n",
|
|||
|
|
" <td>1</td>\n",
|
|||
|
|
" <td>0.5</td>\n",
|
|||
|
|
" <td>0.86603</td>\n",
|
|||
|
|
" <td>0.58779</td>\n",
|
|||
|
|
" <td>...</td>\n",
|
|||
|
|
" <td>-66.666667</td>\n",
|
|||
|
|
" <td>NaN</td>\n",
|
|||
|
|
" <td>NaN</td>\n",
|
|||
|
|
" <td>NaN</td>\n",
|
|||
|
|
" <td>-100.000000</td>\n",
|
|||
|
|
" <td>NaN</td>\n",
|
|||
|
|
" <td>NaN</td>\n",
|
|||
|
|
" <td>0.006945</td>\n",
|
|||
|
|
" <td>NaN</td>\n",
|
|||
|
|
" <td>NaN</td>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" <tr>\n",
|
|||
|
|
" <th>4</th>\n",
|
|||
|
|
" <td>1.33990</td>\n",
|
|||
|
|
" <td>1.34450</td>\n",
|
|||
|
|
" <td>1.33990</td>\n",
|
|||
|
|
" <td>1.34430</td>\n",
|
|||
|
|
" <td>385.0</td>\n",
|
|||
|
|
" <td>1</td>\n",
|
|||
|
|
" <td>1</td>\n",
|
|||
|
|
" <td>0.5</td>\n",
|
|||
|
|
" <td>0.96593</td>\n",
|
|||
|
|
" <td>0.58779</td>\n",
|
|||
|
|
" <td>...</td>\n",
|
|||
|
|
" <td>-66.666667</td>\n",
|
|||
|
|
" <td>NaN</td>\n",
|
|||
|
|
" <td>NaN</td>\n",
|
|||
|
|
" <td>NaN</td>\n",
|
|||
|
|
" <td>-17.948718</td>\n",
|
|||
|
|
" <td>NaN</td>\n",
|
|||
|
|
" <td>-99.117404</td>\n",
|
|||
|
|
" <td>0.004596</td>\n",
|
|||
|
|
" <td>NaN</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",
|
|||
|
|
" <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>118388</th>\n",
|
|||
|
|
" <td>1.03502</td>\n",
|
|||
|
|
" <td>1.03548</td>\n",
|
|||
|
|
" <td>1.03438</td>\n",
|
|||
|
|
" <td>1.03490</td>\n",
|
|||
|
|
" <td>2323.0</td>\n",
|
|||
|
|
" <td>1</td>\n",
|
|||
|
|
" <td>4</td>\n",
|
|||
|
|
" <td>-0.0</td>\n",
|
|||
|
|
" <td>-0.96593</td>\n",
|
|||
|
|
" <td>0.20791</td>\n",
|
|||
|
|
" <td>...</td>\n",
|
|||
|
|
" <td>-66.666667</td>\n",
|
|||
|
|
" <td>-108.467310</td>\n",
|
|||
|
|
" <td>-217.330577</td>\n",
|
|||
|
|
" <td>-0.188861</td>\n",
|
|||
|
|
" <td>-99.184418</td>\n",
|
|||
|
|
" <td>-86.385833</td>\n",
|
|||
|
|
" <td>-1741.904757</td>\n",
|
|||
|
|
" <td>0.001345</td>\n",
|
|||
|
|
" <td>0.001520</td>\n",
|
|||
|
|
" <td>0.001433</td>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" <tr>\n",
|
|||
|
|
" <th>118389</th>\n",
|
|||
|
|
" <td>1.03489</td>\n",
|
|||
|
|
" <td>1.03566</td>\n",
|
|||
|
|
" <td>1.03455</td>\n",
|
|||
|
|
" <td>1.03529</td>\n",
|
|||
|
|
" <td>1900.0</td>\n",
|
|||
|
|
" <td>1</td>\n",
|
|||
|
|
" <td>4</td>\n",
|
|||
|
|
" <td>-0.0</td>\n",
|
|||
|
|
" <td>-0.86603</td>\n",
|
|||
|
|
" <td>0.20791</td>\n",
|
|||
|
|
" <td>...</td>\n",
|
|||
|
|
" <td>66.666667</td>\n",
|
|||
|
|
" <td>-76.572200</td>\n",
|
|||
|
|
" <td>-161.486199</td>\n",
|
|||
|
|
" <td>-0.112263</td>\n",
|
|||
|
|
" <td>-18.839266</td>\n",
|
|||
|
|
" <td>-65.275344</td>\n",
|
|||
|
|
" <td>-1063.099374</td>\n",
|
|||
|
|
" <td>0.001163</td>\n",
|
|||
|
|
" <td>0.001464</td>\n",
|
|||
|
|
" <td>0.001404</td>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" <tr>\n",
|
|||
|
|
" <th>118390</th>\n",
|
|||
|
|
" <td>1.03526</td>\n",
|
|||
|
|
" <td>1.03645</td>\n",
|
|||
|
|
" <td>1.03516</td>\n",
|
|||
|
|
" <td>1.03547</td>\n",
|
|||
|
|
" <td>1445.0</td>\n",
|
|||
|
|
" <td>1</td>\n",
|
|||
|
|
" <td>4</td>\n",
|
|||
|
|
" <td>-0.0</td>\n",
|
|||
|
|
" <td>-0.70711</td>\n",
|
|||
|
|
" <td>0.20791</td>\n",
|
|||
|
|
" <td>...</td>\n",
|
|||
|
|
" <td>66.666667</td>\n",
|
|||
|
|
" <td>-46.257822</td>\n",
|
|||
|
|
" <td>-118.798827</td>\n",
|
|||
|
|
" <td>-0.023335</td>\n",
|
|||
|
|
" <td>13.404055</td>\n",
|
|||
|
|
" <td>-55.138058</td>\n",
|
|||
|
|
" <td>-926.177387</td>\n",
|
|||
|
|
" <td>0.001218</td>\n",
|
|||
|
|
" <td>0.001437</td>\n",
|
|||
|
|
" <td>0.001392</td>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" <tr>\n",
|
|||
|
|
" <th>118391</th>\n",
|
|||
|
|
" <td>1.03547</td>\n",
|
|||
|
|
" <td>1.03631</td>\n",
|
|||
|
|
" <td>1.03544</td>\n",
|
|||
|
|
" <td>1.03582</td>\n",
|
|||
|
|
" <td>1208.0</td>\n",
|
|||
|
|
" <td>0</td>\n",
|
|||
|
|
" <td>4</td>\n",
|
|||
|
|
" <td>-0.0</td>\n",
|
|||
|
|
" <td>-0.50000</td>\n",
|
|||
|
|
" <td>0.20791</td>\n",
|
|||
|
|
" <td>...</td>\n",
|
|||
|
|
" <td>66.666667</td>\n",
|
|||
|
|
" <td>-26.847505</td>\n",
|
|||
|
|
" <td>-97.839834</td>\n",
|
|||
|
|
" <td>0.030747</td>\n",
|
|||
|
|
" <td>57.863488</td>\n",
|
|||
|
|
" <td>-35.010678</td>\n",
|
|||
|
|
" <td>-740.844959</td>\n",
|
|||
|
|
" <td>0.000966</td>\n",
|
|||
|
|
" <td>0.001363</td>\n",
|
|||
|
|
" <td>0.001347</td>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" <tr>\n",
|
|||
|
|
" <th>118392</th>\n",
|
|||
|
|
" <td>1.03585</td>\n",
|
|||
|
|
" <td>1.03608</td>\n",
|
|||
|
|
" <td>1.03489</td>\n",
|
|||
|
|
" <td>1.03493</td>\n",
|
|||
|
|
" <td>616.0</td>\n",
|
|||
|
|
" <td>0</td>\n",
|
|||
|
|
" <td>4</td>\n",
|
|||
|
|
" <td>-0.0</td>\n",
|
|||
|
|
" <td>-0.25882</td>\n",
|
|||
|
|
" <td>0.20791</td>\n",
|
|||
|
|
" <td>...</td>\n",
|
|||
|
|
" <td>-66.666667</td>\n",
|
|||
|
|
" <td>-50.481804</td>\n",
|
|||
|
|
" <td>-99.278507</td>\n",
|
|||
|
|
" <td>0.013201</td>\n",
|
|||
|
|
" <td>-56.283445</td>\n",
|
|||
|
|
" <td>-53.986053</td>\n",
|
|||
|
|
" <td>-726.557174</td>\n",
|
|||
|
|
" <td>0.001089</td>\n",
|
|||
|
|
" <td>0.001336</td>\n",
|
|||
|
|
" <td>0.001332</td>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" </tbody>\n",
|
|||
|
|
"</table>\n",
|
|||
|
|
"<p>113016 rows × 34 columns</p>\n",
|
|||
|
|
"</div>"
|
|||
|
|
],
|
|||
|
|
"text/plain": [
|
|||
|
|
" Open High Low Close Volume Session Quarter \\\n",
|
|||
|
|
"0 1.35790 1.35810 1.35390 1.35470 318.0 1 1 \n",
|
|||
|
|
"1 1.35460 1.35510 1.35290 1.35380 338.0 1 1 \n",
|
|||
|
|
"2 1.35390 1.35390 1.34980 1.35040 356.0 1 1 \n",
|
|||
|
|
"3 1.35040 1.35060 1.33850 1.33990 545.0 1 1 \n",
|
|||
|
|
"4 1.33990 1.34450 1.33990 1.34430 385.0 1 1 \n",
|
|||
|
|
"... ... ... ... ... ... ... ... \n",
|
|||
|
|
"118388 1.03502 1.03548 1.03438 1.03490 2323.0 1 4 \n",
|
|||
|
|
"118389 1.03489 1.03566 1.03455 1.03529 1900.0 1 4 \n",
|
|||
|
|
"118390 1.03526 1.03645 1.03516 1.03547 1445.0 1 4 \n",
|
|||
|
|
"118391 1.03547 1.03631 1.03544 1.03582 1208.0 0 4 \n",
|
|||
|
|
"118392 1.03585 1.03608 1.03489 1.03493 616.0 0 4 \n",
|
|||
|
|
"\n",
|
|||
|
|
" Month_sin Hour_sin Date_sin ... CCI_2 CCI_8 CCI_20 \\\n",
|
|||
|
|
"0 0.5 0.25882 0.58779 ... NaN NaN NaN \n",
|
|||
|
|
"1 0.5 0.50000 0.58779 ... -66.666667 NaN NaN \n",
|
|||
|
|
"2 0.5 0.70711 0.58779 ... -66.666667 NaN NaN \n",
|
|||
|
|
"3 0.5 0.86603 0.58779 ... -66.666667 NaN NaN \n",
|
|||
|
|
"4 0.5 0.96593 0.58779 ... -66.666667 NaN NaN \n",
|
|||
|
|
"... ... ... ... ... ... ... ... \n",
|
|||
|
|
"118388 -0.0 -0.96593 0.20791 ... -66.666667 -108.467310 -217.330577 \n",
|
|||
|
|
"118389 -0.0 -0.86603 0.20791 ... 66.666667 -76.572200 -161.486199 \n",
|
|||
|
|
"118390 -0.0 -0.70711 0.20791 ... 66.666667 -46.257822 -118.798827 \n",
|
|||
|
|
"118391 -0.0 -0.50000 0.20791 ... 66.666667 -26.847505 -97.839834 \n",
|
|||
|
|
"118392 -0.0 -0.25882 0.20791 ... -66.666667 -50.481804 -99.278507 \n",
|
|||
|
|
"\n",
|
|||
|
|
" PPO_2_6 CMO_2 CMO54 ChaikinVol_2_5 KeltnerWidth_2 \\\n",
|
|||
|
|
"0 NaN NaN NaN NaN NaN \n",
|
|||
|
|
"1 NaN NaN NaN NaN 0.002363 \n",
|
|||
|
|
"2 NaN -100.000000 NaN NaN 0.002811 \n",
|
|||
|
|
"3 NaN -100.000000 NaN NaN 0.006945 \n",
|
|||
|
|
"4 NaN -17.948718 NaN -99.117404 0.004596 \n",
|
|||
|
|
"... ... ... ... ... ... \n",
|
|||
|
|
"118388 -0.188861 -99.184418 -86.385833 -1741.904757 0.001345 \n",
|
|||
|
|
"118389 -0.112263 -18.839266 -65.275344 -1063.099374 0.001163 \n",
|
|||
|
|
"118390 -0.023335 13.404055 -55.138058 -926.177387 0.001218 \n",
|
|||
|
|
"118391 0.030747 57.863488 -35.010678 -740.844959 0.000966 \n",
|
|||
|
|
"118392 0.013201 -56.283445 -53.986053 -726.557174 0.001089 \n",
|
|||
|
|
"\n",
|
|||
|
|
" KeltnerWidth_15 KeltnerWidth_24 \n",
|
|||
|
|
"0 NaN NaN \n",
|
|||
|
|
"1 NaN NaN \n",
|
|||
|
|
"2 NaN NaN \n",
|
|||
|
|
"3 NaN NaN \n",
|
|||
|
|
"4 NaN NaN \n",
|
|||
|
|
"... ... ... \n",
|
|||
|
|
"118388 0.001520 0.001433 \n",
|
|||
|
|
"118389 0.001464 0.001404 \n",
|
|||
|
|
"118390 0.001437 0.001392 \n",
|
|||
|
|
"118391 0.001363 0.001347 \n",
|
|||
|
|
"118392 0.001336 0.001332 \n",
|
|||
|
|
"\n",
|
|||
|
|
"[113016 rows x 34 columns]"
|
|||
|
|
]
|
|||
|
|
},
|
|||
|
|
"execution_count": 121,
|
|||
|
|
"metadata": {},
|
|||
|
|
"output_type": "execute_result"
|
|||
|
|
}
|
|||
|
|
],
|
|||
|
|
"source": [
|
|||
|
|
"df"
|
|||
|
|
]
|
|||
|
|
},
|
|||
|
|
{
|
|||
|
|
"cell_type": "code",
|
|||
|
|
"execution_count": 122,
|
|||
|
|
"metadata": {
|
|||
|
|
"colab": {
|
|||
|
|
"base_uri": "https://localhost:8080/"
|
|||
|
|
},
|
|||
|
|
"id": "i44En6xf7NE8",
|
|||
|
|
"outputId": "621a2c38-a80a-4294-c9f6-be83253cac38"
|
|||
|
|
},
|
|||
|
|
"outputs": [
|
|||
|
|
{
|
|||
|
|
"name": "stderr",
|
|||
|
|
"output_type": "stream",
|
|||
|
|
"text": [
|
|||
|
|
"/var/folders/l_/j4rfg9014yvd4jfvv441w26r0000gn/T/ipykernel_54914/4128738175.py:1: SettingWithCopyWarning: \n",
|
|||
|
|
"A value is trying to be set on a copy of a slice from a DataFrame.\n",
|
|||
|
|
"Try using .loc[row_indexer,col_indexer] = value instead\n",
|
|||
|
|
"\n",
|
|||
|
|
"See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n",
|
|||
|
|
" df['ADX_diff_3'] = df['ADX_5'] - df['ADX_2']\n",
|
|||
|
|
"/var/folders/l_/j4rfg9014yvd4jfvv441w26r0000gn/T/ipykernel_54914/4128738175.py:2: SettingWithCopyWarning: \n",
|
|||
|
|
"A value is trying to be set on a copy of a slice from a DataFrame.\n",
|
|||
|
|
"Try using .loc[row_indexer,col_indexer] = value instead\n",
|
|||
|
|
"\n",
|
|||
|
|
"See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n",
|
|||
|
|
" df['ADX_diff_9'] = df['ADX_14'] - df['ADX_5']\n",
|
|||
|
|
"/var/folders/l_/j4rfg9014yvd4jfvv441w26r0000gn/T/ipykernel_54914/4128738175.py:3: SettingWithCopyWarning: \n",
|
|||
|
|
"A value is trying to be set on a copy of a slice from a DataFrame.\n",
|
|||
|
|
"Try using .loc[row_indexer,col_indexer] = value instead\n",
|
|||
|
|
"\n",
|
|||
|
|
"See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n",
|
|||
|
|
" df['ADX_diff_12'] = df['ADX_14'] - df['ADX_2']\n",
|
|||
|
|
"/var/folders/l_/j4rfg9014yvd4jfvv441w26r0000gn/T/ipykernel_54914/4128738175.py:4: SettingWithCopyWarning: \n",
|
|||
|
|
"A value is trying to be set on a copy of a slice from a DataFrame.\n",
|
|||
|
|
"Try using .loc[row_indexer,col_indexer] = value instead\n",
|
|||
|
|
"\n",
|
|||
|
|
"See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n",
|
|||
|
|
" df['ADX_ratio_2_5'] = df['ADX_2'] / df['ADX_5']\n",
|
|||
|
|
"/var/folders/l_/j4rfg9014yvd4jfvv441w26r0000gn/T/ipykernel_54914/4128738175.py:5: SettingWithCopyWarning: \n",
|
|||
|
|
"A value is trying to be set on a copy of a slice from a DataFrame.\n",
|
|||
|
|
"Try using .loc[row_indexer,col_indexer] = value instead\n",
|
|||
|
|
"\n",
|
|||
|
|
"See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n",
|
|||
|
|
" df['ADX_ratio_5_14'] = df['ADX_5'] / df['ADX_14']\n",
|
|||
|
|
"/var/folders/l_/j4rfg9014yvd4jfvv441w26r0000gn/T/ipykernel_54914/4128738175.py:6: SettingWithCopyWarning: \n",
|
|||
|
|
"A value is trying to be set on a copy of a slice from a DataFrame.\n",
|
|||
|
|
"Try using .loc[row_indexer,col_indexer] = value instead\n",
|
|||
|
|
"\n",
|
|||
|
|
"See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n",
|
|||
|
|
" df['ADX_ratio_2_14'] = df['ADX_2'] / df['ADX_14']\n"
|
|||
|
|
]
|
|||
|
|
}
|
|||
|
|
],
|
|||
|
|
"source": [
|
|||
|
|
"df['ADX_diff_3'] = df['ADX_5'] - df['ADX_2']\n",
|
|||
|
|
"df['ADX_diff_9'] = df['ADX_14'] - df['ADX_5']\n",
|
|||
|
|
"df['ADX_diff_12'] = df['ADX_14'] - df['ADX_2']\n",
|
|||
|
|
"df['ADX_ratio_2_5'] = df['ADX_2'] / df['ADX_5']\n",
|
|||
|
|
"df['ADX_ratio_5_14'] = df['ADX_5'] / df['ADX_14']\n",
|
|||
|
|
"df['ADX_ratio_2_14'] = df['ADX_2'] / df['ADX_14']"
|
|||
|
|
]
|
|||
|
|
},
|
|||
|
|
{
|
|||
|
|
"cell_type": "code",
|
|||
|
|
"execution_count": 123,
|
|||
|
|
"metadata": {
|
|||
|
|
"colab": {
|
|||
|
|
"base_uri": "https://localhost:8080/"
|
|||
|
|
},
|
|||
|
|
"id": "-38A7MWM9tAJ",
|
|||
|
|
"outputId": "400182aa-25fa-4900-e078-2324dfff8d81"
|
|||
|
|
},
|
|||
|
|
"outputs": [
|
|||
|
|
{
|
|||
|
|
"name": "stderr",
|
|||
|
|
"output_type": "stream",
|
|||
|
|
"text": [
|
|||
|
|
"/var/folders/l_/j4rfg9014yvd4jfvv441w26r0000gn/T/ipykernel_54914/448491090.py:1: SettingWithCopyWarning: \n",
|
|||
|
|
"A value is trying to be set on a copy of a slice from a DataFrame.\n",
|
|||
|
|
"Try using .loc[row_indexer,col_indexer] = value instead\n",
|
|||
|
|
"\n",
|
|||
|
|
"See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n",
|
|||
|
|
" df['CCI_diff_6'] = df['CCI_8'] - df['CCI_2']\n",
|
|||
|
|
"/var/folders/l_/j4rfg9014yvd4jfvv441w26r0000gn/T/ipykernel_54914/448491090.py:2: SettingWithCopyWarning: \n",
|
|||
|
|
"A value is trying to be set on a copy of a slice from a DataFrame.\n",
|
|||
|
|
"Try using .loc[row_indexer,col_indexer] = value instead\n",
|
|||
|
|
"\n",
|
|||
|
|
"See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n",
|
|||
|
|
" df['CCI_diff_12'] = df['CCI_20'] - df['CCI_8']\n",
|
|||
|
|
"/var/folders/l_/j4rfg9014yvd4jfvv441w26r0000gn/T/ipykernel_54914/448491090.py:3: SettingWithCopyWarning: \n",
|
|||
|
|
"A value is trying to be set on a copy of a slice from a DataFrame.\n",
|
|||
|
|
"Try using .loc[row_indexer,col_indexer] = value instead\n",
|
|||
|
|
"\n",
|
|||
|
|
"See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n",
|
|||
|
|
" df['CCI_diff_18'] = df['CCI_20'] - df['CCI_2']\n",
|
|||
|
|
"/var/folders/l_/j4rfg9014yvd4jfvv441w26r0000gn/T/ipykernel_54914/448491090.py:4: SettingWithCopyWarning: \n",
|
|||
|
|
"A value is trying to be set on a copy of a slice from a DataFrame.\n",
|
|||
|
|
"Try using .loc[row_indexer,col_indexer] = value instead\n",
|
|||
|
|
"\n",
|
|||
|
|
"See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n",
|
|||
|
|
" df['CCI_ratio_2_8'] = df['CCI_2'] / df['CCI_8']\n",
|
|||
|
|
"/var/folders/l_/j4rfg9014yvd4jfvv441w26r0000gn/T/ipykernel_54914/448491090.py:5: SettingWithCopyWarning: \n",
|
|||
|
|
"A value is trying to be set on a copy of a slice from a DataFrame.\n",
|
|||
|
|
"Try using .loc[row_indexer,col_indexer] = value instead\n",
|
|||
|
|
"\n",
|
|||
|
|
"See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n",
|
|||
|
|
" df['CCI_ratio_8_20'] = df['CCI_8'] / df['CCI_20']\n",
|
|||
|
|
"/var/folders/l_/j4rfg9014yvd4jfvv441w26r0000gn/T/ipykernel_54914/448491090.py:6: SettingWithCopyWarning: \n",
|
|||
|
|
"A value is trying to be set on a copy of a slice from a DataFrame.\n",
|
|||
|
|
"Try using .loc[row_indexer,col_indexer] = value instead\n",
|
|||
|
|
"\n",
|
|||
|
|
"See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n",
|
|||
|
|
" df['CCI_ratio_2_20'] = df['CCI_2'] / df['CCI_20']\n"
|
|||
|
|
]
|
|||
|
|
}
|
|||
|
|
],
|
|||
|
|
"source": [
|
|||
|
|
"df['CCI_diff_6'] = df['CCI_8'] - df['CCI_2']\n",
|
|||
|
|
"df['CCI_diff_12'] = df['CCI_20'] - df['CCI_8']\n",
|
|||
|
|
"df['CCI_diff_18'] = df['CCI_20'] - df['CCI_2']\n",
|
|||
|
|
"df['CCI_ratio_2_8'] = df['CCI_2'] / df['CCI_8']\n",
|
|||
|
|
"df['CCI_ratio_8_20'] = df['CCI_8'] / df['CCI_20']\n",
|
|||
|
|
"df['CCI_ratio_2_20'] = df['CCI_2'] / df['CCI_20']"
|
|||
|
|
]
|
|||
|
|
},
|
|||
|
|
{
|
|||
|
|
"cell_type": "code",
|
|||
|
|
"execution_count": 124,
|
|||
|
|
"metadata": {
|
|||
|
|
"colab": {
|
|||
|
|
"base_uri": "https://localhost:8080/"
|
|||
|
|
},
|
|||
|
|
"id": "qMYkeMtQ-YJY",
|
|||
|
|
"outputId": "a7d43769-b59f-4dd0-db3a-c138d1cf2ed4"
|
|||
|
|
},
|
|||
|
|
"outputs": [
|
|||
|
|
{
|
|||
|
|
"name": "stderr",
|
|||
|
|
"output_type": "stream",
|
|||
|
|
"text": [
|
|||
|
|
"/var/folders/l_/j4rfg9014yvd4jfvv441w26r0000gn/T/ipykernel_54914/2351237557.py:1: SettingWithCopyWarning: \n",
|
|||
|
|
"A value is trying to be set on a copy of a slice from a DataFrame.\n",
|
|||
|
|
"Try using .loc[row_indexer,col_indexer] = value instead\n",
|
|||
|
|
"\n",
|
|||
|
|
"See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n",
|
|||
|
|
" df['CMO_diff_12'] = df['CMO_14'] - df['ADX_2']\n",
|
|||
|
|
"/var/folders/l_/j4rfg9014yvd4jfvv441w26r0000gn/T/ipykernel_54914/2351237557.py:2: SettingWithCopyWarning: \n",
|
|||
|
|
"A value is trying to be set on a copy of a slice from a DataFrame.\n",
|
|||
|
|
"Try using .loc[row_indexer,col_indexer] = value instead\n",
|
|||
|
|
"\n",
|
|||
|
|
"See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n",
|
|||
|
|
" df['CMO_ratio_2_14'] = df['CCI_2'] / df['CCI_14']\n",
|
|||
|
|
"/var/folders/l_/j4rfg9014yvd4jfvv441w26r0000gn/T/ipykernel_54914/2351237557.py:3: SettingWithCopyWarning: \n",
|
|||
|
|
"A value is trying to be set on a copy of a slice from a DataFrame.\n",
|
|||
|
|
"Try using .loc[row_indexer,col_indexer] = value instead\n",
|
|||
|
|
"\n",
|
|||
|
|
"See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n",
|
|||
|
|
" df['KeltnerWidth_diff_13'] = df['KeltnerWidth_15'] - df['KeltnerWidth_2']\n",
|
|||
|
|
"/var/folders/l_/j4rfg9014yvd4jfvv441w26r0000gn/T/ipykernel_54914/2351237557.py:4: SettingWithCopyWarning: \n",
|
|||
|
|
"A value is trying to be set on a copy of a slice from a DataFrame.\n",
|
|||
|
|
"Try using .loc[row_indexer,col_indexer] = value instead\n",
|
|||
|
|
"\n",
|
|||
|
|
"See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n",
|
|||
|
|
" df['KeltnerWidth_diff_22'] = df['KeltnerWidth_24'] - df['KeltnerWidth_2']\n",
|
|||
|
|
"/var/folders/l_/j4rfg9014yvd4jfvv441w26r0000gn/T/ipykernel_54914/2351237557.py:5: SettingWithCopyWarning: \n",
|
|||
|
|
"A value is trying to be set on a copy of a slice from a DataFrame.\n",
|
|||
|
|
"Try using .loc[row_indexer,col_indexer] = value instead\n",
|
|||
|
|
"\n",
|
|||
|
|
"See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n",
|
|||
|
|
" df['KeltnerWidth_diff_9'] = df['KeltnerWidth_24'] - df['KeltnerWidth_15']\n",
|
|||
|
|
"/var/folders/l_/j4rfg9014yvd4jfvv441w26r0000gn/T/ipykernel_54914/2351237557.py:6: SettingWithCopyWarning: \n",
|
|||
|
|
"A value is trying to be set on a copy of a slice from a DataFrame.\n",
|
|||
|
|
"Try using .loc[row_indexer,col_indexer] = value instead\n",
|
|||
|
|
"\n",
|
|||
|
|
"See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n",
|
|||
|
|
" df['KeltnerWidth_ratio_2_15'] = df['KeltnerWidth_2'] / df['KeltnerWidth_15']\n",
|
|||
|
|
"/var/folders/l_/j4rfg9014yvd4jfvv441w26r0000gn/T/ipykernel_54914/2351237557.py:7: SettingWithCopyWarning: \n",
|
|||
|
|
"A value is trying to be set on a copy of a slice from a DataFrame.\n",
|
|||
|
|
"Try using .loc[row_indexer,col_indexer] = value instead\n",
|
|||
|
|
"\n",
|
|||
|
|
"See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n",
|
|||
|
|
" df['KeltnerWidth_ratio_15_24'] = df['KeltnerWidth_15'] / df['KeltnerWidth_24']\n",
|
|||
|
|
"/var/folders/l_/j4rfg9014yvd4jfvv441w26r0000gn/T/ipykernel_54914/2351237557.py:8: SettingWithCopyWarning: \n",
|
|||
|
|
"A value is trying to be set on a copy of a slice from a DataFrame.\n",
|
|||
|
|
"Try using .loc[row_indexer,col_indexer] = value instead\n",
|
|||
|
|
"\n",
|
|||
|
|
"See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n",
|
|||
|
|
" df['KeltnerWidth_ratio_2_24'] = df['KeltnerWidth_2'] / df['KeltnerWidth_24']\n"
|
|||
|
|
]
|
|||
|
|
}
|
|||
|
|
],
|
|||
|
|
"source": [
|
|||
|
|
"df['CMO_diff_12'] = df['CMO_14'] - df['ADX_2']\n",
|
|||
|
|
"df['CMO_ratio_2_14'] = df['CCI_2'] / df['CCI_14']\n",
|
|||
|
|
"df['KeltnerWidth_diff_13'] = df['KeltnerWidth_15'] - df['KeltnerWidth_2']\n",
|
|||
|
|
"df['KeltnerWidth_diff_22'] = df['KeltnerWidth_24'] - df['KeltnerWidth_2']\n",
|
|||
|
|
"df['KeltnerWidth_diff_9'] = df['KeltnerWidth_24'] - df['KeltnerWidth_15']\n",
|
|||
|
|
"df['KeltnerWidth_ratio_2_15'] = df['KeltnerWidth_2'] / df['KeltnerWidth_15']\n",
|
|||
|
|
"df['KeltnerWidth_ratio_15_24'] = df['KeltnerWidth_15'] / df['KeltnerWidth_24']\n",
|
|||
|
|
"df['KeltnerWidth_ratio_2_24'] = df['KeltnerWidth_2'] / df['KeltnerWidth_24']"
|
|||
|
|
]
|
|||
|
|
},
|
|||
|
|
{
|
|||
|
|
"cell_type": "code",
|
|||
|
|
"execution_count": 125,
|
|||
|
|
"metadata": {
|
|||
|
|
"colab": {
|
|||
|
|
"base_uri": "https://localhost:8080/",
|
|||
|
|
"height": 444
|
|||
|
|
},
|
|||
|
|
"id": "G8zjp6uf_deD",
|
|||
|
|
"outputId": "3f1b4738-fc34-45b9-ce55-cbc6d71052ed"
|
|||
|
|
},
|
|||
|
|
"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>Open</th>\n",
|
|||
|
|
" <th>High</th>\n",
|
|||
|
|
" <th>Low</th>\n",
|
|||
|
|
" <th>Close</th>\n",
|
|||
|
|
" <th>Volume</th>\n",
|
|||
|
|
" <th>Session</th>\n",
|
|||
|
|
" <th>Quarter</th>\n",
|
|||
|
|
" <th>Month_sin</th>\n",
|
|||
|
|
" <th>Hour_sin</th>\n",
|
|||
|
|
" <th>Date_sin</th>\n",
|
|||
|
|
" <th>...</th>\n",
|
|||
|
|
" <th>CCI_ratio_8_20</th>\n",
|
|||
|
|
" <th>CCI_ratio_2_20</th>\n",
|
|||
|
|
" <th>CMO_diff_12</th>\n",
|
|||
|
|
" <th>CMO_ratio_2_14</th>\n",
|
|||
|
|
" <th>KeltnerWidth_diff_13</th>\n",
|
|||
|
|
" <th>KeltnerWidth_diff_22</th>\n",
|
|||
|
|
" <th>KeltnerWidth_diff_9</th>\n",
|
|||
|
|
" <th>KeltnerWidth_ratio_2_15</th>\n",
|
|||
|
|
" <th>KeltnerWidth_ratio_15_24</th>\n",
|
|||
|
|
" <th>KeltnerWidth_ratio_2_24</th>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" </thead>\n",
|
|||
|
|
" <tbody>\n",
|
|||
|
|
" <tr>\n",
|
|||
|
|
" <th>28</th>\n",
|
|||
|
|
" <td>1.34880</td>\n",
|
|||
|
|
" <td>1.34960</td>\n",
|
|||
|
|
" <td>1.34820</td>\n",
|
|||
|
|
" <td>1.34860</td>\n",
|
|||
|
|
" <td>331.0</td>\n",
|
|||
|
|
" <td>1</td>\n",
|
|||
|
|
" <td>1</td>\n",
|
|||
|
|
" <td>0.5</td>\n",
|
|||
|
|
" <td>0.96593</td>\n",
|
|||
|
|
" <td>0.74314</td>\n",
|
|||
|
|
" <td>...</td>\n",
|
|||
|
|
" <td>-32.989639</td>\n",
|
|||
|
|
" <td>-17.057143</td>\n",
|
|||
|
|
" <td>-82.813262</td>\n",
|
|||
|
|
" <td>0.470803</td>\n",
|
|||
|
|
" <td>0.000697</td>\n",
|
|||
|
|
" <td>0.001281</td>\n",
|
|||
|
|
" <td>0.000583</td>\n",
|
|||
|
|
" <td>0.609548</td>\n",
|
|||
|
|
" <td>0.753818</td>\n",
|
|||
|
|
" <td>0.459488</td>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" <tr>\n",
|
|||
|
|
" <th>29</th>\n",
|
|||
|
|
" <td>1.34840</td>\n",
|
|||
|
|
" <td>1.34970</td>\n",
|
|||
|
|
" <td>1.34810</td>\n",
|
|||
|
|
" <td>1.34910</td>\n",
|
|||
|
|
" <td>324.0</td>\n",
|
|||
|
|
" <td>1</td>\n",
|
|||
|
|
" <td>1</td>\n",
|
|||
|
|
" <td>0.5</td>\n",
|
|||
|
|
" <td>1.00000</td>\n",
|
|||
|
|
" <td>0.74314</td>\n",
|
|||
|
|
" <td>...</td>\n",
|
|||
|
|
" <td>10.711532</td>\n",
|
|||
|
|
" <td>7.213889</td>\n",
|
|||
|
|
" <td>-86.398829</td>\n",
|
|||
|
|
" <td>0.511278</td>\n",
|
|||
|
|
" <td>0.000558</td>\n",
|
|||
|
|
" <td>0.001121</td>\n",
|
|||
|
|
" <td>0.000564</td>\n",
|
|||
|
|
" <td>0.674174</td>\n",
|
|||
|
|
" <td>0.752199</td>\n",
|
|||
|
|
" <td>0.507113</td>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" <tr>\n",
|
|||
|
|
" <th>30</th>\n",
|
|||
|
|
" <td>1.34920</td>\n",
|
|||
|
|
" <td>1.34950</td>\n",
|
|||
|
|
" <td>1.34590</td>\n",
|
|||
|
|
" <td>1.34600</td>\n",
|
|||
|
|
" <td>345.0</td>\n",
|
|||
|
|
" <td>1</td>\n",
|
|||
|
|
" <td>1</td>\n",
|
|||
|
|
" <td>0.5</td>\n",
|
|||
|
|
" <td>0.96593</td>\n",
|
|||
|
|
" <td>0.74314</td>\n",
|
|||
|
|
" <td>...</td>\n",
|
|||
|
|
" <td>0.617531</td>\n",
|
|||
|
|
" <td>1.143775</td>\n",
|
|||
|
|
" <td>-99.281747</td>\n",
|
|||
|
|
" <td>1.652174</td>\n",
|
|||
|
|
" <td>-0.000335</td>\n",
|
|||
|
|
" <td>0.000140</td>\n",
|
|||
|
|
" <td>0.000475</td>\n",
|
|||
|
|
" <td>1.183191</td>\n",
|
|||
|
|
" <td>0.793926</td>\n",
|
|||
|
|
" <td>0.939366</td>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" <tr>\n",
|
|||
|
|
" <th>31</th>\n",
|
|||
|
|
" <td>1.34610</td>\n",
|
|||
|
|
" <td>1.34760</td>\n",
|
|||
|
|
" <td>1.34420</td>\n",
|
|||
|
|
" <td>1.34680</td>\n",
|
|||
|
|
" <td>462.0</td>\n",
|
|||
|
|
" <td>2</td>\n",
|
|||
|
|
" <td>1</td>\n",
|
|||
|
|
" <td>0.5</td>\n",
|
|||
|
|
" <td>0.86603</td>\n",
|
|||
|
|
" <td>0.74314</td>\n",
|
|||
|
|
" <td>...</td>\n",
|
|||
|
|
" <td>0.902003</td>\n",
|
|||
|
|
" <td>0.639500</td>\n",
|
|||
|
|
" <td>-100.097442</td>\n",
|
|||
|
|
" <td>0.608775</td>\n",
|
|||
|
|
" <td>-0.000487</td>\n",
|
|||
|
|
" <td>-0.000081</td>\n",
|
|||
|
|
" <td>0.000406</td>\n",
|
|||
|
|
" <td>1.254089</td>\n",
|
|||
|
|
" <td>0.825234</td>\n",
|
|||
|
|
" <td>1.034918</td>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" <tr>\n",
|
|||
|
|
" <th>32</th>\n",
|
|||
|
|
" <td>1.34690</td>\n",
|
|||
|
|
" <td>1.34720</td>\n",
|
|||
|
|
" <td>1.34110</td>\n",
|
|||
|
|
" <td>1.34210</td>\n",
|
|||
|
|
" <td>512.0</td>\n",
|
|||
|
|
" <td>1</td>\n",
|
|||
|
|
" <td>1</td>\n",
|
|||
|
|
" <td>0.5</td>\n",
|
|||
|
|
" <td>0.70711</td>\n",
|
|||
|
|
" <td>0.74314</td>\n",
|
|||
|
|
" <td>...</td>\n",
|
|||
|
|
" <td>0.755647</td>\n",
|
|||
|
|
" <td>0.264265</td>\n",
|
|||
|
|
" <td>-123.234395</td>\n",
|
|||
|
|
" <td>0.279337</td>\n",
|
|||
|
|
" <td>-0.001585</td>\n",
|
|||
|
|
" <td>-0.001329</td>\n",
|
|||
|
|
" <td>0.000256</td>\n",
|
|||
|
|
" <td>1.705978</td>\n",
|
|||
|
|
" <td>0.897678</td>\n",
|
|||
|
|
" <td>1.531419</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",
|
|||
|
|
" <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>118388</th>\n",
|
|||
|
|
" <td>1.03502</td>\n",
|
|||
|
|
" <td>1.03548</td>\n",
|
|||
|
|
" <td>1.03438</td>\n",
|
|||
|
|
" <td>1.03490</td>\n",
|
|||
|
|
" <td>2323.0</td>\n",
|
|||
|
|
" <td>1</td>\n",
|
|||
|
|
" <td>4</td>\n",
|
|||
|
|
" <td>-0.0</td>\n",
|
|||
|
|
" <td>-0.96593</td>\n",
|
|||
|
|
" <td>0.20791</td>\n",
|
|||
|
|
" <td>...</td>\n",
|
|||
|
|
" <td>0.499089</td>\n",
|
|||
|
|
" <td>0.306752</td>\n",
|
|||
|
|
" <td>-146.708669</td>\n",
|
|||
|
|
" <td>0.415789</td>\n",
|
|||
|
|
" <td>0.000175</td>\n",
|
|||
|
|
" <td>0.000087</td>\n",
|
|||
|
|
" <td>-0.000087</td>\n",
|
|||
|
|
" <td>0.885021</td>\n",
|
|||
|
|
" <td>1.060976</td>\n",
|
|||
|
|
" <td>0.938986</td>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" <tr>\n",
|
|||
|
|
" <th>118389</th>\n",
|
|||
|
|
" <td>1.03489</td>\n",
|
|||
|
|
" <td>1.03566</td>\n",
|
|||
|
|
" <td>1.03455</td>\n",
|
|||
|
|
" <td>1.03529</td>\n",
|
|||
|
|
" <td>1900.0</td>\n",
|
|||
|
|
" <td>1</td>\n",
|
|||
|
|
" <td>4</td>\n",
|
|||
|
|
" <td>-0.0</td>\n",
|
|||
|
|
" <td>-0.86603</td>\n",
|
|||
|
|
" <td>0.20791</td>\n",
|
|||
|
|
" <td>...</td>\n",
|
|||
|
|
" <td>0.474172</td>\n",
|
|||
|
|
" <td>-0.412832</td>\n",
|
|||
|
|
" <td>-120.580881</td>\n",
|
|||
|
|
" <td>-0.558554</td>\n",
|
|||
|
|
" <td>0.000301</td>\n",
|
|||
|
|
" <td>0.000241</td>\n",
|
|||
|
|
" <td>-0.000060</td>\n",
|
|||
|
|
" <td>0.794353</td>\n",
|
|||
|
|
" <td>1.042922</td>\n",
|
|||
|
|
" <td>0.828449</td>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" <tr>\n",
|
|||
|
|
" <th>118390</th>\n",
|
|||
|
|
" <td>1.03526</td>\n",
|
|||
|
|
" <td>1.03645</td>\n",
|
|||
|
|
" <td>1.03516</td>\n",
|
|||
|
|
" <td>1.03547</td>\n",
|
|||
|
|
" <td>1445.0</td>\n",
|
|||
|
|
" <td>1</td>\n",
|
|||
|
|
" <td>4</td>\n",
|
|||
|
|
" <td>-0.0</td>\n",
|
|||
|
|
" <td>-0.70711</td>\n",
|
|||
|
|
" <td>0.20791</td>\n",
|
|||
|
|
" <td>...</td>\n",
|
|||
|
|
" <td>0.389379</td>\n",
|
|||
|
|
" <td>-0.561173</td>\n",
|
|||
|
|
" <td>-101.534169</td>\n",
|
|||
|
|
" <td>-0.781851</td>\n",
|
|||
|
|
" <td>0.000219</td>\n",
|
|||
|
|
" <td>0.000173</td>\n",
|
|||
|
|
" <td>-0.000046</td>\n",
|
|||
|
|
" <td>0.847724</td>\n",
|
|||
|
|
" <td>1.032793</td>\n",
|
|||
|
|
" <td>0.875523</td>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" <tr>\n",
|
|||
|
|
" <th>118391</th>\n",
|
|||
|
|
" <td>1.03547</td>\n",
|
|||
|
|
" <td>1.03631</td>\n",
|
|||
|
|
" <td>1.03544</td>\n",
|
|||
|
|
" <td>1.03582</td>\n",
|
|||
|
|
" <td>1208.0</td>\n",
|
|||
|
|
" <td>0</td>\n",
|
|||
|
|
" <td>4</td>\n",
|
|||
|
|
" <td>-0.0</td>\n",
|
|||
|
|
" <td>-0.50000</td>\n",
|
|||
|
|
" <td>0.20791</td>\n",
|
|||
|
|
" <td>...</td>\n",
|
|||
|
|
" <td>0.274403</td>\n",
|
|||
|
|
" <td>-0.681386</td>\n",
|
|||
|
|
" <td>-87.924347</td>\n",
|
|||
|
|
" <td>-0.965948</td>\n",
|
|||
|
|
" <td>0.000397</td>\n",
|
|||
|
|
" <td>0.000381</td>\n",
|
|||
|
|
" <td>-0.000015</td>\n",
|
|||
|
|
" <td>0.708939</td>\n",
|
|||
|
|
" <td>1.011219</td>\n",
|
|||
|
|
" <td>0.716892</td>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" <tr>\n",
|
|||
|
|
" <th>118392</th>\n",
|
|||
|
|
" <td>1.03585</td>\n",
|
|||
|
|
" <td>1.03608</td>\n",
|
|||
|
|
" <td>1.03489</td>\n",
|
|||
|
|
" <td>1.03493</td>\n",
|
|||
|
|
" <td>616.0</td>\n",
|
|||
|
|
" <td>0</td>\n",
|
|||
|
|
" <td>4</td>\n",
|
|||
|
|
" <td>-0.0</td>\n",
|
|||
|
|
" <td>-0.25882</td>\n",
|
|||
|
|
" <td>0.20791</td>\n",
|
|||
|
|
" <td>...</td>\n",
|
|||
|
|
" <td>0.508487</td>\n",
|
|||
|
|
" <td>0.671512</td>\n",
|
|||
|
|
" <td>-91.887164</td>\n",
|
|||
|
|
" <td>0.912385</td>\n",
|
|||
|
|
" <td>0.000248</td>\n",
|
|||
|
|
" <td>0.000243</td>\n",
|
|||
|
|
" <td>-0.000004</td>\n",
|
|||
|
|
" <td>0.814725</td>\n",
|
|||
|
|
" <td>1.003260</td>\n",
|
|||
|
|
" <td>0.817381</td>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" </tbody>\n",
|
|||
|
|
"</table>\n",
|
|||
|
|
"<p>112986 rows × 54 columns</p>\n",
|
|||
|
|
"</div>"
|
|||
|
|
],
|
|||
|
|
"text/plain": [
|
|||
|
|
" Open High Low Close Volume Session Quarter \\\n",
|
|||
|
|
"28 1.34880 1.34960 1.34820 1.34860 331.0 1 1 \n",
|
|||
|
|
"29 1.34840 1.34970 1.34810 1.34910 324.0 1 1 \n",
|
|||
|
|
"30 1.34920 1.34950 1.34590 1.34600 345.0 1 1 \n",
|
|||
|
|
"31 1.34610 1.34760 1.34420 1.34680 462.0 2 1 \n",
|
|||
|
|
"32 1.34690 1.34720 1.34110 1.34210 512.0 1 1 \n",
|
|||
|
|
"... ... ... ... ... ... ... ... \n",
|
|||
|
|
"118388 1.03502 1.03548 1.03438 1.03490 2323.0 1 4 \n",
|
|||
|
|
"118389 1.03489 1.03566 1.03455 1.03529 1900.0 1 4 \n",
|
|||
|
|
"118390 1.03526 1.03645 1.03516 1.03547 1445.0 1 4 \n",
|
|||
|
|
"118391 1.03547 1.03631 1.03544 1.03582 1208.0 0 4 \n",
|
|||
|
|
"118392 1.03585 1.03608 1.03489 1.03493 616.0 0 4 \n",
|
|||
|
|
"\n",
|
|||
|
|
" Month_sin Hour_sin Date_sin ... CCI_ratio_8_20 CCI_ratio_2_20 \\\n",
|
|||
|
|
"28 0.5 0.96593 0.74314 ... -32.989639 -17.057143 \n",
|
|||
|
|
"29 0.5 1.00000 0.74314 ... 10.711532 7.213889 \n",
|
|||
|
|
"30 0.5 0.96593 0.74314 ... 0.617531 1.143775 \n",
|
|||
|
|
"31 0.5 0.86603 0.74314 ... 0.902003 0.639500 \n",
|
|||
|
|
"32 0.5 0.70711 0.74314 ... 0.755647 0.264265 \n",
|
|||
|
|
"... ... ... ... ... ... ... \n",
|
|||
|
|
"118388 -0.0 -0.96593 0.20791 ... 0.499089 0.306752 \n",
|
|||
|
|
"118389 -0.0 -0.86603 0.20791 ... 0.474172 -0.412832 \n",
|
|||
|
|
"118390 -0.0 -0.70711 0.20791 ... 0.389379 -0.561173 \n",
|
|||
|
|
"118391 -0.0 -0.50000 0.20791 ... 0.274403 -0.681386 \n",
|
|||
|
|
"118392 -0.0 -0.25882 0.20791 ... 0.508487 0.671512 \n",
|
|||
|
|
"\n",
|
|||
|
|
" CMO_diff_12 CMO_ratio_2_14 KeltnerWidth_diff_13 \\\n",
|
|||
|
|
"28 -82.813262 0.470803 0.000697 \n",
|
|||
|
|
"29 -86.398829 0.511278 0.000558 \n",
|
|||
|
|
"30 -99.281747 1.652174 -0.000335 \n",
|
|||
|
|
"31 -100.097442 0.608775 -0.000487 \n",
|
|||
|
|
"32 -123.234395 0.279337 -0.001585 \n",
|
|||
|
|
"... ... ... ... \n",
|
|||
|
|
"118388 -146.708669 0.415789 0.000175 \n",
|
|||
|
|
"118389 -120.580881 -0.558554 0.000301 \n",
|
|||
|
|
"118390 -101.534169 -0.781851 0.000219 \n",
|
|||
|
|
"118391 -87.924347 -0.965948 0.000397 \n",
|
|||
|
|
"118392 -91.887164 0.912385 0.000248 \n",
|
|||
|
|
"\n",
|
|||
|
|
" KeltnerWidth_diff_22 KeltnerWidth_diff_9 KeltnerWidth_ratio_2_15 \\\n",
|
|||
|
|
"28 0.001281 0.000583 0.609548 \n",
|
|||
|
|
"29 0.001121 0.000564 0.674174 \n",
|
|||
|
|
"30 0.000140 0.000475 1.183191 \n",
|
|||
|
|
"31 -0.000081 0.000406 1.254089 \n",
|
|||
|
|
"32 -0.001329 0.000256 1.705978 \n",
|
|||
|
|
"... ... ... ... \n",
|
|||
|
|
"118388 0.000087 -0.000087 0.885021 \n",
|
|||
|
|
"118389 0.000241 -0.000060 0.794353 \n",
|
|||
|
|
"118390 0.000173 -0.000046 0.847724 \n",
|
|||
|
|
"118391 0.000381 -0.000015 0.708939 \n",
|
|||
|
|
"118392 0.000243 -0.000004 0.814725 \n",
|
|||
|
|
"\n",
|
|||
|
|
" KeltnerWidth_ratio_15_24 KeltnerWidth_ratio_2_24 \n",
|
|||
|
|
"28 0.753818 0.459488 \n",
|
|||
|
|
"29 0.752199 0.507113 \n",
|
|||
|
|
"30 0.793926 0.939366 \n",
|
|||
|
|
"31 0.825234 1.034918 \n",
|
|||
|
|
"32 0.897678 1.531419 \n",
|
|||
|
|
"... ... ... \n",
|
|||
|
|
"118388 1.060976 0.938986 \n",
|
|||
|
|
"118389 1.042922 0.828449 \n",
|
|||
|
|
"118390 1.032793 0.875523 \n",
|
|||
|
|
"118391 1.011219 0.716892 \n",
|
|||
|
|
"118392 1.003260 0.817381 \n",
|
|||
|
|
"\n",
|
|||
|
|
"[112986 rows x 54 columns]"
|
|||
|
|
]
|
|||
|
|
},
|
|||
|
|
"execution_count": 125,
|
|||
|
|
"metadata": {},
|
|||
|
|
"output_type": "execute_result"
|
|||
|
|
}
|
|||
|
|
],
|
|||
|
|
"source": [
|
|||
|
|
"df.dropna()"
|
|||
|
|
]
|
|||
|
|
},
|
|||
|
|
{
|
|||
|
|
"cell_type": "markdown",
|
|||
|
|
"metadata": {
|
|||
|
|
"id": "c4OdjOyWBoj8"
|
|||
|
|
},
|
|||
|
|
"source": [
|
|||
|
|
"# Current Features Correlation Heat Map along with Pearson Clustered Feature Correlation\n",
|
|||
|
|
"\n",
|
|||
|
|
"* It can be seen that most features are uncorrleated and even the clustering shows that there are some cross features that are show correlation. We will filter among these after finding feature after finding feature importance in later stages"
|
|||
|
|
]
|
|||
|
|
},
|
|||
|
|
{
|
|||
|
|
"cell_type": "code",
|
|||
|
|
"execution_count": 126,
|
|||
|
|
"metadata": {
|
|||
|
|
"colab": {
|
|||
|
|
"base_uri": "https://localhost:8080/",
|
|||
|
|
"height": 1000
|
|||
|
|
},
|
|||
|
|
"id": "WdT8GMFj_-vR",
|
|||
|
|
"outputId": "072f5126-2b33-4320-c102-5e4461cfe3f8"
|
|||
|
|
},
|
|||
|
|
"outputs": [
|
|||
|
|
{
|
|||
|
|
"name": "stderr",
|
|||
|
|
"output_type": "stream",
|
|||
|
|
"text": [
|
|||
|
|
"/var/folders/l_/j4rfg9014yvd4jfvv441w26r0000gn/T/ipykernel_54914/1159260896.py:31: FutureWarning: The default value of numeric_only in DataFrame.corr is deprecated. In a future version, it will default to False. Select only valid columns or specify the value of numeric_only to silence this warning.\n",
|
|||
|
|
" corr = df.corr(method='pearson')\n"
|
|||
|
|
]
|
|||
|
|
},
|
|||
|
|
{
|
|||
|
|
"data": {
|
|||
|
|
"image/png": "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
|
|||
|
|
"text/plain": [
|
|||
|
|
"<Figure size 1400x1200 with 2 Axes>"
|
|||
|
|
]
|
|||
|
|
},
|
|||
|
|
"metadata": {},
|
|||
|
|
"output_type": "display_data"
|
|||
|
|
},
|
|||
|
|
{
|
|||
|
|
"data": {
|
|||
|
|
"image/png": "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
|
|||
|
|
"text/plain": [
|
|||
|
|
"<Figure size 1400x1400 with 4 Axes>"
|
|||
|
|
]
|
|||
|
|
},
|
|||
|
|
"metadata": {},
|
|||
|
|
"output_type": "display_data"
|
|||
|
|
}
|
|||
|
|
],
|
|||
|
|
"source": [
|
|||
|
|
"import pandas as pd\n",
|
|||
|
|
"import numpy as np\n",
|
|||
|
|
"import matplotlib.pyplot as plt\n",
|
|||
|
|
"import seaborn as sns\n",
|
|||
|
|
"\n",
|
|||
|
|
"# --- 1) List of features you provided ---\n",
|
|||
|
|
"features = [\n",
|
|||
|
|
" 'Session', 'Quarter', 'Month_sin', 'Hour_sin', 'Date_sin', 'DOW_sin',\n",
|
|||
|
|
" 'Diff_10Y_2Y', 'Oil_Volume', 'Oil_Close', 'Gold_Close',\n",
|
|||
|
|
" 'ADX_14', 'CCI_14', 'PPO_12_26', 'CMO_14', 'ChaikinVol_3_10', 'KeltnerWidth_20',\n",
|
|||
|
|
" 'ADX_2', 'ADX_5', 'CCI_2', 'CCI_8', 'CCI_20', 'PPO_2_6', 'CMO_2', 'CMO54',\n",
|
|||
|
|
" 'ChaikinVol_2_5', 'KeltnerWidth_2', 'KeltnerWidth_15', 'KeltnerWidth_24',\n",
|
|||
|
|
" 'ADX_diff_3', 'ADX_diff_9', 'ADX_diff_12', 'ADX_ratio_2_5', 'ADX_ratio_5_14', 'ADX_ratio_2_14',\n",
|
|||
|
|
" 'CCI_diff_6', 'CCI_diff_12', 'CCI_diff_18', 'CCI_ratio_2_8', 'CCI_ratio_8_20', 'CCI_ratio_2_20',\n",
|
|||
|
|
" 'CMO_diff_12', 'CMO_ratio_2_14',\n",
|
|||
|
|
" 'KeltnerWidth_diff_13', 'KeltnerWidth_diff_22', 'KeltnerWidth_diff_9',\n",
|
|||
|
|
" 'KeltnerWidth_ratio_2_15', 'KeltnerWidth_ratio_15_24', 'KeltnerWidth_ratio_2_24'\n",
|
|||
|
|
"]\n",
|
|||
|
|
"\n",
|
|||
|
|
"# --- 2) Keep only columns that exist in df ---\n",
|
|||
|
|
"features = [c for c in features if c in df.columns]\n",
|
|||
|
|
"\n",
|
|||
|
|
"# --- 3) Coerce to numeric (if any are strings) & drop non-numeric/constant cols ---\n",
|
|||
|
|
"df_feat = df[features].apply(pd.to_numeric, errors='coerce')\n",
|
|||
|
|
"\n",
|
|||
|
|
"# # Drop columns that are all NaN or constant (std == 0)\n",
|
|||
|
|
"non_constant = df_feat.columns[(df_feat.nunique(dropna=True) > 1)]\n",
|
|||
|
|
"df_feat = df_feat[non_constant].dropna(how='all')\n",
|
|||
|
|
"\n",
|
|||
|
|
"# --- 4) Correlation matrix ---\n",
|
|||
|
|
"corr = df.corr(method='pearson')\n",
|
|||
|
|
"\n",
|
|||
|
|
"# --- 5) Pretty heatmap (masked upper triangle for readability) ---\n",
|
|||
|
|
"mask = np.triu(np.ones_like(corr, dtype=bool))\n",
|
|||
|
|
"plt.figure(figsize=(14, 12))\n",
|
|||
|
|
"sns.heatmap(\n",
|
|||
|
|
" corr, mask=mask, annot=False, fmt=\".2f\",\n",
|
|||
|
|
" cmap=\"coolwarm\", vmin=-1, vmax=1,\n",
|
|||
|
|
" square=True, linewidths=0.5, cbar_kws={\"shrink\": 0.8}\n",
|
|||
|
|
")\n",
|
|||
|
|
"plt.title(\"Feature Correlation Heatmap (Pearson)\")\n",
|
|||
|
|
"plt.tight_layout()\n",
|
|||
|
|
"plt.show()\n",
|
|||
|
|
"\n",
|
|||
|
|
"# --- 6) (Optional) Clustered heatmap to group similar features ---\n",
|
|||
|
|
"# Comment out if you don't want it\n",
|
|||
|
|
"sns.clustermap(\n",
|
|||
|
|
" corr.fillna(0), cmap=\"coolwarm\", vmin=-1, vmax=1,\n",
|
|||
|
|
" figsize=(14, 14), linewidths=0.3, annot=False,\n",
|
|||
|
|
" cbar_kws={\"shrink\": 0.8}\n",
|
|||
|
|
")\n",
|
|||
|
|
"plt.suptitle(\"Clustered Feature Correlation (Pearson)\", y=1.02)\n",
|
|||
|
|
"plt.show()\n"
|
|||
|
|
]
|
|||
|
|
},
|
|||
|
|
{
|
|||
|
|
"cell_type": "markdown",
|
|||
|
|
"metadata": {
|
|||
|
|
"id": "SyWvRmwZPS6A"
|
|||
|
|
},
|
|||
|
|
"source": [
|
|||
|
|
"# Underlying Trading Strategy Signal Generation as a Feature\n",
|
|||
|
|
"\n",
|
|||
|
|
"* First signals will be generated then based on PnL, we will prepare the Target signal feature for the machine such that it understands the good and bad trades and gives out its own signal.\n",
|
|||
|
|
"* To do this we will label the trades using PnL such that trades with return greater than 0.1% will be label as Profit and trades with return less than -0.1% will be labeld as loss and trades with return between -0.1% and 0.1% will be labeled neutral.\n",
|
|||
|
|
"* So during profit label, the target signal variable will not change the signal. During loss label, the target signal variable will be reversed and during neutral label, the signal will be 0 to not do anything."
|
|||
|
|
]
|
|||
|
|
},
|
|||
|
|
{
|
|||
|
|
"cell_type": "code",
|
|||
|
|
"execution_count": 38,
|
|||
|
|
"metadata": {
|
|||
|
|
"colab": {
|
|||
|
|
"base_uri": "https://localhost:8080/"
|
|||
|
|
},
|
|||
|
|
"id": "KyO7p78wby5Y",
|
|||
|
|
"outputId": "34d4b0af-2d34-41a3-f611-395da6a011e9"
|
|||
|
|
},
|
|||
|
|
"outputs": [
|
|||
|
|
{
|
|||
|
|
"name": "stderr",
|
|||
|
|
"output_type": "stream",
|
|||
|
|
"text": [
|
|||
|
|
"/var/folders/l_/j4rfg9014yvd4jfvv441w26r0000gn/T/ipykernel_16708/2837943448.py:15: SettingWithCopyWarning: \n",
|
|||
|
|
"A value is trying to be set on a copy of a slice from a DataFrame.\n",
|
|||
|
|
"Try using .loc[row_indexer,col_indexer] = value instead\n",
|
|||
|
|
"\n",
|
|||
|
|
"See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n",
|
|||
|
|
" df[col] = pd.to_numeric(df[col], errors=\"coerce\")\n"
|
|||
|
|
]
|
|||
|
|
}
|
|||
|
|
],
|
|||
|
|
"source": [
|
|||
|
|
"import numpy as np\n",
|
|||
|
|
"import pandas as pd\n",
|
|||
|
|
"\n",
|
|||
|
|
"# ---------------- Parameters (your specification) ----------------\n",
|
|||
|
|
"EMA_WIN = 500 # rolling EMA window\n",
|
|||
|
|
"SMA_WIN = 2000 # rolling SMA window\n",
|
|||
|
|
"\n",
|
|||
|
|
"TP_PCT = 0.005 # 1% take-profit (applies to both long & short)\n",
|
|||
|
|
"SL_PCT = 0.0 # stop-loss (0 disables SL). Set >0 if you want an SL.\n",
|
|||
|
|
"MAX_HOLD_LONG = 240 # bars to force-close long (time-based exit)\n",
|
|||
|
|
"MAX_HOLD_SHORT = 240 # bars to force-close short (time-based exit)\n",
|
|||
|
|
"\n",
|
|||
|
|
"# ---------------- Pre-req: df must exist with Open, High, Low, Close ----------------\n",
|
|||
|
|
"for col in [\"Open\", \"High\", \"Low\", \"Close\"]:\n",
|
|||
|
|
" df[col] = pd.to_numeric(df[col], errors=\"coerce\")\n",
|
|||
|
|
"df = df.dropna(subset=[\"Open\", \"High\", \"Low\", \"Close\"]).copy()\n",
|
|||
|
|
"n = len(df)\n",
|
|||
|
|
"\n",
|
|||
|
|
"# ---------------- Indicators (no lookahead) ----------------\n",
|
|||
|
|
"# EMA aligned to current bar, SMA aligned to current bar\n",
|
|||
|
|
"df[\"ema\"] = df[\"Close\"].ewm(span=EMA_WIN, adjust=False, min_periods=EMA_WIN).mean()\n",
|
|||
|
|
"df[\"sma\"] = df[\"Close\"].rolling(window=SMA_WIN, min_periods=SMA_WIN).mean()\n",
|
|||
|
|
"\n",
|
|||
|
|
"# ---------------- schedule/action arrays ----------------\n",
|
|||
|
|
"# Action codes:\n",
|
|||
|
|
"# 0 none, 1=open long (OL), 2=close long (CL), 3=open short (OS), 4=close short (CS)\n",
|
|||
|
|
"act = np.zeros(n, dtype=np.int8)\n",
|
|||
|
|
"\n",
|
|||
|
|
"def action_to_signal(code: int) -> int:\n",
|
|||
|
|
" \"\"\"Map internal action codes to single-column signals:\n",
|
|||
|
|
" 1 or 4 -> +1 (buy), 2 or 3 -> -1 (sell)\n",
|
|||
|
|
" \"\"\"\n",
|
|||
|
|
" if code in (1, 4):\n",
|
|||
|
|
" return +1\n",
|
|||
|
|
" if code in (2, 3):\n",
|
|||
|
|
" return -1\n",
|
|||
|
|
" return 0\n",
|
|||
|
|
"\n",
|
|||
|
|
"def place_action(idx: int, code: int, prefer_close=True):\n",
|
|||
|
|
" \"\"\"Place action at idx or push forward to next free bar.\n",
|
|||
|
|
" If prefer_close and placing a close onto an existing open,\n",
|
|||
|
|
" swap and push the open forward (so closes override opens).\n",
|
|||
|
|
" \"\"\"\n",
|
|||
|
|
" if idx >= n:\n",
|
|||
|
|
" return\n",
|
|||
|
|
" j = idx\n",
|
|||
|
|
" while j < n:\n",
|
|||
|
|
" if act[j] == 0:\n",
|
|||
|
|
" act[j] = code\n",
|
|||
|
|
" return\n",
|
|||
|
|
" if prefer_close and code in (2, 4) and act[j] in (1, 3):\n",
|
|||
|
|
" existing = act[j]\n",
|
|||
|
|
" act[j] = code\n",
|
|||
|
|
" j2 = j + 1\n",
|
|||
|
|
" while j2 < n and act[j2] != 0:\n",
|
|||
|
|
" j2 += 1\n",
|
|||
|
|
" if j2 < n:\n",
|
|||
|
|
" act[j2] = existing\n",
|
|||
|
|
" return\n",
|
|||
|
|
" j += 1\n",
|
|||
|
|
" # ran out of room -> dropped\n",
|
|||
|
|
"\n",
|
|||
|
|
"# ---------------- convenience arrays ----------------\n",
|
|||
|
|
"O = df[\"Open\"].to_numpy()\n",
|
|||
|
|
"H = df[\"High\"].to_numpy()\n",
|
|||
|
|
"L = df[\"Low\"].to_numpy()\n",
|
|||
|
|
"C = df[\"Close\"].to_numpy()\n",
|
|||
|
|
"EMA = df[\"ema\"].to_numpy()\n",
|
|||
|
|
"SMA = df[\"sma\"].to_numpy()\n",
|
|||
|
|
"\n",
|
|||
|
|
"# ---------------- position state ----------------\n",
|
|||
|
|
"long_open = False\n",
|
|||
|
|
"long_entry_idx = None\n",
|
|||
|
|
"long_entry_px = None\n",
|
|||
|
|
"long_close_pending = False\n",
|
|||
|
|
"\n",
|
|||
|
|
"short_open = False\n",
|
|||
|
|
"short_entry_idx = None\n",
|
|||
|
|
"short_entry_px = None\n",
|
|||
|
|
"short_close_pending = False\n",
|
|||
|
|
"\n",
|
|||
|
|
"# ---------------- Walk bars ----------------\n",
|
|||
|
|
"for i in range(n):\n",
|
|||
|
|
" # 0) Execute scheduled action for THIS bar\n",
|
|||
|
|
" code = int(act[i])\n",
|
|||
|
|
" if code == 1: # open long\n",
|
|||
|
|
" long_open = True\n",
|
|||
|
|
" long_entry_idx = i\n",
|
|||
|
|
" long_entry_px = C[i]\n",
|
|||
|
|
" long_close_pending = False\n",
|
|||
|
|
" elif code == 2: # close long\n",
|
|||
|
|
" long_open = False\n",
|
|||
|
|
" long_entry_idx = None\n",
|
|||
|
|
" long_entry_px = None\n",
|
|||
|
|
" long_close_pending = False\n",
|
|||
|
|
" elif code == 3: # open short\n",
|
|||
|
|
" short_open = True\n",
|
|||
|
|
" short_entry_idx = i\n",
|
|||
|
|
" short_entry_px = C[i]\n",
|
|||
|
|
" short_close_pending = False\n",
|
|||
|
|
" elif code == 4: # close short\n",
|
|||
|
|
" short_open = False\n",
|
|||
|
|
" short_entry_idx = None\n",
|
|||
|
|
" short_entry_px = None\n",
|
|||
|
|
" short_close_pending = False\n",
|
|||
|
|
"\n",
|
|||
|
|
" # 1) Manage LONG exits: TP / SL (if enabled) / time-based -> schedule close NEXT bar\n",
|
|||
|
|
" if long_open and not long_close_pending and long_entry_px is not None:\n",
|
|||
|
|
" tp = long_entry_px * (1.0 + TP_PCT)\n",
|
|||
|
|
" sl = long_entry_px * (1.0 - SL_PCT) if SL_PCT > 0 else None\n",
|
|||
|
|
" hit_tp = H[i] >= tp\n",
|
|||
|
|
" hit_sl = (L[i] <= sl) if (SL_PCT > 0) else False\n",
|
|||
|
|
" timeup = (MAX_HOLD_LONG > 0) and (i - long_entry_idx >= MAX_HOLD_LONG)\n",
|
|||
|
|
"\n",
|
|||
|
|
" # conservative intrabar rule: if both touched, treat as SL (worse case)\n",
|
|||
|
|
" if hit_tp and hit_sl:\n",
|
|||
|
|
" hit_tp = False\n",
|
|||
|
|
" hit_sl = True\n",
|
|||
|
|
"\n",
|
|||
|
|
" if hit_tp or hit_sl or timeup:\n",
|
|||
|
|
" place_action(i + 1, 2, prefer_close=True) # close long next bar\n",
|
|||
|
|
" long_close_pending = True\n",
|
|||
|
|
"\n",
|
|||
|
|
" # 2) Manage SHORT exits: TP / SL (if enabled) / time-based -> schedule close NEXT bar\n",
|
|||
|
|
" if short_open and not short_close_pending and short_entry_px is not None:\n",
|
|||
|
|
" tp_s = short_entry_px * (1.0 - TP_PCT) # for short, TP is lower price\n",
|
|||
|
|
" sl_s = short_entry_px * (1.0 + SL_PCT) if SL_PCT > 0 else None\n",
|
|||
|
|
" hit_tp_s = L[i] <= tp_s\n",
|
|||
|
|
" hit_sl_s = (H[i] >= sl_s) if (SL_PCT > 0) else False\n",
|
|||
|
|
" timeup_s = (MAX_HOLD_SHORT > 0) and (i - short_entry_idx >= MAX_HOLD_SHORT)\n",
|
|||
|
|
"\n",
|
|||
|
|
" # conservative intrabar rule: if both touched, treat as SL (worse case)\n",
|
|||
|
|
" if hit_tp_s and hit_sl_s:\n",
|
|||
|
|
" hit_tp_s = False\n",
|
|||
|
|
" hit_sl_s = True\n",
|
|||
|
|
"\n",
|
|||
|
|
" if hit_tp_s or hit_sl_s or timeup_s:\n",
|
|||
|
|
" place_action(i + 1, 4, prefer_close=True) # close short next bar\n",
|
|||
|
|
" short_close_pending = True\n",
|
|||
|
|
"\n",
|
|||
|
|
" # 3) Entry logic (based on indicator cross; place entry for NEXT bar)\n",
|
|||
|
|
" # Only open if flat (no long and no short currently open) and there is room\n",
|
|||
|
|
" if (not long_open) and (not short_open) and (i + 1 < n):\n",
|
|||
|
|
" # require both indicators to be not-NaN for comparison\n",
|
|||
|
|
" if not np.isnan(EMA[i]) and not np.isnan(SMA[i]):\n",
|
|||
|
|
" if EMA[i] > SMA[i]:\n",
|
|||
|
|
" place_action(i + 1, 1, prefer_close=False) # open long next bar\n",
|
|||
|
|
" elif SMA[i] > EMA[i]:\n",
|
|||
|
|
" place_action(i + 1, 3, prefer_close=False) # open short next bar\n",
|
|||
|
|
" # if equal -> no action\n",
|
|||
|
|
"\n",
|
|||
|
|
"# 4) Force-close any leftover positions at the end (close on last bar)\n",
|
|||
|
|
"# If a close was already scheduled beyond last bar it was dropped; so ensure we close at last bar\n",
|
|||
|
|
"if long_open:\n",
|
|||
|
|
" place_action(n - 1, 2, prefer_close=True)\n",
|
|||
|
|
"if short_open:\n",
|
|||
|
|
" place_action(n - 1, 4, prefer_close=True)\n",
|
|||
|
|
"\n",
|
|||
|
|
"# 5) Build single-column signal from actions\n",
|
|||
|
|
"df[\"signal\"] = np.fromiter((action_to_signal(x) for x in act), dtype=int, count=n)\n",
|
|||
|
|
"\n",
|
|||
|
|
"\n"
|
|||
|
|
]
|
|||
|
|
},
|
|||
|
|
{
|
|||
|
|
"cell_type": "code",
|
|||
|
|
"execution_count": 41,
|
|||
|
|
"metadata": {
|
|||
|
|
"id": "wds1reib6iYp"
|
|||
|
|
},
|
|||
|
|
"outputs": [],
|
|||
|
|
"source": [
|
|||
|
|
"import numpy as np\n",
|
|||
|
|
"\n",
|
|||
|
|
"# Ensure the column exists\n",
|
|||
|
|
"df['pnl'] = np.nan\n",
|
|||
|
|
"\n",
|
|||
|
|
"pos = 0 # 0 = flat, +1 = long, -1 = short\n",
|
|||
|
|
"entry_i = None\n",
|
|||
|
|
"entry_px = None\n",
|
|||
|
|
"\n",
|
|||
|
|
"# (optional) keep a trade id to inspect later\n",
|
|||
|
|
"trade_id = np.full(len(df), np.nan, dtype=float)\n",
|
|||
|
|
"tid = 0\n",
|
|||
|
|
"\n",
|
|||
|
|
"sig = df['signal'].to_numpy()\n",
|
|||
|
|
"px = df['Close'].to_numpy()\n",
|
|||
|
|
"\n",
|
|||
|
|
"for i in range(len(df)):\n",
|
|||
|
|
" s = sig[i]\n",
|
|||
|
|
"\n",
|
|||
|
|
" if pos == 0:\n",
|
|||
|
|
" if s == 1: # open long\n",
|
|||
|
|
" pos = 1\n",
|
|||
|
|
" entry_i = i\n",
|
|||
|
|
" entry_px = px[i]\n",
|
|||
|
|
" tid += 1\n",
|
|||
|
|
" elif s == -1: # open short\n",
|
|||
|
|
" pos = -1\n",
|
|||
|
|
" entry_i = i\n",
|
|||
|
|
" entry_px = px[i]\n",
|
|||
|
|
" tid += 1\n",
|
|||
|
|
"\n",
|
|||
|
|
" elif pos == 1:\n",
|
|||
|
|
" if s == -1: # close long\n",
|
|||
|
|
" pnl = ((px[i] - entry_px) / entry_px)*100\n",
|
|||
|
|
" df.iloc[entry_i:i+1, df.columns.get_loc('pnl')] = pnl\n",
|
|||
|
|
" trade_id[entry_i:i+1] = tid\n",
|
|||
|
|
" pos = 0\n",
|
|||
|
|
" entry_i = entry_px = None\n",
|
|||
|
|
"\n",
|
|||
|
|
" elif pos == -1:\n",
|
|||
|
|
" if s == 1: # close short (using your same formula)\n",
|
|||
|
|
" pnl = ((-px[i] +entry_px) / entry_px)*100\n",
|
|||
|
|
" df.iloc[entry_i:i+1, df.columns.get_loc('pnl')] = pnl\n",
|
|||
|
|
" trade_id[entry_i:i+1] = tid\n",
|
|||
|
|
" pos = 0\n",
|
|||
|
|
" entry_i = entry_px = None\n",
|
|||
|
|
"\n",
|
|||
|
|
"\n",
|
|||
|
|
"\n"
|
|||
|
|
]
|
|||
|
|
},
|
|||
|
|
{
|
|||
|
|
"cell_type": "code",
|
|||
|
|
"execution_count": 42,
|
|||
|
|
"metadata": {
|
|||
|
|
"id": "9jyhLNi1-Nug"
|
|||
|
|
},
|
|||
|
|
"outputs": [],
|
|||
|
|
"source": [
|
|||
|
|
"\n",
|
|||
|
|
"\n",
|
|||
|
|
"df['pnl_label'] = np.where(df['pnl'] > 0.1, 'Profit',np.where(df['pnl'] < -0.1, 'Loss', 'Neutral'))\n"
|
|||
|
|
]
|
|||
|
|
},
|
|||
|
|
{
|
|||
|
|
"cell_type": "markdown",
|
|||
|
|
"metadata": {
|
|||
|
|
"id": "FOXl4QunjFgY"
|
|||
|
|
},
|
|||
|
|
"source": [
|
|||
|
|
"## Target Signal Creation based on the signal and pnl of the underlying strategy"
|
|||
|
|
]
|
|||
|
|
},
|
|||
|
|
{
|
|||
|
|
"cell_type": "code",
|
|||
|
|
"execution_count": 43,
|
|||
|
|
"metadata": {
|
|||
|
|
"id": "7Za0BDCYTzqO"
|
|||
|
|
},
|
|||
|
|
"outputs": [],
|
|||
|
|
"source": [
|
|||
|
|
"import numpy as np\n",
|
|||
|
|
"\n",
|
|||
|
|
"# target_signal rules:\n",
|
|||
|
|
"# - 'Neutral' -> 0\n",
|
|||
|
|
"# - 'Loss' -> reverse sign\n",
|
|||
|
|
"# - 'Profit' -> keep as is\n",
|
|||
|
|
"df['target_signal'] = np.select(\n",
|
|||
|
|
" [\n",
|
|||
|
|
" df['pnl_label'].eq('Neutral'),\n",
|
|||
|
|
" df['pnl_label'].eq('Loss')\n",
|
|||
|
|
" ],\n",
|
|||
|
|
" [\n",
|
|||
|
|
" 0,\n",
|
|||
|
|
" -df['signal']\n",
|
|||
|
|
" ],\n",
|
|||
|
|
" default=df['signal']\n",
|
|||
|
|
").astype(int)\n"
|
|||
|
|
]
|
|||
|
|
},
|
|||
|
|
{
|
|||
|
|
"cell_type": "code",
|
|||
|
|
"execution_count": 44,
|
|||
|
|
"metadata": {
|
|||
|
|
"id": "RpEyiY6Ni7QO"
|
|||
|
|
},
|
|||
|
|
"outputs": [],
|
|||
|
|
"source": [
|
|||
|
|
"df = df.drop(columns=['pnl', 'trade_id', 'pnl_label'])"
|
|||
|
|
]
|
|||
|
|
},
|
|||
|
|
{
|
|||
|
|
"cell_type": "code",
|
|||
|
|
"execution_count": 45,
|
|||
|
|
"metadata": {
|
|||
|
|
"id": "CFdQFcb8lIL3"
|
|||
|
|
},
|
|||
|
|
"outputs": [],
|
|||
|
|
"source": [
|
|||
|
|
"df = df.iloc[2000:].reset_index(drop=True)\n"
|
|||
|
|
]
|
|||
|
|
},
|
|||
|
|
{
|
|||
|
|
"cell_type": "code",
|
|||
|
|
"execution_count": null,
|
|||
|
|
"metadata": {},
|
|||
|
|
"outputs": [],
|
|||
|
|
"source": [
|
|||
|
|
"# 70% train, 30% test (time-order safe, no shuffling)\n",
|
|||
|
|
"split_idx = int(len(df) * 0.7)\n",
|
|||
|
|
"\n",
|
|||
|
|
"train_df = df.iloc[:split_idx].copy()\n",
|
|||
|
|
"test_df = df.iloc[split_idx:].copy()\n",
|
|||
|
|
"\n",
|
|||
|
|
"test_df = test_df.drop(columns=[\"target_signal\"])"
|
|||
|
|
]
|
|||
|
|
},
|
|||
|
|
{
|
|||
|
|
"cell_type": "markdown",
|
|||
|
|
"metadata": {
|
|||
|
|
"id": "OG3V9ZArkU1J"
|
|||
|
|
},
|
|||
|
|
"source": [
|
|||
|
|
"# Final Feature Selection by importance and theory using random forest\n",
|
|||
|
|
"\n",
|
|||
|
|
"* In order to avoid any kind of look-ahead bias, I have split the df to 2 parts, one for training with 70% and the other to test with 30% and named them train_data and test_data.\n",
|
|||
|
|
"* In the testing, we have further removed target_signal column also."
|
|||
|
|
]
|
|||
|
|
},
|
|||
|
|
{
|
|||
|
|
"cell_type": "code",
|
|||
|
|
"execution_count": 55,
|
|||
|
|
"metadata": {
|
|||
|
|
"id": "waCH26Xpr4vD"
|
|||
|
|
},
|
|||
|
|
"outputs": [],
|
|||
|
|
"source": [
|
|||
|
|
"train_df.fillna(0, inplace=True)"
|
|||
|
|
]
|
|||
|
|
},
|
|||
|
|
{
|
|||
|
|
"cell_type": "code",
|
|||
|
|
"execution_count": 56,
|
|||
|
|
"metadata": {},
|
|||
|
|
"outputs": [],
|
|||
|
|
"source": [
|
|||
|
|
"# Remove rows where all columns are 0\n",
|
|||
|
|
"train_df = train_df.loc[~(train_df.eq(0).all(axis=1))].copy()\n"
|
|||
|
|
]
|
|||
|
|
},
|
|||
|
|
{
|
|||
|
|
"cell_type": "code",
|
|||
|
|
"execution_count": 50,
|
|||
|
|
"metadata": {
|
|||
|
|
"id": "8djjW2uWkUjy"
|
|||
|
|
},
|
|||
|
|
"outputs": [
|
|||
|
|
{
|
|||
|
|
"name": "stdout",
|
|||
|
|
"output_type": "stream",
|
|||
|
|
"text": [
|
|||
|
|
"\n",
|
|||
|
|
"Top features by OUT-OF-SAMPLE permutation importance (mean across folds):\n",
|
|||
|
|
"\n"
|
|||
|
|
]
|
|||
|
|
},
|
|||
|
|
{
|
|||
|
|
"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>model_importance_mean</th>\n",
|
|||
|
|
" <th>model_importance_std</th>\n",
|
|||
|
|
" <th>perm_importance_mean</th>\n",
|
|||
|
|
" <th>perm_importance_std</th>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" </thead>\n",
|
|||
|
|
" <tbody>\n",
|
|||
|
|
" <tr>\n",
|
|||
|
|
" <th>signal</th>\n",
|
|||
|
|
" <td>0.306649</td>\n",
|
|||
|
|
" <td>0.042522</td>\n",
|
|||
|
|
" <td>0.011702</td>\n",
|
|||
|
|
" <td>0.002480</td>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" <tr>\n",
|
|||
|
|
" <th>CMO_14</th>\n",
|
|||
|
|
" <td>0.028196</td>\n",
|
|||
|
|
" <td>0.000615</td>\n",
|
|||
|
|
" <td>0.001137</td>\n",
|
|||
|
|
" <td>0.000429</td>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" <tr>\n",
|
|||
|
|
" <th>ADX_5</th>\n",
|
|||
|
|
" <td>0.028298</td>\n",
|
|||
|
|
" <td>0.001057</td>\n",
|
|||
|
|
" <td>0.000819</td>\n",
|
|||
|
|
" <td>0.000296</td>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" <tr>\n",
|
|||
|
|
" <th>PPO_2_6</th>\n",
|
|||
|
|
" <td>0.027918</td>\n",
|
|||
|
|
" <td>0.000813</td>\n",
|
|||
|
|
" <td>0.000595</td>\n",
|
|||
|
|
" <td>0.000526</td>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" <tr>\n",
|
|||
|
|
" <th>CCI_ratio_2_20</th>\n",
|
|||
|
|
" <td>0.016868</td>\n",
|
|||
|
|
" <td>0.002119</td>\n",
|
|||
|
|
" <td>0.000582</td>\n",
|
|||
|
|
" <td>0.000256</td>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" <tr>\n",
|
|||
|
|
" <th>CCI_20</th>\n",
|
|||
|
|
" <td>0.022840</td>\n",
|
|||
|
|
" <td>0.001432</td>\n",
|
|||
|
|
" <td>0.000391</td>\n",
|
|||
|
|
" <td>0.000319</td>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" <tr>\n",
|
|||
|
|
" <th>KeltnerWidth_ratio_15_24</th>\n",
|
|||
|
|
" <td>0.020487</td>\n",
|
|||
|
|
" <td>0.000306</td>\n",
|
|||
|
|
" <td>0.000365</td>\n",
|
|||
|
|
" <td>0.000174</td>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" <tr>\n",
|
|||
|
|
" <th>CMO_ratio_2_14</th>\n",
|
|||
|
|
" <td>0.015399</td>\n",
|
|||
|
|
" <td>0.002409</td>\n",
|
|||
|
|
" <td>0.000341</td>\n",
|
|||
|
|
" <td>0.000282</td>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" <tr>\n",
|
|||
|
|
" <th>CCI_ratio_8_20</th>\n",
|
|||
|
|
" <td>0.015631</td>\n",
|
|||
|
|
" <td>0.001033</td>\n",
|
|||
|
|
" <td>0.000318</td>\n",
|
|||
|
|
" <td>0.000115</td>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" <tr>\n",
|
|||
|
|
" <th>CCI_diff_12</th>\n",
|
|||
|
|
" <td>0.012387</td>\n",
|
|||
|
|
" <td>0.001230</td>\n",
|
|||
|
|
" <td>0.000307</td>\n",
|
|||
|
|
" <td>0.000082</td>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" <tr>\n",
|
|||
|
|
" <th>CCI_diff_18</th>\n",
|
|||
|
|
" <td>0.015434</td>\n",
|
|||
|
|
" <td>0.001561</td>\n",
|
|||
|
|
" <td>0.000304</td>\n",
|
|||
|
|
" <td>0.000150</td>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" <tr>\n",
|
|||
|
|
" <th>KeltnerWidth_diff_9</th>\n",
|
|||
|
|
" <td>0.021018</td>\n",
|
|||
|
|
" <td>0.001042</td>\n",
|
|||
|
|
" <td>0.000277</td>\n",
|
|||
|
|
" <td>0.000094</td>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" <tr>\n",
|
|||
|
|
" <th>PPO_12_26</th>\n",
|
|||
|
|
" <td>0.014241</td>\n",
|
|||
|
|
" <td>0.000926</td>\n",
|
|||
|
|
" <td>0.000264</td>\n",
|
|||
|
|
" <td>0.000109</td>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" <tr>\n",
|
|||
|
|
" <th>CCI_8</th>\n",
|
|||
|
|
" <td>0.019527</td>\n",
|
|||
|
|
" <td>0.000839</td>\n",
|
|||
|
|
" <td>0.000193</td>\n",
|
|||
|
|
" <td>0.000339</td>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" <tr>\n",
|
|||
|
|
" <th>CCI_14</th>\n",
|
|||
|
|
" <td>0.020120</td>\n",
|
|||
|
|
" <td>0.002310</td>\n",
|
|||
|
|
" <td>0.000188</td>\n",
|
|||
|
|
" <td>0.000213</td>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" <tr>\n",
|
|||
|
|
" <th>CMO_diff_12</th>\n",
|
|||
|
|
" <td>0.015694</td>\n",
|
|||
|
|
" <td>0.001227</td>\n",
|
|||
|
|
" <td>0.000171</td>\n",
|
|||
|
|
" <td>0.000283</td>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" <tr>\n",
|
|||
|
|
" <th>ADX_ratio_2_5</th>\n",
|
|||
|
|
" <td>0.014738</td>\n",
|
|||
|
|
" <td>0.002739</td>\n",
|
|||
|
|
" <td>0.000170</td>\n",
|
|||
|
|
" <td>0.000203</td>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" <tr>\n",
|
|||
|
|
" <th>ADX_14</th>\n",
|
|||
|
|
" <td>0.013390</td>\n",
|
|||
|
|
" <td>0.000597</td>\n",
|
|||
|
|
" <td>0.000154</td>\n",
|
|||
|
|
" <td>0.000059</td>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" <tr>\n",
|
|||
|
|
" <th>CCI_diff_6</th>\n",
|
|||
|
|
" <td>0.013123</td>\n",
|
|||
|
|
" <td>0.001673</td>\n",
|
|||
|
|
" <td>0.000154</td>\n",
|
|||
|
|
" <td>0.000133</td>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" <tr>\n",
|
|||
|
|
" <th>KeltnerWidth_15</th>\n",
|
|||
|
|
" <td>0.012065</td>\n",
|
|||
|
|
" <td>0.001431</td>\n",
|
|||
|
|
" <td>0.000144</td>\n",
|
|||
|
|
" <td>0.000094</td>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" <tr>\n",
|
|||
|
|
" <th>CMO54</th>\n",
|
|||
|
|
" <td>0.014536</td>\n",
|
|||
|
|
" <td>0.000912</td>\n",
|
|||
|
|
" <td>0.000120</td>\n",
|
|||
|
|
" <td>0.000225</td>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" <tr>\n",
|
|||
|
|
" <th>KeltnerWidth_24</th>\n",
|
|||
|
|
" <td>0.010461</td>\n",
|
|||
|
|
" <td>0.001092</td>\n",
|
|||
|
|
" <td>0.000073</td>\n",
|
|||
|
|
" <td>0.000060</td>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" <tr>\n",
|
|||
|
|
" <th>CCI_ratio_2_8</th>\n",
|
|||
|
|
" <td>0.012882</td>\n",
|
|||
|
|
" <td>0.001430</td>\n",
|
|||
|
|
" <td>0.000070</td>\n",
|
|||
|
|
" <td>0.000183</td>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" <tr>\n",
|
|||
|
|
" <th>KeltnerWidth_2</th>\n",
|
|||
|
|
" <td>0.015248</td>\n",
|
|||
|
|
" <td>0.001092</td>\n",
|
|||
|
|
" <td>0.000059</td>\n",
|
|||
|
|
" <td>0.000102</td>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" <tr>\n",
|
|||
|
|
" <th>ADX_2</th>\n",
|
|||
|
|
" <td>0.015177</td>\n",
|
|||
|
|
" <td>0.003281</td>\n",
|
|||
|
|
" <td>0.000051</td>\n",
|
|||
|
|
" <td>0.000124</td>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" </tbody>\n",
|
|||
|
|
"</table>\n",
|
|||
|
|
"</div>"
|
|||
|
|
],
|
|||
|
|
"text/plain": [
|
|||
|
|
" model_importance_mean model_importance_std \\\n",
|
|||
|
|
"signal 0.306649 0.042522 \n",
|
|||
|
|
"CMO_14 0.028196 0.000615 \n",
|
|||
|
|
"ADX_5 0.028298 0.001057 \n",
|
|||
|
|
"PPO_2_6 0.027918 0.000813 \n",
|
|||
|
|
"CCI_ratio_2_20 0.016868 0.002119 \n",
|
|||
|
|
"CCI_20 0.022840 0.001432 \n",
|
|||
|
|
"KeltnerWidth_ratio_15_24 0.020487 0.000306 \n",
|
|||
|
|
"CMO_ratio_2_14 0.015399 0.002409 \n",
|
|||
|
|
"CCI_ratio_8_20 0.015631 0.001033 \n",
|
|||
|
|
"CCI_diff_12 0.012387 0.001230 \n",
|
|||
|
|
"CCI_diff_18 0.015434 0.001561 \n",
|
|||
|
|
"KeltnerWidth_diff_9 0.021018 0.001042 \n",
|
|||
|
|
"PPO_12_26 0.014241 0.000926 \n",
|
|||
|
|
"CCI_8 0.019527 0.000839 \n",
|
|||
|
|
"CCI_14 0.020120 0.002310 \n",
|
|||
|
|
"CMO_diff_12 0.015694 0.001227 \n",
|
|||
|
|
"ADX_ratio_2_5 0.014738 0.002739 \n",
|
|||
|
|
"ADX_14 0.013390 0.000597 \n",
|
|||
|
|
"CCI_diff_6 0.013123 0.001673 \n",
|
|||
|
|
"KeltnerWidth_15 0.012065 0.001431 \n",
|
|||
|
|
"CMO54 0.014536 0.000912 \n",
|
|||
|
|
"KeltnerWidth_24 0.010461 0.001092 \n",
|
|||
|
|
"CCI_ratio_2_8 0.012882 0.001430 \n",
|
|||
|
|
"KeltnerWidth_2 0.015248 0.001092 \n",
|
|||
|
|
"ADX_2 0.015177 0.003281 \n",
|
|||
|
|
"\n",
|
|||
|
|
" perm_importance_mean perm_importance_std \n",
|
|||
|
|
"signal 0.011702 0.002480 \n",
|
|||
|
|
"CMO_14 0.001137 0.000429 \n",
|
|||
|
|
"ADX_5 0.000819 0.000296 \n",
|
|||
|
|
"PPO_2_6 0.000595 0.000526 \n",
|
|||
|
|
"CCI_ratio_2_20 0.000582 0.000256 \n",
|
|||
|
|
"CCI_20 0.000391 0.000319 \n",
|
|||
|
|
"KeltnerWidth_ratio_15_24 0.000365 0.000174 \n",
|
|||
|
|
"CMO_ratio_2_14 0.000341 0.000282 \n",
|
|||
|
|
"CCI_ratio_8_20 0.000318 0.000115 \n",
|
|||
|
|
"CCI_diff_12 0.000307 0.000082 \n",
|
|||
|
|
"CCI_diff_18 0.000304 0.000150 \n",
|
|||
|
|
"KeltnerWidth_diff_9 0.000277 0.000094 \n",
|
|||
|
|
"PPO_12_26 0.000264 0.000109 \n",
|
|||
|
|
"CCI_8 0.000193 0.000339 \n",
|
|||
|
|
"CCI_14 0.000188 0.000213 \n",
|
|||
|
|
"CMO_diff_12 0.000171 0.000283 \n",
|
|||
|
|
"ADX_ratio_2_5 0.000170 0.000203 \n",
|
|||
|
|
"ADX_14 0.000154 0.000059 \n",
|
|||
|
|
"CCI_diff_6 0.000154 0.000133 \n",
|
|||
|
|
"KeltnerWidth_15 0.000144 0.000094 \n",
|
|||
|
|
"CMO54 0.000120 0.000225 \n",
|
|||
|
|
"KeltnerWidth_24 0.000073 0.000060 \n",
|
|||
|
|
"CCI_ratio_2_8 0.000070 0.000183 \n",
|
|||
|
|
"KeltnerWidth_2 0.000059 0.000102 \n",
|
|||
|
|
"ADX_2 0.000051 0.000124 "
|
|||
|
|
]
|
|||
|
|
},
|
|||
|
|
"metadata": {},
|
|||
|
|
"output_type": "display_data"
|
|||
|
|
}
|
|||
|
|
],
|
|||
|
|
"source": [
|
|||
|
|
"# --- Feature importance for a trading dataset (reproducible, no lookahead) ---\n",
|
|||
|
|
"\n",
|
|||
|
|
"import numpy as np\n",
|
|||
|
|
"import pandas as pd\n",
|
|||
|
|
"\n",
|
|||
|
|
"from sklearn.ensemble import RandomForestClassifier\n",
|
|||
|
|
"from sklearn.inspection import permutation_importance\n",
|
|||
|
|
"from sklearn.model_selection import TimeSeriesSplit\n",
|
|||
|
|
"\n",
|
|||
|
|
"# ---------------- 0) Reproducibility ----------------\n",
|
|||
|
|
"SEED = 42\n",
|
|||
|
|
"np.random.seed(SEED)\n",
|
|||
|
|
"\n",
|
|||
|
|
"# ---------------- 1) Prepare features/target ----------------\n",
|
|||
|
|
"df = train_df.copy()\n",
|
|||
|
|
"\n",
|
|||
|
|
"# Ensure target exists and is binary/ternary int-like\n",
|
|||
|
|
"y = pd.to_numeric(df['target_signal'], errors='coerce').astype('Int64')\n",
|
|||
|
|
"\n",
|
|||
|
|
"# X: all columns except the target. (You said all others are features.)\n",
|
|||
|
|
"X = df.drop(columns=['target_signal']).copy()\n",
|
|||
|
|
"\n",
|
|||
|
|
"# Keep only numeric columns (coerce any stray objects to numeric without peeking ahead)\n",
|
|||
|
|
"for col in X.columns:\n",
|
|||
|
|
" if not pd.api.types.is_numeric_dtype(X[col]):\n",
|
|||
|
|
" X[col] = pd.to_numeric(X[col], errors='coerce')\n",
|
|||
|
|
"\n",
|
|||
|
|
"# Replace inf with NaN, then forward-fill ONLY (uses past info => no lookahead).\n",
|
|||
|
|
"# Drop remaining NaNs (typically at the very start where ffill has nothing to fill).\n",
|
|||
|
|
"X = X.replace([np.inf, -np.inf], np.nan).ffill()\n",
|
|||
|
|
"valid_mask = ~X.isna().any(axis=1) & y.notna()\n",
|
|||
|
|
"X = X.loc[valid_mask]\n",
|
|||
|
|
"y = y.loc[valid_mask].astype(int)\n",
|
|||
|
|
"\n",
|
|||
|
|
"# ---------------- 2) Walk-forward CV with a gap ----------------\n",
|
|||
|
|
"# Use TimeSeriesSplit with a small 'gap' to reduce leakage from overlapping windows.\n",
|
|||
|
|
"n_splits = 5\n",
|
|||
|
|
"gap_bars = 5 # adjust if your target uses future bars that can overlap\n",
|
|||
|
|
"\n",
|
|||
|
|
"tscv = TimeSeriesSplit(n_splits=n_splits, gap=gap_bars)\n",
|
|||
|
|
"\n",
|
|||
|
|
"# Model choice: tree-based (handles scales, interactions). Set random_state for reproducibility.\n",
|
|||
|
|
"rf = RandomForestClassifier(\n",
|
|||
|
|
" n_estimators=600,\n",
|
|||
|
|
" max_depth=None,\n",
|
|||
|
|
" min_samples_leaf=3,\n",
|
|||
|
|
" class_weight=\"balanced_subsample\",\n",
|
|||
|
|
" random_state=SEED,\n",
|
|||
|
|
" n_jobs=-1,\n",
|
|||
|
|
")\n",
|
|||
|
|
"\n",
|
|||
|
|
"# ---------------- 3) Collect importances across folds ----------------\n",
|
|||
|
|
"feat_names = X.columns.to_list()\n",
|
|||
|
|
"all_model_imps = []\n",
|
|||
|
|
"all_perm_imps = []\n",
|
|||
|
|
"\n",
|
|||
|
|
"for fold, (train_idx, test_idx) in enumerate(tscv.split(X), start=1):\n",
|
|||
|
|
" X_tr, y_tr = X.iloc[train_idx], y.iloc[train_idx]\n",
|
|||
|
|
" X_te, y_te = X.iloc[test_idx], y.iloc[test_idx]\n",
|
|||
|
|
"\n",
|
|||
|
|
" # Fit only on past data\n",
|
|||
|
|
" rf.fit(X_tr, y_tr)\n",
|
|||
|
|
"\n",
|
|||
|
|
" # Built-in (in-sample) model importances\n",
|
|||
|
|
" all_model_imps.append(pd.Series(rf.feature_importances_, index=feat_names))\n",
|
|||
|
|
"\n",
|
|||
|
|
" # Out-of-sample permutation importances on the validation fold\n",
|
|||
|
|
" perm = permutation_importance(\n",
|
|||
|
|
" rf, X_te, y_te,\n",
|
|||
|
|
" n_repeats=10,\n",
|
|||
|
|
" random_state=SEED,\n",
|
|||
|
|
" n_jobs=-1,\n",
|
|||
|
|
" scoring=None # default = estimator's score (accuracy). Change if you prefer f1, roc_auc, etc.\n",
|
|||
|
|
" )\n",
|
|||
|
|
" all_perm_imps.append(pd.Series(perm.importances_mean, index=feat_names))\n",
|
|||
|
|
"\n",
|
|||
|
|
"# ---------------- 4) Aggregate & present ----------------\n",
|
|||
|
|
"model_imp_df = pd.concat(all_model_imps, axis=1)\n",
|
|||
|
|
"perm_imp_df = pd.concat(all_perm_imps, axis=1)\n",
|
|||
|
|
"\n",
|
|||
|
|
"model_imp_mean = model_imp_df.mean(axis=1).rename(\"model_importance_mean\")\n",
|
|||
|
|
"model_imp_std = model_imp_df.std(axis=1).rename(\"model_importance_std\")\n",
|
|||
|
|
"\n",
|
|||
|
|
"perm_imp_mean = perm_imp_df.mean(axis=1).rename(\"perm_importance_mean\")\n",
|
|||
|
|
"perm_imp_std = perm_imp_df.std(axis=1).rename(\"perm_importance_std\")\n",
|
|||
|
|
"\n",
|
|||
|
|
"importance = pd.concat([model_imp_mean, model_imp_std, perm_imp_mean, perm_imp_std], axis=1)\n",
|
|||
|
|
"importance = importance.sort_values(\"perm_importance_mean\", ascending=False)\n",
|
|||
|
|
"\n",
|
|||
|
|
"# Show top features (permutation-based is the most trustworthy OOS signal)\n",
|
|||
|
|
"top_k = 25\n",
|
|||
|
|
"print(\"\\nTop features by OUT-OF-SAMPLE permutation importance (mean across folds):\\n\")\n",
|
|||
|
|
"display(importance.head(top_k))\n",
|
|||
|
|
"\n",
|
|||
|
|
"# If you also want the full table:\n",
|
|||
|
|
"importance.to_csv(\"feature_importance_timeseries.csv\")\n"
|
|||
|
|
]
|
|||
|
|
},
|
|||
|
|
{
|
|||
|
|
"cell_type": "code",
|
|||
|
|
"execution_count": 51,
|
|||
|
|
"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>model_importance_mean</th>\n",
|
|||
|
|
" <th>model_importance_std</th>\n",
|
|||
|
|
" <th>perm_importance_mean</th>\n",
|
|||
|
|
" <th>perm_importance_std</th>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" </thead>\n",
|
|||
|
|
" <tbody>\n",
|
|||
|
|
" <tr>\n",
|
|||
|
|
" <th>signal</th>\n",
|
|||
|
|
" <td>0.306649</td>\n",
|
|||
|
|
" <td>0.042522</td>\n",
|
|||
|
|
" <td>1.170155e-02</td>\n",
|
|||
|
|
" <td>0.002480</td>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" <tr>\n",
|
|||
|
|
" <th>ADX_5</th>\n",
|
|||
|
|
" <td>0.028298</td>\n",
|
|||
|
|
" <td>0.001057</td>\n",
|
|||
|
|
" <td>8.187225e-04</td>\n",
|
|||
|
|
" <td>0.000296</td>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" <tr>\n",
|
|||
|
|
" <th>CMO_14</th>\n",
|
|||
|
|
" <td>0.028196</td>\n",
|
|||
|
|
" <td>0.000615</td>\n",
|
|||
|
|
" <td>1.136943e-03</td>\n",
|
|||
|
|
" <td>0.000429</td>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" <tr>\n",
|
|||
|
|
" <th>PPO_2_6</th>\n",
|
|||
|
|
" <td>0.027918</td>\n",
|
|||
|
|
" <td>0.000813</td>\n",
|
|||
|
|
" <td>5.947324e-04</td>\n",
|
|||
|
|
" <td>0.000526</td>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" <tr>\n",
|
|||
|
|
" <th>CCI_20</th>\n",
|
|||
|
|
" <td>0.022840</td>\n",
|
|||
|
|
" <td>0.001432</td>\n",
|
|||
|
|
" <td>3.908241e-04</td>\n",
|
|||
|
|
" <td>0.000319</td>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" <tr>\n",
|
|||
|
|
" <th>KeltnerWidth_diff_9</th>\n",
|
|||
|
|
" <td>0.021018</td>\n",
|
|||
|
|
" <td>0.001042</td>\n",
|
|||
|
|
" <td>2.765119e-04</td>\n",
|
|||
|
|
" <td>0.000094</td>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" <tr>\n",
|
|||
|
|
" <th>KeltnerWidth_ratio_15_24</th>\n",
|
|||
|
|
" <td>0.020487</td>\n",
|
|||
|
|
" <td>0.000306</td>\n",
|
|||
|
|
" <td>3.645632e-04</td>\n",
|
|||
|
|
" <td>0.000174</td>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" <tr>\n",
|
|||
|
|
" <th>CCI_14</th>\n",
|
|||
|
|
" <td>0.020120</td>\n",
|
|||
|
|
" <td>0.002310</td>\n",
|
|||
|
|
" <td>1.884606e-04</td>\n",
|
|||
|
|
" <td>0.000213</td>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" <tr>\n",
|
|||
|
|
" <th>CCI_8</th>\n",
|
|||
|
|
" <td>0.019527</td>\n",
|
|||
|
|
" <td>0.000839</td>\n",
|
|||
|
|
" <td>1.930949e-04</td>\n",
|
|||
|
|
" <td>0.000339</td>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" <tr>\n",
|
|||
|
|
" <th>CCI_ratio_2_20</th>\n",
|
|||
|
|
" <td>0.016868</td>\n",
|
|||
|
|
" <td>0.002119</td>\n",
|
|||
|
|
" <td>5.823743e-04</td>\n",
|
|||
|
|
" <td>0.000256</td>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" <tr>\n",
|
|||
|
|
" <th>CMO_diff_12</th>\n",
|
|||
|
|
" <td>0.015694</td>\n",
|
|||
|
|
" <td>0.001227</td>\n",
|
|||
|
|
" <td>1.714683e-04</td>\n",
|
|||
|
|
" <td>0.000283</td>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" <tr>\n",
|
|||
|
|
" <th>CCI_ratio_8_20</th>\n",
|
|||
|
|
" <td>0.015631</td>\n",
|
|||
|
|
" <td>0.001033</td>\n",
|
|||
|
|
" <td>3.182204e-04</td>\n",
|
|||
|
|
" <td>0.000115</td>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" <tr>\n",
|
|||
|
|
" <th>CCI_diff_18</th>\n",
|
|||
|
|
" <td>0.015434</td>\n",
|
|||
|
|
" <td>0.001561</td>\n",
|
|||
|
|
" <td>3.043176e-04</td>\n",
|
|||
|
|
" <td>0.000150</td>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" <tr>\n",
|
|||
|
|
" <th>CMO_ratio_2_14</th>\n",
|
|||
|
|
" <td>0.015399</td>\n",
|
|||
|
|
" <td>0.002409</td>\n",
|
|||
|
|
" <td>3.413918e-04</td>\n",
|
|||
|
|
" <td>0.000282</td>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" <tr>\n",
|
|||
|
|
" <th>KeltnerWidth_2</th>\n",
|
|||
|
|
" <td>0.015248</td>\n",
|
|||
|
|
" <td>0.001092</td>\n",
|
|||
|
|
" <td>5.870086e-05</td>\n",
|
|||
|
|
" <td>0.000102</td>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" <tr>\n",
|
|||
|
|
" <th>ADX_2</th>\n",
|
|||
|
|
" <td>0.015177</td>\n",
|
|||
|
|
" <td>0.003281</td>\n",
|
|||
|
|
" <td>5.097706e-05</td>\n",
|
|||
|
|
" <td>0.000124</td>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" <tr>\n",
|
|||
|
|
" <th>ADX_ratio_2_5</th>\n",
|
|||
|
|
" <td>0.014738</td>\n",
|
|||
|
|
" <td>0.002739</td>\n",
|
|||
|
|
" <td>1.699235e-04</td>\n",
|
|||
|
|
" <td>0.000203</td>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" <tr>\n",
|
|||
|
|
" <th>CMO54</th>\n",
|
|||
|
|
" <td>0.014536</td>\n",
|
|||
|
|
" <td>0.000912</td>\n",
|
|||
|
|
" <td>1.204912e-04</td>\n",
|
|||
|
|
" <td>0.000225</td>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" <tr>\n",
|
|||
|
|
" <th>PPO_12_26</th>\n",
|
|||
|
|
" <td>0.014241</td>\n",
|
|||
|
|
" <td>0.000926</td>\n",
|
|||
|
|
" <td>2.641539e-04</td>\n",
|
|||
|
|
" <td>0.000109</td>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" <tr>\n",
|
|||
|
|
" <th>KeltnerWidth_ratio_2_24</th>\n",
|
|||
|
|
" <td>0.014073</td>\n",
|
|||
|
|
" <td>0.001852</td>\n",
|
|||
|
|
" <td>1.699235e-05</td>\n",
|
|||
|
|
" <td>0.000338</td>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" <tr>\n",
|
|||
|
|
" <th>ADX_14</th>\n",
|
|||
|
|
" <td>0.013390</td>\n",
|
|||
|
|
" <td>0.000597</td>\n",
|
|||
|
|
" <td>1.544759e-04</td>\n",
|
|||
|
|
" <td>0.000059</td>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" <tr>\n",
|
|||
|
|
" <th>CCI_diff_6</th>\n",
|
|||
|
|
" <td>0.013123</td>\n",
|
|||
|
|
" <td>0.001673</td>\n",
|
|||
|
|
" <td>1.544759e-04</td>\n",
|
|||
|
|
" <td>0.000133</td>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" <tr>\n",
|
|||
|
|
" <th>KeltnerWidth_ratio_2_15</th>\n",
|
|||
|
|
" <td>0.012956</td>\n",
|
|||
|
|
" <td>0.001455</td>\n",
|
|||
|
|
" <td>-4.943230e-05</td>\n",
|
|||
|
|
" <td>0.000295</td>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" <tr>\n",
|
|||
|
|
" <th>CCI_ratio_2_8</th>\n",
|
|||
|
|
" <td>0.012882</td>\n",
|
|||
|
|
" <td>0.001430</td>\n",
|
|||
|
|
" <td>6.951417e-05</td>\n",
|
|||
|
|
" <td>0.000183</td>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" <tr>\n",
|
|||
|
|
" <th>CCI_diff_12</th>\n",
|
|||
|
|
" <td>0.012387</td>\n",
|
|||
|
|
" <td>0.001230</td>\n",
|
|||
|
|
" <td>3.074071e-04</td>\n",
|
|||
|
|
" <td>0.000082</td>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" <tr>\n",
|
|||
|
|
" <th>KeltnerWidth_15</th>\n",
|
|||
|
|
" <td>0.012065</td>\n",
|
|||
|
|
" <td>0.001431</td>\n",
|
|||
|
|
" <td>1.436626e-04</td>\n",
|
|||
|
|
" <td>0.000094</td>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" <tr>\n",
|
|||
|
|
" <th>KeltnerWidth_diff_22</th>\n",
|
|||
|
|
" <td>0.011980</td>\n",
|
|||
|
|
" <td>0.001152</td>\n",
|
|||
|
|
" <td>4.219037e-17</td>\n",
|
|||
|
|
" <td>0.000229</td>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" <tr>\n",
|
|||
|
|
" <th>ChaikinVol_2_5</th>\n",
|
|||
|
|
" <td>0.011735</td>\n",
|
|||
|
|
" <td>0.001426</td>\n",
|
|||
|
|
" <td>7.723797e-06</td>\n",
|
|||
|
|
" <td>0.000190</td>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" <tr>\n",
|
|||
|
|
" <th>KeltnerWidth_diff_13</th>\n",
|
|||
|
|
" <td>0.011701</td>\n",
|
|||
|
|
" <td>0.001045</td>\n",
|
|||
|
|
" <td>-7.723797e-05</td>\n",
|
|||
|
|
" <td>0.000233</td>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" <tr>\n",
|
|||
|
|
" <th>ChaikinVol_3_10</th>\n",
|
|||
|
|
" <td>0.011406</td>\n",
|
|||
|
|
" <td>0.002300</td>\n",
|
|||
|
|
" <td>3.861899e-05</td>\n",
|
|||
|
|
" <td>0.000201</td>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" <tr>\n",
|
|||
|
|
" <th>ADX_diff_9</th>\n",
|
|||
|
|
" <td>0.011238</td>\n",
|
|||
|
|
" <td>0.001878</td>\n",
|
|||
|
|
" <td>-5.561134e-05</td>\n",
|
|||
|
|
" <td>0.000059</td>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" <tr>\n",
|
|||
|
|
" <th>Gold_Close</th>\n",
|
|||
|
|
" <td>0.010996</td>\n",
|
|||
|
|
" <td>0.003362</td>\n",
|
|||
|
|
" <td>-2.317139e-05</td>\n",
|
|||
|
|
" <td>0.000044</td>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" <tr>\n",
|
|||
|
|
" <th>Unnamed: 0</th>\n",
|
|||
|
|
" <td>0.010731</td>\n",
|
|||
|
|
" <td>0.002601</td>\n",
|
|||
|
|
" <td>0.000000e+00</td>\n",
|
|||
|
|
" <td>0.000000</td>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" <tr>\n",
|
|||
|
|
" <th>KeltnerWidth_20</th>\n",
|
|||
|
|
" <td>0.010705</td>\n",
|
|||
|
|
" <td>0.001163</td>\n",
|
|||
|
|
" <td>4.943230e-05</td>\n",
|
|||
|
|
" <td>0.000129</td>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" <tr>\n",
|
|||
|
|
" <th>CMO_2</th>\n",
|
|||
|
|
" <td>0.010696</td>\n",
|
|||
|
|
" <td>0.000290</td>\n",
|
|||
|
|
" <td>4.016374e-05</td>\n",
|
|||
|
|
" <td>0.000088</td>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" <tr>\n",
|
|||
|
|
" <th>KeltnerWidth_24</th>\n",
|
|||
|
|
" <td>0.010461</td>\n",
|
|||
|
|
" <td>0.001092</td>\n",
|
|||
|
|
" <td>7.260369e-05</td>\n",
|
|||
|
|
" <td>0.000060</td>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" <tr>\n",
|
|||
|
|
" <th>Volume</th>\n",
|
|||
|
|
" <td>0.010460</td>\n",
|
|||
|
|
" <td>0.001554</td>\n",
|
|||
|
|
" <td>-7.723797e-06</td>\n",
|
|||
|
|
" <td>0.000081</td>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" <tr>\n",
|
|||
|
|
" <th>ADX_diff_3</th>\n",
|
|||
|
|
" <td>0.010061</td>\n",
|
|||
|
|
" <td>0.000414</td>\n",
|
|||
|
|
" <td>-6.951417e-05</td>\n",
|
|||
|
|
" <td>0.000113</td>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" <tr>\n",
|
|||
|
|
" <th>ADX_ratio_5_14</th>\n",
|
|||
|
|
" <td>0.009508</td>\n",
|
|||
|
|
" <td>0.000785</td>\n",
|
|||
|
|
" <td>-4.634278e-05</td>\n",
|
|||
|
|
" <td>0.000120</td>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" <tr>\n",
|
|||
|
|
" <th>ADX_diff_12</th>\n",
|
|||
|
|
" <td>0.009228</td>\n",
|
|||
|
|
" <td>0.000512</td>\n",
|
|||
|
|
" <td>-4.479802e-05</td>\n",
|
|||
|
|
" <td>0.000100</td>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" <tr>\n",
|
|||
|
|
" <th>Diff_10Y_2Y</th>\n",
|
|||
|
|
" <td>0.009158</td>\n",
|
|||
|
|
" <td>0.001091</td>\n",
|
|||
|
|
" <td>-4.634278e-05</td>\n",
|
|||
|
|
" <td>0.000097</td>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" <tr>\n",
|
|||
|
|
" <th>sma</th>\n",
|
|||
|
|
" <td>0.009080</td>\n",
|
|||
|
|
" <td>0.000535</td>\n",
|
|||
|
|
" <td>-7.723797e-06</td>\n",
|
|||
|
|
" <td>0.000075</td>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" <tr>\n",
|
|||
|
|
" <th>ADX_ratio_2_14</th>\n",
|
|||
|
|
" <td>0.009070</td>\n",
|
|||
|
|
" <td>0.000448</td>\n",
|
|||
|
|
" <td>-3.398471e-05</td>\n",
|
|||
|
|
" <td>0.000109</td>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" <tr>\n",
|
|||
|
|
" <th>Open</th>\n",
|
|||
|
|
" <td>0.008671</td>\n",
|
|||
|
|
" <td>0.000402</td>\n",
|
|||
|
|
" <td>-3.089519e-05</td>\n",
|
|||
|
|
" <td>0.000070</td>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" <tr>\n",
|
|||
|
|
" <th>Oil_Close</th>\n",
|
|||
|
|
" <td>0.008671</td>\n",
|
|||
|
|
" <td>0.000734</td>\n",
|
|||
|
|
" <td>-1.699235e-05</td>\n",
|
|||
|
|
" <td>0.000033</td>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" <tr>\n",
|
|||
|
|
" <th>Oil_Volume</th>\n",
|
|||
|
|
" <td>0.008659</td>\n",
|
|||
|
|
" <td>0.000408</td>\n",
|
|||
|
|
" <td>-5.715610e-05</td>\n",
|
|||
|
|
" <td>0.000074</td>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" <tr>\n",
|
|||
|
|
" <th>Low</th>\n",
|
|||
|
|
" <td>0.008550</td>\n",
|
|||
|
|
" <td>0.000231</td>\n",
|
|||
|
|
" <td>-2.471615e-05</td>\n",
|
|||
|
|
" <td>0.000024</td>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" <tr>\n",
|
|||
|
|
" <th>High</th>\n",
|
|||
|
|
" <td>0.008299</td>\n",
|
|||
|
|
" <td>0.000378</td>\n",
|
|||
|
|
" <td>-4.016374e-05</td>\n",
|
|||
|
|
" <td>0.000047</td>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" <tr>\n",
|
|||
|
|
" <th>Close</th>\n",
|
|||
|
|
" <td>0.008296</td>\n",
|
|||
|
|
" <td>0.000433</td>\n",
|
|||
|
|
" <td>-1.544759e-05</td>\n",
|
|||
|
|
" <td>0.000058</td>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" <tr>\n",
|
|||
|
|
" <th>ema</th>\n",
|
|||
|
|
" <td>0.007906</td>\n",
|
|||
|
|
" <td>0.000204</td>\n",
|
|||
|
|
" <td>-2.317139e-05</td>\n",
|
|||
|
|
" <td>0.000040</td>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" <tr>\n",
|
|||
|
|
" <th>Hour_sin</th>\n",
|
|||
|
|
" <td>0.006267</td>\n",
|
|||
|
|
" <td>0.000311</td>\n",
|
|||
|
|
" <td>1.235808e-05</td>\n",
|
|||
|
|
" <td>0.000065</td>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" <tr>\n",
|
|||
|
|
" <th>Date_sin</th>\n",
|
|||
|
|
" <td>0.005902</td>\n",
|
|||
|
|
" <td>0.000935</td>\n",
|
|||
|
|
" <td>-4.634278e-05</td>\n",
|
|||
|
|
" <td>0.000030</td>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" <tr>\n",
|
|||
|
|
" <th>Month_sin</th>\n",
|
|||
|
|
" <td>0.003765</td>\n",
|
|||
|
|
" <td>0.000437</td>\n",
|
|||
|
|
" <td>-2.008187e-05</td>\n",
|
|||
|
|
" <td>0.000048</td>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" <tr>\n",
|
|||
|
|
" <th>DOW_sin</th>\n",
|
|||
|
|
" <td>0.003258</td>\n",
|
|||
|
|
" <td>0.000196</td>\n",
|
|||
|
|
" <td>1.544759e-06</td>\n",
|
|||
|
|
" <td>0.000045</td>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" <tr>\n",
|
|||
|
|
" <th>Quarter</th>\n",
|
|||
|
|
" <td>0.002403</td>\n",
|
|||
|
|
" <td>0.000197</td>\n",
|
|||
|
|
" <td>-1.235808e-05</td>\n",
|
|||
|
|
" <td>0.000057</td>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" <tr>\n",
|
|||
|
|
" <th>Session</th>\n",
|
|||
|
|
" <td>0.001260</td>\n",
|
|||
|
|
" <td>0.000224</td>\n",
|
|||
|
|
" <td>-2.162663e-05</td>\n",
|
|||
|
|
" <td>0.000037</td>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" <tr>\n",
|
|||
|
|
" <th>CCI_2</th>\n",
|
|||
|
|
" <td>0.000981</td>\n",
|
|||
|
|
" <td>0.000159</td>\n",
|
|||
|
|
" <td>7.723797e-06</td>\n",
|
|||
|
|
" <td>0.000022</td>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" </tbody>\n",
|
|||
|
|
"</table>\n",
|
|||
|
|
"</div>"
|
|||
|
|
],
|
|||
|
|
"text/plain": [
|
|||
|
|
" model_importance_mean model_importance_std \\\n",
|
|||
|
|
"signal 0.306649 0.042522 \n",
|
|||
|
|
"ADX_5 0.028298 0.001057 \n",
|
|||
|
|
"CMO_14 0.028196 0.000615 \n",
|
|||
|
|
"PPO_2_6 0.027918 0.000813 \n",
|
|||
|
|
"CCI_20 0.022840 0.001432 \n",
|
|||
|
|
"KeltnerWidth_diff_9 0.021018 0.001042 \n",
|
|||
|
|
"KeltnerWidth_ratio_15_24 0.020487 0.000306 \n",
|
|||
|
|
"CCI_14 0.020120 0.002310 \n",
|
|||
|
|
"CCI_8 0.019527 0.000839 \n",
|
|||
|
|
"CCI_ratio_2_20 0.016868 0.002119 \n",
|
|||
|
|
"CMO_diff_12 0.015694 0.001227 \n",
|
|||
|
|
"CCI_ratio_8_20 0.015631 0.001033 \n",
|
|||
|
|
"CCI_diff_18 0.015434 0.001561 \n",
|
|||
|
|
"CMO_ratio_2_14 0.015399 0.002409 \n",
|
|||
|
|
"KeltnerWidth_2 0.015248 0.001092 \n",
|
|||
|
|
"ADX_2 0.015177 0.003281 \n",
|
|||
|
|
"ADX_ratio_2_5 0.014738 0.002739 \n",
|
|||
|
|
"CMO54 0.014536 0.000912 \n",
|
|||
|
|
"PPO_12_26 0.014241 0.000926 \n",
|
|||
|
|
"KeltnerWidth_ratio_2_24 0.014073 0.001852 \n",
|
|||
|
|
"ADX_14 0.013390 0.000597 \n",
|
|||
|
|
"CCI_diff_6 0.013123 0.001673 \n",
|
|||
|
|
"KeltnerWidth_ratio_2_15 0.012956 0.001455 \n",
|
|||
|
|
"CCI_ratio_2_8 0.012882 0.001430 \n",
|
|||
|
|
"CCI_diff_12 0.012387 0.001230 \n",
|
|||
|
|
"KeltnerWidth_15 0.012065 0.001431 \n",
|
|||
|
|
"KeltnerWidth_diff_22 0.011980 0.001152 \n",
|
|||
|
|
"ChaikinVol_2_5 0.011735 0.001426 \n",
|
|||
|
|
"KeltnerWidth_diff_13 0.011701 0.001045 \n",
|
|||
|
|
"ChaikinVol_3_10 0.011406 0.002300 \n",
|
|||
|
|
"ADX_diff_9 0.011238 0.001878 \n",
|
|||
|
|
"Gold_Close 0.010996 0.003362 \n",
|
|||
|
|
"Unnamed: 0 0.010731 0.002601 \n",
|
|||
|
|
"KeltnerWidth_20 0.010705 0.001163 \n",
|
|||
|
|
"CMO_2 0.010696 0.000290 \n",
|
|||
|
|
"KeltnerWidth_24 0.010461 0.001092 \n",
|
|||
|
|
"Volume 0.010460 0.001554 \n",
|
|||
|
|
"ADX_diff_3 0.010061 0.000414 \n",
|
|||
|
|
"ADX_ratio_5_14 0.009508 0.000785 \n",
|
|||
|
|
"ADX_diff_12 0.009228 0.000512 \n",
|
|||
|
|
"Diff_10Y_2Y 0.009158 0.001091 \n",
|
|||
|
|
"sma 0.009080 0.000535 \n",
|
|||
|
|
"ADX_ratio_2_14 0.009070 0.000448 \n",
|
|||
|
|
"Open 0.008671 0.000402 \n",
|
|||
|
|
"Oil_Close 0.008671 0.000734 \n",
|
|||
|
|
"Oil_Volume 0.008659 0.000408 \n",
|
|||
|
|
"Low 0.008550 0.000231 \n",
|
|||
|
|
"High 0.008299 0.000378 \n",
|
|||
|
|
"Close 0.008296 0.000433 \n",
|
|||
|
|
"ema 0.007906 0.000204 \n",
|
|||
|
|
"Hour_sin 0.006267 0.000311 \n",
|
|||
|
|
"Date_sin 0.005902 0.000935 \n",
|
|||
|
|
"Month_sin 0.003765 0.000437 \n",
|
|||
|
|
"DOW_sin 0.003258 0.000196 \n",
|
|||
|
|
"Quarter 0.002403 0.000197 \n",
|
|||
|
|
"Session 0.001260 0.000224 \n",
|
|||
|
|
"CCI_2 0.000981 0.000159 \n",
|
|||
|
|
"\n",
|
|||
|
|
" perm_importance_mean perm_importance_std \n",
|
|||
|
|
"signal 1.170155e-02 0.002480 \n",
|
|||
|
|
"ADX_5 8.187225e-04 0.000296 \n",
|
|||
|
|
"CMO_14 1.136943e-03 0.000429 \n",
|
|||
|
|
"PPO_2_6 5.947324e-04 0.000526 \n",
|
|||
|
|
"CCI_20 3.908241e-04 0.000319 \n",
|
|||
|
|
"KeltnerWidth_diff_9 2.765119e-04 0.000094 \n",
|
|||
|
|
"KeltnerWidth_ratio_15_24 3.645632e-04 0.000174 \n",
|
|||
|
|
"CCI_14 1.884606e-04 0.000213 \n",
|
|||
|
|
"CCI_8 1.930949e-04 0.000339 \n",
|
|||
|
|
"CCI_ratio_2_20 5.823743e-04 0.000256 \n",
|
|||
|
|
"CMO_diff_12 1.714683e-04 0.000283 \n",
|
|||
|
|
"CCI_ratio_8_20 3.182204e-04 0.000115 \n",
|
|||
|
|
"CCI_diff_18 3.043176e-04 0.000150 \n",
|
|||
|
|
"CMO_ratio_2_14 3.413918e-04 0.000282 \n",
|
|||
|
|
"KeltnerWidth_2 5.870086e-05 0.000102 \n",
|
|||
|
|
"ADX_2 5.097706e-05 0.000124 \n",
|
|||
|
|
"ADX_ratio_2_5 1.699235e-04 0.000203 \n",
|
|||
|
|
"CMO54 1.204912e-04 0.000225 \n",
|
|||
|
|
"PPO_12_26 2.641539e-04 0.000109 \n",
|
|||
|
|
"KeltnerWidth_ratio_2_24 1.699235e-05 0.000338 \n",
|
|||
|
|
"ADX_14 1.544759e-04 0.000059 \n",
|
|||
|
|
"CCI_diff_6 1.544759e-04 0.000133 \n",
|
|||
|
|
"KeltnerWidth_ratio_2_15 -4.943230e-05 0.000295 \n",
|
|||
|
|
"CCI_ratio_2_8 6.951417e-05 0.000183 \n",
|
|||
|
|
"CCI_diff_12 3.074071e-04 0.000082 \n",
|
|||
|
|
"KeltnerWidth_15 1.436626e-04 0.000094 \n",
|
|||
|
|
"KeltnerWidth_diff_22 4.219037e-17 0.000229 \n",
|
|||
|
|
"ChaikinVol_2_5 7.723797e-06 0.000190 \n",
|
|||
|
|
"KeltnerWidth_diff_13 -7.723797e-05 0.000233 \n",
|
|||
|
|
"ChaikinVol_3_10 3.861899e-05 0.000201 \n",
|
|||
|
|
"ADX_diff_9 -5.561134e-05 0.000059 \n",
|
|||
|
|
"Gold_Close -2.317139e-05 0.000044 \n",
|
|||
|
|
"Unnamed: 0 0.000000e+00 0.000000 \n",
|
|||
|
|
"KeltnerWidth_20 4.943230e-05 0.000129 \n",
|
|||
|
|
"CMO_2 4.016374e-05 0.000088 \n",
|
|||
|
|
"KeltnerWidth_24 7.260369e-05 0.000060 \n",
|
|||
|
|
"Volume -7.723797e-06 0.000081 \n",
|
|||
|
|
"ADX_diff_3 -6.951417e-05 0.000113 \n",
|
|||
|
|
"ADX_ratio_5_14 -4.634278e-05 0.000120 \n",
|
|||
|
|
"ADX_diff_12 -4.479802e-05 0.000100 \n",
|
|||
|
|
"Diff_10Y_2Y -4.634278e-05 0.000097 \n",
|
|||
|
|
"sma -7.723797e-06 0.000075 \n",
|
|||
|
|
"ADX_ratio_2_14 -3.398471e-05 0.000109 \n",
|
|||
|
|
"Open -3.089519e-05 0.000070 \n",
|
|||
|
|
"Oil_Close -1.699235e-05 0.000033 \n",
|
|||
|
|
"Oil_Volume -5.715610e-05 0.000074 \n",
|
|||
|
|
"Low -2.471615e-05 0.000024 \n",
|
|||
|
|
"High -4.016374e-05 0.000047 \n",
|
|||
|
|
"Close -1.544759e-05 0.000058 \n",
|
|||
|
|
"ema -2.317139e-05 0.000040 \n",
|
|||
|
|
"Hour_sin 1.235808e-05 0.000065 \n",
|
|||
|
|
"Date_sin -4.634278e-05 0.000030 \n",
|
|||
|
|
"Month_sin -2.008187e-05 0.000048 \n",
|
|||
|
|
"DOW_sin 1.544759e-06 0.000045 \n",
|
|||
|
|
"Quarter -1.235808e-05 0.000057 \n",
|
|||
|
|
"Session -2.162663e-05 0.000037 \n",
|
|||
|
|
"CCI_2 7.723797e-06 0.000022 "
|
|||
|
|
]
|
|||
|
|
},
|
|||
|
|
"execution_count": 51,
|
|||
|
|
"metadata": {},
|
|||
|
|
"output_type": "execute_result"
|
|||
|
|
}
|
|||
|
|
],
|
|||
|
|
"source": [
|
|||
|
|
"# Or descending (largest → smallest)\n",
|
|||
|
|
"df_sorted_desc = importance.sort_values(by=\"model_importance_mean\", ascending=False)\n",
|
|||
|
|
"\n",
|
|||
|
|
"df_sorted_desc"
|
|||
|
|
]
|
|||
|
|
},
|
|||
|
|
{
|
|||
|
|
"cell_type": "code",
|
|||
|
|
"execution_count": 52,
|
|||
|
|
"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>model_importance_mean</th>\n",
|
|||
|
|
" <th>model_importance_std</th>\n",
|
|||
|
|
" <th>perm_importance_mean</th>\n",
|
|||
|
|
" <th>perm_importance_std</th>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" </thead>\n",
|
|||
|
|
" <tbody>\n",
|
|||
|
|
" <tr>\n",
|
|||
|
|
" <th>signal</th>\n",
|
|||
|
|
" <td>0.306649</td>\n",
|
|||
|
|
" <td>0.042522</td>\n",
|
|||
|
|
" <td>1.170155e-02</td>\n",
|
|||
|
|
" <td>0.002480</td>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" <tr>\n",
|
|||
|
|
" <th>CMO_14</th>\n",
|
|||
|
|
" <td>0.028196</td>\n",
|
|||
|
|
" <td>0.000615</td>\n",
|
|||
|
|
" <td>1.136943e-03</td>\n",
|
|||
|
|
" <td>0.000429</td>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" <tr>\n",
|
|||
|
|
" <th>ADX_5</th>\n",
|
|||
|
|
" <td>0.028298</td>\n",
|
|||
|
|
" <td>0.001057</td>\n",
|
|||
|
|
" <td>8.187225e-04</td>\n",
|
|||
|
|
" <td>0.000296</td>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" <tr>\n",
|
|||
|
|
" <th>PPO_2_6</th>\n",
|
|||
|
|
" <td>0.027918</td>\n",
|
|||
|
|
" <td>0.000813</td>\n",
|
|||
|
|
" <td>5.947324e-04</td>\n",
|
|||
|
|
" <td>0.000526</td>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" <tr>\n",
|
|||
|
|
" <th>CCI_ratio_2_20</th>\n",
|
|||
|
|
" <td>0.016868</td>\n",
|
|||
|
|
" <td>0.002119</td>\n",
|
|||
|
|
" <td>5.823743e-04</td>\n",
|
|||
|
|
" <td>0.000256</td>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" <tr>\n",
|
|||
|
|
" <th>CCI_20</th>\n",
|
|||
|
|
" <td>0.022840</td>\n",
|
|||
|
|
" <td>0.001432</td>\n",
|
|||
|
|
" <td>3.908241e-04</td>\n",
|
|||
|
|
" <td>0.000319</td>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" <tr>\n",
|
|||
|
|
" <th>KeltnerWidth_ratio_15_24</th>\n",
|
|||
|
|
" <td>0.020487</td>\n",
|
|||
|
|
" <td>0.000306</td>\n",
|
|||
|
|
" <td>3.645632e-04</td>\n",
|
|||
|
|
" <td>0.000174</td>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" <tr>\n",
|
|||
|
|
" <th>CMO_ratio_2_14</th>\n",
|
|||
|
|
" <td>0.015399</td>\n",
|
|||
|
|
" <td>0.002409</td>\n",
|
|||
|
|
" <td>3.413918e-04</td>\n",
|
|||
|
|
" <td>0.000282</td>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" <tr>\n",
|
|||
|
|
" <th>CCI_ratio_8_20</th>\n",
|
|||
|
|
" <td>0.015631</td>\n",
|
|||
|
|
" <td>0.001033</td>\n",
|
|||
|
|
" <td>3.182204e-04</td>\n",
|
|||
|
|
" <td>0.000115</td>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" <tr>\n",
|
|||
|
|
" <th>CCI_diff_12</th>\n",
|
|||
|
|
" <td>0.012387</td>\n",
|
|||
|
|
" <td>0.001230</td>\n",
|
|||
|
|
" <td>3.074071e-04</td>\n",
|
|||
|
|
" <td>0.000082</td>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" <tr>\n",
|
|||
|
|
" <th>CCI_diff_18</th>\n",
|
|||
|
|
" <td>0.015434</td>\n",
|
|||
|
|
" <td>0.001561</td>\n",
|
|||
|
|
" <td>3.043176e-04</td>\n",
|
|||
|
|
" <td>0.000150</td>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" <tr>\n",
|
|||
|
|
" <th>KeltnerWidth_diff_9</th>\n",
|
|||
|
|
" <td>0.021018</td>\n",
|
|||
|
|
" <td>0.001042</td>\n",
|
|||
|
|
" <td>2.765119e-04</td>\n",
|
|||
|
|
" <td>0.000094</td>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" <tr>\n",
|
|||
|
|
" <th>PPO_12_26</th>\n",
|
|||
|
|
" <td>0.014241</td>\n",
|
|||
|
|
" <td>0.000926</td>\n",
|
|||
|
|
" <td>2.641539e-04</td>\n",
|
|||
|
|
" <td>0.000109</td>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" <tr>\n",
|
|||
|
|
" <th>CCI_8</th>\n",
|
|||
|
|
" <td>0.019527</td>\n",
|
|||
|
|
" <td>0.000839</td>\n",
|
|||
|
|
" <td>1.930949e-04</td>\n",
|
|||
|
|
" <td>0.000339</td>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" <tr>\n",
|
|||
|
|
" <th>CCI_14</th>\n",
|
|||
|
|
" <td>0.020120</td>\n",
|
|||
|
|
" <td>0.002310</td>\n",
|
|||
|
|
" <td>1.884606e-04</td>\n",
|
|||
|
|
" <td>0.000213</td>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" <tr>\n",
|
|||
|
|
" <th>CMO_diff_12</th>\n",
|
|||
|
|
" <td>0.015694</td>\n",
|
|||
|
|
" <td>0.001227</td>\n",
|
|||
|
|
" <td>1.714683e-04</td>\n",
|
|||
|
|
" <td>0.000283</td>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" <tr>\n",
|
|||
|
|
" <th>ADX_ratio_2_5</th>\n",
|
|||
|
|
" <td>0.014738</td>\n",
|
|||
|
|
" <td>0.002739</td>\n",
|
|||
|
|
" <td>1.699235e-04</td>\n",
|
|||
|
|
" <td>0.000203</td>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" <tr>\n",
|
|||
|
|
" <th>ADX_14</th>\n",
|
|||
|
|
" <td>0.013390</td>\n",
|
|||
|
|
" <td>0.000597</td>\n",
|
|||
|
|
" <td>1.544759e-04</td>\n",
|
|||
|
|
" <td>0.000059</td>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" <tr>\n",
|
|||
|
|
" <th>CCI_diff_6</th>\n",
|
|||
|
|
" <td>0.013123</td>\n",
|
|||
|
|
" <td>0.001673</td>\n",
|
|||
|
|
" <td>1.544759e-04</td>\n",
|
|||
|
|
" <td>0.000133</td>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" <tr>\n",
|
|||
|
|
" <th>KeltnerWidth_15</th>\n",
|
|||
|
|
" <td>0.012065</td>\n",
|
|||
|
|
" <td>0.001431</td>\n",
|
|||
|
|
" <td>1.436626e-04</td>\n",
|
|||
|
|
" <td>0.000094</td>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" <tr>\n",
|
|||
|
|
" <th>CMO54</th>\n",
|
|||
|
|
" <td>0.014536</td>\n",
|
|||
|
|
" <td>0.000912</td>\n",
|
|||
|
|
" <td>1.204912e-04</td>\n",
|
|||
|
|
" <td>0.000225</td>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" <tr>\n",
|
|||
|
|
" <th>KeltnerWidth_24</th>\n",
|
|||
|
|
" <td>0.010461</td>\n",
|
|||
|
|
" <td>0.001092</td>\n",
|
|||
|
|
" <td>7.260369e-05</td>\n",
|
|||
|
|
" <td>0.000060</td>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" <tr>\n",
|
|||
|
|
" <th>CCI_ratio_2_8</th>\n",
|
|||
|
|
" <td>0.012882</td>\n",
|
|||
|
|
" <td>0.001430</td>\n",
|
|||
|
|
" <td>6.951417e-05</td>\n",
|
|||
|
|
" <td>0.000183</td>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" <tr>\n",
|
|||
|
|
" <th>KeltnerWidth_2</th>\n",
|
|||
|
|
" <td>0.015248</td>\n",
|
|||
|
|
" <td>0.001092</td>\n",
|
|||
|
|
" <td>5.870086e-05</td>\n",
|
|||
|
|
" <td>0.000102</td>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" <tr>\n",
|
|||
|
|
" <th>ADX_2</th>\n",
|
|||
|
|
" <td>0.015177</td>\n",
|
|||
|
|
" <td>0.003281</td>\n",
|
|||
|
|
" <td>5.097706e-05</td>\n",
|
|||
|
|
" <td>0.000124</td>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" <tr>\n",
|
|||
|
|
" <th>KeltnerWidth_20</th>\n",
|
|||
|
|
" <td>0.010705</td>\n",
|
|||
|
|
" <td>0.001163</td>\n",
|
|||
|
|
" <td>4.943230e-05</td>\n",
|
|||
|
|
" <td>0.000129</td>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" <tr>\n",
|
|||
|
|
" <th>CMO_2</th>\n",
|
|||
|
|
" <td>0.010696</td>\n",
|
|||
|
|
" <td>0.000290</td>\n",
|
|||
|
|
" <td>4.016374e-05</td>\n",
|
|||
|
|
" <td>0.000088</td>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" <tr>\n",
|
|||
|
|
" <th>ChaikinVol_3_10</th>\n",
|
|||
|
|
" <td>0.011406</td>\n",
|
|||
|
|
" <td>0.002300</td>\n",
|
|||
|
|
" <td>3.861899e-05</td>\n",
|
|||
|
|
" <td>0.000201</td>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" <tr>\n",
|
|||
|
|
" <th>KeltnerWidth_ratio_2_24</th>\n",
|
|||
|
|
" <td>0.014073</td>\n",
|
|||
|
|
" <td>0.001852</td>\n",
|
|||
|
|
" <td>1.699235e-05</td>\n",
|
|||
|
|
" <td>0.000338</td>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" <tr>\n",
|
|||
|
|
" <th>Hour_sin</th>\n",
|
|||
|
|
" <td>0.006267</td>\n",
|
|||
|
|
" <td>0.000311</td>\n",
|
|||
|
|
" <td>1.235808e-05</td>\n",
|
|||
|
|
" <td>0.000065</td>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" <tr>\n",
|
|||
|
|
" <th>ChaikinVol_2_5</th>\n",
|
|||
|
|
" <td>0.011735</td>\n",
|
|||
|
|
" <td>0.001426</td>\n",
|
|||
|
|
" <td>7.723797e-06</td>\n",
|
|||
|
|
" <td>0.000190</td>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" <tr>\n",
|
|||
|
|
" <th>CCI_2</th>\n",
|
|||
|
|
" <td>0.000981</td>\n",
|
|||
|
|
" <td>0.000159</td>\n",
|
|||
|
|
" <td>7.723797e-06</td>\n",
|
|||
|
|
" <td>0.000022</td>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" <tr>\n",
|
|||
|
|
" <th>DOW_sin</th>\n",
|
|||
|
|
" <td>0.003258</td>\n",
|
|||
|
|
" <td>0.000196</td>\n",
|
|||
|
|
" <td>1.544759e-06</td>\n",
|
|||
|
|
" <td>0.000045</td>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" <tr>\n",
|
|||
|
|
" <th>KeltnerWidth_diff_22</th>\n",
|
|||
|
|
" <td>0.011980</td>\n",
|
|||
|
|
" <td>0.001152</td>\n",
|
|||
|
|
" <td>4.219037e-17</td>\n",
|
|||
|
|
" <td>0.000229</td>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" <tr>\n",
|
|||
|
|
" <th>Unnamed: 0</th>\n",
|
|||
|
|
" <td>0.010731</td>\n",
|
|||
|
|
" <td>0.002601</td>\n",
|
|||
|
|
" <td>0.000000e+00</td>\n",
|
|||
|
|
" <td>0.000000</td>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" <tr>\n",
|
|||
|
|
" <th>Volume</th>\n",
|
|||
|
|
" <td>0.010460</td>\n",
|
|||
|
|
" <td>0.001554</td>\n",
|
|||
|
|
" <td>-7.723797e-06</td>\n",
|
|||
|
|
" <td>0.000081</td>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" <tr>\n",
|
|||
|
|
" <th>sma</th>\n",
|
|||
|
|
" <td>0.009080</td>\n",
|
|||
|
|
" <td>0.000535</td>\n",
|
|||
|
|
" <td>-7.723797e-06</td>\n",
|
|||
|
|
" <td>0.000075</td>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" <tr>\n",
|
|||
|
|
" <th>Quarter</th>\n",
|
|||
|
|
" <td>0.002403</td>\n",
|
|||
|
|
" <td>0.000197</td>\n",
|
|||
|
|
" <td>-1.235808e-05</td>\n",
|
|||
|
|
" <td>0.000057</td>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" <tr>\n",
|
|||
|
|
" <th>Close</th>\n",
|
|||
|
|
" <td>0.008296</td>\n",
|
|||
|
|
" <td>0.000433</td>\n",
|
|||
|
|
" <td>-1.544759e-05</td>\n",
|
|||
|
|
" <td>0.000058</td>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" <tr>\n",
|
|||
|
|
" <th>Oil_Close</th>\n",
|
|||
|
|
" <td>0.008671</td>\n",
|
|||
|
|
" <td>0.000734</td>\n",
|
|||
|
|
" <td>-1.699235e-05</td>\n",
|
|||
|
|
" <td>0.000033</td>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" <tr>\n",
|
|||
|
|
" <th>Month_sin</th>\n",
|
|||
|
|
" <td>0.003765</td>\n",
|
|||
|
|
" <td>0.000437</td>\n",
|
|||
|
|
" <td>-2.008187e-05</td>\n",
|
|||
|
|
" <td>0.000048</td>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" <tr>\n",
|
|||
|
|
" <th>Session</th>\n",
|
|||
|
|
" <td>0.001260</td>\n",
|
|||
|
|
" <td>0.000224</td>\n",
|
|||
|
|
" <td>-2.162663e-05</td>\n",
|
|||
|
|
" <td>0.000037</td>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" <tr>\n",
|
|||
|
|
" <th>ema</th>\n",
|
|||
|
|
" <td>0.007906</td>\n",
|
|||
|
|
" <td>0.000204</td>\n",
|
|||
|
|
" <td>-2.317139e-05</td>\n",
|
|||
|
|
" <td>0.000040</td>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" <tr>\n",
|
|||
|
|
" <th>Gold_Close</th>\n",
|
|||
|
|
" <td>0.010996</td>\n",
|
|||
|
|
" <td>0.003362</td>\n",
|
|||
|
|
" <td>-2.317139e-05</td>\n",
|
|||
|
|
" <td>0.000044</td>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" <tr>\n",
|
|||
|
|
" <th>Low</th>\n",
|
|||
|
|
" <td>0.008550</td>\n",
|
|||
|
|
" <td>0.000231</td>\n",
|
|||
|
|
" <td>-2.471615e-05</td>\n",
|
|||
|
|
" <td>0.000024</td>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" <tr>\n",
|
|||
|
|
" <th>Open</th>\n",
|
|||
|
|
" <td>0.008671</td>\n",
|
|||
|
|
" <td>0.000402</td>\n",
|
|||
|
|
" <td>-3.089519e-05</td>\n",
|
|||
|
|
" <td>0.000070</td>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" <tr>\n",
|
|||
|
|
" <th>ADX_ratio_2_14</th>\n",
|
|||
|
|
" <td>0.009070</td>\n",
|
|||
|
|
" <td>0.000448</td>\n",
|
|||
|
|
" <td>-3.398471e-05</td>\n",
|
|||
|
|
" <td>0.000109</td>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" <tr>\n",
|
|||
|
|
" <th>High</th>\n",
|
|||
|
|
" <td>0.008299</td>\n",
|
|||
|
|
" <td>0.000378</td>\n",
|
|||
|
|
" <td>-4.016374e-05</td>\n",
|
|||
|
|
" <td>0.000047</td>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" <tr>\n",
|
|||
|
|
" <th>ADX_diff_12</th>\n",
|
|||
|
|
" <td>0.009228</td>\n",
|
|||
|
|
" <td>0.000512</td>\n",
|
|||
|
|
" <td>-4.479802e-05</td>\n",
|
|||
|
|
" <td>0.000100</td>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" <tr>\n",
|
|||
|
|
" <th>ADX_ratio_5_14</th>\n",
|
|||
|
|
" <td>0.009508</td>\n",
|
|||
|
|
" <td>0.000785</td>\n",
|
|||
|
|
" <td>-4.634278e-05</td>\n",
|
|||
|
|
" <td>0.000120</td>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" <tr>\n",
|
|||
|
|
" <th>Date_sin</th>\n",
|
|||
|
|
" <td>0.005902</td>\n",
|
|||
|
|
" <td>0.000935</td>\n",
|
|||
|
|
" <td>-4.634278e-05</td>\n",
|
|||
|
|
" <td>0.000030</td>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" <tr>\n",
|
|||
|
|
" <th>Diff_10Y_2Y</th>\n",
|
|||
|
|
" <td>0.009158</td>\n",
|
|||
|
|
" <td>0.001091</td>\n",
|
|||
|
|
" <td>-4.634278e-05</td>\n",
|
|||
|
|
" <td>0.000097</td>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" <tr>\n",
|
|||
|
|
" <th>KeltnerWidth_ratio_2_15</th>\n",
|
|||
|
|
" <td>0.012956</td>\n",
|
|||
|
|
" <td>0.001455</td>\n",
|
|||
|
|
" <td>-4.943230e-05</td>\n",
|
|||
|
|
" <td>0.000295</td>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" <tr>\n",
|
|||
|
|
" <th>ADX_diff_9</th>\n",
|
|||
|
|
" <td>0.011238</td>\n",
|
|||
|
|
" <td>0.001878</td>\n",
|
|||
|
|
" <td>-5.561134e-05</td>\n",
|
|||
|
|
" <td>0.000059</td>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" <tr>\n",
|
|||
|
|
" <th>Oil_Volume</th>\n",
|
|||
|
|
" <td>0.008659</td>\n",
|
|||
|
|
" <td>0.000408</td>\n",
|
|||
|
|
" <td>-5.715610e-05</td>\n",
|
|||
|
|
" <td>0.000074</td>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" <tr>\n",
|
|||
|
|
" <th>ADX_diff_3</th>\n",
|
|||
|
|
" <td>0.010061</td>\n",
|
|||
|
|
" <td>0.000414</td>\n",
|
|||
|
|
" <td>-6.951417e-05</td>\n",
|
|||
|
|
" <td>0.000113</td>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" <tr>\n",
|
|||
|
|
" <th>KeltnerWidth_diff_13</th>\n",
|
|||
|
|
" <td>0.011701</td>\n",
|
|||
|
|
" <td>0.001045</td>\n",
|
|||
|
|
" <td>-7.723797e-05</td>\n",
|
|||
|
|
" <td>0.000233</td>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" </tbody>\n",
|
|||
|
|
"</table>\n",
|
|||
|
|
"</div>"
|
|||
|
|
],
|
|||
|
|
"text/plain": [
|
|||
|
|
" model_importance_mean model_importance_std \\\n",
|
|||
|
|
"signal 0.306649 0.042522 \n",
|
|||
|
|
"CMO_14 0.028196 0.000615 \n",
|
|||
|
|
"ADX_5 0.028298 0.001057 \n",
|
|||
|
|
"PPO_2_6 0.027918 0.000813 \n",
|
|||
|
|
"CCI_ratio_2_20 0.016868 0.002119 \n",
|
|||
|
|
"CCI_20 0.022840 0.001432 \n",
|
|||
|
|
"KeltnerWidth_ratio_15_24 0.020487 0.000306 \n",
|
|||
|
|
"CMO_ratio_2_14 0.015399 0.002409 \n",
|
|||
|
|
"CCI_ratio_8_20 0.015631 0.001033 \n",
|
|||
|
|
"CCI_diff_12 0.012387 0.001230 \n",
|
|||
|
|
"CCI_diff_18 0.015434 0.001561 \n",
|
|||
|
|
"KeltnerWidth_diff_9 0.021018 0.001042 \n",
|
|||
|
|
"PPO_12_26 0.014241 0.000926 \n",
|
|||
|
|
"CCI_8 0.019527 0.000839 \n",
|
|||
|
|
"CCI_14 0.020120 0.002310 \n",
|
|||
|
|
"CMO_diff_12 0.015694 0.001227 \n",
|
|||
|
|
"ADX_ratio_2_5 0.014738 0.002739 \n",
|
|||
|
|
"ADX_14 0.013390 0.000597 \n",
|
|||
|
|
"CCI_diff_6 0.013123 0.001673 \n",
|
|||
|
|
"KeltnerWidth_15 0.012065 0.001431 \n",
|
|||
|
|
"CMO54 0.014536 0.000912 \n",
|
|||
|
|
"KeltnerWidth_24 0.010461 0.001092 \n",
|
|||
|
|
"CCI_ratio_2_8 0.012882 0.001430 \n",
|
|||
|
|
"KeltnerWidth_2 0.015248 0.001092 \n",
|
|||
|
|
"ADX_2 0.015177 0.003281 \n",
|
|||
|
|
"KeltnerWidth_20 0.010705 0.001163 \n",
|
|||
|
|
"CMO_2 0.010696 0.000290 \n",
|
|||
|
|
"ChaikinVol_3_10 0.011406 0.002300 \n",
|
|||
|
|
"KeltnerWidth_ratio_2_24 0.014073 0.001852 \n",
|
|||
|
|
"Hour_sin 0.006267 0.000311 \n",
|
|||
|
|
"ChaikinVol_2_5 0.011735 0.001426 \n",
|
|||
|
|
"CCI_2 0.000981 0.000159 \n",
|
|||
|
|
"DOW_sin 0.003258 0.000196 \n",
|
|||
|
|
"KeltnerWidth_diff_22 0.011980 0.001152 \n",
|
|||
|
|
"Unnamed: 0 0.010731 0.002601 \n",
|
|||
|
|
"Volume 0.010460 0.001554 \n",
|
|||
|
|
"sma 0.009080 0.000535 \n",
|
|||
|
|
"Quarter 0.002403 0.000197 \n",
|
|||
|
|
"Close 0.008296 0.000433 \n",
|
|||
|
|
"Oil_Close 0.008671 0.000734 \n",
|
|||
|
|
"Month_sin 0.003765 0.000437 \n",
|
|||
|
|
"Session 0.001260 0.000224 \n",
|
|||
|
|
"ema 0.007906 0.000204 \n",
|
|||
|
|
"Gold_Close 0.010996 0.003362 \n",
|
|||
|
|
"Low 0.008550 0.000231 \n",
|
|||
|
|
"Open 0.008671 0.000402 \n",
|
|||
|
|
"ADX_ratio_2_14 0.009070 0.000448 \n",
|
|||
|
|
"High 0.008299 0.000378 \n",
|
|||
|
|
"ADX_diff_12 0.009228 0.000512 \n",
|
|||
|
|
"ADX_ratio_5_14 0.009508 0.000785 \n",
|
|||
|
|
"Date_sin 0.005902 0.000935 \n",
|
|||
|
|
"Diff_10Y_2Y 0.009158 0.001091 \n",
|
|||
|
|
"KeltnerWidth_ratio_2_15 0.012956 0.001455 \n",
|
|||
|
|
"ADX_diff_9 0.011238 0.001878 \n",
|
|||
|
|
"Oil_Volume 0.008659 0.000408 \n",
|
|||
|
|
"ADX_diff_3 0.010061 0.000414 \n",
|
|||
|
|
"KeltnerWidth_diff_13 0.011701 0.001045 \n",
|
|||
|
|
"\n",
|
|||
|
|
" perm_importance_mean perm_importance_std \n",
|
|||
|
|
"signal 1.170155e-02 0.002480 \n",
|
|||
|
|
"CMO_14 1.136943e-03 0.000429 \n",
|
|||
|
|
"ADX_5 8.187225e-04 0.000296 \n",
|
|||
|
|
"PPO_2_6 5.947324e-04 0.000526 \n",
|
|||
|
|
"CCI_ratio_2_20 5.823743e-04 0.000256 \n",
|
|||
|
|
"CCI_20 3.908241e-04 0.000319 \n",
|
|||
|
|
"KeltnerWidth_ratio_15_24 3.645632e-04 0.000174 \n",
|
|||
|
|
"CMO_ratio_2_14 3.413918e-04 0.000282 \n",
|
|||
|
|
"CCI_ratio_8_20 3.182204e-04 0.000115 \n",
|
|||
|
|
"CCI_diff_12 3.074071e-04 0.000082 \n",
|
|||
|
|
"CCI_diff_18 3.043176e-04 0.000150 \n",
|
|||
|
|
"KeltnerWidth_diff_9 2.765119e-04 0.000094 \n",
|
|||
|
|
"PPO_12_26 2.641539e-04 0.000109 \n",
|
|||
|
|
"CCI_8 1.930949e-04 0.000339 \n",
|
|||
|
|
"CCI_14 1.884606e-04 0.000213 \n",
|
|||
|
|
"CMO_diff_12 1.714683e-04 0.000283 \n",
|
|||
|
|
"ADX_ratio_2_5 1.699235e-04 0.000203 \n",
|
|||
|
|
"ADX_14 1.544759e-04 0.000059 \n",
|
|||
|
|
"CCI_diff_6 1.544759e-04 0.000133 \n",
|
|||
|
|
"KeltnerWidth_15 1.436626e-04 0.000094 \n",
|
|||
|
|
"CMO54 1.204912e-04 0.000225 \n",
|
|||
|
|
"KeltnerWidth_24 7.260369e-05 0.000060 \n",
|
|||
|
|
"CCI_ratio_2_8 6.951417e-05 0.000183 \n",
|
|||
|
|
"KeltnerWidth_2 5.870086e-05 0.000102 \n",
|
|||
|
|
"ADX_2 5.097706e-05 0.000124 \n",
|
|||
|
|
"KeltnerWidth_20 4.943230e-05 0.000129 \n",
|
|||
|
|
"CMO_2 4.016374e-05 0.000088 \n",
|
|||
|
|
"ChaikinVol_3_10 3.861899e-05 0.000201 \n",
|
|||
|
|
"KeltnerWidth_ratio_2_24 1.699235e-05 0.000338 \n",
|
|||
|
|
"Hour_sin 1.235808e-05 0.000065 \n",
|
|||
|
|
"ChaikinVol_2_5 7.723797e-06 0.000190 \n",
|
|||
|
|
"CCI_2 7.723797e-06 0.000022 \n",
|
|||
|
|
"DOW_sin 1.544759e-06 0.000045 \n",
|
|||
|
|
"KeltnerWidth_diff_22 4.219037e-17 0.000229 \n",
|
|||
|
|
"Unnamed: 0 0.000000e+00 0.000000 \n",
|
|||
|
|
"Volume -7.723797e-06 0.000081 \n",
|
|||
|
|
"sma -7.723797e-06 0.000075 \n",
|
|||
|
|
"Quarter -1.235808e-05 0.000057 \n",
|
|||
|
|
"Close -1.544759e-05 0.000058 \n",
|
|||
|
|
"Oil_Close -1.699235e-05 0.000033 \n",
|
|||
|
|
"Month_sin -2.008187e-05 0.000048 \n",
|
|||
|
|
"Session -2.162663e-05 0.000037 \n",
|
|||
|
|
"ema -2.317139e-05 0.000040 \n",
|
|||
|
|
"Gold_Close -2.317139e-05 0.000044 \n",
|
|||
|
|
"Low -2.471615e-05 0.000024 \n",
|
|||
|
|
"Open -3.089519e-05 0.000070 \n",
|
|||
|
|
"ADX_ratio_2_14 -3.398471e-05 0.000109 \n",
|
|||
|
|
"High -4.016374e-05 0.000047 \n",
|
|||
|
|
"ADX_diff_12 -4.479802e-05 0.000100 \n",
|
|||
|
|
"ADX_ratio_5_14 -4.634278e-05 0.000120 \n",
|
|||
|
|
"Date_sin -4.634278e-05 0.000030 \n",
|
|||
|
|
"Diff_10Y_2Y -4.634278e-05 0.000097 \n",
|
|||
|
|
"KeltnerWidth_ratio_2_15 -4.943230e-05 0.000295 \n",
|
|||
|
|
"ADX_diff_9 -5.561134e-05 0.000059 \n",
|
|||
|
|
"Oil_Volume -5.715610e-05 0.000074 \n",
|
|||
|
|
"ADX_diff_3 -6.951417e-05 0.000113 \n",
|
|||
|
|
"KeltnerWidth_diff_13 -7.723797e-05 0.000233 "
|
|||
|
|
]
|
|||
|
|
},
|
|||
|
|
"execution_count": 52,
|
|||
|
|
"metadata": {},
|
|||
|
|
"output_type": "execute_result"
|
|||
|
|
}
|
|||
|
|
],
|
|||
|
|
"source": [
|
|||
|
|
"# Or descending (largest → smallest)\n",
|
|||
|
|
"df_sorted_desc = importance.sort_values(by=\"perm_importance_mean\", ascending=False)\n",
|
|||
|
|
"\n",
|
|||
|
|
"\n",
|
|||
|
|
"df_sorted_desc"
|
|||
|
|
]
|
|||
|
|
},
|
|||
|
|
{
|
|||
|
|
"cell_type": "code",
|
|||
|
|
"execution_count": 64,
|
|||
|
|
"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>Hour_sin</th>\n",
|
|||
|
|
" <th>DOW_sin</th>\n",
|
|||
|
|
" <th>ADX_14</th>\n",
|
|||
|
|
" <th>CCI_14</th>\n",
|
|||
|
|
" <th>PPO_12_26</th>\n",
|
|||
|
|
" <th>CMO_14</th>\n",
|
|||
|
|
" <th>ADX_2</th>\n",
|
|||
|
|
" <th>ADX_5</th>\n",
|
|||
|
|
" <th>CCI_8</th>\n",
|
|||
|
|
" <th>CCI_20</th>\n",
|
|||
|
|
" <th>...</th>\n",
|
|||
|
|
" <th>CCI_diff_18</th>\n",
|
|||
|
|
" <th>CCI_ratio_8_20</th>\n",
|
|||
|
|
" <th>CCI_ratio_2_20</th>\n",
|
|||
|
|
" <th>CMO_diff_12</th>\n",
|
|||
|
|
" <th>CMO_ratio_2_14</th>\n",
|
|||
|
|
" <th>KeltnerWidth_diff_9</th>\n",
|
|||
|
|
" <th>KeltnerWidth_ratio_15_24</th>\n",
|
|||
|
|
" <th>KeltnerWidth_ratio_2_24</th>\n",
|
|||
|
|
" <th>signal</th>\n",
|
|||
|
|
" <th>target_signal</th>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" </thead>\n",
|
|||
|
|
" <tbody>\n",
|
|||
|
|
" <tr>\n",
|
|||
|
|
" <th>0</th>\n",
|
|||
|
|
" <td>0.86603</td>\n",
|
|||
|
|
" <td>0.974928</td>\n",
|
|||
|
|
" <td>25.930420</td>\n",
|
|||
|
|
" <td>39.315068</td>\n",
|
|||
|
|
" <td>0.121403</td>\n",
|
|||
|
|
" <td>7.355190</td>\n",
|
|||
|
|
" <td>41.651610</td>\n",
|
|||
|
|
" <td>42.154713</td>\n",
|
|||
|
|
" <td>-6.549708</td>\n",
|
|||
|
|
" <td>59.300273</td>\n",
|
|||
|
|
" <td>...</td>\n",
|
|||
|
|
" <td>125.966939</td>\n",
|
|||
|
|
" <td>-0.110450</td>\n",
|
|||
|
|
" <td>-1.124222</td>\n",
|
|||
|
|
" <td>-34.296419</td>\n",
|
|||
|
|
" <td>-1.695703</td>\n",
|
|||
|
|
" <td>0.000011</td>\n",
|
|||
|
|
" <td>0.993302</td>\n",
|
|||
|
|
" <td>1.370979</td>\n",
|
|||
|
|
" <td>-1.0</td>\n",
|
|||
|
|
" <td>-1.0</td>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" <tr>\n",
|
|||
|
|
" <th>1</th>\n",
|
|||
|
|
" <td>0.96593</td>\n",
|
|||
|
|
" <td>0.974928</td>\n",
|
|||
|
|
" <td>25.909992</td>\n",
|
|||
|
|
" <td>-65.160075</td>\n",
|
|||
|
|
" <td>0.107986</td>\n",
|
|||
|
|
" <td>8.428157</td>\n",
|
|||
|
|
" <td>31.880359</td>\n",
|
|||
|
|
" <td>37.044387</td>\n",
|
|||
|
|
" <td>-132.473118</td>\n",
|
|||
|
|
" <td>23.189994</td>\n",
|
|||
|
|
" <td>...</td>\n",
|
|||
|
|
" <td>89.856660</td>\n",
|
|||
|
|
" <td>-5.712512</td>\n",
|
|||
|
|
" <td>-2.874803</td>\n",
|
|||
|
|
" <td>-23.452201</td>\n",
|
|||
|
|
" <td>1.023121</td>\n",
|
|||
|
|
" <td>0.000036</td>\n",
|
|||
|
|
" <td>0.977000</td>\n",
|
|||
|
|
" <td>0.906158</td>\n",
|
|||
|
|
" <td>0.0</td>\n",
|
|||
|
|
" <td>0.0</td>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" <tr>\n",
|
|||
|
|
" <th>2</th>\n",
|
|||
|
|
" <td>1.00000</td>\n",
|
|||
|
|
" <td>0.974928</td>\n",
|
|||
|
|
" <td>25.381184</td>\n",
|
|||
|
|
" <td>-146.502058</td>\n",
|
|||
|
|
" <td>0.095970</td>\n",
|
|||
|
|
" <td>3.275771</td>\n",
|
|||
|
|
" <td>48.925969</td>\n",
|
|||
|
|
" <td>30.959935</td>\n",
|
|||
|
|
" <td>-167.017544</td>\n",
|
|||
|
|
" <td>-12.596221</td>\n",
|
|||
|
|
" <td>...</td>\n",
|
|||
|
|
" <td>54.070446</td>\n",
|
|||
|
|
" <td>13.259337</td>\n",
|
|||
|
|
" <td>5.292593</td>\n",
|
|||
|
|
" <td>-45.650197</td>\n",
|
|||
|
|
" <td>0.455056</td>\n",
|
|||
|
|
" <td>0.000055</td>\n",
|
|||
|
|
" <td>0.963263</td>\n",
|
|||
|
|
" <td>0.758581</td>\n",
|
|||
|
|
" <td>0.0</td>\n",
|
|||
|
|
" <td>0.0</td>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" <tr>\n",
|
|||
|
|
" <th>3</th>\n",
|
|||
|
|
" <td>0.96593</td>\n",
|
|||
|
|
" <td>0.974928</td>\n",
|
|||
|
|
" <td>25.225738</td>\n",
|
|||
|
|
" <td>-88.888889</td>\n",
|
|||
|
|
" <td>0.085549</td>\n",
|
|||
|
|
" <td>7.984586</td>\n",
|
|||
|
|
" <td>35.433883</td>\n",
|
|||
|
|
" <td>27.694438</td>\n",
|
|||
|
|
" <td>-79.830149</td>\n",
|
|||
|
|
" <td>-3.902146</td>\n",
|
|||
|
|
" <td>...</td>\n",
|
|||
|
|
" <td>-70.568813</td>\n",
|
|||
|
|
" <td>20.458011</td>\n",
|
|||
|
|
" <td>-17.084615</td>\n",
|
|||
|
|
" <td>-27.449297</td>\n",
|
|||
|
|
" <td>-0.750000</td>\n",
|
|||
|
|
" <td>0.000060</td>\n",
|
|||
|
|
" <td>0.959495</td>\n",
|
|||
|
|
" <td>0.815246</td>\n",
|
|||
|
|
" <td>0.0</td>\n",
|
|||
|
|
" <td>0.0</td>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" <tr>\n",
|
|||
|
|
" <th>4</th>\n",
|
|||
|
|
" <td>0.86603</td>\n",
|
|||
|
|
" <td>0.974928</td>\n",
|
|||
|
|
" <td>26.060597</td>\n",
|
|||
|
|
" <td>86.264929</td>\n",
|
|||
|
|
" <td>0.084842</td>\n",
|
|||
|
|
" <td>24.751330</td>\n",
|
|||
|
|
" <td>59.426680</td>\n",
|
|||
|
|
" <td>33.035738</td>\n",
|
|||
|
|
" <td>67.208672</td>\n",
|
|||
|
|
" <td>96.026205</td>\n",
|
|||
|
|
" <td>...</td>\n",
|
|||
|
|
" <td>29.359538</td>\n",
|
|||
|
|
" <td>0.699899</td>\n",
|
|||
|
|
" <td>0.694255</td>\n",
|
|||
|
|
" <td>-34.675350</td>\n",
|
|||
|
|
" <td>0.772813</td>\n",
|
|||
|
|
" <td>0.000025</td>\n",
|
|||
|
|
" <td>0.983683</td>\n",
|
|||
|
|
" <td>1.174859</td>\n",
|
|||
|
|
" <td>0.0</td>\n",
|
|||
|
|
" <td>0.0</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",
|
|||
|
|
" <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>77682</th>\n",
|
|||
|
|
" <td>-1.00000</td>\n",
|
|||
|
|
" <td>0.433884</td>\n",
|
|||
|
|
" <td>33.262839</td>\n",
|
|||
|
|
" <td>-172.486839</td>\n",
|
|||
|
|
" <td>-0.129321</td>\n",
|
|||
|
|
" <td>-67.588764</td>\n",
|
|||
|
|
" <td>97.465878</td>\n",
|
|||
|
|
" <td>70.027283</td>\n",
|
|||
|
|
" <td>-111.789483</td>\n",
|
|||
|
|
" <td>-233.479963</td>\n",
|
|||
|
|
" <td>...</td>\n",
|
|||
|
|
" <td>-166.813296</td>\n",
|
|||
|
|
" <td>0.478797</td>\n",
|
|||
|
|
" <td>0.285535</td>\n",
|
|||
|
|
" <td>-165.054643</td>\n",
|
|||
|
|
" <td>0.386503</td>\n",
|
|||
|
|
" <td>-0.000233</td>\n",
|
|||
|
|
" <td>1.176570</td>\n",
|
|||
|
|
" <td>1.682584</td>\n",
|
|||
|
|
" <td>0.0</td>\n",
|
|||
|
|
" <td>0.0</td>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" <tr>\n",
|
|||
|
|
" <th>77683</th>\n",
|
|||
|
|
" <td>-0.96593</td>\n",
|
|||
|
|
" <td>0.433884</td>\n",
|
|||
|
|
" <td>36.313543</td>\n",
|
|||
|
|
" <td>-125.872774</td>\n",
|
|||
|
|
" <td>-0.160356</td>\n",
|
|||
|
|
" <td>-51.571693</td>\n",
|
|||
|
|
" <td>98.306065</td>\n",
|
|||
|
|
" <td>74.257578</td>\n",
|
|||
|
|
" <td>-82.237004</td>\n",
|
|||
|
|
" <td>-172.632282</td>\n",
|
|||
|
|
" <td>...</td>\n",
|
|||
|
|
" <td>-239.298949</td>\n",
|
|||
|
|
" <td>0.476371</td>\n",
|
|||
|
|
" <td>-0.386177</td>\n",
|
|||
|
|
" <td>-149.877758</td>\n",
|
|||
|
|
" <td>-0.529635</td>\n",
|
|||
|
|
" <td>-0.000231</td>\n",
|
|||
|
|
" <td>1.169284</td>\n",
|
|||
|
|
" <td>1.484021</td>\n",
|
|||
|
|
" <td>0.0</td>\n",
|
|||
|
|
" <td>0.0</td>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" <tr>\n",
|
|||
|
|
" <th>77684</th>\n",
|
|||
|
|
" <td>-0.86603</td>\n",
|
|||
|
|
" <td>0.433884</td>\n",
|
|||
|
|
" <td>39.146339</td>\n",
|
|||
|
|
" <td>-103.217265</td>\n",
|
|||
|
|
" <td>-0.188601</td>\n",
|
|||
|
|
" <td>-54.267195</td>\n",
|
|||
|
|
" <td>98.726158</td>\n",
|
|||
|
|
" <td>77.641815</td>\n",
|
|||
|
|
" <td>-68.714640</td>\n",
|
|||
|
|
" <td>-140.468984</td>\n",
|
|||
|
|
" <td>...</td>\n",
|
|||
|
|
" <td>-73.802317</td>\n",
|
|||
|
|
" <td>0.489180</td>\n",
|
|||
|
|
" <td>0.474601</td>\n",
|
|||
|
|
" <td>-152.993353</td>\n",
|
|||
|
|
" <td>0.645887</td>\n",
|
|||
|
|
" <td>-0.000180</td>\n",
|
|||
|
|
" <td>1.135452</td>\n",
|
|||
|
|
" <td>0.940292</td>\n",
|
|||
|
|
" <td>0.0</td>\n",
|
|||
|
|
" <td>0.0</td>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" <tr>\n",
|
|||
|
|
" <th>77685</th>\n",
|
|||
|
|
" <td>-0.70711</td>\n",
|
|||
|
|
" <td>0.433884</td>\n",
|
|||
|
|
" <td>42.314998</td>\n",
|
|||
|
|
" <td>-125.764047</td>\n",
|
|||
|
|
" <td>-0.234321</td>\n",
|
|||
|
|
" <td>-65.243593</td>\n",
|
|||
|
|
" <td>99.321072</td>\n",
|
|||
|
|
" <td>81.298451</td>\n",
|
|||
|
|
" <td>-123.954156</td>\n",
|
|||
|
|
" <td>-160.044002</td>\n",
|
|||
|
|
" <td>...</td>\n",
|
|||
|
|
" <td>-93.377336</td>\n",
|
|||
|
|
" <td>0.774500</td>\n",
|
|||
|
|
" <td>0.416552</td>\n",
|
|||
|
|
" <td>-164.564665</td>\n",
|
|||
|
|
" <td>0.530093</td>\n",
|
|||
|
|
" <td>-0.000271</td>\n",
|
|||
|
|
" <td>1.177650</td>\n",
|
|||
|
|
" <td>1.960267</td>\n",
|
|||
|
|
" <td>0.0</td>\n",
|
|||
|
|
" <td>0.0</td>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" <tr>\n",
|
|||
|
|
" <th>77686</th>\n",
|
|||
|
|
" <td>-0.50000</td>\n",
|
|||
|
|
" <td>0.433884</td>\n",
|
|||
|
|
" <td>45.257324</td>\n",
|
|||
|
|
" <td>-118.285292</td>\n",
|
|||
|
|
" <td>-0.287115</td>\n",
|
|||
|
|
" <td>-65.720496</td>\n",
|
|||
|
|
" <td>99.618529</td>\n",
|
|||
|
|
" <td>84.223761</td>\n",
|
|||
|
|
" <td>-137.559041</td>\n",
|
|||
|
|
" <td>-148.659237</td>\n",
|
|||
|
|
" <td>...</td>\n",
|
|||
|
|
" <td>-81.992570</td>\n",
|
|||
|
|
" <td>0.925331</td>\n",
|
|||
|
|
" <td>0.448453</td>\n",
|
|||
|
|
" <td>-165.339025</td>\n",
|
|||
|
|
" <td>0.563609</td>\n",
|
|||
|
|
" <td>-0.000205</td>\n",
|
|||
|
|
" <td>1.139376</td>\n",
|
|||
|
|
" <td>1.040766</td>\n",
|
|||
|
|
" <td>1.0</td>\n",
|
|||
|
|
" <td>1.0</td>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" </tbody>\n",
|
|||
|
|
"</table>\n",
|
|||
|
|
"<p>77687 rows × 26 columns</p>\n",
|
|||
|
|
"</div>"
|
|||
|
|
],
|
|||
|
|
"text/plain": [
|
|||
|
|
" Hour_sin DOW_sin ADX_14 CCI_14 PPO_12_26 CMO_14 \\\n",
|
|||
|
|
"0 0.86603 0.974928 25.930420 39.315068 0.121403 7.355190 \n",
|
|||
|
|
"1 0.96593 0.974928 25.909992 -65.160075 0.107986 8.428157 \n",
|
|||
|
|
"2 1.00000 0.974928 25.381184 -146.502058 0.095970 3.275771 \n",
|
|||
|
|
"3 0.96593 0.974928 25.225738 -88.888889 0.085549 7.984586 \n",
|
|||
|
|
"4 0.86603 0.974928 26.060597 86.264929 0.084842 24.751330 \n",
|
|||
|
|
"... ... ... ... ... ... ... \n",
|
|||
|
|
"77682 -1.00000 0.433884 33.262839 -172.486839 -0.129321 -67.588764 \n",
|
|||
|
|
"77683 -0.96593 0.433884 36.313543 -125.872774 -0.160356 -51.571693 \n",
|
|||
|
|
"77684 -0.86603 0.433884 39.146339 -103.217265 -0.188601 -54.267195 \n",
|
|||
|
|
"77685 -0.70711 0.433884 42.314998 -125.764047 -0.234321 -65.243593 \n",
|
|||
|
|
"77686 -0.50000 0.433884 45.257324 -118.285292 -0.287115 -65.720496 \n",
|
|||
|
|
"\n",
|
|||
|
|
" ADX_2 ADX_5 CCI_8 CCI_20 ... CCI_diff_18 \\\n",
|
|||
|
|
"0 41.651610 42.154713 -6.549708 59.300273 ... 125.966939 \n",
|
|||
|
|
"1 31.880359 37.044387 -132.473118 23.189994 ... 89.856660 \n",
|
|||
|
|
"2 48.925969 30.959935 -167.017544 -12.596221 ... 54.070446 \n",
|
|||
|
|
"3 35.433883 27.694438 -79.830149 -3.902146 ... -70.568813 \n",
|
|||
|
|
"4 59.426680 33.035738 67.208672 96.026205 ... 29.359538 \n",
|
|||
|
|
"... ... ... ... ... ... ... \n",
|
|||
|
|
"77682 97.465878 70.027283 -111.789483 -233.479963 ... -166.813296 \n",
|
|||
|
|
"77683 98.306065 74.257578 -82.237004 -172.632282 ... -239.298949 \n",
|
|||
|
|
"77684 98.726158 77.641815 -68.714640 -140.468984 ... -73.802317 \n",
|
|||
|
|
"77685 99.321072 81.298451 -123.954156 -160.044002 ... -93.377336 \n",
|
|||
|
|
"77686 99.618529 84.223761 -137.559041 -148.659237 ... -81.992570 \n",
|
|||
|
|
"\n",
|
|||
|
|
" CCI_ratio_8_20 CCI_ratio_2_20 CMO_diff_12 CMO_ratio_2_14 \\\n",
|
|||
|
|
"0 -0.110450 -1.124222 -34.296419 -1.695703 \n",
|
|||
|
|
"1 -5.712512 -2.874803 -23.452201 1.023121 \n",
|
|||
|
|
"2 13.259337 5.292593 -45.650197 0.455056 \n",
|
|||
|
|
"3 20.458011 -17.084615 -27.449297 -0.750000 \n",
|
|||
|
|
"4 0.699899 0.694255 -34.675350 0.772813 \n",
|
|||
|
|
"... ... ... ... ... \n",
|
|||
|
|
"77682 0.478797 0.285535 -165.054643 0.386503 \n",
|
|||
|
|
"77683 0.476371 -0.386177 -149.877758 -0.529635 \n",
|
|||
|
|
"77684 0.489180 0.474601 -152.993353 0.645887 \n",
|
|||
|
|
"77685 0.774500 0.416552 -164.564665 0.530093 \n",
|
|||
|
|
"77686 0.925331 0.448453 -165.339025 0.563609 \n",
|
|||
|
|
"\n",
|
|||
|
|
" KeltnerWidth_diff_9 KeltnerWidth_ratio_15_24 KeltnerWidth_ratio_2_24 \\\n",
|
|||
|
|
"0 0.000011 0.993302 1.370979 \n",
|
|||
|
|
"1 0.000036 0.977000 0.906158 \n",
|
|||
|
|
"2 0.000055 0.963263 0.758581 \n",
|
|||
|
|
"3 0.000060 0.959495 0.815246 \n",
|
|||
|
|
"4 0.000025 0.983683 1.174859 \n",
|
|||
|
|
"... ... ... ... \n",
|
|||
|
|
"77682 -0.000233 1.176570 1.682584 \n",
|
|||
|
|
"77683 -0.000231 1.169284 1.484021 \n",
|
|||
|
|
"77684 -0.000180 1.135452 0.940292 \n",
|
|||
|
|
"77685 -0.000271 1.177650 1.960267 \n",
|
|||
|
|
"77686 -0.000205 1.139376 1.040766 \n",
|
|||
|
|
"\n",
|
|||
|
|
" signal target_signal \n",
|
|||
|
|
"0 -1.0 -1.0 \n",
|
|||
|
|
"1 0.0 0.0 \n",
|
|||
|
|
"2 0.0 0.0 \n",
|
|||
|
|
"3 0.0 0.0 \n",
|
|||
|
|
"4 0.0 0.0 \n",
|
|||
|
|
"... ... ... \n",
|
|||
|
|
"77682 0.0 0.0 \n",
|
|||
|
|
"77683 0.0 0.0 \n",
|
|||
|
|
"77684 0.0 0.0 \n",
|
|||
|
|
"77685 0.0 0.0 \n",
|
|||
|
|
"77686 1.0 1.0 \n",
|
|||
|
|
"\n",
|
|||
|
|
"[77687 rows x 26 columns]"
|
|||
|
|
]
|
|||
|
|
},
|
|||
|
|
"execution_count": 64,
|
|||
|
|
"metadata": {},
|
|||
|
|
"output_type": "execute_result"
|
|||
|
|
}
|
|||
|
|
],
|
|||
|
|
"source": [
|
|||
|
|
"train_df[\"CCI_ratio_8_20\"] = pd.to_numeric(train_df[\"CCI_ratio_8_20\"].replace(\"#NAME?\", 0), errors=\"coerce\")\n",
|
|||
|
|
"train_df\n"
|
|||
|
|
]
|
|||
|
|
},
|
|||
|
|
{
|
|||
|
|
"cell_type": "code",
|
|||
|
|
"execution_count": 57,
|
|||
|
|
"metadata": {},
|
|||
|
|
"outputs": [],
|
|||
|
|
"source": [
|
|||
|
|
"cols_to_drop = [\"Quarter\", \"Month_sin\", \"Date_sin\", \"Close\", \"ema\", \"Open\", \"Oil_Close\", \"CCI_2\",\n",
|
|||
|
|
" \"KeltnerWidth_diff_22\",\"KeltnerWidth_ratio_2_15\", \"ADX_diff_12\", \"ADX_diff_3\",\"ADX_diff_9\",\n",
|
|||
|
|
" \"CMO_2\", \"KeltnerWidth_diff_13\", \"ADX_ratio_2_14\", \"ADX_ratio_5_14\", \"ChaikinVol_2_5\", \"CCI_ratio_2_8\",\n",
|
|||
|
|
" \"Volume\", \"CMO_2\", \"KeltnerWidth_15\", \"KeltnerWidth_20\", \"KeltnerWidth_24\",\n",
|
|||
|
|
" \"ChaikinVol_3_10\", \"Unnamed: 0\", \"High\", \"Low\", \"sma\", \"Session\", \"Gold_Close\", \"Oil_Volume\", \"Diff_10Y_2Y\"]\n",
|
|||
|
|
"train_df = train_df.drop(columns=cols_to_drop)\n"
|
|||
|
|
]
|
|||
|
|
},
|
|||
|
|
{
|
|||
|
|
"cell_type": "markdown",
|
|||
|
|
"metadata": {},
|
|||
|
|
"source": [
|
|||
|
|
"# Model Training and Optimisation"
|
|||
|
|
]
|
|||
|
|
},
|
|||
|
|
{
|
|||
|
|
"cell_type": "code",
|
|||
|
|
"execution_count": 65,
|
|||
|
|
"metadata": {},
|
|||
|
|
"outputs": [
|
|||
|
|
{
|
|||
|
|
"name": "stdout",
|
|||
|
|
"output_type": "stream",
|
|||
|
|
"text": [
|
|||
|
|
"\n",
|
|||
|
|
"=== Hyperparameter Tuning (Randomized Search) ===\n",
|
|||
|
|
"[01/30] BA=0.8559 | F1m=0.8482 | Acc=0.9946 | best_n_estimators≈1001\n",
|
|||
|
|
"[02/30] BA=0.8510 | F1m=0.8434 | Acc=0.9944 | best_n_estimators≈844\n",
|
|||
|
|
"[03/30] BA=0.8579 | F1m=0.8503 | Acc=0.9946 | best_n_estimators≈470\n",
|
|||
|
|
"[04/30] BA=0.8478 | F1m=0.8403 | Acc=0.9943 | best_n_estimators≈181\n",
|
|||
|
|
"[05/30] BA=0.8528 | F1m=0.8451 | Acc=0.9945 | best_n_estimators≈1021\n",
|
|||
|
|
"[06/30] BA=0.8542 | F1m=0.8466 | Acc=0.9945 | best_n_estimators≈1374\n",
|
|||
|
|
"[07/30] BA=0.8589 | F1m=0.8512 | Acc=0.9947 | best_n_estimators≈253\n",
|
|||
|
|
"[08/30] BA=0.8544 | F1m=0.8466 | Acc=0.9945 | best_n_estimators≈371\n",
|
|||
|
|
"[09/30] BA=0.8551 | F1m=0.8475 | Acc=0.9945 | best_n_estimators≈800\n",
|
|||
|
|
"[10/30] BA=0.8564 | F1m=0.8487 | Acc=0.9946 | best_n_estimators≈821\n",
|
|||
|
|
"[11/30] BA=0.8498 | F1m=0.8422 | Acc=0.9944 | best_n_estimators≈133\n",
|
|||
|
|
"[12/30] BA=0.8421 | F1m=0.8346 | Acc=0.9941 | best_n_estimators≈144\n",
|
|||
|
|
"[13/30] BA=0.8523 | F1m=0.8445 | Acc=0.9945 | best_n_estimators≈612\n",
|
|||
|
|
"[14/30] BA=0.8519 | F1m=0.8442 | Acc=0.9945 | best_n_estimators≈193\n",
|
|||
|
|
"[15/30] BA=0.8521 | F1m=0.8443 | Acc=0.9945 | best_n_estimators≈423\n",
|
|||
|
|
"[16/30] BA=0.8522 | F1m=0.8445 | Acc=0.9945 | best_n_estimators≈429\n",
|
|||
|
|
"[17/30] BA=0.8535 | F1m=0.8458 | Acc=0.9945 | best_n_estimators≈394\n",
|
|||
|
|
"[18/30] BA=0.8620 | F1m=0.8543 | Acc=0.9948 | best_n_estimators≈360\n",
|
|||
|
|
"[19/30] BA=0.8537 | F1m=0.8460 | Acc=0.9945 | best_n_estimators≈116\n",
|
|||
|
|
"[20/30] BA=0.8515 | F1m=0.8438 | Acc=0.9944 | best_n_estimators≈216\n",
|
|||
|
|
"[21/30] BA=0.8515 | F1m=0.8438 | Acc=0.9944 | best_n_estimators≈142\n",
|
|||
|
|
"[22/30] BA=0.8599 | F1m=0.8523 | Acc=0.9947 | best_n_estimators≈666\n",
|
|||
|
|
"[23/30] BA=0.8618 | F1m=0.8541 | Acc=0.9947 | best_n_estimators≈222\n",
|
|||
|
|
"[24/30] BA=0.8560 | F1m=0.8483 | Acc=0.9946 | best_n_estimators≈646\n",
|
|||
|
|
"[25/30] BA=0.8560 | F1m=0.8484 | Acc=0.9946 | best_n_estimators≈487\n",
|
|||
|
|
"[26/30] BA=0.8516 | F1m=0.8439 | Acc=0.9945 | best_n_estimators≈465\n",
|
|||
|
|
"[27/30] BA=0.8539 | F1m=0.8460 | Acc=0.9945 | best_n_estimators≈577\n",
|
|||
|
|
"[28/30] BA=0.8529 | F1m=0.8452 | Acc=0.9945 | best_n_estimators≈1658\n",
|
|||
|
|
"[29/30] BA=0.8571 | F1m=0.8493 | Acc=0.9946 | best_n_estimators≈250\n",
|
|||
|
|
"[30/30] BA=0.8524 | F1m=0.8446 | Acc=0.9945 | best_n_estimators≈869\n",
|
|||
|
|
"\n",
|
|||
|
|
"=== Best Params (by balanced_accuracy) ===\n",
|
|||
|
|
"{'eta': 0.03, 'max_depth': 4, 'min_child_weight': 2.0, 'subsample': 0.8, 'colsample_bytree': 1.0, 'lambda': 1.0, 'alpha': 0.1, 'gamma': 0.1}\n",
|
|||
|
|
"Best mean_best_iters: 360\n",
|
|||
|
|
"\n",
|
|||
|
|
"Top-5 tuning results:\n",
|
|||
|
|
" iter eta max_depth min_child_weight subsample colsample_bytree \\\n",
|
|||
|
|
"0 18 0.03 4 2.0 0.8 1.0 \n",
|
|||
|
|
"1 23 0.05 4 5.0 0.8 1.0 \n",
|
|||
|
|
"2 22 0.02 4 1.0 0.6 0.9 \n",
|
|||
|
|
"3 7 0.05 7 5.0 0.6 0.7 \n",
|
|||
|
|
"4 3 0.03 4 5.0 0.8 0.8 \n",
|
|||
|
|
"\n",
|
|||
|
|
" lambda alpha gamma mean_best_iters accuracy balanced_accuracy \\\n",
|
|||
|
|
"0 1.0 0.1 0.1 360 0.994763 0.861978 \n",
|
|||
|
|
"1 0.5 0.1 0.3 222 0.994748 0.861802 \n",
|
|||
|
|
"2 3.0 0.3 0.1 666 0.994686 0.859866 \n",
|
|||
|
|
"3 2.0 0.1 0.0 253 0.994655 0.858883 \n",
|
|||
|
|
"4 1.0 0.0 0.5 470 0.994624 0.857905 \n",
|
|||
|
|
"\n",
|
|||
|
|
" f1_macro \n",
|
|||
|
|
"0 0.854291 \n",
|
|||
|
|
"1 0.854148 \n",
|
|||
|
|
"2 0.852296 \n",
|
|||
|
|
"3 0.851186 \n",
|
|||
|
|
"4 0.850265 \n"
|
|||
|
|
]
|
|||
|
|
}
|
|||
|
|
],
|
|||
|
|
"source": [
|
|||
|
|
"# === Robust, reproducible no-lookahead XGBoost (xgb.train) with tuning ===\n",
|
|||
|
|
"\n",
|
|||
|
|
"import numpy as np\n",
|
|||
|
|
"import pandas as pd\n",
|
|||
|
|
"from sklearn.model_selection import TimeSeriesSplit\n",
|
|||
|
|
"from sklearn.metrics import accuracy_score, balanced_accuracy_score, f1_score, classification_report\n",
|
|||
|
|
"from sklearn.utils.class_weight import compute_class_weight\n",
|
|||
|
|
"import xgboost as xgb\n",
|
|||
|
|
"\n",
|
|||
|
|
"# ---------------- Config ----------------\n",
|
|||
|
|
"SEED = 42\n",
|
|||
|
|
"np.random.seed(SEED)\n",
|
|||
|
|
"\n",
|
|||
|
|
"N_ITER = 30 # hyperparam search iterations\n",
|
|||
|
|
"N_SPLITS = 5 # TimeSeries CV splits\n",
|
|||
|
|
"GAP_BARS = 5 # purge gap between train/valid\n",
|
|||
|
|
"NUM_BOOST_ROUND = 3000\n",
|
|||
|
|
"EARLY_STOP_ROUNDS = 150\n",
|
|||
|
|
"\n",
|
|||
|
|
"# ---------------- 1) Load ----------------\n",
|
|||
|
|
"df = train_df.copy()\n",
|
|||
|
|
"\n",
|
|||
|
|
"# Target\n",
|
|||
|
|
"y = pd.to_numeric(df[\"target_signal\"], errors=\"coerce\")\n",
|
|||
|
|
"valid_idx = y.notna()\n",
|
|||
|
|
"df = df.loc[valid_idx].copy()\n",
|
|||
|
|
"y = y.loc[valid_idx]\n",
|
|||
|
|
"\n",
|
|||
|
|
"# Features\n",
|
|||
|
|
"X = df.drop(columns=[\"target_signal\"]).copy()\n",
|
|||
|
|
"\n",
|
|||
|
|
"# Replace ±inf with 0 (no NaNs)\n",
|
|||
|
|
"X = X.replace([np.inf, -np.inf], 0)\n",
|
|||
|
|
"\n",
|
|||
|
|
"# Ensure numeric array\n",
|
|||
|
|
"X_np = X.to_numpy(dtype=float, copy=False)\n",
|
|||
|
|
"\n",
|
|||
|
|
"# Label encoding (supports {-1,0,1} or binary)\n",
|
|||
|
|
"valid_labels = sorted(y.unique())\n",
|
|||
|
|
"label_to_idx = {lab: i for i, lab in enumerate(valid_labels)}\n",
|
|||
|
|
"idx_to_label = {i: lab for lab, i in label_to_idx.items()}\n",
|
|||
|
|
"y_enc = pd.Series(y.map(label_to_idx).astype(int)).reset_index(drop=True)\n",
|
|||
|
|
"\n",
|
|||
|
|
"num_classes = len(valid_labels)\n",
|
|||
|
|
"is_multiclass = num_classes > 2\n",
|
|||
|
|
"\n",
|
|||
|
|
"# ---------------- 2) XGBoost params ----------------\n",
|
|||
|
|
"OBJECTIVE = \"multi:softprob\" if is_multiclass else \"binary:logistic\"\n",
|
|||
|
|
"EVAL_METRIC = \"mlogloss\" if is_multiclass else \"logloss\"\n",
|
|||
|
|
"\n",
|
|||
|
|
"BASE_PARAMS = {\n",
|
|||
|
|
" \"objective\": OBJECTIVE,\n",
|
|||
|
|
" \"eval_metric\": EVAL_METRIC,\n",
|
|||
|
|
" \"eta\": 0.03,\n",
|
|||
|
|
" \"max_depth\": 6, # <- INT\n",
|
|||
|
|
" \"min_child_weight\": 1.0,\n",
|
|||
|
|
" \"subsample\": 0.8,\n",
|
|||
|
|
" \"colsample_bytree\": 0.8,\n",
|
|||
|
|
" \"lambda\": 1.0,\n",
|
|||
|
|
" \"alpha\": 0.0,\n",
|
|||
|
|
" \"gamma\": 0.0,\n",
|
|||
|
|
" \"tree_method\": \"hist\",\n",
|
|||
|
|
" \"seed\": SEED,\n",
|
|||
|
|
" \"verbosity\": 0,\n",
|
|||
|
|
"}\n",
|
|||
|
|
"if is_multiclass:\n",
|
|||
|
|
" BASE_PARAMS[\"num_class\"] = num_classes\n",
|
|||
|
|
"\n",
|
|||
|
|
"# ---------------- 3) Search space ----------------\n",
|
|||
|
|
"# Keep integer params as Python ints to start with\n",
|
|||
|
|
"SEARCH_SPACE = {\n",
|
|||
|
|
" \"eta\": np.array([0.01, 0.015, 0.02, 0.03, 0.05, 0.07], dtype=float),\n",
|
|||
|
|
" \"max_depth\": np.array([4, 5, 6, 7, 8], dtype=int), # <- ints\n",
|
|||
|
|
" \"min_child_weight\": np.array([1.0, 2.0, 3.0, 5.0], dtype=float),\n",
|
|||
|
|
" \"subsample\": np.array([0.6, 0.7, 0.8, 0.9, 1.0], dtype=float),\n",
|
|||
|
|
" \"colsample_bytree\": np.array([0.6, 0.7, 0.8, 0.9, 1.0], dtype=float),\n",
|
|||
|
|
" \"lambda\": np.array([0.5, 1.0, 2.0, 3.0, 5.0], dtype=float),\n",
|
|||
|
|
" \"alpha\": np.array([0.0, 0.1, 0.3, 0.5], dtype=float),\n",
|
|||
|
|
" \"gamma\": np.array([0.0, 0.1, 0.3, 0.5], dtype=float),\n",
|
|||
|
|
"}\n",
|
|||
|
|
"\n",
|
|||
|
|
"# ---------------- 4) Helpers ----------------\n",
|
|||
|
|
"def compute_sample_weights(y_arr: np.ndarray) -> np.ndarray:\n",
|
|||
|
|
" classes = np.unique(y_arr)\n",
|
|||
|
|
" cw = compute_class_weight(class_weight=\"balanced\", classes=classes, y=y_arr)\n",
|
|||
|
|
" mp = {cls: w for cls, w in zip(classes, cw)}\n",
|
|||
|
|
" return np.vectorize(mp.get)(y_arr).astype(float)\n",
|
|||
|
|
"\n",
|
|||
|
|
"def sample_params(rng: np.random.Generator):\n",
|
|||
|
|
" return {k: rng.choice(v) for k, v in SEARCH_SPACE.items()}\n",
|
|||
|
|
"\n",
|
|||
|
|
"def cast_params_for_xgb(params: dict) -> dict:\n",
|
|||
|
|
" \"\"\"Ensure correct Python types for xgboost.\"\"\"\n",
|
|||
|
|
" out = {}\n",
|
|||
|
|
" for k, v in params.items():\n",
|
|||
|
|
" if isinstance(v, np.generic): # numpy scalar -> Python scalar\n",
|
|||
|
|
" v = v.item()\n",
|
|||
|
|
" if k in {\"max_depth\"}:\n",
|
|||
|
|
" v = int(v) # must be int\n",
|
|||
|
|
" else:\n",
|
|||
|
|
" v = float(v) if isinstance(v, (int, float)) else v\n",
|
|||
|
|
" out[k] = v\n",
|
|||
|
|
" return out\n",
|
|||
|
|
"\n",
|
|||
|
|
"def _best_ntree_limit(booster):\n",
|
|||
|
|
" if getattr(booster, \"best_ntree_limit\", 0):\n",
|
|||
|
|
" return int(booster.best_ntree_limit)\n",
|
|||
|
|
" if getattr(booster, \"best_iteration\", None) is not None:\n",
|
|||
|
|
" return int(booster.best_iteration) + 1\n",
|
|||
|
|
" return int(NUM_BOOST_ROUND)\n",
|
|||
|
|
"\n",
|
|||
|
|
"def _predict_labels(booster, dmat, is_multiclass):\n",
|
|||
|
|
" ntree = _best_ntree_limit(booster)\n",
|
|||
|
|
" try:\n",
|
|||
|
|
" pred = booster.predict(dmat, ntree_limit=ntree)\n",
|
|||
|
|
" except TypeError:\n",
|
|||
|
|
" try:\n",
|
|||
|
|
" pred = booster.predict(dmat, iteration_range=(0, ntree))\n",
|
|||
|
|
" except TypeError:\n",
|
|||
|
|
" pred = booster.predict(dmat)\n",
|
|||
|
|
" pred = np.asarray(pred)\n",
|
|||
|
|
" if is_multiclass:\n",
|
|||
|
|
" return pred.argmax(axis=1)\n",
|
|||
|
|
" return (pred >= 0.5).astype(int)\n",
|
|||
|
|
"\n",
|
|||
|
|
"# ---------------- 5) CV evaluation ----------------\n",
|
|||
|
|
"tscv = TimeSeriesSplit(n_splits=N_SPLITS, gap=GAP_BARS)\n",
|
|||
|
|
"\n",
|
|||
|
|
"def evaluate_params(params: dict, X_np: np.ndarray, y_enc_series: pd.Series):\n",
|
|||
|
|
" # cast types robustly for this trial\n",
|
|||
|
|
" trial_params = cast_params_for_xgb(params)\n",
|
|||
|
|
" fold_metrics, best_iters = [], []\n",
|
|||
|
|
" for fold, (tr_idx, te_idx) in enumerate(tscv.split(X_np), start=1):\n",
|
|||
|
|
" X_tr, X_te = X_np[tr_idx], X_np[te_idx]\n",
|
|||
|
|
" y_tr = y_enc_series.iloc[tr_idx].to_numpy()\n",
|
|||
|
|
" y_te = y_enc_series.iloc[te_idx].to_numpy()\n",
|
|||
|
|
"\n",
|
|||
|
|
" w_tr = compute_sample_weights(y_tr)\n",
|
|||
|
|
"\n",
|
|||
|
|
" dtrain = xgb.DMatrix(X_tr, label=y_tr, weight=w_tr)\n",
|
|||
|
|
" dvalid = xgb.DMatrix(X_te, label=y_te)\n",
|
|||
|
|
"\n",
|
|||
|
|
" bst = xgb.train(\n",
|
|||
|
|
" params={**BASE_PARAMS, **trial_params},\n",
|
|||
|
|
" dtrain=dtrain,\n",
|
|||
|
|
" num_boost_round=NUM_BOOST_ROUND,\n",
|
|||
|
|
" evals=[(dtrain, \"train\"), (dvalid, \"valid\")],\n",
|
|||
|
|
" early_stopping_rounds=EARLY_STOP_ROUNDS,\n",
|
|||
|
|
" verbose_eval=False\n",
|
|||
|
|
" )\n",
|
|||
|
|
"\n",
|
|||
|
|
" best_iters.append(_best_ntree_limit(bst))\n",
|
|||
|
|
"\n",
|
|||
|
|
" y_pred_enc = _predict_labels(bst, dvalid, is_multiclass)\n",
|
|||
|
|
" y_true_lbl = np.vectorize(idx_to_label.get)(y_te)\n",
|
|||
|
|
" y_pred_lbl = np.vectorize(idx_to_label.get)(y_pred_enc)\n",
|
|||
|
|
"\n",
|
|||
|
|
" fold_metrics.append({\n",
|
|||
|
|
" \"accuracy\": accuracy_score(y_true_lbl, y_pred_lbl),\n",
|
|||
|
|
" \"balanced_accuracy\": balanced_accuracy_score(y_true_lbl, y_pred_lbl),\n",
|
|||
|
|
" \"f1_macro\": f1_score(y_true_lbl, y_pred_lbl, average=\"macro\", zero_division=0),\n",
|
|||
|
|
" })\n",
|
|||
|
|
"\n",
|
|||
|
|
" mean_metrics = {k: float(np.mean([m[k] for m in fold_metrics])) for k in fold_metrics[0].keys()}\n",
|
|||
|
|
" mean_best_iters = int(np.round(np.mean(best_iters)))\n",
|
|||
|
|
" return mean_metrics, mean_best_iters\n",
|
|||
|
|
"\n",
|
|||
|
|
"# ---------------- 6) Randomized search ----------------\n",
|
|||
|
|
"rng = np.random.default_rng(SEED)\n",
|
|||
|
|
"results = []\n",
|
|||
|
|
"\n",
|
|||
|
|
"print(\"\\n=== Hyperparameter Tuning (Randomized Search) ===\")\n",
|
|||
|
|
"for i in range(1, N_ITER + 1):\n",
|
|||
|
|
" params = sample_params(rng)\n",
|
|||
|
|
" mean_metrics, mean_best_iters = evaluate_params(params, X_np, y_enc)\n",
|
|||
|
|
" entry = {\"iter\": i, **params, \"mean_best_iters\": mean_best_iters, **mean_metrics}\n",
|
|||
|
|
" results.append(entry)\n",
|
|||
|
|
" print(f\"[{i:02d}/{N_ITER}] BA={entry['balanced_accuracy']:.4f} | F1m={entry['f1_macro']:.4f} | \"\n",
|
|||
|
|
" f\"Acc={entry['accuracy']:.4f} | best_n_estimators≈{mean_best_iters}\")\n",
|
|||
|
|
"\n",
|
|||
|
|
"results_df = pd.DataFrame(results).sort_values(\n",
|
|||
|
|
" by=[\"balanced_accuracy\", \"f1_macro\", \"accuracy\"], ascending=False\n",
|
|||
|
|
").reset_index(drop=True)\n",
|
|||
|
|
"\n",
|
|||
|
|
"best = results_df.iloc[0].to_dict()\n",
|
|||
|
|
"best_params_raw = {k: best[k] for k in SEARCH_SPACE.keys()}\n",
|
|||
|
|
"best_params = cast_params_for_xgb(best_params_raw) # <-- enforce correct types here\n",
|
|||
|
|
"best_n_estimators = int(best[\"mean_best_iters\"])\n",
|
|||
|
|
"\n",
|
|||
|
|
"print(\"\\n=== Best Params (by balanced_accuracy) ===\")\n",
|
|||
|
|
"print(best_params)\n",
|
|||
|
|
"print(f\"Best mean_best_iters: {best_n_estimators}\")\n",
|
|||
|
|
"print(\"\\nTop-5 tuning results:\")\n",
|
|||
|
|
"print(results_df.head(5))\n",
|
|||
|
|
"\n",
|
|||
|
|
"\n"
|
|||
|
|
]
|
|||
|
|
},
|
|||
|
|
{
|
|||
|
|
"cell_type": "code",
|
|||
|
|
"execution_count": 66,
|
|||
|
|
"metadata": {},
|
|||
|
|
"outputs": [],
|
|||
|
|
"source": [
|
|||
|
|
"def _num_boosted_rounds(booster) -> int:\n",
|
|||
|
|
" \"\"\"How many trees the model actually has.\"\"\"\n",
|
|||
|
|
" try:\n",
|
|||
|
|
" return int(booster.num_boosted_rounds())\n",
|
|||
|
|
" except AttributeError:\n",
|
|||
|
|
" # Fallback for very old versions\n",
|
|||
|
|
" try:\n",
|
|||
|
|
" return int(getattr(booster, \"best_iteration\")) + 1\n",
|
|||
|
|
" except Exception:\n",
|
|||
|
|
" return int(NUM_BOOST_ROUND)\n",
|
|||
|
|
"\n",
|
|||
|
|
"def _best_iteration_limit(booster) -> int:\n",
|
|||
|
|
" \"\"\"\n",
|
|||
|
|
" Best usable iteration count for prediction:\n",
|
|||
|
|
" prefer early-stopped best_iteration+1 if available,\n",
|
|||
|
|
" otherwise the model's actual number of rounds.\n",
|
|||
|
|
" \"\"\"\n",
|
|||
|
|
" bi = getattr(booster, \"best_iteration\", None)\n",
|
|||
|
|
" if bi is not None:\n",
|
|||
|
|
" return int(bi) + 1\n",
|
|||
|
|
" return _num_boosted_rounds(booster)\n",
|
|||
|
|
"\n",
|
|||
|
|
"def _predict_labels(booster, dmat, is_multiclass):\n",
|
|||
|
|
" \"\"\"\n",
|
|||
|
|
" Works for XGBoost >= 2.0 (no ntree_limit). Uses iteration_range\n",
|
|||
|
|
" and clamps to the model's true number of trees to avoid OOR errors.\n",
|
|||
|
|
" \"\"\"\n",
|
|||
|
|
" # What we'd *like* to use\n",
|
|||
|
|
" limit = _best_iteration_limit(booster)\n",
|
|||
|
|
" # What the model *has*\n",
|
|||
|
|
" total = _num_boosted_rounds(booster)\n",
|
|||
|
|
" # Clamp\n",
|
|||
|
|
" end = min(limit, total)\n",
|
|||
|
|
"\n",
|
|||
|
|
" # Predict\n",
|
|||
|
|
" try:\n",
|
|||
|
|
" pred = booster.predict(dmat, iteration_range=(0, end))\n",
|
|||
|
|
" except TypeError:\n",
|
|||
|
|
" # Very old versions: no iteration_range\n",
|
|||
|
|
" pred = booster.predict(dmat)\n",
|
|||
|
|
"\n",
|
|||
|
|
" pred = np.asarray(pred)\n",
|
|||
|
|
" if is_multiclass:\n",
|
|||
|
|
" return pred.argmax(axis=1)\n",
|
|||
|
|
" return (pred >= 0.5).astype(int)\n"
|
|||
|
|
]
|
|||
|
|
},
|
|||
|
|
{
|
|||
|
|
"cell_type": "code",
|
|||
|
|
"execution_count": 80,
|
|||
|
|
"metadata": {
|
|||
|
|
"collapsed": true
|
|||
|
|
},
|
|||
|
|
"outputs": [
|
|||
|
|
{
|
|||
|
|
"name": "stdout",
|
|||
|
|
"output_type": "stream",
|
|||
|
|
"text": [
|
|||
|
|
"Final model saved -> xgb_trading_model_tuned.json\n",
|
|||
|
|
"\n",
|
|||
|
|
"In-sample classification report (sanity only; use CV for OOS):\n",
|
|||
|
|
" precision recall f1-score support\n",
|
|||
|
|
"\n",
|
|||
|
|
" -1.0 0.93 0.94 0.94 852\n",
|
|||
|
|
" 0.0 1.00 1.00 1.00 75983\n",
|
|||
|
|
" 1.0 0.91 0.96 0.94 852\n",
|
|||
|
|
"\n",
|
|||
|
|
" accuracy 1.00 77687\n",
|
|||
|
|
" macro avg 0.95 0.97 0.96 77687\n",
|
|||
|
|
"weighted avg 1.00 1.00 1.00 77687\n",
|
|||
|
|
"\n"
|
|||
|
|
]
|
|||
|
|
}
|
|||
|
|
],
|
|||
|
|
"source": [
|
|||
|
|
"# === Final XGBoost training with your tuned params (no lookahead) ===\n",
|
|||
|
|
"\n",
|
|||
|
|
"import numpy as np\n",
|
|||
|
|
"import pandas as pd\n",
|
|||
|
|
"from sklearn.metrics import classification_report\n",
|
|||
|
|
"from sklearn.utils.class_weight import compute_class_weight\n",
|
|||
|
|
"import xgboost as xgb\n",
|
|||
|
|
"\n",
|
|||
|
|
"# ---------------- Config ----------------\n",
|
|||
|
|
"SEED = 42\n",
|
|||
|
|
"BEST_PARAMS = {\n",
|
|||
|
|
" \"eta\": 0.03,\n",
|
|||
|
|
" \"max_depth\": 4, # must be int\n",
|
|||
|
|
" \"min_child_weight\": 2.0,\n",
|
|||
|
|
" \"subsample\": 0.8,\n",
|
|||
|
|
" \"colsample_bytree\": 1.0,\n",
|
|||
|
|
" \"lambda\": 1.0,\n",
|
|||
|
|
" \"alpha\": 0.1,\n",
|
|||
|
|
" \"gamma\": 0.1,\n",
|
|||
|
|
"}\n",
|
|||
|
|
"BEST_N_ESTIMATORS = 360 # from your tuning\n",
|
|||
|
|
"\n",
|
|||
|
|
"# ---------------- 1) Prepare data ----------------\n",
|
|||
|
|
"df = train_df.copy()\n",
|
|||
|
|
"\n",
|
|||
|
|
"# Target (assumed cleaned): -1/0/1 (or binary)\n",
|
|||
|
|
"y = pd.to_numeric(df[\"target_signal\"], errors=\"coerce\")\n",
|
|||
|
|
"keep = y.notna()\n",
|
|||
|
|
"df = df.loc[keep].copy()\n",
|
|||
|
|
"y = y.loc[keep]\n",
|
|||
|
|
"\n",
|
|||
|
|
"# Features\n",
|
|||
|
|
"X = df.drop(columns=[\"target_signal\"]).copy()\n",
|
|||
|
|
"\n",
|
|||
|
|
"# Safety: replace ±inf with 0 (no NaNs)\n",
|
|||
|
|
"X = X.replace([np.inf, -np.inf], 0)\n",
|
|||
|
|
"\n",
|
|||
|
|
"# To numpy\n",
|
|||
|
|
"X_np = X.to_numpy(dtype=float, copy=False)\n",
|
|||
|
|
"\n",
|
|||
|
|
"# Encode labels\n",
|
|||
|
|
"labels_sorted = sorted(y.unique())\n",
|
|||
|
|
"lab2idx = {lab: i for i, lab in enumerate(labels_sorted)}\n",
|
|||
|
|
"idx2lab = {i: lab for lab, i in lab2idx.items()}\n",
|
|||
|
|
"y_enc = y.map(lab2idx).astype(int).to_numpy()\n",
|
|||
|
|
"\n",
|
|||
|
|
"num_classes = len(labels_sorted)\n",
|
|||
|
|
"is_multiclass = num_classes > 2\n",
|
|||
|
|
"\n",
|
|||
|
|
"# ---------------- 2) XGBoost params ----------------\n",
|
|||
|
|
"params = {\n",
|
|||
|
|
" \"objective\": \"multi:softprob\" if is_multiclass else \"binary:logistic\",\n",
|
|||
|
|
" \"eval_metric\": \"mlogloss\" if is_multiclass else \"logloss\",\n",
|
|||
|
|
" \"tree_method\": \"hist\",\n",
|
|||
|
|
" \"seed\": SEED,\n",
|
|||
|
|
" \"verbosity\": 0,\n",
|
|||
|
|
" **BEST_PARAMS,\n",
|
|||
|
|
"}\n",
|
|||
|
|
"if is_multiclass:\n",
|
|||
|
|
" params[\"num_class\"] = num_classes\n",
|
|||
|
|
"\n",
|
|||
|
|
"# ---------------- 3) Class-balanced weights ----------------\n",
|
|||
|
|
"classes = np.unique(y_enc)\n",
|
|||
|
|
"cw = compute_class_weight(class_weight=\"balanced\", classes=classes, y=y_enc)\n",
|
|||
|
|
"weight_map = {cls: w for cls, w in zip(classes, cw)}\n",
|
|||
|
|
"w_full = np.vectorize(weight_map.get)(y_enc).astype(float)\n",
|
|||
|
|
"\n",
|
|||
|
|
"# ---------------- 4) Train final model ----------------\n",
|
|||
|
|
"dtrain_full = xgb.DMatrix(X_np, label=y_enc, weight=w_full)\n",
|
|||
|
|
"bst_final = xgb.train(\n",
|
|||
|
|
" params=params,\n",
|
|||
|
|
" dtrain=dtrain_full,\n",
|
|||
|
|
" num_boost_round=BEST_N_ESTIMATORS, # use tuned trees\n",
|
|||
|
|
" evals=[(dtrain_full, \"train\")],\n",
|
|||
|
|
" verbose_eval=False\n",
|
|||
|
|
")\n",
|
|||
|
|
"\n",
|
|||
|
|
"bst_final.save_model(\"xgb_trading_model_tuned.json\")\n",
|
|||
|
|
"\n",
|
|||
|
|
"\n"
|
|||
|
|
]
|
|||
|
|
},
|
|||
|
|
{
|
|||
|
|
"cell_type": "markdown",
|
|||
|
|
"metadata": {},
|
|||
|
|
"source": [
|
|||
|
|
"# Predictions for Trading"
|
|||
|
|
]
|
|||
|
|
},
|
|||
|
|
{
|
|||
|
|
"cell_type": "code",
|
|||
|
|
"execution_count": 194,
|
|||
|
|
"metadata": {},
|
|||
|
|
"outputs": [],
|
|||
|
|
"source": [
|
|||
|
|
"test_df.fillna(0, inplace=True)"
|
|||
|
|
]
|
|||
|
|
},
|
|||
|
|
{
|
|||
|
|
"cell_type": "code",
|
|||
|
|
"execution_count": 195,
|
|||
|
|
"metadata": {},
|
|||
|
|
"outputs": [],
|
|||
|
|
"source": [
|
|||
|
|
"# Remove rows where all columns are 0\n",
|
|||
|
|
"test_df = test_df.loc[~(train_df.eq(0).all(axis=1))].copy()\n"
|
|||
|
|
]
|
|||
|
|
},
|
|||
|
|
{
|
|||
|
|
"cell_type": "code",
|
|||
|
|
"execution_count": 196,
|
|||
|
|
"metadata": {},
|
|||
|
|
"outputs": [],
|
|||
|
|
"source": [
|
|||
|
|
"cols_to_drop = [\"Quarter\", \"Month_sin\", \"Date_sin\", \"ema\", \"Oil_Close\", \"CCI_2\",\n",
|
|||
|
|
" \"KeltnerWidth_diff_22\",\"KeltnerWidth_ratio_2_15\", \"ADX_diff_12\", \"ADX_diff_3\",\"ADX_diff_9\",\n",
|
|||
|
|
" \"CMO_2\", \"KeltnerWidth_diff_13\", \"ADX_ratio_2_14\", \"ADX_ratio_5_14\", \"ChaikinVol_2_5\", \"CCI_ratio_2_8\",\n",
|
|||
|
|
" \"CMO_2\", \"KeltnerWidth_15\", \"KeltnerWidth_20\", \"KeltnerWidth_24\",\n",
|
|||
|
|
" \"ChaikinVol_3_10\", \"Unnamed: 0\", \"sma\", \"Session\", \"Gold_Close\", \"Oil_Volume\", \"Diff_10Y_2Y\"]\n",
|
|||
|
|
"test_df = test_df.drop(columns=cols_to_drop)\n"
|
|||
|
|
]
|
|||
|
|
},
|
|||
|
|
{
|
|||
|
|
"cell_type": "code",
|
|||
|
|
"execution_count": 197,
|
|||
|
|
"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>Open</th>\n",
|
|||
|
|
" <th>High</th>\n",
|
|||
|
|
" <th>Low</th>\n",
|
|||
|
|
" <th>Close</th>\n",
|
|||
|
|
" <th>Volume</th>\n",
|
|||
|
|
" <th>Hour_sin</th>\n",
|
|||
|
|
" <th>DOW_sin</th>\n",
|
|||
|
|
" <th>DateTime</th>\n",
|
|||
|
|
" <th>ADX_14</th>\n",
|
|||
|
|
" <th>CCI_14</th>\n",
|
|||
|
|
" <th>...</th>\n",
|
|||
|
|
" <th>CCI_diff_18</th>\n",
|
|||
|
|
" <th>CCI_ratio_8_20</th>\n",
|
|||
|
|
" <th>CCI_ratio_2_20</th>\n",
|
|||
|
|
" <th>CMO_diff_12</th>\n",
|
|||
|
|
" <th>CMO_ratio_2_14</th>\n",
|
|||
|
|
" <th>KeltnerWidth_diff_9</th>\n",
|
|||
|
|
" <th>KeltnerWidth_ratio_15_24</th>\n",
|
|||
|
|
" <th>KeltnerWidth_ratio_2_24</th>\n",
|
|||
|
|
" <th>signal</th>\n",
|
|||
|
|
" <th>target_signal</th>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" </thead>\n",
|
|||
|
|
" <tbody>\n",
|
|||
|
|
" <tr>\n",
|
|||
|
|
" <th>0</th>\n",
|
|||
|
|
" <td>1.11810</td>\n",
|
|||
|
|
" <td>1.11944</td>\n",
|
|||
|
|
" <td>1.11797</td>\n",
|
|||
|
|
" <td>1.11923</td>\n",
|
|||
|
|
" <td>963</td>\n",
|
|||
|
|
" <td>-0.25882</td>\n",
|
|||
|
|
" <td>0.433884</td>\n",
|
|||
|
|
" <td>07/03/19 23:00</td>\n",
|
|||
|
|
" <td>47.175526</td>\n",
|
|||
|
|
" <td>-94.082772</td>\n",
|
|||
|
|
" <td>...</td>\n",
|
|||
|
|
" <td>-185.557987</td>\n",
|
|||
|
|
" <td>0.716473</td>\n",
|
|||
|
|
" <td>-0.560736</td>\n",
|
|||
|
|
" <td>-112.484341</td>\n",
|
|||
|
|
" <td>-0.708596</td>\n",
|
|||
|
|
" <td>-0.000172</td>\n",
|
|||
|
|
" <td>1.118244</td>\n",
|
|||
|
|
" <td>0.950727</td>\n",
|
|||
|
|
" <td>-1</td>\n",
|
|||
|
|
" <td>1</td>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" <tr>\n",
|
|||
|
|
" <th>1</th>\n",
|
|||
|
|
" <td>1.11916</td>\n",
|
|||
|
|
" <td>1.11985</td>\n",
|
|||
|
|
" <td>1.11916</td>\n",
|
|||
|
|
" <td>1.11976</td>\n",
|
|||
|
|
" <td>764</td>\n",
|
|||
|
|
" <td>0.25882</td>\n",
|
|||
|
|
" <td>-0.433884</td>\n",
|
|||
|
|
" <td>08/03/19 1:00</td>\n",
|
|||
|
|
" <td>48.511681</td>\n",
|
|||
|
|
" <td>-75.385246</td>\n",
|
|||
|
|
" <td>...</td>\n",
|
|||
|
|
" <td>-161.694000</td>\n",
|
|||
|
|
" <td>0.444908</td>\n",
|
|||
|
|
" <td>-0.701553</td>\n",
|
|||
|
|
" <td>-84.682762</td>\n",
|
|||
|
|
" <td>-0.884346</td>\n",
|
|||
|
|
" <td>-0.000113</td>\n",
|
|||
|
|
" <td>1.081275</td>\n",
|
|||
|
|
" <td>0.627573</td>\n",
|
|||
|
|
" <td>0</td>\n",
|
|||
|
|
" <td>0</td>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" <tr>\n",
|
|||
|
|
" <th>2</th>\n",
|
|||
|
|
" <td>1.11976</td>\n",
|
|||
|
|
" <td>1.11977</td>\n",
|
|||
|
|
" <td>1.11855</td>\n",
|
|||
|
|
" <td>1.11907</td>\n",
|
|||
|
|
" <td>1620</td>\n",
|
|||
|
|
" <td>0.50000</td>\n",
|
|||
|
|
" <td>-0.433884</td>\n",
|
|||
|
|
" <td>08/03/19 2:00</td>\n",
|
|||
|
|
" <td>49.885998</td>\n",
|
|||
|
|
" <td>-75.857692</td>\n",
|
|||
|
|
" <td>...</td>\n",
|
|||
|
|
" <td>-24.224772</td>\n",
|
|||
|
|
" <td>0.522943</td>\n",
|
|||
|
|
" <td>0.733476</td>\n",
|
|||
|
|
" <td>-87.926650</td>\n",
|
|||
|
|
" <td>0.878839</td>\n",
|
|||
|
|
" <td>-0.000085</td>\n",
|
|||
|
|
" <td>1.062512</td>\n",
|
|||
|
|
" <td>0.744744</td>\n",
|
|||
|
|
" <td>0</td>\n",
|
|||
|
|
" <td>0</td>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" <tr>\n",
|
|||
|
|
" <th>3</th>\n",
|
|||
|
|
" <td>1.11906</td>\n",
|
|||
|
|
" <td>1.11944</td>\n",
|
|||
|
|
" <td>1.11848</td>\n",
|
|||
|
|
" <td>1.11881</td>\n",
|
|||
|
|
" <td>1091</td>\n",
|
|||
|
|
" <td>0.70711</td>\n",
|
|||
|
|
" <td>-0.433884</td>\n",
|
|||
|
|
" <td>08/03/19 3:00</td>\n",
|
|||
|
|
" <td>51.177650</td>\n",
|
|||
|
|
" <td>-74.037359</td>\n",
|
|||
|
|
" <td>...</td>\n",
|
|||
|
|
" <td>-18.661185</td>\n",
|
|||
|
|
" <td>0.579275</td>\n",
|
|||
|
|
" <td>0.781300</td>\n",
|
|||
|
|
" <td>-92.209732</td>\n",
|
|||
|
|
" <td>0.900446</td>\n",
|
|||
|
|
" <td>-0.000052</td>\n",
|
|||
|
|
" <td>1.039139</td>\n",
|
|||
|
|
" <td>0.687263</td>\n",
|
|||
|
|
" <td>0</td>\n",
|
|||
|
|
" <td>0</td>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" <tr>\n",
|
|||
|
|
" <th>4</th>\n",
|
|||
|
|
" <td>1.11881</td>\n",
|
|||
|
|
" <td>1.12003</td>\n",
|
|||
|
|
" <td>1.11860</td>\n",
|
|||
|
|
" <td>1.11979</td>\n",
|
|||
|
|
" <td>992</td>\n",
|
|||
|
|
" <td>0.86603</td>\n",
|
|||
|
|
" <td>-0.433884</td>\n",
|
|||
|
|
" <td>08/03/19 4:00</td>\n",
|
|||
|
|
" <td>51.686381</td>\n",
|
|||
|
|
" <td>-55.926237</td>\n",
|
|||
|
|
" <td>...</td>\n",
|
|||
|
|
" <td>-137.969772</td>\n",
|
|||
|
|
" <td>-0.063312</td>\n",
|
|||
|
|
" <td>-0.934976</td>\n",
|
|||
|
|
" <td>-82.338745</td>\n",
|
|||
|
|
" <td>-1.192046</td>\n",
|
|||
|
|
" <td>-0.000043</td>\n",
|
|||
|
|
" <td>1.032691</td>\n",
|
|||
|
|
" <td>0.873788</td>\n",
|
|||
|
|
" <td>0</td>\n",
|
|||
|
|
" <td>0</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",
|
|||
|
|
" <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>33324</th>\n",
|
|||
|
|
" <td>1.03502</td>\n",
|
|||
|
|
" <td>1.03548</td>\n",
|
|||
|
|
" <td>1.03438</td>\n",
|
|||
|
|
" <td>1.03490</td>\n",
|
|||
|
|
" <td>2323</td>\n",
|
|||
|
|
" <td>-0.96593</td>\n",
|
|||
|
|
" <td>0.781831</td>\n",
|
|||
|
|
" <td>31/12/24 19:00</td>\n",
|
|||
|
|
" <td>23.611404</td>\n",
|
|||
|
|
" <td>-160.337614</td>\n",
|
|||
|
|
" <td>...</td>\n",
|
|||
|
|
" <td>-150.663910</td>\n",
|
|||
|
|
" <td>0.499089</td>\n",
|
|||
|
|
" <td>0.306752</td>\n",
|
|||
|
|
" <td>-146.708669</td>\n",
|
|||
|
|
" <td>0.415789</td>\n",
|
|||
|
|
" <td>-0.000087</td>\n",
|
|||
|
|
" <td>1.060976</td>\n",
|
|||
|
|
" <td>0.938986</td>\n",
|
|||
|
|
" <td>0</td>\n",
|
|||
|
|
" <td>0</td>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" <tr>\n",
|
|||
|
|
" <th>33325</th>\n",
|
|||
|
|
" <td>1.03489</td>\n",
|
|||
|
|
" <td>1.03566</td>\n",
|
|||
|
|
" <td>1.03455</td>\n",
|
|||
|
|
" <td>1.03529</td>\n",
|
|||
|
|
" <td>1900</td>\n",
|
|||
|
|
" <td>-0.86603</td>\n",
|
|||
|
|
" <td>0.781831</td>\n",
|
|||
|
|
" <td>31/12/24 20:00</td>\n",
|
|||
|
|
" <td>25.551370</td>\n",
|
|||
|
|
" <td>-119.355906</td>\n",
|
|||
|
|
" <td>...</td>\n",
|
|||
|
|
" <td>-228.152865</td>\n",
|
|||
|
|
" <td>0.474172</td>\n",
|
|||
|
|
" <td>-0.412832</td>\n",
|
|||
|
|
" <td>-120.580881</td>\n",
|
|||
|
|
" <td>-0.558554</td>\n",
|
|||
|
|
" <td>-0.000060</td>\n",
|
|||
|
|
" <td>1.042922</td>\n",
|
|||
|
|
" <td>0.828449</td>\n",
|
|||
|
|
" <td>0</td>\n",
|
|||
|
|
" <td>0</td>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" <tr>\n",
|
|||
|
|
" <th>33326</th>\n",
|
|||
|
|
" <td>1.03526</td>\n",
|
|||
|
|
" <td>1.03645</td>\n",
|
|||
|
|
" <td>1.03516</td>\n",
|
|||
|
|
" <td>1.03547</td>\n",
|
|||
|
|
" <td>1445</td>\n",
|
|||
|
|
" <td>-0.70711</td>\n",
|
|||
|
|
" <td>0.781831</td>\n",
|
|||
|
|
" <td>31/12/24 21:00</td>\n",
|
|||
|
|
" <td>26.385304</td>\n",
|
|||
|
|
" <td>-85.267741</td>\n",
|
|||
|
|
" <td>...</td>\n",
|
|||
|
|
" <td>-185.465493</td>\n",
|
|||
|
|
" <td>0.389379</td>\n",
|
|||
|
|
" <td>-0.561173</td>\n",
|
|||
|
|
" <td>-101.534169</td>\n",
|
|||
|
|
" <td>-0.781851</td>\n",
|
|||
|
|
" <td>-0.000046</td>\n",
|
|||
|
|
" <td>1.032793</td>\n",
|
|||
|
|
" <td>0.875523</td>\n",
|
|||
|
|
" <td>0</td>\n",
|
|||
|
|
" <td>0</td>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" <tr>\n",
|
|||
|
|
" <th>33327</th>\n",
|
|||
|
|
" <td>1.03547</td>\n",
|
|||
|
|
" <td>1.03631</td>\n",
|
|||
|
|
" <td>1.03544</td>\n",
|
|||
|
|
" <td>1.03582</td>\n",
|
|||
|
|
" <td>1208</td>\n",
|
|||
|
|
" <td>-0.50000</td>\n",
|
|||
|
|
" <td>0.781831</td>\n",
|
|||
|
|
" <td>31/12/24 22:00</td>\n",
|
|||
|
|
" <td>27.159672</td>\n",
|
|||
|
|
" <td>-69.016843</td>\n",
|
|||
|
|
" <td>...</td>\n",
|
|||
|
|
" <td>-164.506501</td>\n",
|
|||
|
|
" <td>0.274403</td>\n",
|
|||
|
|
" <td>-0.681386</td>\n",
|
|||
|
|
" <td>-87.924347</td>\n",
|
|||
|
|
" <td>-0.965948</td>\n",
|
|||
|
|
" <td>-0.000015</td>\n",
|
|||
|
|
" <td>1.011219</td>\n",
|
|||
|
|
" <td>0.716892</td>\n",
|
|||
|
|
" <td>0</td>\n",
|
|||
|
|
" <td>0</td>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" <tr>\n",
|
|||
|
|
" <th>33328</th>\n",
|
|||
|
|
" <td>1.03585</td>\n",
|
|||
|
|
" <td>1.03608</td>\n",
|
|||
|
|
" <td>1.03489</td>\n",
|
|||
|
|
" <td>1.03493</td>\n",
|
|||
|
|
" <td>616</td>\n",
|
|||
|
|
" <td>-0.25882</td>\n",
|
|||
|
|
" <td>0.781831</td>\n",
|
|||
|
|
" <td>31/12/24 23:00</td>\n",
|
|||
|
|
" <td>28.181968</td>\n",
|
|||
|
|
" <td>-73.068540</td>\n",
|
|||
|
|
" <td>...</td>\n",
|
|||
|
|
" <td>-32.611841</td>\n",
|
|||
|
|
" <td>0.508487</td>\n",
|
|||
|
|
" <td>0.671512</td>\n",
|
|||
|
|
" <td>-91.887164</td>\n",
|
|||
|
|
" <td>0.912385</td>\n",
|
|||
|
|
" <td>-0.000004</td>\n",
|
|||
|
|
" <td>1.003260</td>\n",
|
|||
|
|
" <td>0.817381</td>\n",
|
|||
|
|
" <td>1</td>\n",
|
|||
|
|
" <td>0</td>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" </tbody>\n",
|
|||
|
|
"</table>\n",
|
|||
|
|
"<p>33329 rows × 32 columns</p>\n",
|
|||
|
|
"</div>"
|
|||
|
|
],
|
|||
|
|
"text/plain": [
|
|||
|
|
" Open High Low Close Volume Hour_sin DOW_sin \\\n",
|
|||
|
|
"0 1.11810 1.11944 1.11797 1.11923 963 -0.25882 0.433884 \n",
|
|||
|
|
"1 1.11916 1.11985 1.11916 1.11976 764 0.25882 -0.433884 \n",
|
|||
|
|
"2 1.11976 1.11977 1.11855 1.11907 1620 0.50000 -0.433884 \n",
|
|||
|
|
"3 1.11906 1.11944 1.11848 1.11881 1091 0.70711 -0.433884 \n",
|
|||
|
|
"4 1.11881 1.12003 1.11860 1.11979 992 0.86603 -0.433884 \n",
|
|||
|
|
"... ... ... ... ... ... ... ... \n",
|
|||
|
|
"33324 1.03502 1.03548 1.03438 1.03490 2323 -0.96593 0.781831 \n",
|
|||
|
|
"33325 1.03489 1.03566 1.03455 1.03529 1900 -0.86603 0.781831 \n",
|
|||
|
|
"33326 1.03526 1.03645 1.03516 1.03547 1445 -0.70711 0.781831 \n",
|
|||
|
|
"33327 1.03547 1.03631 1.03544 1.03582 1208 -0.50000 0.781831 \n",
|
|||
|
|
"33328 1.03585 1.03608 1.03489 1.03493 616 -0.25882 0.781831 \n",
|
|||
|
|
"\n",
|
|||
|
|
" DateTime ADX_14 CCI_14 ... CCI_diff_18 \\\n",
|
|||
|
|
"0 07/03/19 23:00 47.175526 -94.082772 ... -185.557987 \n",
|
|||
|
|
"1 08/03/19 1:00 48.511681 -75.385246 ... -161.694000 \n",
|
|||
|
|
"2 08/03/19 2:00 49.885998 -75.857692 ... -24.224772 \n",
|
|||
|
|
"3 08/03/19 3:00 51.177650 -74.037359 ... -18.661185 \n",
|
|||
|
|
"4 08/03/19 4:00 51.686381 -55.926237 ... -137.969772 \n",
|
|||
|
|
"... ... ... ... ... ... \n",
|
|||
|
|
"33324 31/12/24 19:00 23.611404 -160.337614 ... -150.663910 \n",
|
|||
|
|
"33325 31/12/24 20:00 25.551370 -119.355906 ... -228.152865 \n",
|
|||
|
|
"33326 31/12/24 21:00 26.385304 -85.267741 ... -185.465493 \n",
|
|||
|
|
"33327 31/12/24 22:00 27.159672 -69.016843 ... -164.506501 \n",
|
|||
|
|
"33328 31/12/24 23:00 28.181968 -73.068540 ... -32.611841 \n",
|
|||
|
|
"\n",
|
|||
|
|
" CCI_ratio_8_20 CCI_ratio_2_20 CMO_diff_12 CMO_ratio_2_14 \\\n",
|
|||
|
|
"0 0.716473 -0.560736 -112.484341 -0.708596 \n",
|
|||
|
|
"1 0.444908 -0.701553 -84.682762 -0.884346 \n",
|
|||
|
|
"2 0.522943 0.733476 -87.926650 0.878839 \n",
|
|||
|
|
"3 0.579275 0.781300 -92.209732 0.900446 \n",
|
|||
|
|
"4 -0.063312 -0.934976 -82.338745 -1.192046 \n",
|
|||
|
|
"... ... ... ... ... \n",
|
|||
|
|
"33324 0.499089 0.306752 -146.708669 0.415789 \n",
|
|||
|
|
"33325 0.474172 -0.412832 -120.580881 -0.558554 \n",
|
|||
|
|
"33326 0.389379 -0.561173 -101.534169 -0.781851 \n",
|
|||
|
|
"33327 0.274403 -0.681386 -87.924347 -0.965948 \n",
|
|||
|
|
"33328 0.508487 0.671512 -91.887164 0.912385 \n",
|
|||
|
|
"\n",
|
|||
|
|
" KeltnerWidth_diff_9 KeltnerWidth_ratio_15_24 KeltnerWidth_ratio_2_24 \\\n",
|
|||
|
|
"0 -0.000172 1.118244 0.950727 \n",
|
|||
|
|
"1 -0.000113 1.081275 0.627573 \n",
|
|||
|
|
"2 -0.000085 1.062512 0.744744 \n",
|
|||
|
|
"3 -0.000052 1.039139 0.687263 \n",
|
|||
|
|
"4 -0.000043 1.032691 0.873788 \n",
|
|||
|
|
"... ... ... ... \n",
|
|||
|
|
"33324 -0.000087 1.060976 0.938986 \n",
|
|||
|
|
"33325 -0.000060 1.042922 0.828449 \n",
|
|||
|
|
"33326 -0.000046 1.032793 0.875523 \n",
|
|||
|
|
"33327 -0.000015 1.011219 0.716892 \n",
|
|||
|
|
"33328 -0.000004 1.003260 0.817381 \n",
|
|||
|
|
"\n",
|
|||
|
|
" signal target_signal \n",
|
|||
|
|
"0 -1 1 \n",
|
|||
|
|
"1 0 0 \n",
|
|||
|
|
"2 0 0 \n",
|
|||
|
|
"3 0 0 \n",
|
|||
|
|
"4 0 0 \n",
|
|||
|
|
"... ... ... \n",
|
|||
|
|
"33324 0 0 \n",
|
|||
|
|
"33325 0 0 \n",
|
|||
|
|
"33326 0 0 \n",
|
|||
|
|
"33327 0 0 \n",
|
|||
|
|
"33328 1 0 \n",
|
|||
|
|
"\n",
|
|||
|
|
"[33329 rows x 32 columns]"
|
|||
|
|
]
|
|||
|
|
},
|
|||
|
|
"execution_count": 197,
|
|||
|
|
"metadata": {},
|
|||
|
|
"output_type": "execute_result"
|
|||
|
|
}
|
|||
|
|
],
|
|||
|
|
"source": [
|
|||
|
|
"\n",
|
|||
|
|
"# Replace the bad value in CCI_8_20 with 0 and ensure numeric dtype\n",
|
|||
|
|
"test_df[\"CCI_ratio_8_20\"] = pd.to_numeric(test_df[\"CCI_ratio_8_20\"].replace(\"#NAME?\", 0), errors=\"coerce\")\n",
|
|||
|
|
"test_df\n"
|
|||
|
|
]
|
|||
|
|
},
|
|||
|
|
{
|
|||
|
|
"cell_type": "code",
|
|||
|
|
"execution_count": 198,
|
|||
|
|
"metadata": {},
|
|||
|
|
"outputs": [],
|
|||
|
|
"source": [
|
|||
|
|
"test_df.to_csv('test_with_dates.csv')\n",
|
|||
|
|
"test_df = test_df.drop(columns= ['DateTime', 'target_signal', \"Close\",\"Open\",\"Volume\",\"High\", \"Low\", ])"
|
|||
|
|
]
|
|||
|
|
},
|
|||
|
|
{
|
|||
|
|
"cell_type": "code",
|
|||
|
|
"execution_count": 199,
|
|||
|
|
"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>Hour_sin</th>\n",
|
|||
|
|
" <th>DOW_sin</th>\n",
|
|||
|
|
" <th>ADX_14</th>\n",
|
|||
|
|
" <th>CCI_14</th>\n",
|
|||
|
|
" <th>PPO_12_26</th>\n",
|
|||
|
|
" <th>CMO_14</th>\n",
|
|||
|
|
" <th>ADX_2</th>\n",
|
|||
|
|
" <th>ADX_5</th>\n",
|
|||
|
|
" <th>CCI_8</th>\n",
|
|||
|
|
" <th>CCI_20</th>\n",
|
|||
|
|
" <th>...</th>\n",
|
|||
|
|
" <th>CCI_diff_12</th>\n",
|
|||
|
|
" <th>CCI_diff_18</th>\n",
|
|||
|
|
" <th>CCI_ratio_8_20</th>\n",
|
|||
|
|
" <th>CCI_ratio_2_20</th>\n",
|
|||
|
|
" <th>CMO_diff_12</th>\n",
|
|||
|
|
" <th>CMO_ratio_2_14</th>\n",
|
|||
|
|
" <th>KeltnerWidth_diff_9</th>\n",
|
|||
|
|
" <th>KeltnerWidth_ratio_15_24</th>\n",
|
|||
|
|
" <th>KeltnerWidth_ratio_2_24</th>\n",
|
|||
|
|
" <th>signal</th>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" </thead>\n",
|
|||
|
|
" <tbody>\n",
|
|||
|
|
" <tr>\n",
|
|||
|
|
" <th>0</th>\n",
|
|||
|
|
" <td>-0.25882</td>\n",
|
|||
|
|
" <td>0.433884</td>\n",
|
|||
|
|
" <td>47.175526</td>\n",
|
|||
|
|
" <td>-94.082772</td>\n",
|
|||
|
|
" <td>-0.334313</td>\n",
|
|||
|
|
" <td>-52.333017</td>\n",
|
|||
|
|
" <td>60.151324</td>\n",
|
|||
|
|
" <td>81.362946</td>\n",
|
|||
|
|
" <td>-85.182427</td>\n",
|
|||
|
|
" <td>-118.891320</td>\n",
|
|||
|
|
" <td>...</td>\n",
|
|||
|
|
" <td>-33.708893</td>\n",
|
|||
|
|
" <td>-185.557987</td>\n",
|
|||
|
|
" <td>0.716473</td>\n",
|
|||
|
|
" <td>-0.560736</td>\n",
|
|||
|
|
" <td>-112.484341</td>\n",
|
|||
|
|
" <td>-0.708596</td>\n",
|
|||
|
|
" <td>-0.000172</td>\n",
|
|||
|
|
" <td>1.118244</td>\n",
|
|||
|
|
" <td>0.950727</td>\n",
|
|||
|
|
" <td>-1</td>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" <tr>\n",
|
|||
|
|
" <th>1</th>\n",
|
|||
|
|
" <td>0.25882</td>\n",
|
|||
|
|
" <td>-0.433884</td>\n",
|
|||
|
|
" <td>48.511681</td>\n",
|
|||
|
|
" <td>-75.385246</td>\n",
|
|||
|
|
" <td>-0.384653</td>\n",
|
|||
|
|
" <td>-46.360881</td>\n",
|
|||
|
|
" <td>38.321881</td>\n",
|
|||
|
|
" <td>76.177460</td>\n",
|
|||
|
|
" <td>-42.278460</td>\n",
|
|||
|
|
" <td>-95.027334</td>\n",
|
|||
|
|
" <td>...</td>\n",
|
|||
|
|
" <td>-52.748874</td>\n",
|
|||
|
|
" <td>-161.694000</td>\n",
|
|||
|
|
" <td>0.444908</td>\n",
|
|||
|
|
" <td>-0.701553</td>\n",
|
|||
|
|
" <td>-84.682762</td>\n",
|
|||
|
|
" <td>-0.884346</td>\n",
|
|||
|
|
" <td>-0.000113</td>\n",
|
|||
|
|
" <td>1.081275</td>\n",
|
|||
|
|
" <td>0.627573</td>\n",
|
|||
|
|
" <td>0</td>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" <tr>\n",
|
|||
|
|
" <th>2</th>\n",
|
|||
|
|
" <td>0.50000</td>\n",
|
|||
|
|
" <td>-0.433884</td>\n",
|
|||
|
|
" <td>49.885998</td>\n",
|
|||
|
|
" <td>-75.857692</td>\n",
|
|||
|
|
" <td>-0.430903</td>\n",
|
|||
|
|
" <td>-49.155591</td>\n",
|
|||
|
|
" <td>38.771059</td>\n",
|
|||
|
|
" <td>73.248674</td>\n",
|
|||
|
|
" <td>-47.531006</td>\n",
|
|||
|
|
" <td>-90.891438</td>\n",
|
|||
|
|
" <td>...</td>\n",
|
|||
|
|
" <td>-43.360433</td>\n",
|
|||
|
|
" <td>-24.224772</td>\n",
|
|||
|
|
" <td>0.522943</td>\n",
|
|||
|
|
" <td>0.733476</td>\n",
|
|||
|
|
" <td>-87.926650</td>\n",
|
|||
|
|
" <td>0.878839</td>\n",
|
|||
|
|
" <td>-0.000085</td>\n",
|
|||
|
|
" <td>1.062512</td>\n",
|
|||
|
|
" <td>0.744744</td>\n",
|
|||
|
|
" <td>0</td>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" <tr>\n",
|
|||
|
|
" <th>3</th>\n",
|
|||
|
|
" <td>0.70711</td>\n",
|
|||
|
|
" <td>-0.433884</td>\n",
|
|||
|
|
" <td>51.177650</td>\n",
|
|||
|
|
" <td>-74.037359</td>\n",
|
|||
|
|
" <td>-0.465194</td>\n",
|
|||
|
|
" <td>-50.208330</td>\n",
|
|||
|
|
" <td>42.001402</td>\n",
|
|||
|
|
" <td>71.053743</td>\n",
|
|||
|
|
" <td>-49.428255</td>\n",
|
|||
|
|
" <td>-85.327852</td>\n",
|
|||
|
|
" <td>...</td>\n",
|
|||
|
|
" <td>-35.899597</td>\n",
|
|||
|
|
" <td>-18.661185</td>\n",
|
|||
|
|
" <td>0.579275</td>\n",
|
|||
|
|
" <td>0.781300</td>\n",
|
|||
|
|
" <td>-92.209732</td>\n",
|
|||
|
|
" <td>0.900446</td>\n",
|
|||
|
|
" <td>-0.000052</td>\n",
|
|||
|
|
" <td>1.039139</td>\n",
|
|||
|
|
" <td>0.687263</td>\n",
|
|||
|
|
" <td>0</td>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" <tr>\n",
|
|||
|
|
" <th>4</th>\n",
|
|||
|
|
" <td>0.86603</td>\n",
|
|||
|
|
" <td>-0.433884</td>\n",
|
|||
|
|
" <td>51.686381</td>\n",
|
|||
|
|
" <td>-55.926237</td>\n",
|
|||
|
|
" <td>-0.472084</td>\n",
|
|||
|
|
" <td>-38.562741</td>\n",
|
|||
|
|
" <td>43.776003</td>\n",
|
|||
|
|
" <td>63.825371</td>\n",
|
|||
|
|
" <td>4.514309</td>\n",
|
|||
|
|
" <td>-71.303106</td>\n",
|
|||
|
|
" <td>...</td>\n",
|
|||
|
|
" <td>-75.817414</td>\n",
|
|||
|
|
" <td>-137.969772</td>\n",
|
|||
|
|
" <td>-0.063312</td>\n",
|
|||
|
|
" <td>-0.934976</td>\n",
|
|||
|
|
" <td>-82.338745</td>\n",
|
|||
|
|
" <td>-1.192046</td>\n",
|
|||
|
|
" <td>-0.000043</td>\n",
|
|||
|
|
" <td>1.032691</td>\n",
|
|||
|
|
" <td>0.873788</td>\n",
|
|||
|
|
" <td>0</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",
|
|||
|
|
" <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>33324</th>\n",
|
|||
|
|
" <td>-0.96593</td>\n",
|
|||
|
|
" <td>0.781831</td>\n",
|
|||
|
|
" <td>23.611404</td>\n",
|
|||
|
|
" <td>-160.337614</td>\n",
|
|||
|
|
" <td>-0.051720</td>\n",
|
|||
|
|
" <td>-49.033438</td>\n",
|
|||
|
|
" <td>97.675231</td>\n",
|
|||
|
|
" <td>61.594852</td>\n",
|
|||
|
|
" <td>-108.467310</td>\n",
|
|||
|
|
" <td>-217.330577</td>\n",
|
|||
|
|
" <td>...</td>\n",
|
|||
|
|
" <td>-108.863267</td>\n",
|
|||
|
|
" <td>-150.663910</td>\n",
|
|||
|
|
" <td>0.499089</td>\n",
|
|||
|
|
" <td>0.306752</td>\n",
|
|||
|
|
" <td>-146.708669</td>\n",
|
|||
|
|
" <td>0.415789</td>\n",
|
|||
|
|
" <td>-0.000087</td>\n",
|
|||
|
|
" <td>1.060976</td>\n",
|
|||
|
|
" <td>0.938986</td>\n",
|
|||
|
|
" <td>0</td>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" <tr>\n",
|
|||
|
|
" <th>33325</th>\n",
|
|||
|
|
" <td>-0.86603</td>\n",
|
|||
|
|
" <td>0.781831</td>\n",
|
|||
|
|
" <td>25.551370</td>\n",
|
|||
|
|
" <td>-119.355906</td>\n",
|
|||
|
|
" <td>-0.082496</td>\n",
|
|||
|
|
" <td>-43.107288</td>\n",
|
|||
|
|
" <td>77.473593</td>\n",
|
|||
|
|
" <td>64.304066</td>\n",
|
|||
|
|
" <td>-76.572200</td>\n",
|
|||
|
|
" <td>-161.486199</td>\n",
|
|||
|
|
" <td>...</td>\n",
|
|||
|
|
" <td>-84.913999</td>\n",
|
|||
|
|
" <td>-228.152865</td>\n",
|
|||
|
|
" <td>0.474172</td>\n",
|
|||
|
|
" <td>-0.412832</td>\n",
|
|||
|
|
" <td>-120.580881</td>\n",
|
|||
|
|
" <td>-0.558554</td>\n",
|
|||
|
|
" <td>-0.000060</td>\n",
|
|||
|
|
" <td>1.042922</td>\n",
|
|||
|
|
" <td>0.828449</td>\n",
|
|||
|
|
" <td>0</td>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" <tr>\n",
|
|||
|
|
" <th>33326</th>\n",
|
|||
|
|
" <td>-0.70711</td>\n",
|
|||
|
|
" <td>0.781831</td>\n",
|
|||
|
|
" <td>26.385304</td>\n",
|
|||
|
|
" <td>-85.267741</td>\n",
|
|||
|
|
" <td>-0.116771</td>\n",
|
|||
|
|
" <td>-40.333690</td>\n",
|
|||
|
|
" <td>61.200479</td>\n",
|
|||
|
|
" <td>58.403529</td>\n",
|
|||
|
|
" <td>-46.257822</td>\n",
|
|||
|
|
" <td>-118.798827</td>\n",
|
|||
|
|
" <td>...</td>\n",
|
|||
|
|
" <td>-72.541004</td>\n",
|
|||
|
|
" <td>-185.465493</td>\n",
|
|||
|
|
" <td>0.389379</td>\n",
|
|||
|
|
" <td>-0.561173</td>\n",
|
|||
|
|
" <td>-101.534169</td>\n",
|
|||
|
|
" <td>-0.781851</td>\n",
|
|||
|
|
" <td>-0.000046</td>\n",
|
|||
|
|
" <td>1.032793</td>\n",
|
|||
|
|
" <td>0.875523</td>\n",
|
|||
|
|
" <td>0</td>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" <tr>\n",
|
|||
|
|
" <th>33327</th>\n",
|
|||
|
|
" <td>-0.50000</td>\n",
|
|||
|
|
" <td>0.781831</td>\n",
|
|||
|
|
" <td>27.159672</td>\n",
|
|||
|
|
" <td>-69.016843</td>\n",
|
|||
|
|
" <td>-0.151568</td>\n",
|
|||
|
|
" <td>-34.860425</td>\n",
|
|||
|
|
" <td>53.063921</td>\n",
|
|||
|
|
" <td>53.683099</td>\n",
|
|||
|
|
" <td>-26.847505</td>\n",
|
|||
|
|
" <td>-97.839834</td>\n",
|
|||
|
|
" <td>...</td>\n",
|
|||
|
|
" <td>-70.992329</td>\n",
|
|||
|
|
" <td>-164.506501</td>\n",
|
|||
|
|
" <td>0.274403</td>\n",
|
|||
|
|
" <td>-0.681386</td>\n",
|
|||
|
|
" <td>-87.924347</td>\n",
|
|||
|
|
" <td>-0.965948</td>\n",
|
|||
|
|
" <td>-0.000015</td>\n",
|
|||
|
|
" <td>1.011219</td>\n",
|
|||
|
|
" <td>0.716892</td>\n",
|
|||
|
|
" <td>0</td>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" <tr>\n",
|
|||
|
|
" <th>33328</th>\n",
|
|||
|
|
" <td>-0.25882</td>\n",
|
|||
|
|
" <td>0.781831</td>\n",
|
|||
|
|
" <td>28.181968</td>\n",
|
|||
|
|
" <td>-73.068540</td>\n",
|
|||
|
|
" <td>-0.186740</td>\n",
|
|||
|
|
" <td>-41.146290</td>\n",
|
|||
|
|
" <td>50.740874</td>\n",
|
|||
|
|
" <td>52.519310</td>\n",
|
|||
|
|
" <td>-50.481804</td>\n",
|
|||
|
|
" <td>-99.278507</td>\n",
|
|||
|
|
" <td>...</td>\n",
|
|||
|
|
" <td>-48.796704</td>\n",
|
|||
|
|
" <td>-32.611841</td>\n",
|
|||
|
|
" <td>0.508487</td>\n",
|
|||
|
|
" <td>0.671512</td>\n",
|
|||
|
|
" <td>-91.887164</td>\n",
|
|||
|
|
" <td>0.912385</td>\n",
|
|||
|
|
" <td>-0.000004</td>\n",
|
|||
|
|
" <td>1.003260</td>\n",
|
|||
|
|
" <td>0.817381</td>\n",
|
|||
|
|
" <td>1</td>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" </tbody>\n",
|
|||
|
|
"</table>\n",
|
|||
|
|
"<p>33329 rows × 25 columns</p>\n",
|
|||
|
|
"</div>"
|
|||
|
|
],
|
|||
|
|
"text/plain": [
|
|||
|
|
" Hour_sin DOW_sin ADX_14 CCI_14 PPO_12_26 CMO_14 \\\n",
|
|||
|
|
"0 -0.25882 0.433884 47.175526 -94.082772 -0.334313 -52.333017 \n",
|
|||
|
|
"1 0.25882 -0.433884 48.511681 -75.385246 -0.384653 -46.360881 \n",
|
|||
|
|
"2 0.50000 -0.433884 49.885998 -75.857692 -0.430903 -49.155591 \n",
|
|||
|
|
"3 0.70711 -0.433884 51.177650 -74.037359 -0.465194 -50.208330 \n",
|
|||
|
|
"4 0.86603 -0.433884 51.686381 -55.926237 -0.472084 -38.562741 \n",
|
|||
|
|
"... ... ... ... ... ... ... \n",
|
|||
|
|
"33324 -0.96593 0.781831 23.611404 -160.337614 -0.051720 -49.033438 \n",
|
|||
|
|
"33325 -0.86603 0.781831 25.551370 -119.355906 -0.082496 -43.107288 \n",
|
|||
|
|
"33326 -0.70711 0.781831 26.385304 -85.267741 -0.116771 -40.333690 \n",
|
|||
|
|
"33327 -0.50000 0.781831 27.159672 -69.016843 -0.151568 -34.860425 \n",
|
|||
|
|
"33328 -0.25882 0.781831 28.181968 -73.068540 -0.186740 -41.146290 \n",
|
|||
|
|
"\n",
|
|||
|
|
" ADX_2 ADX_5 CCI_8 CCI_20 ... CCI_diff_12 \\\n",
|
|||
|
|
"0 60.151324 81.362946 -85.182427 -118.891320 ... -33.708893 \n",
|
|||
|
|
"1 38.321881 76.177460 -42.278460 -95.027334 ... -52.748874 \n",
|
|||
|
|
"2 38.771059 73.248674 -47.531006 -90.891438 ... -43.360433 \n",
|
|||
|
|
"3 42.001402 71.053743 -49.428255 -85.327852 ... -35.899597 \n",
|
|||
|
|
"4 43.776003 63.825371 4.514309 -71.303106 ... -75.817414 \n",
|
|||
|
|
"... ... ... ... ... ... ... \n",
|
|||
|
|
"33324 97.675231 61.594852 -108.467310 -217.330577 ... -108.863267 \n",
|
|||
|
|
"33325 77.473593 64.304066 -76.572200 -161.486199 ... -84.913999 \n",
|
|||
|
|
"33326 61.200479 58.403529 -46.257822 -118.798827 ... -72.541004 \n",
|
|||
|
|
"33327 53.063921 53.683099 -26.847505 -97.839834 ... -70.992329 \n",
|
|||
|
|
"33328 50.740874 52.519310 -50.481804 -99.278507 ... -48.796704 \n",
|
|||
|
|
"\n",
|
|||
|
|
" CCI_diff_18 CCI_ratio_8_20 CCI_ratio_2_20 CMO_diff_12 \\\n",
|
|||
|
|
"0 -185.557987 0.716473 -0.560736 -112.484341 \n",
|
|||
|
|
"1 -161.694000 0.444908 -0.701553 -84.682762 \n",
|
|||
|
|
"2 -24.224772 0.522943 0.733476 -87.926650 \n",
|
|||
|
|
"3 -18.661185 0.579275 0.781300 -92.209732 \n",
|
|||
|
|
"4 -137.969772 -0.063312 -0.934976 -82.338745 \n",
|
|||
|
|
"... ... ... ... ... \n",
|
|||
|
|
"33324 -150.663910 0.499089 0.306752 -146.708669 \n",
|
|||
|
|
"33325 -228.152865 0.474172 -0.412832 -120.580881 \n",
|
|||
|
|
"33326 -185.465493 0.389379 -0.561173 -101.534169 \n",
|
|||
|
|
"33327 -164.506501 0.274403 -0.681386 -87.924347 \n",
|
|||
|
|
"33328 -32.611841 0.508487 0.671512 -91.887164 \n",
|
|||
|
|
"\n",
|
|||
|
|
" CMO_ratio_2_14 KeltnerWidth_diff_9 KeltnerWidth_ratio_15_24 \\\n",
|
|||
|
|
"0 -0.708596 -0.000172 1.118244 \n",
|
|||
|
|
"1 -0.884346 -0.000113 1.081275 \n",
|
|||
|
|
"2 0.878839 -0.000085 1.062512 \n",
|
|||
|
|
"3 0.900446 -0.000052 1.039139 \n",
|
|||
|
|
"4 -1.192046 -0.000043 1.032691 \n",
|
|||
|
|
"... ... ... ... \n",
|
|||
|
|
"33324 0.415789 -0.000087 1.060976 \n",
|
|||
|
|
"33325 -0.558554 -0.000060 1.042922 \n",
|
|||
|
|
"33326 -0.781851 -0.000046 1.032793 \n",
|
|||
|
|
"33327 -0.965948 -0.000015 1.011219 \n",
|
|||
|
|
"33328 0.912385 -0.000004 1.003260 \n",
|
|||
|
|
"\n",
|
|||
|
|
" KeltnerWidth_ratio_2_24 signal \n",
|
|||
|
|
"0 0.950727 -1 \n",
|
|||
|
|
"1 0.627573 0 \n",
|
|||
|
|
"2 0.744744 0 \n",
|
|||
|
|
"3 0.687263 0 \n",
|
|||
|
|
"4 0.873788 0 \n",
|
|||
|
|
"... ... ... \n",
|
|||
|
|
"33324 0.938986 0 \n",
|
|||
|
|
"33325 0.828449 0 \n",
|
|||
|
|
"33326 0.875523 0 \n",
|
|||
|
|
"33327 0.716892 0 \n",
|
|||
|
|
"33328 0.817381 1 \n",
|
|||
|
|
"\n",
|
|||
|
|
"[33329 rows x 25 columns]"
|
|||
|
|
]
|
|||
|
|
},
|
|||
|
|
"execution_count": 199,
|
|||
|
|
"metadata": {},
|
|||
|
|
"output_type": "execute_result"
|
|||
|
|
}
|
|||
|
|
],
|
|||
|
|
"source": [
|
|||
|
|
"# Drop any unnamed index columns\n",
|
|||
|
|
"test_df = test_df.loc[:, ~test_df.columns.str.contains(\"^Unnamed\")]\n",
|
|||
|
|
"test_df"
|
|||
|
|
]
|
|||
|
|
},
|
|||
|
|
{
|
|||
|
|
"cell_type": "code",
|
|||
|
|
"execution_count": 187,
|
|||
|
|
"metadata": {},
|
|||
|
|
"outputs": [
|
|||
|
|
{
|
|||
|
|
"name": "stdout",
|
|||
|
|
"output_type": "stream",
|
|||
|
|
"text": [
|
|||
|
|
"Predictions ready. Sample:\n",
|
|||
|
|
" predicted_signal\n",
|
|||
|
|
"0 -1.0\n",
|
|||
|
|
"1 0.0\n",
|
|||
|
|
"2 0.0\n",
|
|||
|
|
"3 0.0\n",
|
|||
|
|
"4 0.0\n"
|
|||
|
|
]
|
|||
|
|
}
|
|||
|
|
],
|
|||
|
|
"source": [
|
|||
|
|
"import numpy as np\n",
|
|||
|
|
"import pandas as pd\n",
|
|||
|
|
"import xgboost as xgb\n",
|
|||
|
|
"\n",
|
|||
|
|
"# ---- Load model (if not in memory) ----\n",
|
|||
|
|
"try:\n",
|
|||
|
|
" bst_final # noqa: F821\n",
|
|||
|
|
"except NameError:\n",
|
|||
|
|
" bst_final = xgb.Booster()\n",
|
|||
|
|
" bst_final.load_model(\"xgb_trading_model_tuned.json\")\n",
|
|||
|
|
"\n",
|
|||
|
|
"# Helper: how many features the model expects\n",
|
|||
|
|
"try:\n",
|
|||
|
|
" model_nfeat = bst_final.num_features()\n",
|
|||
|
|
"except Exception:\n",
|
|||
|
|
" # Older xgboost: num_features might be an attribute\n",
|
|||
|
|
" model_nfeat = getattr(bst_final, \"num_features\", None)\n",
|
|||
|
|
"\n",
|
|||
|
|
"# ---- Build the EXACT feature order used at training ----\n",
|
|||
|
|
"# Best practice: if you saved it earlier, load it here\n",
|
|||
|
|
"# feature_order = list(np.load(\"xgb_feature_order.npy\", allow_pickle=True))\n",
|
|||
|
|
"\n",
|
|||
|
|
"# If you don't have it saved, reconstruct from train_df, dropping obvious non-features:\n",
|
|||
|
|
"non_feature_cols = {\"target_signal\", \"predicted_signal\", \"DateTime\"}\n",
|
|||
|
|
"train_features_now = [c for c in train_df.columns if c not in non_feature_cols]\n",
|
|||
|
|
"feature_order = train_features_now # fallback\n",
|
|||
|
|
"\n",
|
|||
|
|
"# Optional: assert against model's expected count if we know it\n",
|
|||
|
|
"if model_nfeat is not None and len(feature_order) != model_nfeat:\n",
|
|||
|
|
" # If off-by-one, try dropping any \"Unnamed\" or accidental columns\n",
|
|||
|
|
" feature_order = [c for c in feature_order if not str(c).startswith(\"Unnamed\")]\n",
|
|||
|
|
" if len(feature_order) != model_nfeat:\n",
|
|||
|
|
" print(f\"[Warn] Training feature count {len(feature_order)} != model expects {model_nfeat}.\")\n",
|
|||
|
|
" # We'll still proceed but also print a diff vs. test below.\n",
|
|||
|
|
"\n",
|
|||
|
|
"# ---- Prepare test features strictly in training order ----\n",
|
|||
|
|
"df_te = test_df.copy()\n",
|
|||
|
|
"\n",
|
|||
|
|
"# Drop obvious non-features from test too (in case they exist)\n",
|
|||
|
|
"df_te = df_te.drop(columns=[c for c in df_te.columns if c in non_feature_cols or str(c).startswith(\"Unnamed\")], errors=\"ignore\")\n",
|
|||
|
|
"\n",
|
|||
|
|
"# Reindex to the training feature order; fill missing with 0 (your policy)\n",
|
|||
|
|
"X_te = df_te.reindex(columns=feature_order, fill_value=0)\n",
|
|||
|
|
"\n",
|
|||
|
|
"# Debug: check shape vs model\n",
|
|||
|
|
"if model_nfeat is not None and X_te.shape[1] != model_nfeat:\n",
|
|||
|
|
" extra_in_test = set(X_te.columns) - set(feature_order)\n",
|
|||
|
|
" missing_in_test = set(feature_order) - set(X_te.columns)\n",
|
|||
|
|
" print(\"[Mismatch] Model expects:\", model_nfeat, \"| X_te has:\", X_te.shape[1])\n",
|
|||
|
|
" print(\"Extra in test (should be none):\", extra_in_test)\n",
|
|||
|
|
" print(\"Missing in test:\", missing_in_test)\n",
|
|||
|
|
" # As a last guard, if X_te has MORE cols than model, trim to first model_nfeat cols in the training order:\n",
|
|||
|
|
" if X_te.shape[1] > model_nfeat:\n",
|
|||
|
|
" X_te = X_te[feature_order[:model_nfeat]]\n",
|
|||
|
|
" elif X_te.shape[1] < model_nfeat:\n",
|
|||
|
|
" # Add missing columns as 0, maintaining order\n",
|
|||
|
|
" for c in feature_order:\n",
|
|||
|
|
" if c not in X_te.columns and len(X_te.columns) < model_nfeat:\n",
|
|||
|
|
" X_te[c] = 0.0\n",
|
|||
|
|
" X_te = X_te[feature_order[:model_nfeat]]\n",
|
|||
|
|
"\n",
|
|||
|
|
"# Final consistency checks\n",
|
|||
|
|
"assert model_nfeat is None or X_te.shape[1] == model_nfeat, \\\n",
|
|||
|
|
" f\"Still mismatched: model expects {model_nfeat}, X_te has {X_te.shape[1]}\"\n",
|
|||
|
|
"\n",
|
|||
|
|
"# Clean infinities like training\n",
|
|||
|
|
"X_te = X_te.replace([np.inf, -np.inf], 0).astype(float)\n",
|
|||
|
|
"\n",
|
|||
|
|
"# ---- Predict ----\n",
|
|||
|
|
"dtest = xgb.DMatrix(X_te.to_numpy(dtype=float, copy=False))\n",
|
|||
|
|
"pred = bst_final.predict(dtest)\n",
|
|||
|
|
"\n",
|
|||
|
|
"# Map back to labels using training mapping\n",
|
|||
|
|
"labels_sorted = sorted(pd.to_numeric(train_df[\"target_signal\"], errors=\"coerce\").dropna().unique())\n",
|
|||
|
|
"lab2idx = {lab: i for i, lab in enumerate(labels_sorted)}\n",
|
|||
|
|
"idx2lab = {i: lab for lab, i in lab2idx.items()}\n",
|
|||
|
|
"\n",
|
|||
|
|
"if pred.ndim == 2: # multiclass\n",
|
|||
|
|
" y_pred_enc = pred.argmax(axis=1)\n",
|
|||
|
|
"else: # binary\n",
|
|||
|
|
" y_pred_enc = (pred >= 0.5).astype(int)\n",
|
|||
|
|
"\n",
|
|||
|
|
"y_pred_lbl = np.vectorize(idx2lab.get)(y_pred_enc)\n",
|
|||
|
|
"\n",
|
|||
|
|
"test_df_with_preds = df_te.copy()\n",
|
|||
|
|
"test_df_with_preds[\"predicted_signal\"] = y_pred_lbl\n",
|
|||
|
|
"\n",
|
|||
|
|
"print(\"Predictions ready. Sample:\")\n",
|
|||
|
|
"print(test_df_with_preds[[\"predicted_signal\"]].head())\n"
|
|||
|
|
]
|
|||
|
|
},
|
|||
|
|
{
|
|||
|
|
"cell_type": "markdown",
|
|||
|
|
"metadata": {},
|
|||
|
|
"source": [
|
|||
|
|
"# Backtesting"
|
|||
|
|
]
|
|||
|
|
},
|
|||
|
|
{
|
|||
|
|
"cell_type": "code",
|
|||
|
|
"execution_count": 189,
|
|||
|
|
"metadata": {},
|
|||
|
|
"outputs": [],
|
|||
|
|
"source": [
|
|||
|
|
"backdf = test_df_with_preds"
|
|||
|
|
]
|
|||
|
|
},
|
|||
|
|
{
|
|||
|
|
"cell_type": "code",
|
|||
|
|
"execution_count": 190,
|
|||
|
|
"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>Unnamed: 0</th>\n",
|
|||
|
|
" <th>Hour_sin</th>\n",
|
|||
|
|
" <th>DOW_sin</th>\n",
|
|||
|
|
" <th>ADX_14</th>\n",
|
|||
|
|
" <th>CCI_14</th>\n",
|
|||
|
|
" <th>PPO_12_26</th>\n",
|
|||
|
|
" <th>CMO_14</th>\n",
|
|||
|
|
" <th>ADX_2</th>\n",
|
|||
|
|
" <th>ADX_5</th>\n",
|
|||
|
|
" <th>CCI_8</th>\n",
|
|||
|
|
" <th>...</th>\n",
|
|||
|
|
" <th>KeltnerWidth_ratio_15_24</th>\n",
|
|||
|
|
" <th>KeltnerWidth_ratio_2_24</th>\n",
|
|||
|
|
" <th>signal</th>\n",
|
|||
|
|
" <th>predicted_signal</th>\n",
|
|||
|
|
" <th>DateTime</th>\n",
|
|||
|
|
" <th>Open</th>\n",
|
|||
|
|
" <th>High</th>\n",
|
|||
|
|
" <th>Low</th>\n",
|
|||
|
|
" <th>Close</th>\n",
|
|||
|
|
" <th>Volume</th>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" </thead>\n",
|
|||
|
|
" <tbody>\n",
|
|||
|
|
" <tr>\n",
|
|||
|
|
" <th>0</th>\n",
|
|||
|
|
" <td>0</td>\n",
|
|||
|
|
" <td>-0.25882</td>\n",
|
|||
|
|
" <td>0.433884</td>\n",
|
|||
|
|
" <td>47.175526</td>\n",
|
|||
|
|
" <td>-94.082772</td>\n",
|
|||
|
|
" <td>-0.334313</td>\n",
|
|||
|
|
" <td>-52.333017</td>\n",
|
|||
|
|
" <td>60.151324</td>\n",
|
|||
|
|
" <td>81.362946</td>\n",
|
|||
|
|
" <td>-85.182427</td>\n",
|
|||
|
|
" <td>...</td>\n",
|
|||
|
|
" <td>1.118244</td>\n",
|
|||
|
|
" <td>0.950727</td>\n",
|
|||
|
|
" <td>-1</td>\n",
|
|||
|
|
" <td>1</td>\n",
|
|||
|
|
" <td>07/03/19 23:00</td>\n",
|
|||
|
|
" <td>1.11810</td>\n",
|
|||
|
|
" <td>1.11944</td>\n",
|
|||
|
|
" <td>1.11797</td>\n",
|
|||
|
|
" <td>1.11923</td>\n",
|
|||
|
|
" <td>963</td>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" <tr>\n",
|
|||
|
|
" <th>1</th>\n",
|
|||
|
|
" <td>1</td>\n",
|
|||
|
|
" <td>0.25882</td>\n",
|
|||
|
|
" <td>-0.433884</td>\n",
|
|||
|
|
" <td>48.511681</td>\n",
|
|||
|
|
" <td>-75.385246</td>\n",
|
|||
|
|
" <td>-0.384653</td>\n",
|
|||
|
|
" <td>-46.360881</td>\n",
|
|||
|
|
" <td>38.321881</td>\n",
|
|||
|
|
" <td>76.177460</td>\n",
|
|||
|
|
" <td>-42.278460</td>\n",
|
|||
|
|
" <td>...</td>\n",
|
|||
|
|
" <td>1.081275</td>\n",
|
|||
|
|
" <td>0.627573</td>\n",
|
|||
|
|
" <td>0</td>\n",
|
|||
|
|
" <td>0</td>\n",
|
|||
|
|
" <td>08/03/19 1:00</td>\n",
|
|||
|
|
" <td>1.11916</td>\n",
|
|||
|
|
" <td>1.11985</td>\n",
|
|||
|
|
" <td>1.11916</td>\n",
|
|||
|
|
" <td>1.11976</td>\n",
|
|||
|
|
" <td>764</td>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" <tr>\n",
|
|||
|
|
" <th>2</th>\n",
|
|||
|
|
" <td>2</td>\n",
|
|||
|
|
" <td>0.50000</td>\n",
|
|||
|
|
" <td>-0.433884</td>\n",
|
|||
|
|
" <td>49.885998</td>\n",
|
|||
|
|
" <td>-75.857692</td>\n",
|
|||
|
|
" <td>-0.430903</td>\n",
|
|||
|
|
" <td>-49.155591</td>\n",
|
|||
|
|
" <td>38.771059</td>\n",
|
|||
|
|
" <td>73.248674</td>\n",
|
|||
|
|
" <td>-47.531006</td>\n",
|
|||
|
|
" <td>...</td>\n",
|
|||
|
|
" <td>1.062512</td>\n",
|
|||
|
|
" <td>0.744744</td>\n",
|
|||
|
|
" <td>0</td>\n",
|
|||
|
|
" <td>0</td>\n",
|
|||
|
|
" <td>08/03/19 2:00</td>\n",
|
|||
|
|
" <td>1.11976</td>\n",
|
|||
|
|
" <td>1.11977</td>\n",
|
|||
|
|
" <td>1.11855</td>\n",
|
|||
|
|
" <td>1.11907</td>\n",
|
|||
|
|
" <td>1620</td>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" <tr>\n",
|
|||
|
|
" <th>3</th>\n",
|
|||
|
|
" <td>3</td>\n",
|
|||
|
|
" <td>0.70711</td>\n",
|
|||
|
|
" <td>-0.433884</td>\n",
|
|||
|
|
" <td>51.177650</td>\n",
|
|||
|
|
" <td>-74.037359</td>\n",
|
|||
|
|
" <td>-0.465194</td>\n",
|
|||
|
|
" <td>-50.208330</td>\n",
|
|||
|
|
" <td>42.001402</td>\n",
|
|||
|
|
" <td>71.053743</td>\n",
|
|||
|
|
" <td>-49.428255</td>\n",
|
|||
|
|
" <td>...</td>\n",
|
|||
|
|
" <td>1.039139</td>\n",
|
|||
|
|
" <td>0.687263</td>\n",
|
|||
|
|
" <td>0</td>\n",
|
|||
|
|
" <td>0</td>\n",
|
|||
|
|
" <td>08/03/19 3:00</td>\n",
|
|||
|
|
" <td>1.11906</td>\n",
|
|||
|
|
" <td>1.11944</td>\n",
|
|||
|
|
" <td>1.11848</td>\n",
|
|||
|
|
" <td>1.11881</td>\n",
|
|||
|
|
" <td>1091</td>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" <tr>\n",
|
|||
|
|
" <th>4</th>\n",
|
|||
|
|
" <td>4</td>\n",
|
|||
|
|
" <td>0.86603</td>\n",
|
|||
|
|
" <td>-0.433884</td>\n",
|
|||
|
|
" <td>51.686381</td>\n",
|
|||
|
|
" <td>-55.926237</td>\n",
|
|||
|
|
" <td>-0.472084</td>\n",
|
|||
|
|
" <td>-38.562741</td>\n",
|
|||
|
|
" <td>43.776003</td>\n",
|
|||
|
|
" <td>63.825371</td>\n",
|
|||
|
|
" <td>4.514309</td>\n",
|
|||
|
|
" <td>...</td>\n",
|
|||
|
|
" <td>1.032691</td>\n",
|
|||
|
|
" <td>0.873788</td>\n",
|
|||
|
|
" <td>0</td>\n",
|
|||
|
|
" <td>0</td>\n",
|
|||
|
|
" <td>08/03/19 4:00</td>\n",
|
|||
|
|
" <td>1.11881</td>\n",
|
|||
|
|
" <td>1.12003</td>\n",
|
|||
|
|
" <td>1.11860</td>\n",
|
|||
|
|
" <td>1.11979</td>\n",
|
|||
|
|
" <td>992</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",
|
|||
|
|
" <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>33324</th>\n",
|
|||
|
|
" <td>33324</td>\n",
|
|||
|
|
" <td>-0.96593</td>\n",
|
|||
|
|
" <td>0.781831</td>\n",
|
|||
|
|
" <td>23.611404</td>\n",
|
|||
|
|
" <td>-160.337614</td>\n",
|
|||
|
|
" <td>-0.051720</td>\n",
|
|||
|
|
" <td>-49.033438</td>\n",
|
|||
|
|
" <td>97.675231</td>\n",
|
|||
|
|
" <td>61.594852</td>\n",
|
|||
|
|
" <td>-108.467310</td>\n",
|
|||
|
|
" <td>...</td>\n",
|
|||
|
|
" <td>1.060976</td>\n",
|
|||
|
|
" <td>0.938986</td>\n",
|
|||
|
|
" <td>0</td>\n",
|
|||
|
|
" <td>0</td>\n",
|
|||
|
|
" <td>31/12/24 19:00</td>\n",
|
|||
|
|
" <td>1.03502</td>\n",
|
|||
|
|
" <td>1.03548</td>\n",
|
|||
|
|
" <td>1.03438</td>\n",
|
|||
|
|
" <td>1.03490</td>\n",
|
|||
|
|
" <td>2323</td>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" <tr>\n",
|
|||
|
|
" <th>33325</th>\n",
|
|||
|
|
" <td>33325</td>\n",
|
|||
|
|
" <td>-0.86603</td>\n",
|
|||
|
|
" <td>0.781831</td>\n",
|
|||
|
|
" <td>25.551370</td>\n",
|
|||
|
|
" <td>-119.355906</td>\n",
|
|||
|
|
" <td>-0.082496</td>\n",
|
|||
|
|
" <td>-43.107288</td>\n",
|
|||
|
|
" <td>77.473593</td>\n",
|
|||
|
|
" <td>64.304066</td>\n",
|
|||
|
|
" <td>-76.572200</td>\n",
|
|||
|
|
" <td>...</td>\n",
|
|||
|
|
" <td>1.042922</td>\n",
|
|||
|
|
" <td>0.828449</td>\n",
|
|||
|
|
" <td>0</td>\n",
|
|||
|
|
" <td>0</td>\n",
|
|||
|
|
" <td>31/12/24 20:00</td>\n",
|
|||
|
|
" <td>1.03489</td>\n",
|
|||
|
|
" <td>1.03566</td>\n",
|
|||
|
|
" <td>1.03455</td>\n",
|
|||
|
|
" <td>1.03529</td>\n",
|
|||
|
|
" <td>1900</td>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" <tr>\n",
|
|||
|
|
" <th>33326</th>\n",
|
|||
|
|
" <td>33326</td>\n",
|
|||
|
|
" <td>-0.70711</td>\n",
|
|||
|
|
" <td>0.781831</td>\n",
|
|||
|
|
" <td>26.385304</td>\n",
|
|||
|
|
" <td>-85.267741</td>\n",
|
|||
|
|
" <td>-0.116771</td>\n",
|
|||
|
|
" <td>-40.333690</td>\n",
|
|||
|
|
" <td>61.200479</td>\n",
|
|||
|
|
" <td>58.403529</td>\n",
|
|||
|
|
" <td>-46.257822</td>\n",
|
|||
|
|
" <td>...</td>\n",
|
|||
|
|
" <td>1.032793</td>\n",
|
|||
|
|
" <td>0.875523</td>\n",
|
|||
|
|
" <td>0</td>\n",
|
|||
|
|
" <td>0</td>\n",
|
|||
|
|
" <td>31/12/24 21:00</td>\n",
|
|||
|
|
" <td>1.03526</td>\n",
|
|||
|
|
" <td>1.03645</td>\n",
|
|||
|
|
" <td>1.03516</td>\n",
|
|||
|
|
" <td>1.03547</td>\n",
|
|||
|
|
" <td>1445</td>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" <tr>\n",
|
|||
|
|
" <th>33327</th>\n",
|
|||
|
|
" <td>33327</td>\n",
|
|||
|
|
" <td>-0.50000</td>\n",
|
|||
|
|
" <td>0.781831</td>\n",
|
|||
|
|
" <td>27.159672</td>\n",
|
|||
|
|
" <td>-69.016843</td>\n",
|
|||
|
|
" <td>-0.151568</td>\n",
|
|||
|
|
" <td>-34.860425</td>\n",
|
|||
|
|
" <td>53.063921</td>\n",
|
|||
|
|
" <td>53.683099</td>\n",
|
|||
|
|
" <td>-26.847505</td>\n",
|
|||
|
|
" <td>...</td>\n",
|
|||
|
|
" <td>1.011219</td>\n",
|
|||
|
|
" <td>0.716892</td>\n",
|
|||
|
|
" <td>0</td>\n",
|
|||
|
|
" <td>0</td>\n",
|
|||
|
|
" <td>31/12/24 22:00</td>\n",
|
|||
|
|
" <td>1.03547</td>\n",
|
|||
|
|
" <td>1.03631</td>\n",
|
|||
|
|
" <td>1.03544</td>\n",
|
|||
|
|
" <td>1.03582</td>\n",
|
|||
|
|
" <td>1208</td>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" <tr>\n",
|
|||
|
|
" <th>33328</th>\n",
|
|||
|
|
" <td>33328</td>\n",
|
|||
|
|
" <td>-0.25882</td>\n",
|
|||
|
|
" <td>0.781831</td>\n",
|
|||
|
|
" <td>28.181968</td>\n",
|
|||
|
|
" <td>-73.068540</td>\n",
|
|||
|
|
" <td>-0.186740</td>\n",
|
|||
|
|
" <td>-41.146290</td>\n",
|
|||
|
|
" <td>50.740874</td>\n",
|
|||
|
|
" <td>52.519310</td>\n",
|
|||
|
|
" <td>-50.481804</td>\n",
|
|||
|
|
" <td>...</td>\n",
|
|||
|
|
" <td>1.003260</td>\n",
|
|||
|
|
" <td>0.817381</td>\n",
|
|||
|
|
" <td>1</td>\n",
|
|||
|
|
" <td>1</td>\n",
|
|||
|
|
" <td>31/12/24 23:00</td>\n",
|
|||
|
|
" <td>1.03585</td>\n",
|
|||
|
|
" <td>1.03608</td>\n",
|
|||
|
|
" <td>1.03489</td>\n",
|
|||
|
|
" <td>1.03493</td>\n",
|
|||
|
|
" <td>616</td>\n",
|
|||
|
|
" </tr>\n",
|
|||
|
|
" </tbody>\n",
|
|||
|
|
"</table>\n",
|
|||
|
|
"<p>33329 rows × 33 columns</p>\n",
|
|||
|
|
"</div>"
|
|||
|
|
],
|
|||
|
|
"text/plain": [
|
|||
|
|
" Unnamed: 0 Hour_sin DOW_sin ADX_14 CCI_14 PPO_12_26 \\\n",
|
|||
|
|
"0 0 -0.25882 0.433884 47.175526 -94.082772 -0.334313 \n",
|
|||
|
|
"1 1 0.25882 -0.433884 48.511681 -75.385246 -0.384653 \n",
|
|||
|
|
"2 2 0.50000 -0.433884 49.885998 -75.857692 -0.430903 \n",
|
|||
|
|
"3 3 0.70711 -0.433884 51.177650 -74.037359 -0.465194 \n",
|
|||
|
|
"4 4 0.86603 -0.433884 51.686381 -55.926237 -0.472084 \n",
|
|||
|
|
"... ... ... ... ... ... ... \n",
|
|||
|
|
"33324 33324 -0.96593 0.781831 23.611404 -160.337614 -0.051720 \n",
|
|||
|
|
"33325 33325 -0.86603 0.781831 25.551370 -119.355906 -0.082496 \n",
|
|||
|
|
"33326 33326 -0.70711 0.781831 26.385304 -85.267741 -0.116771 \n",
|
|||
|
|
"33327 33327 -0.50000 0.781831 27.159672 -69.016843 -0.151568 \n",
|
|||
|
|
"33328 33328 -0.25882 0.781831 28.181968 -73.068540 -0.186740 \n",
|
|||
|
|
"\n",
|
|||
|
|
" CMO_14 ADX_2 ADX_5 CCI_8 ... \\\n",
|
|||
|
|
"0 -52.333017 60.151324 81.362946 -85.182427 ... \n",
|
|||
|
|
"1 -46.360881 38.321881 76.177460 -42.278460 ... \n",
|
|||
|
|
"2 -49.155591 38.771059 73.248674 -47.531006 ... \n",
|
|||
|
|
"3 -50.208330 42.001402 71.053743 -49.428255 ... \n",
|
|||
|
|
"4 -38.562741 43.776003 63.825371 4.514309 ... \n",
|
|||
|
|
"... ... ... ... ... ... \n",
|
|||
|
|
"33324 -49.033438 97.675231 61.594852 -108.467310 ... \n",
|
|||
|
|
"33325 -43.107288 77.473593 64.304066 -76.572200 ... \n",
|
|||
|
|
"33326 -40.333690 61.200479 58.403529 -46.257822 ... \n",
|
|||
|
|
"33327 -34.860425 53.063921 53.683099 -26.847505 ... \n",
|
|||
|
|
"33328 -41.146290 50.740874 52.519310 -50.481804 ... \n",
|
|||
|
|
"\n",
|
|||
|
|
" KeltnerWidth_ratio_15_24 KeltnerWidth_ratio_2_24 signal \\\n",
|
|||
|
|
"0 1.118244 0.950727 -1 \n",
|
|||
|
|
"1 1.081275 0.627573 0 \n",
|
|||
|
|
"2 1.062512 0.744744 0 \n",
|
|||
|
|
"3 1.039139 0.687263 0 \n",
|
|||
|
|
"4 1.032691 0.873788 0 \n",
|
|||
|
|
"... ... ... ... \n",
|
|||
|
|
"33324 1.060976 0.938986 0 \n",
|
|||
|
|
"33325 1.042922 0.828449 0 \n",
|
|||
|
|
"33326 1.032793 0.875523 0 \n",
|
|||
|
|
"33327 1.011219 0.716892 0 \n",
|
|||
|
|
"33328 1.003260 0.817381 1 \n",
|
|||
|
|
"\n",
|
|||
|
|
" predicted_signal DateTime Open High Low Close \\\n",
|
|||
|
|
"0 1 07/03/19 23:00 1.11810 1.11944 1.11797 1.11923 \n",
|
|||
|
|
"1 0 08/03/19 1:00 1.11916 1.11985 1.11916 1.11976 \n",
|
|||
|
|
"2 0 08/03/19 2:00 1.11976 1.11977 1.11855 1.11907 \n",
|
|||
|
|
"3 0 08/03/19 3:00 1.11906 1.11944 1.11848 1.11881 \n",
|
|||
|
|
"4 0 08/03/19 4:00 1.11881 1.12003 1.11860 1.11979 \n",
|
|||
|
|
"... ... ... ... ... ... ... \n",
|
|||
|
|
"33324 0 31/12/24 19:00 1.03502 1.03548 1.03438 1.03490 \n",
|
|||
|
|
"33325 0 31/12/24 20:00 1.03489 1.03566 1.03455 1.03529 \n",
|
|||
|
|
"33326 0 31/12/24 21:00 1.03526 1.03645 1.03516 1.03547 \n",
|
|||
|
|
"33327 0 31/12/24 22:00 1.03547 1.03631 1.03544 1.03582 \n",
|
|||
|
|
"33328 1 31/12/24 23:00 1.03585 1.03608 1.03489 1.03493 \n",
|
|||
|
|
"\n",
|
|||
|
|
" Volume \n",
|
|||
|
|
"0 963 \n",
|
|||
|
|
"1 764 \n",
|
|||
|
|
"2 1620 \n",
|
|||
|
|
"3 1091 \n",
|
|||
|
|
"4 992 \n",
|
|||
|
|
"... ... \n",
|
|||
|
|
"33324 2323 \n",
|
|||
|
|
"33325 1900 \n",
|
|||
|
|
"33326 1445 \n",
|
|||
|
|
"33327 1208 \n",
|
|||
|
|
"33328 616 \n",
|
|||
|
|
"\n",
|
|||
|
|
"[33329 rows x 33 columns]"
|
|||
|
|
]
|
|||
|
|
},
|
|||
|
|
"execution_count": 190,
|
|||
|
|
"metadata": {},
|
|||
|
|
"output_type": "execute_result"
|
|||
|
|
}
|
|||
|
|
],
|
|||
|
|
"source": [
|
|||
|
|
"back_df"
|
|||
|
|
]
|
|||
|
|
},
|
|||
|
|
{
|
|||
|
|
"cell_type": "code",
|
|||
|
|
"execution_count": null,
|
|||
|
|
"metadata": {},
|
|||
|
|
"outputs": [],
|
|||
|
|
"source": [
|
|||
|
|
"from backtesting import Backtest, Strategy\n",
|
|||
|
|
"import pandas as pd\n",
|
|||
|
|
"import numpy as np\n",
|
|||
|
|
"\n",
|
|||
|
|
"# --- Clean + prepare back_df for backtesting.py ---\n",
|
|||
|
|
"df_bt = back_df.copy()\n",
|
|||
|
|
"\n",
|
|||
|
|
"# 1) Ensure DateTime is proper datetime and is the index\n",
|
|||
|
|
"if \"DateTime\" in df_bt.columns:\n",
|
|||
|
|
" df_bt[\"DateTime\"] = pd.to_datetime(df_bt[\"DateTime\"], errors=\"coerce\")\n",
|
|||
|
|
" df_bt = df_bt.dropna(subset=[\"DateTime\"]).sort_values(\"DateTime\").set_index(\"DateTime\")\n",
|
|||
|
|
"else:\n",
|
|||
|
|
" # If it's already the index but as strings, coerce:\n",
|
|||
|
|
" df_bt.index = pd.to_datetime(df_bt.index, errors=\"coerce\")\n",
|
|||
|
|
" df_bt = df_bt[~df_bt.index.isna()].sort_index()\n",
|
|||
|
|
"\n",
|
|||
|
|
"# Deduplicate index if needed (backtesting.py expects increasing, unique index)\n",
|
|||
|
|
"df_bt = df_bt[~df_bt.index.duplicated(keep=\"first\")]\n",
|
|||
|
|
"\n",
|
|||
|
|
"# 2) Ensure required columns exist and are numeric\n",
|
|||
|
|
"required = [\"Open\", \"High\", \"Low\", \"Close\", \"Volume\", \"predicted_signal\"]\n",
|
|||
|
|
"missing = [c for c in required if c not in df_bt.columns]\n",
|
|||
|
|
"if missing:\n",
|
|||
|
|
" raise ValueError(f\"Missing required columns in back_df: {missing}\")\n",
|
|||
|
|
"\n",
|
|||
|
|
"for c in [\"Open\", \"High\", \"Low\", \"Close\", \"Volume\", \"predicted_signal\"]:\n",
|
|||
|
|
" df_bt[c] = pd.to_numeric(df_bt[c], errors=\"coerce\")\n",
|
|||
|
|
"\n",
|
|||
|
|
"# Fill OHLCV gaps (use past data only); set signal to int in {-1,0,1}\n",
|
|||
|
|
"df_bt[[\"Open\", \"High\", \"Low\", \"Close\", \"Volume\"]] = (\n",
|
|||
|
|
" df_bt[[\"Open\", \"High\", \"Low\", \"Close\", \"Volume\"]].ffill().bfill()\n",
|
|||
|
|
")\n",
|
|||
|
|
"df_bt[\"predicted_signal\"] = df_bt[\"predicted_signal\"].fillna(0).astype(int).clip(-1, 1)\n",
|
|||
|
|
"\n",
|
|||
|
|
"# Final sanity checks\n",
|
|||
|
|
"assert isinstance(df_bt.index, pd.DatetimeIndex)\n",
|
|||
|
|
"assert df_bt.index.is_monotonic_increasing\n",
|
|||
|
|
"\n",
|
|||
|
|
"# --- Strategy: +1 long, -1 short, 0 flat; execute on close; exclusive orders ---\n",
|
|||
|
|
"class SignalStrategy(Strategy):\n",
|
|||
|
|
" def init(self): pass\n",
|
|||
|
|
" def next(self):\n",
|
|||
|
|
" sig = int(self.data.predicted_signal[-1])\n",
|
|||
|
|
" if sig == 0:\n",
|
|||
|
|
" if self.position:\n",
|
|||
|
|
" self.position.close()\n",
|
|||
|
|
" return\n",
|
|||
|
|
" if sig == 1:\n",
|
|||
|
|
" if self.position.is_short:\n",
|
|||
|
|
" self.position.close()\n",
|
|||
|
|
" if not self.position.is_long:\n",
|
|||
|
|
" self.buy()\n",
|
|||
|
|
" return\n",
|
|||
|
|
" if sig == -1:\n",
|
|||
|
|
" if self.position.is_long:\n",
|
|||
|
|
" self.position.close()\n",
|
|||
|
|
" if not self.position.is_short:\n",
|
|||
|
|
" self.sell()\n",
|
|||
|
|
" return\n",
|
|||
|
|
"\n",
|
|||
|
|
"bt = Backtest(\n",
|
|||
|
|
" df_bt,\n",
|
|||
|
|
" SignalStrategy,\n",
|
|||
|
|
" cash=100_000,\n",
|
|||
|
|
" commission=0.0001, \n",
|
|||
|
|
" # execute on the bar's close because the signal is already generated in the next row from the one that triggered it\n",
|
|||
|
|
" trade_on_close=True, \n",
|
|||
|
|
" exclusive_orders=True, # no long+short at the same time\n",
|
|||
|
|
" hedging=False\n",
|
|||
|
|
")\n",
|
|||
|
|
"\n",
|
|||
|
|
"stats = bt.run()\n"
|
|||
|
|
]
|
|||
|
|
},
|
|||
|
|
{
|
|||
|
|
"cell_type": "code",
|
|||
|
|
"execution_count": 203,
|
|||
|
|
"metadata": {},
|
|||
|
|
"outputs": [
|
|||
|
|
{
|
|||
|
|
"name": "stdout",
|
|||
|
|
"output_type": "stream",
|
|||
|
|
"text": [
|
|||
|
|
"\n",
|
|||
|
|
"=== Performance Metrics ===\n",
|
|||
|
|
" Strategy\n",
|
|||
|
|
"Start 2019-01-04 01:00:00\n",
|
|||
|
|
"End 2024-12-31 23:00:00\n",
|
|||
|
|
"Duration 2188 days 22:00:00\n",
|
|||
|
|
"Exposure Time [%] 3.180413\n",
|
|||
|
|
"Return [%] 87.318208\n",
|
|||
|
|
"Buy & Hold Return [%] -7.771758\n",
|
|||
|
|
"Sharpe Ratio 1.689801\n",
|
|||
|
|
"Sortino Ratio 2.618628\n",
|
|||
|
|
"Calmar Ratio 1.578703\n",
|
|||
|
|
"Max. Drawdown [%] -7.273869\n",
|
|||
|
|
"Win Rate [%] 74.414414\n",
|
|||
|
|
"# Trades 555\n",
|
|||
|
|
"Avg. Trade [%] 0.133164\n",
|
|||
|
|
"Profit Factor 3.314653\n"
|
|||
|
|
]
|
|||
|
|
},
|
|||
|
|
{
|
|||
|
|
"data": {
|
|||
|
|
"image/png": "iVBORw0KGgoAAAANSUhEUgAABAgAAAGHCAYAAAA9R2CwAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjguMCwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy81sbWrAAAACXBIWXMAAA9hAAAPYQGoP6dpAABskElEQVR4nO3deXhU5fn/8c/MJJlsZLKRhAABFI1gWBSURSpQIYAsUq1a0UjQgopKLUtbrAvYqnVDK7aK1pIKVO3vWzfUYlBQsIRVKCA7gmwJS8i+TmbO74+QgSELGUgymfB+XVcu55zzzDn3CbdJzj3PYjIMwxAAAAAAALiomb0dAAAAAAAA8D4KBAAAAAAAgAIBAAAAAACgQAAAAAAAAESBAAAAAAAAiAIBAAAAAAAQBQIAAAAAACAKBAAAAAAAQBQIAAAAAACAKBAAANBipaWlyWQy1fr19ddfN+r1O3bsqNTUVNf2kSNHNGvWLG3atKlRrrd582ZNmDBBnTp1UmBgoEJDQ3X11Vfr+eef18mTJxvlmgAAtCR+3g4AAAA0rvnz5+uKK66otr9r166Net0PP/xQYWFhru0jR45o9uzZ6tixo3r27Nmg13rrrbc0efJkJSYmasaMGeratavsdrvWr1+vN954QxkZGfrwww8b9JoAALQ0FAgAAGjhkpKS1Lt37ya/7lVXXdUk18nIyNADDzygoUOH6qOPPpLVanUdGzp0qKZNm6YlS5Y0yLVKSkoUGBgok8nUIOcDAKA5YYgBAABQfn6+Jk6cqKioKIWGhmr48OHatWuXTCaTZs2a5WqXmpqqjh07Vnv/rFmzqj00nznE4Ouvv9Y111wjSZowYYJrmMOsWbO0YMECmUwmZWRkVDvvU089JX9/fx05cqTW2J955hmZTCa9+eabbsWBKgEBARozZoxr++x7qile6fQQjfT0dN1zzz1q3bq1goOD9f7778tkMumrr76qdo7XX39dJpNJmzdvdu1bv369xowZo8jISAUGBuqqq67Sv/71r1rvBwAAb6FAAABAC+dwOFRRUeH25XA4XMcNw9DYsWO1YMECTZs2TR9++KH69u2rESNGNFgMV199tebPny9Jeuyxx5SRkaGMjAz98pe/1O233664uDj95S9/cXtPRUWF5s2bp5/97GeKj4+v9d6WLVumXr16qX379g0W75nuuece+fv7a8GCBfq///s//exnP1NMTIzrfs6Ulpamq6++Wt27d5ckLV++XNddd51yc3P1xhtv6OOPP1bPnj11++23Ky0trVHiBQDgfDHEAACAFq5v377V9lksFlVUVEiSvvjiCy1fvlx//vOfNWXKFEmVXfMDAgL0+9//vkFiCAsLU1JSkiTp0ksvrRbTfffdp2effVZz5sxRTEyMJOmDDz7QkSNH9NBDD9V63hMnTqi4uFidOnVqkDhrcsMNN2jevHlu++666y69/vrrysvLk81mkyRt375da9eu1dy5c13tJk+erCuvvFLLli2Tn1/ln13Dhg3TiRMn9Oijj+ruu++W2cznNQCA5oHfSAAAtHDvvPOO1q1b5/a1Zs0a1/Hly5dLku688063940bN67JYnzggQckVU42WOW1115Tt27ddP311zdZHDW55ZZbqu275557VFJSovfff9+1b/78+bJara7v2549e7Rjxw7X9/XMHhw33nijMjMztXPnzqa5CQAA6oEeBAAAtHBdunSpc5LC7Oxs+fn5KSoqym1/XFxcY4fmEhsbq9tvv13z5s3T7373O33//fdauXJltU/uzxYdHa3g4GDt27ev0WJr06ZNtX1XXnmlrrnmGs2fP1+TJk2Sw+HQwoULddNNNykyMlKSdPToUUnS9OnTNX369BrPfeLEiUaLGwAAT1EgAADgIhcVFaWKigplZ2e7FQmysrKqtQ0MDFRZWVm1/Q3xoPurX/1KCxYs0Mcff6wlS5YoPDy8Wq+Gs1ksFt1www36z3/+o0OHDqldu3bnvI7Vaq3xHrKzs2tsX9uKBRMmTNDkyZO1fft2/fDDD8rMzNSECRNcx6OjoyVJM2fO1M0331zjORITE88ZLwAATYUhBgAAXOQGDx4sSVq0aJHb/n/+85/V2nbs2FHHjh1zfTouSeXl5friiy/OeZ2qFQZKSkpqPN6rVy/1799fzz33nBYtWqTU1FSFhISc87wzZ86UYRiaOHGiysvLqx232+1avHix2z2cucqAJC1btkyFhYXnvNaZ7rjjDgUGBiotLU1paWlq27atkpOTXccTExN12WWX6X//+5969+5d41erVq08uiYAAI2JHgQAALRwW7dudU1IeKZLL71UrVu3VnJysq6//nr95je/UVFRkXr37q3//ve/WrBgQbX33H777XriiSf0i1/8QjNmzFBpaaleffVVt1URanPppZcqKChIixYtUpcuXRQaGqr4+Hi3FQp+9atf6fbbb5fJZNLkyZPrdX/9+vXT66+/rsmTJ6tXr1564IEHdOWVV8put2vjxo168803lZSUpNGjR0uSUlJS9Pjjj+uJJ57QwIEDtW3bNr322muuyQbrKzw8XD/72c+Ulpam3NxcTZ8+vdqEg/PmzdOIESM0bNgwpaamqm3btjp58qS2b9+u7777Tv/v//0/j64JAEBjogcBAAAt3IQJE9SvX79qXx9//LEkyWw265NPPtGdd96p559/XmPHjtWqVav0+eefVztXp06d9PHHHys3N1c///nPNWPGDN166626++67zxlHcHCw/v73vys7O1vJycm65ppr9Oabb7q1GTt2rKxWq4YNG6bLLrus3vc4ceJErV+/Xr169dJzzz2n5ORkjR07Vu+++67GjRvndp0ZM2ZoxowZSktL0+jRo/Xvf/9b//rXvxQeHl7v61WZMGGCjh07pvLycqWmplY7PnjwYK1du1bh4eF65JFHNGTIED3wwAP68ssvNWTIEI+vBwBAYzIZhmF4OwgAANA8mUwmPfnkk5o1a1aTXG/x4sUaM2aMPvvsM914441Nck0AAFCJIQYAAMDrtm3bph9//FHTpk1Tz549NWLECG+HBADARYchBgAAwOsmT56sMWPGKCIiQu+++26tKwcAAIDGwxADAAAAAABADwIAAAAAAECBAAAAAAAAiAIBAAAAAAAQqxg0OafTqSNHjqhVq1ZMwAQAAAAAaHSGYaigoEDx8fEym2vvJ0CBoIkdOXJE7du393YYAAAAAICLzMGDB9WuXbtaj1MgaGKtWrWSVPkPExYW5uVoama325Wenq7k5GT5+/t7Oxz4AHIGniJn4ClyBp4iZ+Apcgae8qWcyc/PV/v27V3Po7WhQNDEqoYVhIWFNesCQXBwsMLCwpp9oqN5IGfgKXIGniJn4ClyBp4iZ+ApX8yZcw1zZ5JCAAAAAABAgQAAAAAAAFAgAAAAAAAAokAAAAAAAABEgQAAAAAAAIgCAQAAAAAAEAUCAAAAAAAgCgQAAAAAAEAUCAAAAAAAgCgQAAAAAADgsS2H87Qj16STReXeDqXB+Hk7AAAAAAAAfMn/Dubq5jfWSLKoZ688DQsP8XZIDYIeBAAAAAAAeOBofqnrdUiAxYuRNCwKBAAAAAAAnINhGKdfn/pvx1BDfTpFeiegRsAQAwAAAAAA6vBS+k7NXbZHMa2sCvAzq6TcIUkymbwcWAOjQAAAAAAAQB3mLtsjSTpWUOa2PybQqKm5z6JAAAAAAABAHS5pHaIfjhdpxrBEXdc5unKn06F9G7/1bmANjAIBAAAAAAB18DNXjiW4qn24erYPlyTZ7Xb9uMl7MTUGJikEAAAAAKAOzlMjCUwtbdKBs1AgAAAAAADgLKV2hw7nlkg6vYKBuWXXBxhiAAAAAABAlYJSu258daUOnqwsDnRtE6ZSu1OSZG7hFQIKBAAAAAAAnPJS+i5XcUCStmXmu1638PoABQIAAAAAAKo4nKeXLowNs8psMskwpA5Rwboy3ubFyBofBQIAAAAAAE7JL7VLkqbccJmmDr3cy9E0LQoEAAAAAICLVlFZhfJK7LL6mbUzq0AfbzoiSWrhowlqRIEAAAAAAHBRKq9wasi
|
|||
|
|
"text/plain": [
|
|||
|
|
"<Figure size 1200x400 with 1 Axes>"
|
|||
|
|
]
|
|||
|
|
},
|
|||
|
|
"metadata": {},
|
|||
|
|
"output_type": "display_data"
|
|||
|
|
},
|
|||
|
|
{
|
|||
|
|
"data": {
|
|||
|
|
"image/png": "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
|
|||
|
|
"text/plain": [
|
|||
|
|
"<Figure size 1200x400 with 1 Axes>"
|
|||
|
|
]
|
|||
|
|
},
|
|||
|
|
"metadata": {},
|
|||
|
|
"output_type": "display_data"
|
|||
|
|
},
|
|||
|
|
{
|
|||
|
|
"data": {
|
|||
|
|
"image/png": "iVBORw0KGgoAAAANSUhEUgAAA/IAAAGHCAYAAAATEmljAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjguMCwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy81sbWrAAAACXBIWXMAAA9hAAAPYQGoP6dpAAEAAElEQVR4nOydd5wURfr/PzOzGdgl54xEJUsWUUmyeup5nn5Pz4h3hu/9VPQMGE7BOwP6VdQT7oyYUFAMKAuScw4LSIbdZdkEbM6zE/r3x0z3VPd0qJ6dtLvP+/WCnemprq7urq6up55kEQRBAEEQBEEQBEEQBEEQDQJrpBtAEARBEARBEARBEAQ/JMgTBEEQBEEQBEEQRAOCBHmCIAiCIAiCIAiCaECQIE8QBEEQBEEQBEEQDQgS5AmCIAiCIAiCIAiiAUGCPEEQBEEQBEEQBEE0IEiQJwiCIAiCIAiCIIgGBAnyBEEQBEEQBEEQBNGAIEGeIAiCIAiCIAiCIBoQJMgTBEFEmEWLFsFisUj/YmJi0KlTJ/zP//wPTp06Va86s7KypG333HMPevbsKSvXs2dP3HPPPYE3PgAOHjwIi8WCZ555RrPMqVOnYLFY8Mgjj3DXq3Z+vCxevBjz589X/c1iseCll16Svm/cuBEWiwUbN26Utr300kuwWCyy/RYsWIBFixYF1B4jzpw5g/j4eOzYsUP195tvvhkWiwV/+9vfQnL8cKF2Xa+66ipcddVVYW+Lsh98/PHH6NKlC6qqqsLelvr0dS3UrnW08vzzz+P6669Hly5dYLFYNMewjz76CDfddBN69uyJxMREXHLJJXjooYeQn5+vWr6wsBCPPvooevbsifj4eHTo0AEzZsxAcXFxCM+GIAgiMEiQJwiCiBI+/fRT7NixA2vXrsXf/vY3LF++HFdccQVKSkpCdswffvgBL7zwQsjqV2Po0KEYOXIkPv/8c7hcLtUyn376KQBg5syZYWmTniC/Y8cO3H///br733///X5CdSgF+b///e+YOnUqxo0b5/fbhQsX8MsvvwAAvvrqK9TW1oakDZFiwYIFWLBgQaSbgbvvvhvNmjXDvHnzwn7sF154AT/88EPYjxstvP322ygqKsINN9yAuLg4zXIvvvgimjdvjldeeQWrVq3CU089hV9++QUjR47E+fPnZWXz8vIwZswYrFq1Ci+88ALWrFmDhQsX4pJLLkFdXV2oT4kgCMI0MZFuAEEQBOHhsssuw+WXXw7Ao3V0uVx48cUX8eOPP+Lee+8NyTGHDx8eknqNmDlzJh5++GGsXLkS119/vew3l8uFzz//HCNHjsTQoUMj0j6WsWPHGpbp2rUrunbtGobWAMeOHcOPP/6IVatWqf7++eefw+Fw4LrrrsOKFSvw/fff4/bbbw9L28LBoEGDIt0EAEBMTAweeOABvPzyy3j66aeRlJQUtmP36dMnbMeKRioqKmC1enRRX3zxhWa5AwcOoH379tL3SZMmYcSIERg1ahQ+/PBDPP/889JvDz/8MOx2O/bu3YtWrVpJ22+++eYQnAFBEET9IY08QRBElCIK9UrN0fLlyzFu3DgkJSWhRYsWmDp1qqaJtRFK03rRbPzrr7/Gc889h86dOyM5ORlTpkzBiRMnZPsKgoBXXnkFPXr0QEJCAi6//HKsWbOGy/T59ttvR2JioqR5Z1m9ejVyc3Nx3333AQDcbjfmzZuHAQMGID4+Hu3bt8ddd92FnJwcw/N7//33ceWVV6J9+/Zo1qwZBg8ejHnz5sHhcEhlrrrqKqxYsQJnz56VuTiIKE2q1VCaJffs2RNHjhzBpk2bpPp69uyJyspKtGzZEg888IBfHVlZWbDZbHjjjTd0j7Vw4UJ07NgRU6dOVf39k08+QYcOHfDZZ58hMTERn3zyiV8Z0fViw4YNeOihh9C2bVu0adMGN998M/Ly8mRle/bsieuvvx6rVq3CiBEjkJiYiAEDBvjVq2WarebmsWTJEkybNg2dOnVCYmIiBg4ciGeeeYbLTF3Zv+655x7ZfWP/sfetvLwcf//739GrVy/ExcWhS5cueOyxx/yOWV5ejr/85S9o06YNmjdvjmuvvRYnT55Ubcsdd9yB8vJyfPPNN4btVlJeXo6YmBjZ/S4sLITVakVKSgqcTqe0/ZFHHkG7du0gCIJ0zkrTetGV4osvvsDAgQORlJSEoUOHStYZLCtWrMCwYcMQHx+PXr164c0331RtY21tLWbPni27Zv/7v/+L0tJSqcyTTz6JlJQUmXXN//t//w8Wi0V2bkVFRbBarXjvvfdMXSc1RCHeCFaIFxk5ciRsNhvOnTsnbcvKysLy5cvxl7/8RSbEEwRBRDMkyBMEQUQpmZmZAIB+/fpJ2xYvXowbb7wRycnJ+Prrr/Hxxx+jpKQEV111FbZu3Rq0Yz/77LM4e/YsPvroI3zwwQc4deoUfve738km68899xyee+45XHvttfjpp5/w4IMP4v7779cUelhSUlLwhz/8AT///DMuXrwo++3TTz9FQkKCpEV+6KGH8PTTT2Pq1KlYvnw5Xn75ZaxatQrjx49HYWGh7nHOnDmD22+/HV988QV++eUXzJw5E2+88YZMkF6wYAEmTJiAjh07YseOHdK/+vDDDz+gd+/eGD58uFTfDz/8gObNm+O+++7DV199hbKyMtk+CxYsQFxcnLSAocWKFStw5ZVXqgoz27dvx7Fjx3DXXXehTZs2+MMf/oD169dLfUnJ/fffj9jYWCxevBjz5s3Dxo0b8ec//9mv3MGDB/HEE09g1qxZ+OmnnzBkyBDMnDkTmzdvNnFVfJw6dQqpqan4+OOPsWrVKjz22GNYunQpfve735mu64UXXpDdtx07dkjnIGrvq6urMWnSJHz22Wd45JFHsHLlSjz99NNYtGgRbrjhBklAFgQBN910E7744gs88cQT+OGHHzB27FjMmDFD9dgdO3bEgAEDsGLFCtPtTk5OxqhRo7B27Vpp27p16xAfH4+Kigrs3r1b2r527Vpcc801hj7sK1aswL///W/MnTsXy5YtQ+vWrfH73/8eGRkZsmPceOONaNGiBb755hu88cYbWLp0qd+imngt3nzzTdx5551YsWIFHn/8cXz22We45pprYLfbAQBTpkxBeXm5X3sTExOxZs0a2XEFQcCUKVOkbU6nk+ufeH+CwaZNm+ByuXDppZdK27Zs2QJBENC5c2f86U9/QvPmzZGQkICrrrqq3mMBQRBEyBAIgiCIiPLpp58KAISdO3cKDodDqKioEFatWiV07NhRuPLKKwWHwyEIgiC4XC6hc+fOwuDBgwWXyyXtX1FRIbRv314YP368X52ZmZnStrvvvlvo0aOH7Ng9evQQ7r77bun7hg0bBABCamqqrNzSpUsFAMKOHTsEQRCE4uJiIT4+Xrjttttk5Xbs2CEAECZNmmR43uKx3nrrLWlbUVGREB8fL9xxxx2CIAjCsWPHBADCww8/LNt3165dAgDh2Wef1T0/FpfLJTgcDuHzzz8XbDabUFxcLP123XXXae4LQHjxxRf92r1hwwZp24svvigoX6mXXnqp6nU4c+aMYLVahbffflvaVlNTI7Rp00a49957NdsvCIJw/vx5AYDw2muvqf5+3333CQCEY8eOydr6wgsvyMqJ/UN5XefNmycAEPLz86VtPXr0EBISEoSzZ8/K2tu6dWvhgQce0L0G7LHYvsjidrsFh8MhbNq0SQAgHDx4ULfOSZMm6favpUuXChaLRdY3Xn31VcFqtQp79uyRlf3uu+8EAEJaWpogCIKwcuVKAYDwzjvvyMr961//8usHInfccYfQoUMHzfbo8fzzzwuJiYlCbW2tIAiCcP/99wvXXnutMGTIEGHOnDmCIAhCbm6uAED44IMPpP3U+joAoUOHDkJ5ebm0raCgQLBarcKrr74qbRszZozQuXNnoaamRtpWXl4utG7dWnatV61aJQAQ5s2bJzvOkiVLZO2pqqoS4uLihLlz5wqCIAg5OTkCAOHpp5+Wndtf/vIXoXPnzn5t5vn36aefal7DZs2aycYwPcrLy4WBAwcK3bp1Eyo
|
|||
|
|
"text/plain": [
|
|||
|
|
"<Figure size 1200x400 with 1 Axes>"
|
|||
|
|
]
|
|||
|
|
},
|
|||
|
|
"metadata": {},
|
|||
|
|
"output_type": "display_data"
|
|||
|
|
},
|
|||
|
|
{
|
|||
|
|
"data": {
|
|||
|
|
"image/png": "iVBORw0KGgoAAAANSUhEUgAAA/IAAAIhCAYAAADtv4ENAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjguMCwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy81sbWrAAAACXBIWXMAAA9hAAAPYQGoP6dpAAEAAElEQVR4nOydd5wU5f3H3zPbrlfK3dGrgohgBwRFKSq2qNHYuyZqNNHEkhh7wxZbLEkU9GeBRMVeUKoFEUSQKnC0g7uDO47rZXdnnt8fszu7e1tuDykSvu/X617czjzzzDOzs7d8ns/3+300pZRCEARBEARBEARBEIR9An1vD0AQBEEQBEEQBEEQhOQRIS8IgiAIgiAIgiAI+xAi5AVBEARBEARBEARhH0KEvCAIgiAIgiAIgiDsQ4iQFwRBEARBEARBEIR9CBHygiAIgiAIgiAIgrAPIUJeEARBEARBEARBEPYhRMgLgiAIgiAIgiAIwj6ECHlBEARBEARBEARB2IcQIS8IgrCPMXnyZDRNs3+cTiddu3blsssuY8uWLUn1cemll9KzZ8/dO9BdRKyxPvjgg7z77rtRbYP3ZuHChTt1rrvvvhtN06isrNyp42Mxe/ZsNE1j9uzZ9rbdff8//vhj7r777t3W/67ms88+Y9y4cRQVFeHxeCgqKuK4447j4YcfjmjXs2dPLr300r0zyBj80sazs2zYsAFN05g8eXLcNj179oz4uxPvJ1EfP4fgZ1MQBEGwcO7tAQiCIAg7x6RJkzjwwANpampi7ty5PPTQQ8yZM4elS5eSnp6e8Ni//e1v3HjjjXtopD+PWGN98MEHOfvssznjjDP2zqB+Jrv7/n/88cf84x//2CfE/AsvvMDvfvc7zjrrLJ599lny8vIoKSnhm2++4a233uK2226z206bNo2srKy9ONr9l2nTptHS0mK//ve//81LL73Ep59+SnZ2tr29T58+e2N4giAI+x0i5AVBEPZRBg0axOGHHw7A6NGjMQyD++67j3fffZcLLrgg5jGNjY2kpaXtU//Z3pfGmiz76jU1NTWRmpq6S/t86KGHGDVqFG+99VbE9osuugjTNCO2DR06dJeeW0ie1vf+008/BeCwww6jQ4cOcY8L/s0RBEEQdi0SWi8IgvA/wtFHHw3Axo0bASt8OyMjg6VLlzJu3DgyMzM54YQT7H2tQ7tN0+SZZ55hyJAhpKamkpOTw9FHH837778f0W7q1KkMGzaM9PR0MjIyGD9+PD/88EPCsdXW1uJ0Onn00UftbZWVlei6TnZ2Nn6/395+ww030LFjR5RSMceqaRoNDQ288sordjjvcccdF3G+uro6fve739GhQwfy8/M588wzKS0tbfsmxuC4445j0KBBLFiwgJEjR5KWlkbv3r15+OGHo4TmqlWrOPHEE0lLS6NDhw789re/pa6uLqrPnb3/U6dOZdy4cRQWFpKamsqAAQO47bbbaGhoiOj7H//4h32vgj8bNmwAoLm5mdtvv51evXrhdrvp0qUL1113HdXV1RHj6dmzJ6eccgrvvPMOQ4cOJSUlhXvuuQeA//73vxx11FFkZ2fb9+Pyyy/fqfu7fft2CgsLY+7T9cj/psQKZV++fDnjxo0jLS2Njh07ct111/HRRx9FpTMk+z42Nzdz8803M2TIELKzs8nLy2PYsGG89957bV6LaZrcf//9HHDAAfZ7OHjwYJ566qnkb0gYybzfEPqsr127lpNPPpmMjAy6devGzTffHOGiA5SWlnLOOeeQmZlJdnY25557LuXl5Ts1vtYk+pvz+eefc/rpp9O1a1dSUlLo27cv11xzTcw0lo8++oghQ4bg8Xjo1asXjz32WMzzKaV47rnn7M9Mbm4uZ599NuvWrYto98MPP3DKKafQqVMnO3VjwoQJbN68eZdctyAIwt5AHHlBEIT/EdauXQtAx44d7W1er5fTTjuNa665httuuy1CMLfm0ksv5bXXXuOKK67g3nvvxe12s2jRIlsAghXSfscdd3DZZZdxxx134PV6efTRRxk5ciTfffcdAwcOjNl3VlYWRxxxBF988QV//vOfAZgxYwYej4e6ujq+++47hg8fDsAXX3zB8ccfHzcfdt68eRx//PGMHj2av/3tb3b/4Vx55ZVMmDCBN954g5KSEv785z9z4YUXMnPmzDbuYmzKy8u54IILuPnmm7nrrruYNm0at99+O0VFRVx88cUAbN26lWOPPRaXy8Vzzz1H586def3117n++uuTOkcy93/NmjWcfPLJ/OEPfyA9PZ1Vq1YxceJEvvvuO/va/va3v9HQ0MBbb73FvHnz7GMLCwtRSnHGGWcwY8YMbr/9dkaOHMmPP/7IXXfdxbx585g3bx4ej8c+ZtGiRaxcuZI77riDXr16kZ6ezrx58zj33HM599xzufvuu0lJSWHjxo07fW+HDRvG22+/zd13382vfvUrBg0ahMPhSOrYsrIyjj32WNLT03n++efp1KkTb775Ztx7nsz72NLSQlVVFX/605/o0qULXq+XL774gjPPPJNJkybZ7WLxyCOPcPfdd3PHHXcwatQofD4fq1atipokSZZk3u8gPp+P0047jSuuuIKbb76ZuXPnct9995Gdnc2dd94JWBEVY8aMobS0lIceeoj+/fvz0Ucfce655+7U+GIR729OcXExw4YN48orryQ7O5sNGzbwxBNPcMwxx7B06VJcLhdg/V04/fTTGTZsGFOmTMEwDB555BG2bt0ada5rrrmGyZMnc8MNNzBx4kSqqqq49957GT58OEuWLKFz5840NDQwduxYevXqxT/+8Q86d+5MeXk5s2bNijnJJgiCsM+gBEEQhH2KSZMmKUB9++23yufzqbq6OvXhhx+qjh07qszMTFVeXq6UUuqSSy5RgHr55Zej+rjkkktUjx497Ndz585VgPrrX/8a97ybNm1STqdT/f73v4/YXldXpwoKCtQ555yTcNx33HGHSk1NVc3NzUoppa688kp14oknqsGDB6t77rlHKaXUli1bFKD++c9/xh2rUkqlp6erSy65JO69ufbaayO2P/LIIwpQZWVlCcd41113KUBVVFTY24499lgFqPnz50e0HThwoBo/frz9+tZbb1WapqnFixdHtBs7dqwC1KxZs+JeUzL3vzWmaSqfz6fmzJmjALVkyRJ733XXXadifcV/+umnClCPPPJIxPapU6dG3fcePXooh8Ohfvrpp4i2jz32mAJUdXV10mNNxNq1a9WgQYMUoACVmpqqTjjhBPXss88qr9cb0bZHjx4R7/uf//xnpWmaWr58eUS78ePHR93zZN/H1vj9fuXz+dQVV1yhhg4dmnA8p5xyihoyZEiSV94+Er3fwc/6f/7zn4hjTj75ZHXAAQfYr59//nkFqPfeey+i3VVXXaUANWnSpKTHE+uzkuhvTqxr2bhxY9R4jjrqKFVUVKSamprsbbW1tSovLy/imZ43b54C1OOPPx7Rd0lJiUpNTVW33HKLUkqphQsXKkC9++67SV+bIAjCvoCE1guCIOyjHH300bhcLjIzMznllFMoKCjgk08+oXPnzhHtzjrrrDb7+uSTTwC47rrr4rb57LPP8Pv9XHzxxfj9fvsnJSWFY489NiKMORYnnHACTU1NfPPNN4DlvI8dO5YxY8bw+eef29sAxowZ0+aYE3HaaadFvB48eDAQSjtoLwUFBRx55JFRfYb3N2vWLA466CAOOeSQiHbnn39+m/0nc/8B1q1bx/nnn09BQQEOhwOXy8Wxxx4LwMqVK9s8T9DFbR2e/utf/5r09HRmzJgRsX3w4MH0798/YtsRRxwBwDnnnMN//vOfpFdKiEefPn1YsmQJc+bM4Z577mHMmDEsWLCA66+/nmHDhtHc3Bz32Dlz5jBo0KCoSJDzzjsvZvtk3kewUgdGjBhBRkYGTqcTl8vFSy+91OY9PvLII1myZAnXXnstn332GbW1tQnbt0V73m9N0zj11FMTXtusWbPIzMyM+nwk84y2h1h/c7Zt28Zvf/tbunXrZt/THj16AKFraWhoYMGCBZx55pmkpKTYx2ZmZkZd24c
|
|||
|
|
"text/plain": [
|
|||
|
|
"<Figure size 1200x600 with 1 Axes>"
|
|||
|
|
]
|
|||
|
|
},
|
|||
|
|
"metadata": {},
|
|||
|
|
"output_type": "display_data"
|
|||
|
|
}
|
|||
|
|
],
|
|||
|
|
"source": [
|
|||
|
|
"# ================= Diagnostics & Plots for backtesting.py =================\n",
|
|||
|
|
"import pandas as pd\n",
|
|||
|
|
"import numpy as np\n",
|
|||
|
|
"import matplotlib.pyplot as plt\n",
|
|||
|
|
"\n",
|
|||
|
|
"plt.rcParams[\"figure.figsize\"] = (12, 4)\n",
|
|||
|
|
"plt.rcParams[\"axes.grid\"] = True\n",
|
|||
|
|
"\n",
|
|||
|
|
"# ---- 1) Pull useful internals ----\n",
|
|||
|
|
"trades = stats.get(\"_trades\", None)\n",
|
|||
|
|
"equity_curve = stats.get(\"_equity_curve\", None) # index: DateTime; columns: ['Equity', 'Drawdown', ...] (depends on version)\n",
|
|||
|
|
"\n",
|
|||
|
|
"# Graceful fallback if equity_curve missing: rebuild a minimal curve from stats (flat line won’t be useful for drawdown)\n",
|
|||
|
|
"if equity_curve is None:\n",
|
|||
|
|
" # Try to reconstruct cumulative equity using provided metrics (approx)\n",
|
|||
|
|
" # Not perfect, but avoids hard failure if your backtesting.py version doesn’t expose _equity_curve.\n",
|
|||
|
|
" start_equity = bt._cash if hasattr(bt, \"_cash\") else 100_000\n",
|
|||
|
|
" # If total Return [%] available:\n",
|
|||
|
|
" total_ret_pct = stats.get(\"Return [%]\", 0.0)\n",
|
|||
|
|
" equity_curve = pd.DataFrame(\n",
|
|||
|
|
" {\"Equity\": np.linspace(start_equity, start_equity * (1 + total_ret_pct / 100.0), len(df_bt))},\n",
|
|||
|
|
" index=df_bt.index\n",
|
|||
|
|
" )\n",
|
|||
|
|
" equity_curve[\"Peak\"] = equity_curve[\"Equity\"].cummax()\n",
|
|||
|
|
" equity_curve[\"Drawdown\"] = equity_curve[\"Equity\"] / equity_curve[\"Peak\"] - 1.0\n",
|
|||
|
|
"\n",
|
|||
|
|
"# Standardize columns if needed\n",
|
|||
|
|
"if \"Equity\" not in equity_curve.columns:\n",
|
|||
|
|
" # Some versions name it 'Equity Final [$]' only at the end; then just map Close to a pseudo curve.\n",
|
|||
|
|
" equity_curve = equity_curve.rename(columns={equity_curve.columns[0]: \"Equity\"})\n",
|
|||
|
|
"if \"Drawdown\" not in equity_curve.columns:\n",
|
|||
|
|
" equity_curve[\"Peak\"] = equity_curve[\"Equity\"].cummax()\n",
|
|||
|
|
" equity_curve[\"Drawdown\"] = equity_curve[\"Equity\"] / equity_curve[\"Peak\"] - 1.0\n",
|
|||
|
|
"\n",
|
|||
|
|
"# ---- 2) Performance metrics (concise) ----\n",
|
|||
|
|
"perf_cols = [\n",
|
|||
|
|
" \"Start\", \"End\", \"Duration\", \"Exposure Time [%]\",\n",
|
|||
|
|
" \"Return [%]\", \"Buy & Hold Return [%]\",\n",
|
|||
|
|
" \"Sharpe Ratio\", \"Sortino Ratio\",\n",
|
|||
|
|
" \"Calmar Ratio\", \"Max. Drawdown [%]\",\n",
|
|||
|
|
" \"Win Rate [%]\", \"# Trades\", \"Avg. Trade [%]\", \"Profit Factor\"\n",
|
|||
|
|
"]\n",
|
|||
|
|
"perf = {}\n",
|
|||
|
|
"for k in perf_cols:\n",
|
|||
|
|
" val = stats.get(k, None)\n",
|
|||
|
|
" if val is not None:\n",
|
|||
|
|
" perf[k] = val\n",
|
|||
|
|
"perf_df = pd.DataFrame(perf, index=[\"Strategy\"]).T\n",
|
|||
|
|
"print(\"\\n=== Performance Metrics ===\")\n",
|
|||
|
|
"print(perf_df)\n",
|
|||
|
|
"\n",
|
|||
|
|
"# ---- 3) Equity curve ----\n",
|
|||
|
|
"fig1, ax1 = plt.subplots()\n",
|
|||
|
|
"ax1.plot(equity_curve.index, equity_curve[\"Equity\"])\n",
|
|||
|
|
"ax1.set_title(\"Equity Curve\")\n",
|
|||
|
|
"ax1.set_xlabel(\"Time\")\n",
|
|||
|
|
"ax1.set_ylabel(\"Equity ($)\")\n",
|
|||
|
|
"plt.show()\n",
|
|||
|
|
"\n",
|
|||
|
|
"# ---- 4) Drawdown series ----\n",
|
|||
|
|
"fig2, ax2 = plt.subplots()\n",
|
|||
|
|
"ax2.plot(equity_curve.index, equity_curve[\"Drawdown\"] * 100.0)\n",
|
|||
|
|
"ax2.set_title(\"Drawdown (%)\")\n",
|
|||
|
|
"ax2.set_xlabel(\"Time\")\n",
|
|||
|
|
"ax2.set_ylabel(\"Drawdown (%)\")\n",
|
|||
|
|
"plt.show()\n",
|
|||
|
|
"\n",
|
|||
|
|
"# ---- 5) Rolling volatility (annualized) ----\n",
|
|||
|
|
"# Use log returns of Close; adapt 'per_year' to your bar frequency (e.g., 252 daily, 365 for daily crypto, 78*252 for 5-min, etc.)\n",
|
|||
|
|
"per_year = 252\n",
|
|||
|
|
"ret = np.log(df_bt[\"Close\"]).diff()\n",
|
|||
|
|
"roll_win = per_year // 2 if per_year > 20 else 50 # default: half a year window\n",
|
|||
|
|
"rolling_vol = ret.rolling(roll_win).std() * np.sqrt(per_year)\n",
|
|||
|
|
"\n",
|
|||
|
|
"fig3, ax3 = plt.subplots()\n",
|
|||
|
|
"ax3.plot(rolling_vol.index, rolling_vol)\n",
|
|||
|
|
"ax3.set_title(f\"Rolling Volatility (Annualized), window={roll_win}\")\n",
|
|||
|
|
"ax3.set_xlabel(\"Time\")\n",
|
|||
|
|
"ax3.set_ylabel(\"Volatility\")\n",
|
|||
|
|
"plt.show()\n",
|
|||
|
|
"\n",
|
|||
|
|
"# ---- 6) Price + indicators + signals + trades ----\n",
|
|||
|
|
"# Example indicators (customize as you like)\n",
|
|||
|
|
"def ema(s, n): return s.ewm(span=n, adjust=False).mean()\n",
|
|||
|
|
"def sma(s, n): return s.rolling(n).mean()\n",
|
|||
|
|
"\n",
|
|||
|
|
"ema_fast = ema(df_bt[\"Close\"], 50)\n",
|
|||
|
|
"ema_slow = ema(df_bt[\"Close\"], 200)\n",
|
|||
|
|
"sig = df_bt[\"predicted_signal\"].astype(int)\n",
|
|||
|
|
"\n",
|
|||
|
|
"fig4, ax4 = plt.subplots(figsize=(12, 6))\n",
|
|||
|
|
"ax4.plot(df_bt.index, df_bt[\"Close\"], label=\"Close\")\n",
|
|||
|
|
"ax4.plot(df_bt.index, ema_fast, label=\"EMA 50\")\n",
|
|||
|
|
"ax4.plot(df_bt.index, ema_slow, label=\"EMA 200\")\n",
|
|||
|
|
"\n",
|
|||
|
|
"# Show long/short background regions from signal\n",
|
|||
|
|
"# (Optional) Shade regions: +1 green, -1 red, 0 clear\n",
|
|||
|
|
"state = sig.shift(1).fillna(0) # position taken on close of prior bar\n",
|
|||
|
|
"up = state == 1\n",
|
|||
|
|
"dn = state == -1\n",
|
|||
|
|
"ax4.fill_between(df_bt.index, df_bt[\"Close\"].min(), df_bt[\"Close\"].max(), where=up, alpha=0.06)\n",
|
|||
|
|
"ax4.fill_between(df_bt.index, df_bt[\"Close\"].min(), df_bt[\"Close\"].max(), where=dn, alpha=0.06)\n",
|
|||
|
|
"\n",
|
|||
|
|
"# Trade markers (if trades table available)\n",
|
|||
|
|
"if isinstance(trades, pd.DataFrame) and not trades.empty:\n",
|
|||
|
|
" # Expect columns: EntryTime, ExitTime, EntryPrice, ExitPrice, Size, Direction/Side or similar\n",
|
|||
|
|
" # backtesting.py _trades usually has:\n",
|
|||
|
|
" # ['EntryTime', 'ExitTime', 'EntryPrice', 'ExitPrice', 'PnL', 'ReturnPct', 'Duration', 'Direction', ...]\n",
|
|||
|
|
" # We'll handle common variants.\n",
|
|||
|
|
" et_col = next((c for c in [\"EntryTime\", \"Entry Bar\", \"Entry\"] if c in trades.columns), None)\n",
|
|||
|
|
" ep_col = next((c for c in [\"EntryPrice\", \"Entry Price\"] if c in trades.columns), None)\n",
|
|||
|
|
" dir_col = next((c for c in [\"Direction\", \"Side\", \"Signal\"] if c in trades.columns), None)\n",
|
|||
|
|
"\n",
|
|||
|
|
" # Marker placement\n",
|
|||
|
|
" if et_col is not None and ep_col is not None:\n",
|
|||
|
|
" for _, tr in trades.iterrows():\n",
|
|||
|
|
" t = tr[et_col]\n",
|
|||
|
|
" p = tr[ep_col]\n",
|
|||
|
|
" # Align type\n",
|
|||
|
|
" if isinstance(t, (int, np.integer)):\n",
|
|||
|
|
" # If it's a bar index, map to timestamp\n",
|
|||
|
|
" if t >= 0 and t < len(df_bt.index):\n",
|
|||
|
|
" t = df_bt.index[int(t)]\n",
|
|||
|
|
" else:\n",
|
|||
|
|
" continue\n",
|
|||
|
|
" # Direction sign\n",
|
|||
|
|
" d = np.sign(tr.get(dir_col, 1)) if dir_col in trades.columns else 1\n",
|
|||
|
|
" # Use different marker for long/short\n",
|
|||
|
|
" if d >= 0:\n",
|
|||
|
|
" ax4.plot(t, p, marker=\"^\", markersize=7)\n",
|
|||
|
|
" else:\n",
|
|||
|
|
" ax4.plot(t, p, marker=\"v\", markersize=7)\n",
|
|||
|
|
"\n",
|
|||
|
|
"ax4.set_title(\"Price with Indicators, Signals, and Trades\")\n",
|
|||
|
|
"ax4.set_xlabel(\"Time\")\n",
|
|||
|
|
"ax4.set_ylabel(\"Price\")\n",
|
|||
|
|
"ax4.legend(loc=\"best\")\n",
|
|||
|
|
"plt.show()\n",
|
|||
|
|
"\n"
|
|||
|
|
]
|
|||
|
|
},
|
|||
|
|
{
|
|||
|
|
"cell_type": "code",
|
|||
|
|
"execution_count": null,
|
|||
|
|
"metadata": {},
|
|||
|
|
"outputs": [],
|
|||
|
|
"source": []
|
|||
|
|
}
|
|||
|
|
],
|
|||
|
|
"metadata": {
|
|||
|
|
"colab": {
|
|||
|
|
"provenance": []
|
|||
|
|
},
|
|||
|
|
"kernelspec": {
|
|||
|
|
"display_name": "Python 3 (ipykernel)",
|
|||
|
|
"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.11.5"
|
|||
|
|
}
|
|||
|
|
},
|
|||
|
|
"nbformat": 4,
|
|||
|
|
"nbformat_minor": 1
|
|||
|
|
}
|