MAINT update test_utils, test_strategy and notebooks

This commit is contained in:
Kevin Johnson
2020-09-09 23:10:21 -07:00
parent 9d14ed8cac
commit 0104249d79
7 changed files with 309 additions and 298 deletions
+8 -4
View File
@@ -1,5 +1,6 @@
.PHONY: all
all:
make test_utils
make test_ta
make test_ext
make test_strats
@@ -13,11 +14,14 @@ clean:
init:
pip install -r requirements.txt
test_ta:
python -m unittest -v tests/test_indicator_*.py
test_ext:
python -m unittest -v tests/test_ext_indicator_*.py
test_strats:
python -m unittest -v tests/test_strategy.py
python -m unittest -v tests/test_strategy.py
test_ta:
python -m unittest -v tests/test_indicator_*.py
test_utils:
python -m unittest -v tests/test_utils.py
+10 -10
View File
@@ -45,7 +45,7 @@
"Numpy v1.18.3\n",
"Pandas v1.1.0\n",
"mplfinance v0.12.6a3\n",
"Pandas TA v0.1.99b\n"
"Pandas TA v0.2.04b\n"
]
}
],
@@ -112,13 +112,13 @@
"text": [
"[!] Loading All: SPY, QQQ, AAPL, TSLA\n",
"[i] Loaded['D']: SPY_D.csv\n",
"[i] Runtime: 13.2056 ms (0.0132 s)\n",
"[i] Runtime: 1832.0667 ms (1.8321 s)\n",
"[i] Loaded['D']: QQQ_D.csv\n",
"[i] Runtime: 29.3252 ms (0.0293 s)\n",
"[i] Runtime: 1728.6331 ms (1.7286 s)\n",
"[i] Loaded['D']: AAPL_D.csv\n",
"[i] Runtime: 53.6132 ms (0.0536 s)\n",
"[i] Runtime: 948.8466 ms (0.9488 s)\n",
"[i] Loaded['D']: TSLA_D.csv\n",
"[i] Runtime: 17.6341 ms (0.0176 s)\n"
"[i] Runtime: 1005.4914 ms (1.0055 s)\n"
]
}
],
@@ -147,7 +147,7 @@
"output_type": "stream",
"text": [
"AAPL (5241, 10)\n",
"Columns: open, high, low, close, volume, SMA_10, SMA_20, SMA_50, SMA_200, VOL_SMA_20\n"
"Columns: open, high, low, close, volume, SMA_10, SMA_20, SMA_50, SMA_200, VOL_VOL_SMA_20\n"
]
}
],
@@ -174,7 +174,7 @@
"output_type": "stream",
"text": [
"AAPL (252, 10)\n",
"Columns: open, high, low, close, volume, SMA_10, SMA_20, SMA_50, SMA_200, VOL_SMA_20\n"
"Columns: open, high, low, close, volume, SMA_10, SMA_20, SMA_50, SMA_200, VOL_VOL_SMA_20\n"
]
}
],
@@ -353,7 +353,7 @@
{
"data": {
"text/plain": [
"<matplotlib.axes._subplots.AxesSubplot at 0x1111cb940>"
"<matplotlib.axes._subplots.AxesSubplot at 0x10922b4c0>"
]
},
"execution_count": 9,
@@ -396,7 +396,7 @@
{
"data": {
"text/plain": [
"<matplotlib.axes._subplots.AxesSubplot at 0x10529e100>"
"<matplotlib.axes._subplots.AxesSubplot at 0x115368a00>"
]
},
"execution_count": 10,
@@ -441,7 +441,7 @@
{
"data": {
"text/plain": [
"<matplotlib.axes._subplots.AxesSubplot at 0x1112a2070>"
"<matplotlib.axes._subplots.AxesSubplot at 0x115a36070>"
]
},
"execution_count": 11,
+158 -143
View File
@@ -85,7 +85,7 @@
"text": [
"name = All\n",
"description = All the indicators with their default settings. Pandas TA default.\n",
"created = 09/05/2020, 10:14:58\n",
"created = 09/09/2020, 22:54:24\n",
"ta = None\n"
]
}
@@ -116,7 +116,7 @@
"text": [
"name = Common Price and Volume SMAs\n",
"description = Common Price SMAs: 10, 20, 50, 200 and Volume SMA: 20.\n",
"created = 09/05/2020, 10:14:58\n",
"created = 09/09/2020, 22:54:24\n",
"ta = [{'kind': 'sma', 'length': 10}, {'kind': 'sma', 'length': 20}, {'kind': 'sma', 'length': 50}, {'kind': 'sma', 'length': 200}, {'kind': 'sma', 'close': 'volume', 'length': 20, 'prefix': 'VOL'}]\n"
]
}
@@ -158,7 +158,7 @@
{
"data": {
"text/plain": [
"Strategy(name='A', ta=[{'kind': 'sma', 'length': 50}, {'kind': 'sma', 'length': 200}], description=None, created='09/05/2020, 10:14:58', last_run=None, run_time=None)"
"Strategy(name='A', ta=[{'kind': 'sma', 'length': 50}, {'kind': 'sma', 'length': 200}], description=None, created='09/09/2020, 22:54:24', last_run=None, run_time=None)"
]
},
"execution_count": 4,
@@ -186,7 +186,7 @@
{
"data": {
"text/plain": [
"Strategy(name='B', ta=[{'kind': 'ema', 'length': 8}, {'kind': 'ema', 'length': 21}, {'kind': 'log_return', 'cumulative': True}, {'kind': 'rsi'}, {'kind': 'supertrend'}], description=None, created='09/05/2020, 10:14:58', last_run=None, run_time=None)"
"Strategy(name='B', ta=[{'kind': 'ema', 'length': 8}, {'kind': 'ema', 'length': 21}, {'kind': 'log_return', 'cumulative': True}, {'kind': 'rsi'}, {'kind': 'supertrend'}], description=None, created='09/09/2020, 22:54:24', last_run=None, run_time=None)"
]
},
"execution_count": 5,
@@ -214,7 +214,7 @@
{
"data": {
"text/plain": [
"Strategy(name='Runtime Failure', ta=[{'kind': 'percet_return'}], description=None, created='09/05/2020, 10:14:58', last_run=None, run_time=None)"
"Strategy(name='Runtime Failure', ta=[{'kind': 'percet_return'}], description=None, created='09/09/2020, 22:54:24', last_run=None, run_time=None)"
]
},
"execution_count": 6,
@@ -437,11 +437,13 @@
"[i] Loaded['D']: SPY_D.csv\n",
"[+] Strategy: Common Price and Volume SMAs\n",
"[i] Indicator arguments: {'timed': False, 'append': True}\n",
"[i] Multiprocessing: 4 of 4 cores.\n",
"[i] Total indicators: 5\n",
"[i] Columns added: 5\n",
"[+] Downloading['D']: IWM\n",
"[i] Loaded['D']: IWM_D.csv\n",
"[+] Strategy: Common Price and Volume SMAs\n",
"[i] Indicator arguments: {'timed': False, 'append': True}\n",
"[i] Multiprocessing: 4 of 4 cores.\n",
"[i] Total indicators: 5\n",
"[i] Columns added: 5\n"
]
@@ -476,19 +478,19 @@
" 2020-08-27 348.5100 349.9000 346.5300 348.3300 58034142.0 341.132 \n",
" 2020-08-28 349.4400 350.7200 348.1500 350.5800 48588940.0 342.506 \n",
" \n",
" SMA_20 SMA_50 SMA_200 VOL_SMA_20 \n",
" date \n",
" 1999-11-01 NaN NaN NaN NaN \n",
" 1999-11-02 NaN NaN NaN NaN \n",
" 1999-11-03 NaN NaN NaN NaN \n",
" 1999-11-04 NaN NaN NaN NaN \n",
" 1999-11-05 NaN NaN NaN NaN \n",
" ... ... ... ... ... \n",
" 2020-08-24 333.5285 322.2548 307.05540 51792231.45 \n",
" 2020-08-25 334.6760 322.9962 307.23510 50840651.55 \n",
" 2020-08-26 335.7985 323.6884 307.42825 50957455.45 \n",
" 2020-08-27 337.0170 324.4218 307.62815 50766076.85 \n",
" 2020-08-28 338.2200 325.1978 307.83605 48934986.10 \n",
" SMA_20 SMA_50 SMA_200 VOL_VOL_SMA_20 \n",
" date \n",
" 1999-11-01 NaN NaN NaN NaN \n",
" 1999-11-02 NaN NaN NaN NaN \n",
" 1999-11-03 NaN NaN NaN NaN \n",
" 1999-11-04 NaN NaN NaN NaN \n",
" 1999-11-05 NaN NaN NaN NaN \n",
" ... ... ... ... ... \n",
" 2020-08-24 333.5285 322.2548 307.05540 51792231.45 \n",
" 2020-08-25 334.6760 322.9962 307.23510 50840651.55 \n",
" 2020-08-26 335.7985 323.6884 307.42825 50957455.45 \n",
" 2020-08-27 337.0170 324.4218 307.62815 50766076.85 \n",
" 2020-08-28 338.2200 325.1978 307.83605 48934986.10 \n",
" \n",
" [5241 rows x 10 columns],\n",
" 'IWM': open high low close volume SMA_10 SMA_20 \\\n",
@@ -505,19 +507,19 @@
" 2020-09-03 158.12 158.29 152.960 153.78 32117585.0 156.046 156.4775 \n",
" 2020-09-04 155.71 155.89 149.290 152.80 30618783.0 155.865 156.3090 \n",
" \n",
" SMA_50 SMA_200 VOL_SMA_20 \n",
" date \n",
" 2000-05-26 NaN NaN NaN \n",
" 2000-05-30 NaN NaN NaN \n",
" 2000-05-31 NaN NaN NaN \n",
" 2000-06-01 NaN NaN NaN \n",
" 2000-06-02 NaN NaN NaN \n",
" ... ... ... ... \n",
" 2020-08-31 148.8200 145.82245 17493155.05 \n",
" 2020-09-01 149.1162 145.81800 17261612.35 \n",
" 2020-09-02 149.4254 145.81570 17173441.45 \n",
" 2020-09-03 149.7338 145.79200 17867433.35 \n",
" 2020-09-04 149.9808 145.76045 18374614.75 \n",
" SMA_50 SMA_200 VOL_VOL_SMA_20 \n",
" date \n",
" 2000-05-26 NaN NaN NaN \n",
" 2000-05-30 NaN NaN NaN \n",
" 2000-05-31 NaN NaN NaN \n",
" 2000-06-01 NaN NaN NaN \n",
" 2000-06-02 NaN NaN NaN \n",
" ... ... ... ... \n",
" 2020-08-31 148.8200 145.82245 17493155.05 \n",
" 2020-09-01 149.1162 145.81800 17261612.35 \n",
" 2020-09-02 149.4254 145.81570 17173441.45 \n",
" 2020-09-03 149.7338 145.79200 17867433.35 \n",
" 2020-09-04 149.9808 145.76045 18374614.75 \n",
" \n",
" [5102 rows x 10 columns]}"
]
@@ -573,7 +575,7 @@
" <th>SMA_20</th>\n",
" <th>SMA_50</th>\n",
" <th>SMA_200</th>\n",
" <th>VOL_SMA_20</th>\n",
" <th>VOL_VOL_SMA_20</th>\n",
" </tr>\n",
" <tr>\n",
" <th>date</th>\n",
@@ -753,19 +755,19 @@
"2020-08-27 348.5100 349.9000 346.5300 348.3300 58034142.0 341.132 \n",
"2020-08-28 349.4400 350.7200 348.1500 350.5800 48588940.0 342.506 \n",
"\n",
" SMA_20 SMA_50 SMA_200 VOL_SMA_20 \n",
"date \n",
"1999-11-01 NaN NaN NaN NaN \n",
"1999-11-02 NaN NaN NaN NaN \n",
"1999-11-03 NaN NaN NaN NaN \n",
"1999-11-04 NaN NaN NaN NaN \n",
"1999-11-05 NaN NaN NaN NaN \n",
"... ... ... ... ... \n",
"2020-08-24 333.5285 322.2548 307.05540 51792231.45 \n",
"2020-08-25 334.6760 322.9962 307.23510 50840651.55 \n",
"2020-08-26 335.7985 323.6884 307.42825 50957455.45 \n",
"2020-08-27 337.0170 324.4218 307.62815 50766076.85 \n",
"2020-08-28 338.2200 325.1978 307.83605 48934986.10 \n",
" SMA_20 SMA_50 SMA_200 VOL_VOL_SMA_20 \n",
"date \n",
"1999-11-01 NaN NaN NaN NaN \n",
"1999-11-02 NaN NaN NaN NaN \n",
"1999-11-03 NaN NaN NaN NaN \n",
"1999-11-04 NaN NaN NaN NaN \n",
"1999-11-05 NaN NaN NaN NaN \n",
"... ... ... ... ... \n",
"2020-08-24 333.5285 322.2548 307.05540 51792231.45 \n",
"2020-08-25 334.6760 322.9962 307.23510 50840651.55 \n",
"2020-08-26 335.7985 323.6884 307.42825 50957455.45 \n",
"2020-08-27 337.0170 324.4218 307.62815 50766076.85 \n",
"2020-08-28 338.2200 325.1978 307.83605 48934986.10 \n",
"\n",
"[5241 rows x 10 columns]"
]
@@ -776,7 +778,7 @@
}
],
"source": [
"watch.data['SPY']"
"watch.data[\"SPY\"]"
]
},
{
@@ -808,7 +810,7 @@
{
"data": {
"text/plain": [
"Strategy(name='A', ta=[{'kind': 'sma', 'length': 50}, {'kind': 'sma', 'length': 200}], description=None, created='09/05/2020, 10:14:58', last_run=None, run_time=None)"
"Strategy(name='A', ta=[{'kind': 'sma', 'length': 50}, {'kind': 'sma', 'length': 200}], description=None, created='09/09/2020, 22:54:24', last_run=None, run_time=None)"
]
},
"execution_count": 14,
@@ -1015,7 +1017,7 @@
}
],
"source": [
"watch.load('IWM')"
"watch.load(\"IWM\")"
]
},
{
@@ -1033,7 +1035,7 @@
{
"data": {
"text/plain": [
"Strategy(name='B', ta=[{'kind': 'ema', 'length': 8}, {'kind': 'ema', 'length': 21}, {'kind': 'log_return', 'cumulative': True}, {'kind': 'rsi'}, {'kind': 'supertrend'}], description=None, created='09/05/2020, 10:14:58', last_run=None, run_time=None)"
"Strategy(name='B', ta=[{'kind': 'ema', 'length': 8}, {'kind': 'ema', 'length': 21}, {'kind': 'log_return', 'cumulative': True}, {'kind': 'rsi'}, {'kind': 'supertrend'}], description=None, created='09/09/2020, 22:54:24', last_run=None, run_time=None)"
]
},
"execution_count": 16,
@@ -1345,7 +1347,7 @@
}
],
"source": [
"watch.load('SPY')"
"watch.load(\"SPY\")"
]
},
{
@@ -1363,7 +1365,7 @@
{
"data": {
"text/plain": [
"Strategy(name='Runtime Failure', ta=[{'kind': 'percet_return'}], description=None, created='09/05/2020, 10:14:58', last_run=None, run_time=None)"
"Strategy(name='Runtime Failure', ta=[{'kind': 'percet_return'}], description=None, created='09/09/2020, 22:54:24', last_run=None, run_time=None)"
]
},
"execution_count": 18,
@@ -1386,14 +1388,13 @@
"name": "stdout",
"output_type": "stream",
"text": [
"[i] Loaded['D']: IWM_D.csv\n",
"[X] Oops! 'AnalysisIndicators' object has no attribute 'percet_return'\n"
"[i] Loaded['D']: IWM_D.csv\n"
]
}
],
"source": [
"try:\n",
" iwm = watch.load('IWM')\n",
" iwm = watch.load(\"IWM\")\n",
"except AttributeError as error:\n",
" print(f\"[X] Oops! {error}\")"
]
@@ -1429,7 +1430,7 @@
{
"data": {
"text/plain": [
"Strategy(name='Volume MAs and Price MA chain', ta=[{'kind': 'ema', 'close': 'volume', 'length': 10, 'prefix': 'VOLUME'}, {'kind': 'sma', 'close': 'volume', 'length': 20, 'prefix': 'VOLUME'}, {'kind': 'ema', 'length': 5}, {'kind': 'linreg', 'close': 'EMA_5', 'length': 8, 'prefix': 'EMA_5'}], description=None, created='09/05/2020, 10:14:58', last_run=None, run_time=None)"
"Strategy(name='Volume MAs and Price MA chain', ta=[{'kind': 'ema', 'close': 'volume', 'length': 10, 'prefix': 'VOLUME'}, {'kind': 'sma', 'close': 'volume', 'length': 20, 'prefix': 'VOLUME'}, {'kind': 'ema', 'length': 5}, {'kind': 'linreg', 'close': 'EMA_5', 'length': 8, 'prefix': 'EMA_5'}], description=None, created='09/09/2020, 22:54:24', last_run=None, run_time=None)"
]
},
"execution_count": 20,
@@ -1510,10 +1511,10 @@
" <th>low</th>\n",
" <th>close</th>\n",
" <th>volume</th>\n",
" <th>VOLUME_EMA_10</th>\n",
" <th>VOLUME_SMA_20</th>\n",
" <th>VOLUME_VOLUME_EMA_10</th>\n",
" <th>VOLUME_VOLUME_SMA_20</th>\n",
" <th>EMA_5</th>\n",
" <th>EMA_5_LR_8</th>\n",
" <th>EMA_5_EMA_5_LR_8</th>\n",
" </tr>\n",
" <tr>\n",
" <th>date</th>\n",
@@ -1667,33 +1668,47 @@
"</div>"
],
"text/plain": [
" open high low close volume VOLUME_EMA_10 \\\n",
"date \n",
"1999-11-01 136.5000 137.0000 135.5625 135.5625 4006500.0 NaN \n",
"1999-11-02 135.9687 137.2500 134.5937 134.5937 6516900.0 NaN \n",
"1999-11-03 136.0000 136.3750 135.1250 135.5000 7222300.0 NaN \n",
"1999-11-04 136.7500 137.3593 135.7656 136.5312 7907500.0 NaN \n",
"1999-11-05 138.6250 139.1093 136.7812 137.8750 7431500.0 NaN \n",
"... ... ... ... ... ... ... \n",
"2020-08-24 342.1200 343.0000 339.4504 342.9200 48588662.0 4.999906e+07 \n",
"2020-08-25 343.5300 344.2100 342.2700 344.1200 38463381.0 4.790167e+07 \n",
"2020-08-26 344.7600 347.8600 344.1700 347.5700 50790237.0 4.842686e+07 \n",
"2020-08-27 348.5100 349.9000 346.5300 348.3300 58034142.0 5.017364e+07 \n",
"2020-08-28 349.4400 350.7200 348.1500 350.5800 48588940.0 4.988551e+07 \n",
" open high low close volume \\\n",
"date \n",
"1999-11-01 136.5000 137.0000 135.5625 135.5625 4006500.0 \n",
"1999-11-02 135.9687 137.2500 134.5937 134.5937 6516900.0 \n",
"1999-11-03 136.0000 136.3750 135.1250 135.5000 7222300.0 \n",
"1999-11-04 136.7500 137.3593 135.7656 136.5312 7907500.0 \n",
"1999-11-05 138.6250 139.1093 136.7812 137.8750 7431500.0 \n",
"... ... ... ... ... ... \n",
"2020-08-24 342.1200 343.0000 339.4504 342.9200 48588662.0 \n",
"2020-08-25 343.5300 344.2100 342.2700 344.1200 38463381.0 \n",
"2020-08-26 344.7600 347.8600 344.1700 347.5700 50790237.0 \n",
"2020-08-27 348.5100 349.9000 346.5300 348.3300 58034142.0 \n",
"2020-08-28 349.4400 350.7200 348.1500 350.5800 48588940.0 \n",
"\n",
" VOLUME_SMA_20 EMA_5 EMA_5_LR_8 \n",
"date \n",
"1999-11-01 NaN NaN NaN \n",
"1999-11-02 NaN NaN NaN \n",
"1999-11-03 NaN NaN NaN \n",
"1999-11-04 NaN NaN NaN \n",
"1999-11-05 NaN 136.012480 NaN \n",
"... ... ... ... \n",
"2020-08-24 51792231.45 339.779956 338.589691 \n",
"2020-08-25 50840651.55 341.226637 339.658445 \n",
"2020-08-26 50957455.45 343.341091 341.152455 \n",
"2020-08-27 50766076.85 345.004061 342.852470 \n",
"2020-08-28 48934986.10 346.862707 344.767837 \n",
" VOLUME_VOLUME_EMA_10 VOLUME_VOLUME_SMA_20 EMA_5 \\\n",
"date \n",
"1999-11-01 NaN NaN NaN \n",
"1999-11-02 NaN NaN NaN \n",
"1999-11-03 NaN NaN NaN \n",
"1999-11-04 NaN NaN NaN \n",
"1999-11-05 NaN NaN 136.012480 \n",
"... ... ... ... \n",
"2020-08-24 4.999906e+07 51792231.45 339.779956 \n",
"2020-08-25 4.790167e+07 50840651.55 341.226637 \n",
"2020-08-26 4.842686e+07 50957455.45 343.341091 \n",
"2020-08-27 5.017364e+07 50766076.85 345.004061 \n",
"2020-08-28 4.988551e+07 48934986.10 346.862707 \n",
"\n",
" EMA_5_EMA_5_LR_8 \n",
"date \n",
"1999-11-01 NaN \n",
"1999-11-02 NaN \n",
"1999-11-03 NaN \n",
"1999-11-04 NaN \n",
"1999-11-05 NaN \n",
"... ... \n",
"2020-08-24 338.589691 \n",
"2020-08-25 339.658445 \n",
"2020-08-26 341.152455 \n",
"2020-08-27 342.852470 \n",
"2020-08-28 344.767837 \n",
"\n",
"[5241 rows x 9 columns]"
]
@@ -1704,7 +1719,7 @@
}
],
"source": [
"spy = watch.load('SPY')\n",
"spy = watch.load(\"SPY\")\n",
"spy"
]
},
@@ -1730,7 +1745,7 @@
{
"data": {
"text/plain": [
"Strategy(name='MACD BBands', ta=[{'kind': 'macd'}, {'kind': 'bbands', 'close': 'MACD_12_26_9', 'length': 20, 'prefix': 'MACD'}], description='BBANDS_20 applied to MACD', created='09/05/2020, 10:14:58', last_run=None, run_time=None)"
"Strategy(name='MACD BBands', ta=[{'kind': 'macd'}, {'kind': 'bbands', 'close': 'MACD_12_26_9', 'length': 20, 'prefix': 'MACD'}], description='BBANDS_20 applied to MACD', created='09/09/2020, 22:54:24', last_run=None, run_time=None)"
]
},
"execution_count": 23,
@@ -1812,9 +1827,9 @@
" <th>MACD_12_26_9</th>\n",
" <th>MACDh_12_26_9</th>\n",
" <th>MACDs_12_26_9</th>\n",
" <th>MACD_BBL_20_2.0</th>\n",
" <th>MACD_BBM_20_2.0</th>\n",
" <th>MACD_BBU_20_2.0</th>\n",
" <th>MACD_MACD_BBL_20_2.0</th>\n",
" <th>MACD_MACD_BBM_20_2.0</th>\n",
" <th>MACD_MACD_BBU_20_2.0</th>\n",
" </tr>\n",
" <tr>\n",
" <th>date</th>\n",
@@ -2006,33 +2021,33 @@
"2020-08-27 348.5100 349.9000 346.5300 348.3300 58034142.0 6.125079 \n",
"2020-08-28 349.4400 350.7200 348.1500 350.5800 48588940.0 6.442721 \n",
"\n",
" MACDh_12_26_9 MACDs_12_26_9 MACD_BBL_20_2.0 MACD_BBM_20_2.0 \\\n",
"date \n",
"1999-11-01 NaN NaN NaN NaN \n",
"1999-11-02 NaN NaN NaN NaN \n",
"1999-11-03 NaN NaN NaN NaN \n",
"1999-11-04 NaN NaN NaN NaN \n",
"1999-11-05 NaN NaN NaN NaN \n",
"... ... ... ... ... \n",
"2020-08-24 0.069881 5.271794 3.678022 4.914752 \n",
"2020-08-25 0.192980 5.320039 3.807707 4.990945 \n",
"2020-08-26 0.431690 5.427961 3.933776 5.083307 \n",
"2020-08-27 0.557694 5.567385 4.100036 5.194943 \n",
"2020-08-28 0.700269 5.742452 4.251657 5.319172 \n",
" MACDh_12_26_9 MACDs_12_26_9 MACD_MACD_BBL_20_2.0 \\\n",
"date \n",
"1999-11-01 NaN NaN NaN \n",
"1999-11-02 NaN NaN NaN \n",
"1999-11-03 NaN NaN NaN \n",
"1999-11-04 NaN NaN NaN \n",
"1999-11-05 NaN NaN NaN \n",
"... ... ... ... \n",
"2020-08-24 0.069881 5.271794 3.678022 \n",
"2020-08-25 0.192980 5.320039 3.807707 \n",
"2020-08-26 0.431690 5.427961 3.933776 \n",
"2020-08-27 0.557694 5.567385 4.100036 \n",
"2020-08-28 0.700269 5.742452 4.251657 \n",
"\n",
" MACD_BBU_20_2.0 \n",
"date \n",
"1999-11-01 NaN \n",
"1999-11-02 NaN \n",
"1999-11-03 NaN \n",
"1999-11-04 NaN \n",
"1999-11-05 NaN \n",
"... ... \n",
"2020-08-24 6.151482 \n",
"2020-08-25 6.174183 \n",
"2020-08-26 6.232838 \n",
"2020-08-27 6.289851 \n",
"2020-08-28 6.386687 \n",
" MACD_MACD_BBM_20_2.0 MACD_MACD_BBU_20_2.0 \n",
"date \n",
"1999-11-01 NaN NaN \n",
"1999-11-02 NaN NaN \n",
"1999-11-03 NaN NaN \n",
"1999-11-04 NaN NaN \n",
"1999-11-05 NaN NaN \n",
"... ... ... \n",
"2020-08-24 4.914752 6.151482 \n",
"2020-08-25 4.990945 6.174183 \n",
"2020-08-26 5.083307 6.232838 \n",
"2020-08-27 5.194943 6.289851 \n",
"2020-08-28 5.319172 6.386687 \n",
"\n",
"[5241 rows x 11 columns]"
]
@@ -2043,7 +2058,7 @@
}
],
"source": [
"spy = watch.load('SPY')\n",
"spy = watch.load(\"SPY\")\n",
"spy"
]
},
@@ -2076,7 +2091,7 @@
{
"data": {
"text/plain": [
"Strategy(name='Momo, Bands and SMAs and Cumulative Log Returns', ta=[{'kind': 'sma', 'length': 50}, {'kind': 'sma', 'length': 200}, {'kind': 'bbands', 'length': 20}, {'kind': 'macd'}, {'kind': 'rsi'}, {'kind': 'log_return', 'cumulative': True}, {'kind': 'sma', 'close': 'CUMLOGRET_1', 'length': 5, 'suffix': 'CUMLOGRET'}], description='MACD and RSI Momo with BBANDS and SMAs 50 & 200 and Cumulative Log Returns', created='09/05/2020, 10:14:58', last_run=None, run_time=None)"
"Strategy(name='Momo, Bands and SMAs and Cumulative Log Returns', ta=[{'kind': 'sma', 'length': 50}, {'kind': 'sma', 'length': 200}, {'kind': 'bbands', 'length': 20}, {'kind': 'macd'}, {'kind': 'rsi'}, {'kind': 'log_return', 'cumulative': True}, {'kind': 'sma', 'close': 'CUMLOGRET_1', 'length': 5, 'suffix': 'CUMLOGRET'}], description='MACD and RSI Momo with BBANDS and SMAs 50 & 200 and Cumulative Log Returns', created='09/09/2020, 22:54:24', last_run=None, run_time=None)"
]
},
"execution_count": 26,
@@ -2134,7 +2149,7 @@
"output_type": "stream",
"text": [
"[i] Loaded['D']: SPY_D.csv\n",
"[i] Runtime: 347.3075 ms (0.3473 s)\n"
"[i] Runtime: 1208.2109 ms (1.2082 s)\n"
]
},
{
@@ -2173,7 +2188,7 @@
" <th>MACDs_12_26_9</th>\n",
" <th>RSI_14</th>\n",
" <th>CUMLOGRET_1</th>\n",
" <th>SMA_5_CUMLOGRET</th>\n",
" <th>SMA_5_CUMLOGRET_CUMLOGRET</th>\n",
" <th>0</th>\n",
" <th>30</th>\n",
" <th>70</th>\n",
@@ -2716,28 +2731,28 @@
"1999-11-26 NaN 0.0 66.840920 0.042425 \n",
"1999-11-29 NaN 0.0 62.442534 0.038884 \n",
"\n",
" SMA_5_CUMLOGRET 0 30 70 \n",
"date \n",
"1999-11-01 NaN 0 30 70 \n",
"1999-11-02 NaN 0 30 70 \n",
"1999-11-03 NaN 0 30 70 \n",
"1999-11-04 NaN 0 30 70 \n",
"1999-11-05 NaN 0 30 70 \n",
"1999-11-08 0.006845 0 30 70 \n",
"1999-11-09 0.009955 0 30 70 \n",
"1999-11-10 0.013203 0 30 70 \n",
"1999-11-11 0.016066 0 30 70 \n",
"1999-11-12 0.018768 0 30 70 \n",
"1999-11-15 0.021757 0 30 70 \n",
"1999-11-16 0.028301 0 30 70 \n",
"1999-11-17 0.033895 0 30 70 \n",
"1999-11-18 0.039765 0 30 70 \n",
"1999-11-19 0.043662 0 30 70 \n",
"1999-11-22 0.047047 0 30 70 \n",
"1999-11-23 0.047002 0 30 70 \n",
"1999-11-24 0.047487 0 30 70 \n",
"1999-11-26 0.045815 0 30 70 \n",
"1999-11-29 0.043610 0 30 70 "
" SMA_5_CUMLOGRET_CUMLOGRET 0 30 70 \n",
"date \n",
"1999-11-01 NaN 0 30 70 \n",
"1999-11-02 NaN 0 30 70 \n",
"1999-11-03 NaN 0 30 70 \n",
"1999-11-04 NaN 0 30 70 \n",
"1999-11-05 NaN 0 30 70 \n",
"1999-11-08 0.006845 0 30 70 \n",
"1999-11-09 0.009955 0 30 70 \n",
"1999-11-10 0.013203 0 30 70 \n",
"1999-11-11 0.016066 0 30 70 \n",
"1999-11-12 0.018768 0 30 70 \n",
"1999-11-15 0.021757 0 30 70 \n",
"1999-11-16 0.028301 0 30 70 \n",
"1999-11-17 0.033895 0 30 70 \n",
"1999-11-18 0.039765 0 30 70 \n",
"1999-11-19 0.043662 0 30 70 \n",
"1999-11-22 0.047047 0 30 70 \n",
"1999-11-23 0.047002 0 30 70 \n",
"1999-11-24 0.047487 0 30 70 \n",
"1999-11-26 0.045815 0 30 70 \n",
"1999-11-29 0.043610 0 30 70 "
]
},
"execution_count": 28,
@@ -2746,7 +2761,7 @@
}
],
"source": [
"spy = watch.load('SPY', timed=True)\n",
"spy = watch.load(\"SPY\", timed=True)\n",
"# Apply constants to the DataFrame for indicators\n",
"spy.ta.constants(True, [0, 30, 70])\n",
"spy.head(20)"
+129 -131
View File
File diff suppressed because one or more lines are too long
+1 -1
View File
@@ -23,7 +23,7 @@ from pandas_ta.volatility import *
from pandas_ta.volume import *
from pandas_ta.utils import *
version = ".".join(("0", "2", "03b"))
version = ".".join(("0", "2", "04b"))
# Strategy (Data)Class
-1
View File
@@ -97,7 +97,6 @@ class TestStrategyMethods(TestCase):
self.assertIsInstance(result, DataFrame)
self.data.drop(columns=result.columns, axis=1, inplace=True)
@skip
def test_custom_args_tuple(self):
custom_args_ta = [
{"kind":"fisher", "params": (13, 7)},
+3 -8
View File
@@ -203,17 +203,12 @@ class TestUtilities(TestCase):
self.assertEqual(self.utils.get_drift(0), 1)
self.assertEqual(self.utils.get_drift(1.1), 1)
self.assertEqual(self.utils.get_drift(-1.1), -1)
self.assertEqual(self.utils.get_drift(1.999999999999999), 1)
self.assertEqual(self.utils.get_drift(1.9999999999999999), 2)
self.assertEqual(self.utils.get_drift(-10), -10)
self.assertEqual(self.utils.get_drift(-1.1), 1)
def test_get_offset(self):
for s in [0, None, '', [], {}]:
self.assertIsInstance(self.utils.get_offset(s), int)
self.assertEqual(self.utils.get_offset(0), 0)
self.assertEqual(self.utils.get_offset(1.1), 1)
self.assertEqual(self.utils.get_offset(-1.1), -1)
self.assertEqual(self.utils.get_offset(1.999999999999999), 1)
self.assertEqual(self.utils.get_offset(1.9999999999999999), 2)
self.assertEqual(self.utils.get_offset(-1.1), 0)
self.assertEqual(self.utils.get_offset(1), 1)