update notebooks with new results

This commit is contained in:
Filip Stefaniuk 2025-02-09 15:32:17 +01:00
parent 96950fcf90
commit f7485d9a2d
7 changed files with 1415 additions and 1350514 deletions

View File

@ -2,7 +2,7 @@
"cells": [
{
"cell_type": "code",
"execution_count": 2,
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
@ -42,7 +42,7 @@
},
{
"cell_type": "code",
"execution_count": 3,
"execution_count": 2,
"metadata": {},
"outputs": [
{
@ -52,7 +52,7 @@
"Failed to detect the name of this notebook, you can set it manually with the WANDB_NOTEBOOK_NAME environment variable to enable code saving.\n",
"\u001b[34m\u001b[1mwandb\u001b[0m: Downloading large artifact btc-usdt-15m:latest, 248.65MB. 12 files... \n",
"\u001b[34m\u001b[1mwandb\u001b[0m: 12 of 12 files downloaded. \n",
"Done. 0:0:0.5\n"
"Done. 0:0:0.8\n"
]
}
],
@ -67,7 +67,7 @@
},
{
"cell_type": "code",
"execution_count": 4,
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
@ -81,7 +81,7 @@
},
{
"cell_type": "code",
"execution_count": 5,
"execution_count": 4,
"metadata": {},
"outputs": [],
"source": [
@ -90,19 +90,19 @@
},
{
"cell_type": "code",
"execution_count": 6,
"execution_count": 5,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"100%|██████████| 3840/3840 [00:06<00:00, 614.41it/s]\n",
"100%|██████████| 3840/3840 [00:08<00:00, 479.05it/s]\n",
"100%|██████████| 3840/3840 [00:06<00:00, 554.94it/s]\n",
"100%|██████████| 3840/3840 [00:06<00:00, 575.21it/s]\n",
"100%|██████████| 3840/3840 [00:06<00:00, 571.03it/s]\n",
"100%|██████████| 3840/3840 [00:06<00:00, 576.86it/s]\n"
"100%|██████████| 3840/3840 [00:06<00:00, 639.58it/s]\n",
"100%|██████████| 3840/3840 [00:05<00:00, 658.38it/s]\n",
"100%|██████████| 3840/3840 [00:06<00:00, 624.58it/s]\n",
"100%|██████████| 3840/3840 [00:05<00:00, 649.63it/s]\n",
"100%|██████████| 3840/3840 [00:06<00:00, 627.23it/s]\n",
"100%|██████████| 3840/3840 [00:06<00:00, 633.46it/s]\n"
]
}
],
@ -136,19 +136,19 @@
},
{
"cell_type": "code",
"execution_count": 7,
"execution_count": 6,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"100%|██████████| 11088/11088 [00:19<00:00, 580.54it/s]\n",
"100%|██████████| 11088/11088 [00:17<00:00, 627.38it/s]\n",
"100%|██████████| 11088/11088 [00:17<00:00, 624.72it/s]\n",
"100%|██████████| 11088/11088 [00:18<00:00, 586.62it/s]\n",
"100%|██████████| 11088/11088 [00:17<00:00, 618.44it/s]\n",
"100%|██████████| 11088/11088 [00:18<00:00, 597.40it/s]\n"
"100%|██████████| 11088/11088 [00:19<00:00, 560.36it/s]\n",
"100%|██████████| 11088/11088 [00:22<00:00, 495.98it/s]\n",
"100%|██████████| 11088/11088 [00:19<00:00, 556.67it/s]\n",
"100%|██████████| 11088/11088 [00:19<00:00, 554.79it/s]\n",
"100%|██████████| 11088/11088 [00:18<00:00, 590.13it/s]\n",
"100%|██████████| 11088/11088 [00:17<00:00, 650.44it/s]\n"
]
}
],
@ -179,6 +179,95 @@
"# plot_sweep_results(pd.DataFrame([result for result, _ in rsi_sweep_results[0]]), parameters=RSI_PARAMS.keys())"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"\u001b[34m\u001b[1mwandb\u001b[0m: 2 of 2 files downloaded. \n",
"\u001b[34m\u001b[1mwandb\u001b[0m: 2 of 2 files downloaded. \n",
"\u001b[34m\u001b[1mwandb\u001b[0m: 2 of 2 files downloaded. \n",
"\u001b[34m\u001b[1mwandb\u001b[0m: 2 of 2 files downloaded. \n",
"\u001b[34m\u001b[1mwandb\u001b[0m: 2 of 2 files downloaded. \n",
"\u001b[34m\u001b[1mwandb\u001b[0m: 2 of 2 files downloaded. \n",
"\u001b[34m\u001b[1mwandb\u001b[0m: 2 of 2 files downloaded. \n",
"\u001b[34m\u001b[1mwandb\u001b[0m: 2 of 2 files downloaded. \n",
"\u001b[34m\u001b[1mwandb\u001b[0m: 2 of 2 files downloaded. \n",
"\u001b[34m\u001b[1mwandb\u001b[0m: 2 of 2 files downloaded. \n",
"\u001b[34m\u001b[1mwandb\u001b[0m: 2 of 2 files downloaded. \n",
"\u001b[34m\u001b[1mwandb\u001b[0m: 2 of 2 files downloaded. \n",
"\u001b[34m\u001b[1mwandb\u001b[0m: 2 of 2 files downloaded. \n",
"\u001b[34m\u001b[1mwandb\u001b[0m: 2 of 2 files downloaded. \n",
"\u001b[34m\u001b[1mwandb\u001b[0m: 2 of 2 files downloaded. \n",
"\u001b[34m\u001b[1mwandb\u001b[0m: 2 of 2 files downloaded. \n",
"\u001b[34m\u001b[1mwandb\u001b[0m: 2 of 2 files downloaded. \n",
"\u001b[34m\u001b[1mwandb\u001b[0m: 2 of 2 files downloaded. \n"
]
}
],
"source": [
"# Model with rmse loss\n",
"SWEEP_ID = 'filipstefaniuk/wne-masters-thesis-testing/inpvjdsp'\n",
"train_pred_windows = get_sweep_window_predictions(SWEEP_ID, 'train')\n",
"valid_pred_windows = get_sweep_window_predictions(SWEEP_ID, 'valid')\n",
"test_pred_windows = get_sweep_window_predictions(SWEEP_ID, 'test')"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"100%|██████████| 1176/1176 [00:39<00:00, 29.69it/s]\n",
"100%|██████████| 1176/1176 [00:41<00:00, 28.17it/s]\n",
"100%|██████████| 1176/1176 [00:40<00:00, 29.34it/s]\n",
"100%|██████████| 1176/1176 [00:40<00:00, 29.28it/s]\n",
"100%|██████████| 1176/1176 [00:40<00:00, 29.11it/s]\n",
"100%|██████████| 1176/1176 [00:40<00:00, 29.39it/s]\n"
]
}
],
"source": [
"MODEL_RMSE_LOSS_FILTER = lambda p: (\n",
" ((p['enter_long'] is not None and (p['enter_short'] is not None or p['exit_long'] is not None))\n",
" or (p['enter_short'] is not None and (p['exit_short'] is not None or p['enter_long'] is not None)))\n",
" and (p['enter_short'] is None or p['exit_long'] is None or (p['exit_long'] > p['enter_short']))\n",
" and (p['enter_long'] is None or p['exit_short'] is None or (p['exit_short'] < p['enter_long'])))\n",
"\n",
"rmse_model_sweep_results = []\n",
"for (in_sample, _), train_preds, valid_preds, test_preds in zip(data_windows, train_pred_windows, valid_pred_windows, test_pred_windows):\n",
" data_part = int((1 - VALID_PART) * len(in_sample))\n",
" params={\n",
" 'predictions': [get_predictions_dataframe(train_preds, valid_preds, test_preds)],\n",
" 'enter_long': [None, 0.001, 0.002, 0.003, 0.004, 0.005, 0.006, 0.007],\n",
" 'exit_long': [None, -0.001, -0.002, -0.003, -0.004, -0.005, -0.006, -0.007],\n",
" 'enter_short': [None, -0.001, -0.002, -0.003, -0.004, -0.005, -0.006, -0.007],\n",
" 'exit_short': [None, 0.001, 0.002, 0.003, 0.004, 0.005, 0.006, 0.007],\n",
" # 'enter_short': [None],\n",
" # 'exit_short': [None],\n",
" }\n",
" \n",
" rmse_model_sweep_results.append(parameter_sweep(\n",
" in_sample[data_part-PADDING:],\n",
" ModelGmadlPredictionsStrategy,\n",
" params,\n",
" params_filter=MODEL_RMSE_LOSS_FILTER,\n",
" padding=PADDING,\n",
" interval=INTERVAL,\n",
" sort_by=METRIC))\n",
" \n",
"\n",
"rmse_model_best_strategies = [[strat for _, strat in results[:TOP_N]] for results in rmse_model_sweep_results]"
]
},
{
"cell_type": "markdown",
"metadata": {},
@ -186,7 +275,7 @@
},
{
"cell_type": "code",
"execution_count": 8,
"execution_count": 9,
"metadata": {},
"outputs": [
{
@ -231,12 +320,12 @@
"name": "stderr",
"output_type": "stream",
"text": [
"100%|██████████| 1125/1125 [00:21<00:00, 51.66it/s]\n",
"100%|██████████| 1125/1125 [00:20<00:00, 53.98it/s]\n",
"100%|██████████| 1125/1125 [00:22<00:00, 49.63it/s]\n",
"100%|██████████| 1125/1125 [00:24<00:00, 45.57it/s]\n",
"100%|██████████| 1125/1125 [00:23<00:00, 47.76it/s]\n",
"100%|██████████| 1125/1125 [00:24<00:00, 46.33it/s]\n"
"100%|██████████| 1125/1125 [00:25<00:00, 44.03it/s]\n",
"100%|██████████| 1125/1125 [00:20<00:00, 53.68it/s]\n",
"100%|██████████| 1125/1125 [00:20<00:00, 54.38it/s]\n",
"100%|██████████| 1125/1125 [00:20<00:00, 54.70it/s]\n",
"100%|██████████| 1125/1125 [00:20<00:00, 54.23it/s]\n",
"100%|██████████| 1125/1125 [00:21<00:00, 53.31it/s]\n"
]
}
],
@ -323,19 +412,19 @@
},
{
"cell_type": "code",
"execution_count": 13,
"execution_count": 12,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"100%|██████████| 1176/1176 [00:19<00:00, 60.00it/s]\n",
"100%|██████████| 1176/1176 [00:19<00:00, 61.63it/s]\n",
"100%|██████████| 1176/1176 [00:16<00:00, 69.59it/s]\n",
"100%|██████████| 1176/1176 [00:17<00:00, 65.37it/s]\n",
"100%|██████████| 1176/1176 [00:17<00:00, 66.33it/s]\n",
"100%|██████████| 1176/1176 [00:17<00:00, 67.86it/s]\n"
"100%|██████████| 1176/1176 [00:22<00:00, 53.42it/s]\n",
"100%|██████████| 1176/1176 [00:19<00:00, 59.87it/s]\n",
"100%|██████████| 1176/1176 [00:17<00:00, 66.89it/s]\n",
"100%|██████████| 1176/1176 [00:17<00:00, 65.52it/s]\n",
"100%|██████████| 1176/1176 [00:17<00:00, 67.44it/s]\n",
"100%|██████████| 1176/1176 [00:17<00:00, 67.15it/s]\n"
]
}
],
@ -372,7 +461,7 @@
},
{
"cell_type": "code",
"execution_count": 14,
"execution_count": 13,
"metadata": {},
"outputs": [],
"source": [
@ -381,11 +470,12 @@
" 'buy_and_hold': buyandhold_best_strategies,\n",
" 'macd_strategies': macd_best_strategies,\n",
" 'rsi_strategies': rsi_best_strategies,\n",
" 'rmse_model': rmse_model_best_strategies,\n",
" 'quantile_model': quantile_model_best_strategies,\n",
" 'gmadl_model': gmadl_model_best_strategies\n",
"}\n",
"\n",
"with open('cache/15min-best-strategies.pkl', 'wb') as outp:\n",
"with open('cache/15min-best-strategies-v2.pkl', 'wb') as outp:\n",
" pickle.dump(best_strategies, outp, pickle.HIGHEST_PROTOCOL)"
]
},
@ -398,11 +488,11 @@
},
{
"cell_type": "code",
"execution_count": 15,
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
"with open('cache/15min-best-strategies.pkl', 'rb') as inpt:\n",
"with open('cache/15min-best-strategies-v2.pkl', 'rb') as inpt:\n",
" best_strategies = pickle.load(inpt)"
]
},
@ -516,6 +606,56 @@
"print(latextable.draw_latex(table_rsi_params))"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"\\begin{table}\n",
"\t\\begin{center}\n",
"\t\t\\begin{tabular}{lcccc}\n",
"\t\t\t\\textbf{Window} & \\textbf{\\textit{enter long}} & \\textbf{\\textit{exit Long}} & \\textbf{\\textit{enter Short}} & \\textbf{\\textit{exit Short}} \\\\\n",
"\t\t\t\\hline\n",
"\t\t\tW1-15min & 0.002 & - & -0.001 & - \\\\\n",
"\t\t\tW2-15min & - & - & -0.002 & 0.002 \\\\\n",
"\t\t\tW3-15min & - & - & -0.001 & 0.002 \\\\\n",
"\t\t\tW4-15min & 0.001 & - & -0.002 & - \\\\\n",
"\t\t\tW5-15min & - & - & -0.001 & 0.001 \\\\\n",
"\t\t\tW6-15min & - & - & -0.002 & 0.001 \\\\\n",
"\t\t\\end{tabular}\n",
"\t\\end{center}\n",
"\\end{table}\n"
]
}
],
"source": [
"table_rmse_params = Texttable()\n",
"table_rmse_params.set_deco(Texttable.HEADER)\n",
"table_rmse_params.set_cols_align([\"l\", \"c\",\"c\", \"c\", \"c\"])\n",
"table_rmse_params.header([\n",
" \"\\\\textbf{Window}\",\n",
" \"\\\\textbf{\\\\textit{enter long}}\",\n",
" \"\\\\textbf{\\\\textit{exit Long}}\",\n",
" \"\\\\textbf{\\\\textit{enter Short}}\",\n",
" \"\\\\textbf{\\\\textit{exit Short}}\",\n",
"])\n",
"\n",
"for i, rmse_strategy in enumerate(best_strategies['rmse_model']):\n",
" rmse_strategy_info = rmse_strategy[0].info()\n",
" table_rmse_params.add_row([\n",
" f\"W{i+1}-{INTERVAL}\",\n",
" rmse_strategy_info['enter_long'] or '-',\n",
" rmse_strategy_info['exit_long'] or '-',\n",
" rmse_strategy_info['enter_short'] or '-',\n",
" rmse_strategy_info['exit_short'] or '-'\n",
" ])\n",
"print(latextable.draw_latex(table_rmse_params))"
]
},
{
"cell_type": "code",
"execution_count": 18,
@ -627,19 +767,32 @@
},
{
"cell_type": "code",
"execution_count": 29,
"execution_count": 5,
"metadata": {},
"outputs": [],
"source": [
"def results_plot(idx, result_buyandhold, result_macd, result_rsi, result_quantile_model, result_gmadl_model, width=850, height=500, notitle=False):\n",
"def results_plot(idx, result_buyandhold, result_macd, result_rsi, result_rmse_model, result_quantile_model, result_gmadl_model, width=850, height=500, notitle=False, v_lines=None):\n",
"\n",
" fig = go.Figure([\n",
" go.Scatter(y=result_buyandhold['portfolio_value'], x=result_buyandhold['time'], name=\"Buy and Hold\"),\n",
" go.Scatter(y=result_macd['portfolio_value'], x=result_macd['time'], name=\"MACD Strategy\"),\n",
" go.Scatter(y=result_rsi['portfolio_value'], x=result_rsi['time'], name=\"RSI Strategy\"),\n",
" go.Scatter(y=result_rmse_model['portfolio_value'], x=result_rmse_model['time'], name='RMSE Informer Strategy'),\n",
" go.Scatter(y=result_quantile_model['portfolio_value'], x=result_quantile_model['time'], name='Quantile Informer Strategy'),\n",
" go.Scatter(y=result_gmadl_model['portfolio_value'], x=result_gmadl_model['time'], name='GMADL Informer Strategy')\n",
" ])\n",
" \n",
" if v_lines:\n",
" for v_line in v_lines:\n",
" fig.add_shape(\n",
" go.layout.Shape(type=\"line\",\n",
" yref=\"paper\",\n",
" xref=\"x\",\n",
" x0=v_line,\n",
" x1=v_line,\n",
" y0=0,\n",
" y1=1,\n",
" line=dict(dash='dash', color='rgb(140,140,140)')))\n",
" fig.update_layout(\n",
" title={\n",
" 'text': f\"W{idx}-{INTERVAL}\",\n",
@ -683,7 +836,7 @@
" fig.write_image(f\"images/eval-w{idx}-{INTERVAL}.png\")\n",
" fig.show()\n",
" \n",
"def results_table(result_buyandhold, result_macd, result_rsi, result_quantile_model, result_gmadl_model):\n",
"def results_table(result_buyandhold, result_macd, result_rsi, result_rmse_model, result_quantile_model, result_gmadl_model):\n",
" table_eval_windows = Texttable()\n",
" table_eval_windows.set_deco(Texttable.HEADER)\n",
" table_eval_windows.set_cols_align([\"l\", \"c\",\"c\", \"c\", \"c\", \"c\", \"c\", \"c\", \"c\", \"c\"])\n",
@ -706,6 +859,7 @@
" ('Buy and Hold', result_buyandhold),\n",
" ('MACD Strategy', result_macd),\n",
" ('RSI Strategy', result_rsi),\n",
" ('RMSE Informer', result_rmse_model),\n",
" ('Quantile Informer', result_quantile_model),\n",
" ('GMADL Informer', result_gmadl_model)\n",
" ]\n",
@ -713,10 +867,10 @@
" table_eval_windows.add_row([\n",
" strategy_name,\n",
" result['value'],\n",
" result['arc'],\n",
" result['asd'],\n",
" f\"{result['arc']*100:.2f}\\%\",\n",
" f\"{result['asd']*100:.2f}\\%\",\n",
" result['ir'],\n",
" result['md'],\n",
" f\"{result['md']*100:.2f}\\%\",\n",
" result['mod_ir'],\n",
" result['n_trades'],\n",
" f\"{result['long_pos']*100:.2f}\\%\",\n",
@ -728,61 +882,154 @@
},
{
"cell_type": "code",
"execution_count": 1,
"execution_count": 11,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"\\begin{table}\n",
"\t\\begin{center}\n",
"\t\t\\begin{tabular}{lccccccccc}\n",
"\t\t\t\\textbf{Strategy} & \\textbf{VAL} & \\textbf{ARC} & \\textbf{ASD} & \\textbf{IR*} & \\textbf{MD} & \\textbf{IR**} & \\textbf{N} & \\textbf{LONG} & \\textbf{SHORT} \\\\\n",
"\t\t\t\\hline\n",
"\t\t\tBuy and Hold & 0.933 & -13.15\\% & 66.69\\% & -0.197 & 51.81\\% & -0.050 & 2 & 100.00\\% & 0.00\\% \\\\\n",
"\t\t\tMACD Strategy & 0.357 & -87.59\\% & 66.96\\% & -1.308 & 73.46\\% & -1.559 & 852 & 52.49\\% & 47.51\\% \\\\\n",
"\t\t\tRSI Strategy & 0.621 & -61.93\\% & 66.94\\% & -0.925 & 48.44\\% & -1.183 & 882 & 58.61\\% & 41.39\\% \\\\\n",
"\t\t\tRMSE Informer & 1.498 & 127.03\\% & 52.56\\% & 2.417 & 22.20\\% & 13.827 & 3 & 0.00\\% & 61.05\\% \\\\\n",
"\t\t\tQuantile Informer & 0.715 & -49.34\\% & 66.74\\% & -0.739 & 40.17\\% & -0.908 & 182 & 52.75\\% & 47.25\\% \\\\\n",
"\t\t\tGMADL Informer & 2.173 & 382.27\\% & 66.83\\% & 5.720 & 29.76\\% & 73.474 & 146 & 36.88\\% & 63.12\\% \\\\\n",
"\t\t\\end{tabular}\n",
"\t\\end{center}\n",
"\\end{table}\n",
"\\begin{table}\n",
"\t\\begin{center}\n",
"\t\t\\begin{tabular}{lccccccccc}\n",
"\t\t\t\\textbf{Strategy} & \\textbf{VAL} & \\textbf{ARC} & \\textbf{ASD} & \\textbf{IR*} & \\textbf{MD} & \\textbf{IR**} & \\textbf{N} & \\textbf{LONG} & \\textbf{SHORT} \\\\\n",
"\t\t\t\\hline\n",
"\t\t\tBuy and Hold & 0.548 & -70.48\\% & 72.12\\% & -0.977 & 63.18\\% & -1.090 & 2 & 100.00\\% & 0.00\\% \\\\\n",
"\t\t\tMACD Strategy & 0.714 & -49.48\\% & 72.07\\% & -0.687 & 50.67\\% & -0.670 & 118 & 57.61\\% & 42.39\\% \\\\\n",
"\t\t\tRSI Strategy & 1.141 & 30.61\\% & 72.05\\% & 0.425 & 49.51\\% & 0.263 & 58 & 19.64\\% & 80.36\\% \\\\\n",
"\t\t\tRMSE Informer & 1 & 0.00\\% & 0.00\\% & 0 & 0.00\\% & 0 & 0 & 0.00\\% & 0.00\\% \\\\\n",
"\t\t\tQuantile Informer & 0.903 & -18.73\\% & 15.66\\% & -1.196 & 14.91\\% & -1.503 & 202 & 4.74\\% & 0.00\\% \\\\\n",
"\t\t\tGMADL Informer & 0.885 & -21.88\\% & 72.10\\% & -0.303 & 43.48\\% & -0.153 & 54 & 35.85\\% & 64.15\\% \\\\\n",
"\t\t\\end{tabular}\n",
"\t\\end{center}\n",
"\\end{table}\n",
"\\begin{table}\n",
"\t\\begin{center}\n",
"\t\t\\begin{tabular}{lccccccccc}\n",
"\t\t\t\\textbf{Strategy} & \\textbf{VAL} & \\textbf{ARC} & \\textbf{ASD} & \\textbf{IR*} & \\textbf{MD} & \\textbf{IR**} & \\textbf{N} & \\textbf{LONG} & \\textbf{SHORT} \\\\\n",
"\t\t\t\\hline\n",
"\t\t\tBuy and Hold & 1.016 & 3.26\\% & 50.58\\% & 0.065 & 37.76\\% & 0.006 & 2 & 100.00\\% & 0.00\\% \\\\\n",
"\t\t\tMACD Strategy & 1.060 & 12.62\\% & 50.57\\% & 0.250 & 38.35\\% & 0.082 & 55 & 66.38\\% & 32.66\\% \\\\\n",
"\t\t\tRSI Strategy & 0.898 & -19.62\\% & 50.65\\% & -0.387 & 25.20\\% & -0.302 & 174 & 23.30\\% & 76.70\\% \\\\\n",
"\t\t\tRMSE Informer & 0.982 & -3.55\\% & 50.69\\% & -0.070 & 34.60\\% & -0.007 & 2 & 0.00\\% & 100.00\\% \\\\\n",
"\t\t\tQuantile Informer & 1.081 & 17.17\\% & 40.53\\% & 0.424 & 31.82\\% & 0.229 & 103 & 0.00\\% & 53.36\\% \\\\\n",
"\t\t\tGMADL Informer & 1.158 & 34.60\\% & 31.80\\% & 1.088 & 18.06\\% & 2.085 & 32 & 0.00\\% & 59.07\\% \\\\\n",
"\t\t\\end{tabular}\n",
"\t\\end{center}\n",
"\\end{table}\n",
"\\begin{table}\n",
"\t\\begin{center}\n",
"\t\t\\begin{tabular}{lccccccccc}\n",
"\t\t\t\\textbf{Strategy} & \\textbf{VAL} & \\textbf{ARC} & \\textbf{ASD} & \\textbf{IR*} & \\textbf{MD} & \\textbf{IR**} & \\textbf{N} & \\textbf{LONG} & \\textbf{SHORT} \\\\\n",
"\t\t\t\\hline\n",
"\t\t\tBuy and Hold & 1.231 & 52.34\\% & 44.11\\% & 1.186 & 22.01\\% & 2.822 & 2 & 100.00\\% & 0.00\\% \\\\\n",
"\t\t\tMACD Strategy & 1.020 & 4.03\\% & 44.11\\% & 0.091 & 25.36\\% & 0.015 & 74 & 34.59\\% & 65.41\\% \\\\\n",
"\t\t\tRSI Strategy & 0.794 & -37.41\\% & 44.15\\% & -0.848 & 43.03\\% & -0.737 & 86 & 39.98\\% & 60.02\\% \\\\\n",
"\t\t\tRMSE Informer & 1.232 & 52.63\\% & 42.30\\% & 1.244 & 22.01\\% & 2.975 & 3 & 91.43\\% & 0.00\\% \\\\\n",
"\t\t\tQuantile Informer & 1.122 & 26.21\\% & 21.18\\% & 1.238 & 9.32\\% & 3.481 & 106 & 24.72\\% & 0.00\\% \\\\\n",
"\t\t\tGMADL Informer & 0.718 & -48.86\\% & 44.08\\% & -1.108 & 41.58\\% & -1.302 & 10 & 60.34\\% & 39.66\\% \\\\\n",
"\t\t\\end{tabular}\n",
"\t\\end{center}\n",
"\\end{table}\n",
"\\begin{table}\n",
"\t\\begin{center}\n",
"\t\t\\begin{tabular}{lccccccccc}\n",
"\t\t\t\\textbf{Strategy} & \\textbf{VAL} & \\textbf{ARC} & \\textbf{ASD} & \\textbf{IR*} & \\textbf{MD} & \\textbf{IR**} & \\textbf{N} & \\textbf{LONG} & \\textbf{SHORT} \\\\\n",
"\t\t\t\\hline\n",
"\t\t\tBuy and Hold & 1.440 & 109.38\\% & 44.60\\% & 2.452 & 20.31\\% & 13.204 & 2 & 100.00\\% & 0.00\\% \\\\\n",
"\t\t\tMACD Strategy & 1.218 & 49.24\\% & 33.63\\% & 1.464 & 13.88\\% & 5.195 & 118 & 50.76\\% & 0.00\\% \\\\\n",
"\t\t\tRSI Strategy & 1.440 & 109.38\\% & 44.60\\% & 2.452 & 20.31\\% & 13.204 & 2 & 100.00\\% & 0.00\\% \\\\\n",
"\t\t\tRMSE Informer & 0.832 & -31.06\\% & 13.66\\% & -2.274 & 19.29\\% & -3.662 & 4 & 0.00\\% & 4.56\\% \\\\\n",
"\t\t\tQuantile Informer & 1.206 & 46.21\\% & 37.95\\% & 1.218 & 19.49\\% & 2.887 & 147 & 78.97\\% & 0.00\\% \\\\\n",
"\t\t\tGMADL Informer & 1.398 & 97.31\\% & 44.61\\% & 2.181 & 22.22\\% & 9.554 & 26 & 99.64\\% & 0.36\\% \\\\\n",
"\t\t\\end{tabular}\n",
"\t\\end{center}\n",
"\\end{table}\n",
"\\begin{table}\n",
"\t\\begin{center}\n",
"\t\t\\begin{tabular}{lccccccccc}\n",
"\t\t\t\\textbf{Strategy} & \\textbf{VAL} & \\textbf{ARC} & \\textbf{ASD} & \\textbf{IR*} & \\textbf{MD} & \\textbf{IR**} & \\textbf{N} & \\textbf{LONG} & \\textbf{SHORT} \\\\\n",
"\t\t\t\\hline\n",
"\t\t\tBuy and Hold & 1.558 & 145.73\\% & 51.90\\% & 2.808 & 26.76\\% & 15.290 & 2 & 100.00\\% & 0.00\\% \\\\\n",
"\t\t\tMACD Strategy & 1.402 & 98.29\\% & 34.32\\% & 2.864 & 20.22\\% & 13.925 & 93 & 48.96\\% & 0.00\\% \\\\\n",
"\t\t\tRSI Strategy & 1.104 & 22.18\\% & 49.12\\% & 0.452 & 26.76\\% & 0.374 & 3 & 82.57\\% & 0.00\\% \\\\\n",
"\t\t\tRMSE Informer & 1 & 0.00\\% & 0.00\\% & 0 & 0.00\\% & 0 & 0 & 0.00\\% & 0.00\\% \\\\\n",
"\t\t\tQuantile Informer & 1.000 & 0.04\\% & 18.06\\% & 0.002 & 9.32\\% & 0.000 & 81 & 9.73\\% & 0.00\\% \\\\\n",
"\t\t\tGMADL Informer & 1.463 & 116.41\\% & 45.31\\% & 2.569 & 21.45\\% & 13.942 & 94 & 63.52\\% & 0.00\\% \\\\\n",
"\t\t\\end{tabular}\n",
"\t\\end{center}\n",
"\\end{table}\n"
]
}
],
"source": [
"# for i, (in_sample, out_of_sample) in enumerate(data_windows):\n",
"# padded_window = pd.concat([in_sample.iloc[-PADDING:], out_of_sample])\n",
"# result_buyandhold = evaluate_strategy(padded_window, best_strategies['buy_and_hold'][i], padding=PADDING, interval=INTERVAL)\n",
"# result_macd = evaluate_strategy(padded_window, [s[0] for s in best_strategies['macd_strategies']][i], padding=PADDING, interval=INTERVAL)\n",
"# result_rsi = evaluate_strategy(padded_window, [s[0] for s in best_strategies['rsi_strategies']][i], padding=PADDING, interval=INTERVAL)\n",
"# result_quantile_model = evaluate_strategy(padded_window, [s[0] for s in best_strategies['quantile_model']][i], padding=PADDING, interval=INTERVAL)\n",
"# result_gmadl_model = evaluate_strategy(padded_window, [s[0] for s in best_strategies['gmadl_model']][i], padding=PADDING, interval=INTERVAL)\n",
"for i, (in_sample, out_of_sample) in enumerate(data_windows):\n",
" padded_window = pd.concat([in_sample.iloc[-PADDING:], out_of_sample])\n",
" result_buyandhold = evaluate_strategy(padded_window, best_strategies['buy_and_hold'][i], padding=PADDING, interval=INTERVAL)\n",
" result_macd = evaluate_strategy(padded_window, [s[0] for s in best_strategies['macd_strategies']][i], padding=PADDING, interval=INTERVAL)\n",
" result_rsi = evaluate_strategy(padded_window, [s[0] for s in best_strategies['rsi_strategies']][i], padding=PADDING, interval=INTERVAL)\n",
" result_rmse_model = evaluate_strategy(padded_window, [s[0] for s in best_strategies['rmse_model']][i], padding=PADDING, interval=INTERVAL)\n",
" result_quantile_model = evaluate_strategy(padded_window, [s[0] for s in best_strategies['quantile_model']][i], padding=PADDING, interval=INTERVAL)\n",
" result_gmadl_model = evaluate_strategy(padded_window, [s[0] for s in best_strategies['gmadl_model']][i], padding=PADDING, interval=INTERVAL)\n",
"\n",
"# results_table(result_buyandhold, result_macd, result_rsi, result_quantile_model, result_gmadl_model)\n",
"# results_plot(i+1, result_buyandhold, result_macd, result_rsi, result_quantile_model, result_gmadl_model)\n",
" results_table(result_buyandhold, result_macd, result_rsi, result_rmse_model, result_quantile_model, result_gmadl_model)\n",
" # results_plot(i+1, result_buyandhold, result_macd, result_rsi, result_rmse_model, result_quantile_model, result_gmadl_model)\n",
" "
]
},
{
"cell_type": "code",
"execution_count": 2,
"execution_count": 12,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"\\begin{table}\n",
"\t\\begin{center}\n",
"\t\t\\begin{tabular}{lccccccccc}\n",
"\t\t\t\\textbf{Strategy} & \\textbf{VAL} & \\textbf{ARC} & \\textbf{ASD} & \\textbf{IR*} & \\textbf{MD} & \\textbf{IR**} & \\textbf{N} & \\textbf{LONG} & \\textbf{SHORT} \\\\\n",
"\t\t\t\\hline\n",
"\t\t\tBuy and Hold & 1.440 & 13.10\\% & 56.03\\% & 0.234 & 77.23\\% & 0.040 & 2 & 100.00\\% & 0.00\\% \\\\\n",
"\t\t\tMACD Strategy & 0.468 & -22.64\\% & 52.43\\% & -0.432 & 83.18\\% & -0.118 & 1311 & 51.80\\% & 31.33\\% \\\\\n",
"\t\t\tRSI Strategy & 0.800 & -7.28\\% & 55.66\\% & -0.131 & 66.67\\% & -0.014 & 1206 & 54.02\\% & 43.08\\% \\\\\n",
"\t\t\tRMSE Informer & 1.509 & 14.93\\% & 34.90\\% & 0.428 & 45.54\\% & 0.140 & 16 & 15.24\\% & 27.60\\% \\\\\n",
"\t\t\tQuantile Informer & 0.945 & -1.91\\% & 37.77\\% & -0.051 & 48.30\\% & -0.002 & 824 & 28.48\\% & 16.77\\% \\\\\n",
"\t\t\tGMADL Informer & 3.296 & 49.65\\% & 52.70\\% & 0.942 & 47.39\\% & 0.987 & 362 & 49.37\\% & 37.72\\% \\\\\n",
"\t\t\\end{tabular}\n",
"\t\\end{center}\n",
"\\end{table}\n"
]
}
],
"source": [
"# test_data = pd.concat([data_windows[0][0][-PADDING:]] + [data_window[1] for data_window in data_windows])\n",
"# buy_and_hold_concat = evaluate_strategy(test_data, BuyAndHoldStrategy(), padding=PADDING, interval=INTERVAL)\n",
"# macd_concat = evaluate_strategy(test_data, ConcatenatedStrategies(len(data_windows[0][1]), [s[0] for s in best_strategies['macd_strategies']], padding=PADDING), padding=PADDING, interval=INTERVAL)\n",
"# rsi_concat = evaluate_strategy(test_data, ConcatenatedStrategies(len(data_windows[0][1]), [s[0] for s in best_strategies['rsi_strategies']], padding=PADDING), padding=PADDING, interval=INTERVAL)\n",
"# quantile_model_concat = evaluate_strategy(test_data, ConcatenatedStrategies(len(data_windows[0][1]), [s[0] for s in best_strategies['quantile_model']], padding=PADDING), padding=PADDING, interval=INTERVAL)\n",
"# gmadl_model_concat = evaluate_strategy(test_data, ConcatenatedStrategies(len(data_windows[0][1]), [s[0] for s in best_strategies['gmadl_model']], padding=PADDING), padding=PADDING, interval=INTERVAL)\n",
"test_data = pd.concat([data_windows[0][0][-PADDING:]] + [data_window[1] for data_window in data_windows])\n",
"buy_and_hold_concat = evaluate_strategy(test_data, BuyAndHoldStrategy(), padding=PADDING, interval=INTERVAL)\n",
"macd_concat = evaluate_strategy(test_data, ConcatenatedStrategies(len(data_windows[0][1]), [s[0] for s in best_strategies['macd_strategies']], padding=PADDING), padding=PADDING, interval=INTERVAL)\n",
"rsi_concat = evaluate_strategy(test_data, ConcatenatedStrategies(len(data_windows[0][1]), [s[0] for s in best_strategies['rsi_strategies']], padding=PADDING), padding=PADDING, interval=INTERVAL)\n",
"rmse_model_concat = evaluate_strategy(test_data, ConcatenatedStrategies(len(data_windows[0][1]), [s[0] for s in best_strategies['rmse_model']], padding=PADDING), padding=PADDING, interval=INTERVAL)\n",
"quantile_model_concat = evaluate_strategy(test_data, ConcatenatedStrategies(len(data_windows[0][1]), [s[0] for s in best_strategies['quantile_model']], padding=PADDING), padding=PADDING, interval=INTERVAL)\n",
"gmadl_model_concat = evaluate_strategy(test_data, ConcatenatedStrategies(len(data_windows[0][1]), [s[0] for s in best_strategies['gmadl_model']], padding=PADDING), padding=PADDING, interval=INTERVAL)\n",
"\n",
"# results_table(buy_and_hold_concat, macd_concat, rsi_concat, quantile_model_concat, gmadl_model_concat)\n",
"# results_plot(0, buy_and_hold_concat, macd_concat, rsi_concat, quantile_model_concat, gmadl_model_concat, width=1200, notitle=True)\n"
]
},
{
"cell_type": "code",
"execution_count": 23,
"metadata": {},
"outputs": [],
"source": [
"# for i, (in_sample, out_of_sample) in enumerate(data_windows):\n",
"# padded_window = pd.concat([in_sample.iloc[-PADDING:], out_of_sample])\n",
"# result_buyandhold = evaluate_strategy(padded_window, buyandhold_best_strategies[i], padding=PADDING, interval='15min')\n",
"# result_macd = evaluate_strategy(padded_window, macd_best_strategies[i], padding=PADDING, interval='15min')\n",
"# result_rsi = evaluate_strategy(padded_window, rsi_best_strategies[i], padding=PADDING, interval='15min')\n",
"# result_quantile_model = evaluate_strategy(padded_window, quantile_model_best_strategies[i], padding=PADDING, interval='15min')\n",
"# result_gmadl_model = evaluate_strategy(padded_window, gmadl_model_best_strategies[i], padding=PADDING, interval='15min')\n",
"# v_lines=[data_window[1]['close_time'].iloc[-1] for data_window in data_windows][:-1]\n",
"\n",
"# go.Figure([\n",
"# go.Scatter(y=result_buyandhold['portfolio_value'], x=result_buyandhold['time'], name=result_buyandhold['strategy_name']),\n",
"# go.Scatter(y=result_macd['portfolio_value'], x=result_macd['time'], name=result_macd['strategy_name']),\n",
"# go.Scatter(y=result_rsi['portfolio_value'], x=result_rsi['time'], name=result_rsi['strategy_name']),\n",
"# go.Scatter(y=result_quantile_model['portfolio_value'], x=result_quantile_model['time'], name='Quantile Model'),\n",
"# go.Scatter(y=result_gmadl_model['portfolio_value'], x=result_gmadl_model['time'], name='GMADL model')\n",
"# ]).show()"
"results_table(buy_and_hold_concat, macd_concat, rsi_concat, rmse_model_concat, quantile_model_concat, gmadl_model_concat)\n",
"# results_plot(0, buy_and_hold_concat, macd_concat, rsi_concat, rmse_model_concat, quantile_model_concat, gmadl_model_concat, width=1300, height=500, notitle=True)\n"
]
},
{

View File

@ -2,7 +2,7 @@
"cells": [
{
"cell_type": "code",
"execution_count": 11,
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
@ -42,16 +42,17 @@
},
{
"cell_type": "code",
"execution_count": 17,
"execution_count": 2,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"\u001b[34m\u001b[1mwandb\u001b[0m: Downloading large artifact btc-usdt-30m-long:latest, 74.51MB. 6 files... \n",
"\u001b[34m\u001b[1mwandb\u001b[0m: 6 of 6 files downloaded. \n",
"Done. 0:0:0.4\n"
"Failed to detect the name of this notebook, you can set it manually with the WANDB_NOTEBOOK_NAME environment variable to enable code saving.\n",
"\u001b[34m\u001b[1mwandb\u001b[0m: Downloading large artifact btc-usdt-30m:latest, 124.19MB. 12 files... \n",
"\u001b[34m\u001b[1mwandb\u001b[0m: 12 of 12 files downloaded. \n",
"Done. 0:0:0.5\n"
]
}
],
@ -66,7 +67,7 @@
},
{
"cell_type": "code",
"execution_count": 18,
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
@ -80,7 +81,7 @@
},
{
"cell_type": "code",
"execution_count": 19,
"execution_count": 4,
"metadata": {},
"outputs": [],
"source": [
@ -89,19 +90,19 @@
},
{
"cell_type": "code",
"execution_count": 44,
"execution_count": 5,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"100%|██████████| 3840/3840 [00:04<00:00, 769.13it/s]\n",
"100%|██████████| 3840/3840 [00:04<00:00, 779.61it/s]\n",
"100%|██████████| 3840/3840 [00:05<00:00, 754.69it/s]\n",
"100%|██████████| 3840/3840 [00:06<00:00, 579.24it/s]\n",
"100%|██████████| 3840/3840 [00:04<00:00, 777.65it/s]\n",
"100%|██████████| 3840/3840 [00:04<00:00, 782.54it/s]\n"
"100%|██████████| 3840/3840 [00:05<00:00, 762.16it/s] \n",
"100%|██████████| 3840/3840 [00:04<00:00, 937.71it/s] \n",
"100%|██████████| 3840/3840 [00:03<00:00, 990.52it/s] \n",
"100%|██████████| 3840/3840 [00:04<00:00, 956.93it/s] \n",
"100%|██████████| 3840/3840 [00:04<00:00, 931.01it/s] \n",
"100%|██████████| 3840/3840 [00:04<00:00, 951.89it/s] \n"
]
}
],
@ -126,7 +127,7 @@
},
{
"cell_type": "code",
"execution_count": 14,
"execution_count": 6,
"metadata": {},
"outputs": [],
"source": [
@ -135,16 +136,19 @@
},
{
"cell_type": "code",
"execution_count": 20,
"execution_count": 7,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"100%|██████████| 11088/11088 [00:13<00:00, 814.39it/s]\n",
"100%|██████████| 11088/11088 [00:13<00:00, 802.08it/s]\n",
"100%|██████████| 11088/11088 [00:14<00:00, 771.08it/s]\n"
"100%|██████████| 11088/11088 [00:13<00:00, 838.13it/s]\n",
"100%|██████████| 11088/11088 [00:10<00:00, 1054.57it/s]\n",
"100%|██████████| 11088/11088 [00:10<00:00, 1032.31it/s]\n",
"100%|██████████| 11088/11088 [00:11<00:00, 967.27it/s] \n",
"100%|██████████| 11088/11088 [00:11<00:00, 995.52it/s] \n",
"100%|██████████| 11088/11088 [00:10<00:00, 1023.57it/s]\n"
]
}
],
@ -170,7 +174,7 @@
},
{
"cell_type": "code",
"execution_count": 89,
"execution_count": 8,
"metadata": {},
"outputs": [],
"source": [
@ -192,7 +196,7 @@
},
{
"cell_type": "code",
"execution_count": 90,
"execution_count": 9,
"metadata": {},
"outputs": [],
"source": [
@ -201,7 +205,105 @@
},
{
"cell_type": "code",
"execution_count": 46,
"execution_count": 10,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"\u001b[34m\u001b[1mwandb\u001b[0m: 2 of 2 files downloaded. \n",
"\u001b[34m\u001b[1mwandb\u001b[0m: 2 of 2 files downloaded. \n",
"\u001b[34m\u001b[1mwandb\u001b[0m: 2 of 2 files downloaded. \n",
"\u001b[34m\u001b[1mwandb\u001b[0m: 2 of 2 files downloaded. \n",
"\u001b[34m\u001b[1mwandb\u001b[0m: 2 of 2 files downloaded. \n",
"\u001b[34m\u001b[1mwandb\u001b[0m: 2 of 2 files downloaded. \n",
"\u001b[34m\u001b[1mwandb\u001b[0m: 2 of 2 files downloaded. \n",
"\u001b[34m\u001b[1mwandb\u001b[0m: 2 of 2 files downloaded. \n",
"\u001b[34m\u001b[1mwandb\u001b[0m: 2 of 2 files downloaded. \n",
"\u001b[34m\u001b[1mwandb\u001b[0m: 2 of 2 files downloaded. \n",
"\u001b[34m\u001b[1mwandb\u001b[0m: 2 of 2 files downloaded. \n",
"\u001b[34m\u001b[1mwandb\u001b[0m: 2 of 2 files downloaded. \n",
"\u001b[34m\u001b[1mwandb\u001b[0m: 2 of 2 files downloaded. \n",
"\u001b[34m\u001b[1mwandb\u001b[0m: 2 of 2 files downloaded. \n",
"\u001b[34m\u001b[1mwandb\u001b[0m: 2 of 2 files downloaded. \n",
"\u001b[34m\u001b[1mwandb\u001b[0m: 2 of 2 files downloaded. \n",
"\u001b[34m\u001b[1mwandb\u001b[0m: 2 of 2 files downloaded. \n",
"\u001b[34m\u001b[1mwandb\u001b[0m: 2 of 2 files downloaded. \n"
]
}
],
"source": [
"# Model with rmse loss\n",
"SWEEP_ID = 'filipstefaniuk/wne-masters-thesis-testing/j9d5r6tg'\n",
"train_pred_windows = get_sweep_window_predictions(SWEEP_ID, 'train')\n",
"valid_pred_windows = get_sweep_window_predictions(SWEEP_ID, 'valid')\n",
"test_pred_windows = get_sweep_window_predictions(SWEEP_ID, 'test')"
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"100%|██████████| 1176/1176 [00:20<00:00, 57.99it/s]\n",
"100%|██████████| 1176/1176 [00:20<00:00, 58.14it/s]\n",
"100%|██████████| 1176/1176 [00:20<00:00, 57.39it/s]\n",
"100%|██████████| 1176/1176 [00:20<00:00, 57.46it/s]\n",
"100%|██████████| 1176/1176 [00:22<00:00, 52.43it/s]\n",
"100%|██████████| 1176/1176 [00:20<00:00, 57.39it/s]\n"
]
}
],
"source": [
"MODEL_RMSE_LOSS_FILTER = lambda p: (\n",
" ((p['enter_long'] is not None and (p['enter_short'] is not None or p['exit_long'] is not None))\n",
" or (p['enter_short'] is not None and (p['exit_short'] is not None or p['enter_long'] is not None)))\n",
" and (p['enter_short'] is None or p['exit_long'] is None or (p['exit_long'] > p['enter_short']))\n",
" and (p['enter_long'] is None or p['exit_short'] is None or (p['exit_short'] < p['enter_long'])))\n",
"\n",
"rmse_model_sweep_results = []\n",
"for (in_sample, _), train_preds, valid_preds, test_preds in zip(data_windows, train_pred_windows, valid_pred_windows, test_pred_windows):\n",
" data_part = int((1 - VALID_PART) * len(in_sample))\n",
" params={\n",
" 'predictions': [get_predictions_dataframe(train_preds, valid_preds, test_preds)],\n",
" 'enter_long': [None, 0.001, 0.002, 0.003, 0.004, 0.005, 0.006, 0.007],\n",
" 'exit_long': [None, -0.001, -0.002, -0.003, -0.004, -0.005, -0.006, -0.007],\n",
" 'enter_short': [None, -0.001, -0.002, -0.003, -0.004, -0.005, -0.006, -0.007],\n",
" 'exit_short': [None, 0.001, 0.002, 0.003, 0.004, 0.005, 0.006, 0.007],\n",
" # 'enter_short': [None],\n",
" # 'exit_short': [None],\n",
" }\n",
" \n",
" rmse_model_sweep_results.append(parameter_sweep(\n",
" in_sample[data_part-PADDING:],\n",
" ModelGmadlPredictionsStrategy,\n",
" params,\n",
" params_filter=MODEL_RMSE_LOSS_FILTER,\n",
" padding=PADDING,\n",
" interval=INTERVAL,\n",
" sort_by=METRIC))\n",
" \n",
"\n",
"rmse_model_best_strategies = [[strat for _, strat in results[:TOP_N]] for results in rmse_model_sweep_results]"
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {},
"outputs": [],
"source": [
"# plot_sweep_results(pd.DataFrame([result for result, _ in rmse_model_sweep_results[0]]), parameters=['enter_long', 'exit_long', 'enter_short', 'exit_short'], round=5)"
]
},
{
"cell_type": "code",
"execution_count": 12,
"metadata": {},
"outputs": [
{
@ -239,19 +341,19 @@
},
{
"cell_type": "code",
"execution_count": 48,
"execution_count": 13,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"100%|██████████| 1125/1125 [00:28<00:00, 40.16it/s]\n",
"100%|██████████| 1125/1125 [00:27<00:00, 41.37it/s]\n",
"100%|██████████| 1125/1125 [00:27<00:00, 41.47it/s]\n",
"100%|██████████| 1125/1125 [00:27<00:00, 40.47it/s]\n",
"100%|██████████| 1125/1125 [00:25<00:00, 44.84it/s]\n",
"100%|██████████| 1125/1125 [00:25<00:00, 44.11it/s]\n"
"100%|██████████| 1125/1125 [00:23<00:00, 47.74it/s]\n",
"100%|██████████| 1125/1125 [00:23<00:00, 48.10it/s]\n",
"100%|██████████| 1125/1125 [00:23<00:00, 47.79it/s]\n",
"100%|██████████| 1125/1125 [00:23<00:00, 47.27it/s]\n",
"100%|██████████| 1125/1125 [00:23<00:00, 47.82it/s]\n",
"100%|██████████| 1125/1125 [00:23<00:00, 47.74it/s]\n"
]
}
],
@ -293,7 +395,7 @@
},
{
"cell_type": "code",
"execution_count": 12,
"execution_count": 14,
"metadata": {},
"outputs": [],
"source": [
@ -302,7 +404,7 @@
},
{
"cell_type": "code",
"execution_count": 50,
"execution_count": 5,
"metadata": {},
"outputs": [
{
@ -333,7 +435,9 @@
"source": [
"# Model with gmadl loss\n",
"# SWEEP_ID = 'filipstefaniuk/wne-masters-thesis-testing/tmqx4epx'\n",
"SWEEP_ID = 'filipstefaniuk/wne-masters-thesis-testing/7p7tdxbn'\n",
"# SWEEP_ID = 'filipstefaniuk/wne-masters-thesis-testing/7p7tdxbn' (old)\n",
"# SWEEP_ID = 'filipstefaniuk/wne-masters-thesis-testing/7x42xn5j'\n",
"SWEEP_ID = 'filipstefaniuk/wne-masters-thesis-testing/z776cpvj'\n",
"train_gmadl_pred_windows = get_sweep_window_predictions(SWEEP_ID, 'train')\n",
"valid_gmadl_pred_windows = get_sweep_window_predictions(SWEEP_ID, 'valid')\n",
"test_gmadl_pred_windows = get_sweep_window_predictions(SWEEP_ID, 'test')"
@ -341,19 +445,19 @@
},
{
"cell_type": "code",
"execution_count": 51,
"execution_count": 6,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"100%|██████████| 1176/1176 [00:22<00:00, 51.45it/s]\n",
"100%|██████████| 1176/1176 [00:24<00:00, 48.45it/s]\n",
"100%|██████████| 1176/1176 [00:21<00:00, 53.53it/s]\n",
"100%|██████████| 1176/1176 [00:24<00:00, 48.36it/s]\n",
"100%|██████████| 1176/1176 [00:22<00:00, 51.90it/s]\n",
"100%|██████████| 1176/1176 [00:21<00:00, 54.04it/s]\n"
"100%|██████████| 1176/1176 [00:20<00:00, 58.39it/s]\n",
"100%|██████████| 1176/1176 [00:20<00:00, 57.42it/s]\n",
"100%|██████████| 1176/1176 [00:20<00:00, 57.34it/s]\n",
"100%|██████████| 1176/1176 [00:20<00:00, 57.48it/s]\n",
"100%|██████████| 1176/1176 [00:20<00:00, 58.43it/s]\n",
"100%|██████████| 1176/1176 [00:20<00:00, 57.45it/s]\n"
]
}
],
@ -401,7 +505,7 @@
},
{
"cell_type": "code",
"execution_count": 21,
"execution_count": 7,
"metadata": {},
"outputs": [],
"source": [
@ -410,11 +514,12 @@
" 'buy_and_hold': buyandhold_best_strategies,\n",
" 'macd_strategies': macd_best_strategies,\n",
" 'rsi_strategies': rsi_best_strategies,\n",
" 'rmse_model': rmse_model_best_strategies,\n",
" 'quantile_model': quantile_model_best_strategies,\n",
" 'gmadl_model': gmadl_model_best_strategies\n",
"}\n",
"\n",
"with open('cache/30min-best-strategies-long.pkl', 'wb') as outp:\n",
"with open('cache/30min-best-strategies-v6.pkl', 'wb') as outp:\n",
" pickle.dump(best_strategies, outp, pickle.HIGHEST_PROTOCOL)"
]
},
@ -427,12 +532,18 @@
},
{
"cell_type": "code",
"execution_count": 4,
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
"with open('cache/30min-best-strategies.pkl', 'rb') as inpt:\n",
" best_strategies = pickle.load(inpt)"
"with open('cache/30min-best-strategies-v6.pkl', 'rb') as inpt:\n",
" best_strategies = pickle.load(inpt)\n",
" buyandhold_best_strategies = best_strategies['buy_and_hold']\n",
" macd_best_strategies = best_strategies['macd_strategies']\n",
" rsi_best_strategies = best_strategies['rsi_strategies']\n",
" rmse_model_best_strategies = best_strategies['rmse_model']\n",
" quantile_model_best_strategies = best_strategies['quantile_model']\n",
" gmadl_model_best_strategies = best_strategies['gmadl_model']"
]
},
{
@ -599,7 +710,7 @@
},
{
"cell_type": "code",
"execution_count": 60,
"execution_count": 4,
"metadata": {},
"outputs": [
{
@ -611,12 +722,62 @@
"\t\t\\begin{tabular}{lcccc}\n",
"\t\t\t\\textbf{Window} & \\textbf{\\textit{enter long}} & \\textbf{\\textit{exit Long}} & \\textbf{\\textit{enter Short}} & \\textbf{\\textit{exit Short}} \\\\\n",
"\t\t\t\\hline\n",
"\t\t\tW1-30min & 0.007 & - & -0.001 & - \\\\\n",
"\t\t\tW2-30min & 0.003 & - & -0.007 & - \\\\\n",
"\t\t\tW3-30min & - & - & -0.001 & 0.005 \\\\\n",
"\t\t\tW4-30min & 0.002 & - & -0.006 & - \\\\\n",
"\t\t\tW5-30min & 0.005 & -0.001 & - & - \\\\\n",
"\t\t\tW6-30min & 0.003 & - & -0.004 & - \\\\\n",
"\t\t\tW1-30min & 0.002 & - & -0.003 & - \\\\\n",
"\t\t\tW2-30min & - & - & -0.002 & 0.001 \\\\\n",
"\t\t\tW3-30min & - & - & -0.001 & 0.002 \\\\\n",
"\t\t\tW4-30min & 0.001 & - & -0.002 & - \\\\\n",
"\t\t\tW5-30min & 0.001 & - & -0.002 & - \\\\\n",
"\t\t\tW6-30min & 0.001 & - & -0.002 & - \\\\\n",
"\t\t\\end{tabular}\n",
"\t\\end{center}\n",
"\\end{table}\n"
]
}
],
"source": [
"table_rmse_params = Texttable()\n",
"table_rmse_params.set_deco(Texttable.HEADER)\n",
"table_rmse_params.set_cols_align([\"l\", \"c\",\"c\", \"c\", \"c\"])\n",
"table_rmse_params.header([\n",
" \"\\\\textbf{Window}\",\n",
" \"\\\\textbf{\\\\textit{enter long}}\",\n",
" \"\\\\textbf{\\\\textit{exit Long}}\",\n",
" \"\\\\textbf{\\\\textit{enter Short}}\",\n",
" \"\\\\textbf{\\\\textit{exit Short}}\",\n",
"])\n",
"\n",
"for i, rmse_strategy in enumerate(best_strategies['rmse_model']):\n",
" rmse_strategy_info = rmse_strategy[0].info()\n",
" table_rmse_params.add_row([\n",
" f\"W{i+1}-{INTERVAL}\",\n",
" rmse_strategy_info['enter_long'] or '-',\n",
" rmse_strategy_info['exit_long'] or '-',\n",
" rmse_strategy_info['enter_short'] or '-',\n",
" rmse_strategy_info['exit_short'] or '-'\n",
" ])\n",
"print(latextable.draw_latex(table_rmse_params))"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"\\begin{table}\n",
"\t\\begin{center}\n",
"\t\t\\begin{tabular}{lcccc}\n",
"\t\t\t\\textbf{Window} & \\textbf{\\textit{enter long}} & \\textbf{\\textit{exit Long}} & \\textbf{\\textit{enter Short}} & \\textbf{\\textit{exit Short}} \\\\\n",
"\t\t\t\\hline\n",
"\t\t\tW1-30min & - & - & -0.007 & 0.005 \\\\\n",
"\t\t\tW2-30min & - & -0.006 & -0.007 & 0.004 \\\\\n",
"\t\t\tW3-30min & - & - & -0.004 & 0.007 \\\\\n",
"\t\t\tW4-30min & 0.003 & -0.007 & - & - \\\\\n",
"\t\t\tW5-30min & 0.006 & - & -0.004 & - \\\\\n",
"\t\t\tW6-30min & 0.001 & - & -0.005 & - \\\\\n",
"\t\t\\end{tabular}\n",
"\t\\end{center}\n",
"\\end{table}\n"
@ -656,19 +817,32 @@
},
{
"cell_type": "code",
"execution_count": 9,
"execution_count": 12,
"metadata": {},
"outputs": [],
"source": [
"def results_plot(idx, result_buyandhold, result_macd, result_rsi, result_quantile_model, result_gmadl_model, width=850, height=500, notitle=False):\n",
"def results_plot(idx, result_buyandhold, result_macd, result_rsi, result_rmse_model, result_quantile_model, result_gmadl_model, width=850, height=500, notitle=False, v_lines=None):\n",
"\n",
" fig = go.Figure([\n",
" go.Scatter(y=result_buyandhold['portfolio_value'], x=result_buyandhold['time'], name=\"Buy and Hold\"),\n",
" go.Scatter(y=result_macd['portfolio_value'], x=result_macd['time'], name=\"MACD Strategy\"),\n",
" go.Scatter(y=result_rsi['portfolio_value'], x=result_rsi['time'], name=\"RSI Strategy\"),\n",
" go.Scatter(y=result_rmse_model['portfolio_value'], x=result_rmse_model['time'], name='RMSE Informer Strategy'),\n",
" go.Scatter(y=result_quantile_model['portfolio_value'], x=result_quantile_model['time'], name='Quantile Informer Strategy'),\n",
" go.Scatter(y=result_gmadl_model['portfolio_value'], x=result_gmadl_model['time'], name='GMADL Informer Strategy')\n",
" ])\n",
" \n",
" if v_lines:\n",
" for v_line in v_lines:\n",
" fig.add_shape(\n",
" go.layout.Shape(type=\"line\",\n",
" yref=\"paper\",\n",
" xref=\"x\",\n",
" x0=v_line,\n",
" x1=v_line,\n",
" y0=0,\n",
" y1=1,\n",
" line=dict(width=1.5, dash='dash', color='rgb(140,140,140)')))\n",
" fig.update_layout(\n",
" title={\n",
" 'text': f\"W{idx}-{INTERVAL}\",\n",
@ -712,7 +886,7 @@
" fig.write_image(f\"images/eval-w{idx}-{INTERVAL}.png\")\n",
" fig.show()\n",
" \n",
"def results_table(result_buyandhold, result_macd, result_rsi, result_quantile_model, result_gmadl_model):\n",
"def results_table(result_buyandhold, result_macd, result_rsi, result_rmse_model, result_quantile_model, result_gmadl_model):\n",
" table_eval_windows = Texttable()\n",
" table_eval_windows.set_deco(Texttable.HEADER)\n",
" table_eval_windows.set_cols_align([\"l\", \"c\",\"c\", \"c\", \"c\", \"c\", \"c\", \"c\", \"c\", \"c\"])\n",
@ -735,6 +909,7 @@
" ('Buy and Hold', result_buyandhold),\n",
" ('MACD Strategy', result_macd),\n",
" ('RSI Strategy', result_rsi),\n",
" ('RMSE Informer', result_rmse_model),\n",
" ('Quantile Informer', result_quantile_model),\n",
" ('GMADL Informer', result_gmadl_model)\n",
" ]\n",
@ -742,14 +917,14 @@
" table_eval_windows.add_row([\n",
" strategy_name,\n",
" result['value'],\n",
" f\"{result['arc']*100:.1f}\\%\",\n",
" f\"{result['asd']*100:.1f}\\%\",\n",
" f\"{result['arc']*100:.2f}\\%\",\n",
" f\"{result['asd']*100:.2f}\\%\",\n",
" result['ir'],\n",
" f\"{result['md']*100:.1f}\\%\",\n",
" f\"{result['md']*100:.2f}\\%\",\n",
" result['mod_ir'],\n",
" result['n_trades'],\n",
" f\"{result['long_pos']*100:.1f}\\%\",\n",
" f\"{result['short_pos']*100:.1f}\\%\",\n",
" f\"{result['long_pos']*100:.2f}\\%\",\n",
" f\"{result['short_pos']*100:.2f}\\%\",\n",
" ])\n",
" print(latextable.draw_latex(table_eval_windows))\n",
"\n"
@ -757,20 +932,112 @@
},
{
"cell_type": "code",
"execution_count": 22,
"execution_count": 18,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"\\begin{table}\n",
"\t\\begin{center}\n",
"\t\t\\begin{tabular}{lccccccccc}\n",
"\t\t\t\\textbf{Strategy} & \\textbf{VAL} & \\textbf{ARC} & \\textbf{ASD} & \\textbf{IR*} & \\textbf{MD} & \\textbf{IR**} & \\textbf{N} & \\textbf{LONG} & \\textbf{SHORT} \\\\\n",
"\t\t\t\\hline\n",
"\t\t\tBuy and Hold & 0.924 & -14.84\\% & 66.12\\% & -0.225 & 51.75\\% & -0.064 & 2 & 100.00\\% & 0.00\\% \\\\\n",
"\t\t\tMACD Strategy & 1.269 & 62.19\\% & 65.90\\% & 0.944 & 31.81\\% & 1.845 & 15 & 50.36\\% & 47.71\\% \\\\\n",
"\t\t\tRSI Strategy & 1.843 & 245.59\\% & 66.51\\% & 3.693 & 35.02\\% & 25.897 & 26 & 42.40\\% & 57.60\\% \\\\\n",
"\t\t\tRMSE Informer & 0.924 & -14.84\\% & 66.12\\% & -0.225 & 51.75\\% & -0.064 & 2 & 100.00\\% & 0.00\\% \\\\\n",
"\t\t\tQuantile Informer & 0.743 & -45.20\\% & 60.57\\% & -0.746 & 29.11\\% & -1.159 & 443 & 30.43\\% & 53.98\\% \\\\\n",
"\t\t\tGMADL Informer & 1.030 & 6.23\\% & 19.98\\% & 0.312 & 10.01\\% & 0.194 & 39 & 0.00\\% & 8.72\\% \\\\\n",
"\t\t\\end{tabular}\n",
"\t\\end{center}\n",
"\\end{table}\n",
"\\begin{table}\n",
"\t\\begin{center}\n",
"\t\t\\begin{tabular}{lccccccccc}\n",
"\t\t\t\\textbf{Strategy} & \\textbf{VAL} & \\textbf{ARC} & \\textbf{ASD} & \\textbf{IR*} & \\textbf{MD} & \\textbf{IR**} & \\textbf{N} & \\textbf{LONG} & \\textbf{SHORT} \\\\\n",
"\t\t\t\\hline\n",
"\t\t\tBuy and Hold & 0.548 & -70.51\\% & 72.38\\% & -0.974 & 63.18\\% & -1.087 & 2 & 100.00\\% & 0.00\\% \\\\\n",
"\t\t\tMACD Strategy & 1.303 & 70.93\\% & 71.82\\% & 0.988 & 36.06\\% & 1.943 & 19 & 57.32\\% & 40.76\\% \\\\\n",
"\t\t\tRSI Strategy & 1.703 & 194.24\\% & 72.36\\% & 2.684 & 34.89\\% & 14.945 & 106 & 39.96\\% & 60.04\\% \\\\\n",
"\t\t\tRMSE Informer & 1.387 & 94.09\\% & 41.55\\% & 2.264 & 16.34\\% & 13.037 & 8 & 0.00\\% & 34.41\\% \\\\\n",
"\t\t\tQuantile Informer & 1.403 & 98.74\\% & 27.62\\% & 3.575 & 9.44\\% & 37.393 & 255 & 0.00\\% & 18.79\\% \\\\\n",
"\t\t\tGMADL Informer & 1.050 & 10.44\\% & 23.40\\% & 0.446 & 14.45\\% & 0.322 & 90 & 0.00\\% & 5.98\\% \\\\\n",
"\t\t\\end{tabular}\n",
"\t\\end{center}\n",
"\\end{table}\n",
"\\begin{table}\n",
"\t\\begin{center}\n",
"\t\t\\begin{tabular}{lccccccccc}\n",
"\t\t\t\\textbf{Strategy} & \\textbf{VAL} & \\textbf{ARC} & \\textbf{ASD} & \\textbf{IR*} & \\textbf{MD} & \\textbf{IR**} & \\textbf{N} & \\textbf{LONG} & \\textbf{SHORT} \\\\\n",
"\t\t\t\\hline\n",
"\t\t\tBuy and Hold & 1.018 & 3.75\\% & 51.25\\% & 0.073 & 37.47\\% & 0.007 & 2 & 100.00\\% & 0.00\\% \\\\\n",
"\t\t\tMACD Strategy & 0.673 & -55.16\\% & 51.01\\% & -1.081 & 59.24\\% & -1.007 & 95 & 81.60\\% & 16.48\\% \\\\\n",
"\t\t\tRSI Strategy & 0.988 & -2.50\\% & 38.04\\% & -0.066 & 30.42\\% & -0.005 & 238 & 2.34\\% & 50.54\\% \\\\\n",
"\t\t\tRMSE Informer & 0.980 & -4.00\\% & 51.36\\% & -0.078 & 34.51\\% & -0.009 & 2 & 0.00\\% & 100.00\\% \\\\\n",
"\t\t\tQuantile Informer & 0.884 & -22.19\\% & 23.41\\% & -0.948 & 18.39\\% & -1.144 & 171 & 0.00\\% & 18.83\\% \\\\\n",
"\t\t\tGMADL Informer & 0.737 & -46.11\\% & 42.58\\% & -1.083 & 42.71\\% & -1.169 & 302 & 0.00\\% & 81.21\\% \\\\\n",
"\t\t\\end{tabular}\n",
"\t\\end{center}\n",
"\\end{table}\n",
"\\begin{table}\n",
"\t\\begin{center}\n",
"\t\t\\begin{tabular}{lccccccccc}\n",
"\t\t\t\\textbf{Strategy} & \\textbf{VAL} & \\textbf{ARC} & \\textbf{ASD} & \\textbf{IR*} & \\textbf{MD} & \\textbf{IR**} & \\textbf{N} & \\textbf{LONG} & \\textbf{SHORT} \\\\\n",
"\t\t\t\\hline\n",
"\t\t\tBuy and Hold & 1.229 & 51.90\\% & 45.01\\% & 1.153 & 21.74\\% & 2.753 & 2 & 100.00\\% & 0.00\\% \\\\\n",
"\t\t\tMACD Strategy & 1.031 & 6.45\\% & 45.08\\% & 0.143 & 30.15\\% & 0.031 & 94 & 35.18\\% & 64.82\\% \\\\\n",
"\t\t\tRSI Strategy & 1.010 & 2.03\\% & 1.87\\% & 1.084 & 0.30\\% & 7.410 & 4 & 0.02\\% & 0.00\\% \\\\\n",
"\t\t\tRMSE Informer & 1.414 & 101.80\\% & 45.03\\% & 2.260 & 21.74\\% & 10.584 & 10 & 92.95\\% & 7.05\\% \\\\\n",
"\t\t\tQuantile Informer & 0.629 & -60.99\\% & 28.76\\% & -2.121 & 39.23\\% & -3.297 & 448 & 36.32\\% & 0.00\\% \\\\\n",
"\t\t\tGMADL Informer & 1.054 & 11.31\\% & 28.25\\% & 0.400 & 24.18\\% & 0.187 & 345 & 34.69\\% & 0.00\\% \\\\\n",
"\t\t\\end{tabular}\n",
"\t\\end{center}\n",
"\\end{table}\n",
"\\begin{table}\n",
"\t\\begin{center}\n",
"\t\t\\begin{tabular}{lccccccccc}\n",
"\t\t\t\\textbf{Strategy} & \\textbf{VAL} & \\textbf{ARC} & \\textbf{ASD} & \\textbf{IR*} & \\textbf{MD} & \\textbf{IR**} & \\textbf{N} & \\textbf{LONG} & \\textbf{SHORT} \\\\\n",
"\t\t\t\\hline\n",
"\t\t\tBuy and Hold & 1.439 & 109.30\\% & 41.49\\% & 2.634 & 20.18\\% & 14.265 & 2 & 100.00\\% & 0.00\\% \\\\\n",
"\t\t\tMACD Strategy & 1.393 & 95.71\\% & 31.47\\% & 3.041 & 15.00\\% & 19.407 & 90 & 48.66\\% & 0.00\\% \\\\\n",
"\t\t\tRSI Strategy & 1.439 & 109.30\\% & 41.49\\% & 2.634 & 20.18\\% & 14.265 & 2 & 100.00\\% & 0.00\\% \\\\\n",
"\t\t\tRMSE Informer & 1.439 & 109.30\\% & 41.49\\% & 2.634 & 20.18\\% & 14.265 & 2 & 100.00\\% & 0.00\\% \\\\\n",
"\t\t\tQuantile Informer & 1.277 & 64.08\\% & 34.28\\% & 1.869 & 16.61\\% & 7.212 & 311 & 76.90\\% & 0.00\\% \\\\\n",
"\t\t\tGMADL Informer & 1.672 & 183.71\\% & 41.56\\% & 4.420 & 20.18\\% & 40.230 & 22 & 78.48\\% & 21.52\\% \\\\\n",
"\t\t\\end{tabular}\n",
"\t\\end{center}\n",
"\\end{table}\n",
"\\begin{table}\n",
"\t\\begin{center}\n",
"\t\t\\begin{tabular}{lccccccccc}\n",
"\t\t\t\\textbf{Strategy} & \\textbf{VAL} & \\textbf{ARC} & \\textbf{ASD} & \\textbf{IR*} & \\textbf{MD} & \\textbf{IR**} & \\textbf{N} & \\textbf{LONG} & \\textbf{SHORT} \\\\\n",
"\t\t\t\\hline\n",
"\t\t\tBuy and Hold & 1.559 & 145.95\\% & 52.85\\% & 2.762 & 26.69\\% & 15.103 & 2 & 100.00\\% & 0.00\\% \\\\\n",
"\t\t\tMACD Strategy & 1.227 & 51.44\\% & 36.38\\% & 1.414 & 18.55\\% & 3.921 & 11 & 40.69\\% & 0.00\\% \\\\\n",
"\t\t\tRSI Strategy & 1 & 0.00\\% & 0.00\\% & 0 & 0.00\\% & 0 & 0 & 0.00\\% & 0.00\\% \\\\\n",
"\t\t\tRMSE Informer & 1.059 & 12.32\\% & 52.86\\% & 0.233 & 41.44\\% & 0.069 & 10 & 93.44\\% & 6.56\\% \\\\\n",
"\t\t\tQuantile Informer & 0.855 & -27.14\\% & 34.50\\% & -0.787 & 35.23\\% & -0.606 & 150 & 37.79\\% & 0.00\\% \\\\\n",
"\t\t\tGMADL Informer & 1.617 & 165.10\\% & 52.85\\% & 3.124 & 24.64\\% & 20.929 & 10 & 99.88\\% & 0.12\\% \\\\\n",
"\t\t\\end{tabular}\n",
"\t\\end{center}\n",
"\\end{table}\n"
]
}
],
"source": [
"# for i, (in_sample, out_of_sample) in enumerate(data_windows):\n",
"# padded_window = pd.concat([in_sample.iloc[-PADDING:], out_of_sample])\n",
"# result_buyandhold = evaluate_strategy(padded_window, best_strategies['buy_and_hold'][i], padding=PADDING, interval=INTERVAL)\n",
"# result_macd = evaluate_strategy(padded_window, [s[0] for s in best_strategies['macd_strategies']][i], padding=PADDING, interval=INTERVAL)\n",
"# result_rsi = evaluate_strategy(padded_window, [s[0] for s in best_strategies['rsi_strategies']][i], padding=PADDING, interval=INTERVAL)\n",
"# result_quantile_model = evaluate_strategy(padded_window, [s[0] for s in best_strategies['quantile_model']][i], padding=PADDING, interval=INTERVAL)\n",
"# result_gmadl_model = evaluate_strategy(padded_window, [s[0] for s in best_strategies['gmadl_model']][i], padding=PADDING, interval=INTERVAL)\n",
"for i, (in_sample, out_of_sample) in enumerate(data_windows):\n",
" padded_window = pd.concat([in_sample.iloc[-PADDING:], out_of_sample])\n",
" result_buyandhold = evaluate_strategy(padded_window, best_strategies['buy_and_hold'][i], padding=PADDING, interval=INTERVAL)\n",
" result_macd = evaluate_strategy(padded_window, [s[0] for s in best_strategies['macd_strategies']][i], padding=PADDING, interval=INTERVAL)\n",
" result_rsi = evaluate_strategy(padded_window, [s[0] for s in best_strategies['rsi_strategies']][i], padding=PADDING, interval=INTERVAL)\n",
" result_rmse_model = evaluate_strategy(padded_window, [s[0] for s in best_strategies['rmse_model']][i], padding=PADDING, interval=INTERVAL)\n",
" result_quantile_model = evaluate_strategy(padded_window, [s[0] for s in best_strategies['quantile_model']][i], padding=PADDING, interval=INTERVAL)\n",
" result_gmadl_model = evaluate_strategy(padded_window, [s[0] for s in best_strategies['gmadl_model']][i], padding=PADDING, interval=INTERVAL)\n",
"\n",
"# results_table(result_buyandhold, result_macd, result_rsi, result_quantile_model, result_gmadl_model)\n",
"# results_plot(i+1, result_buyandhold, result_macd, result_rsi, result_quantile_model, result_gmadl_model)\n",
" results_table(result_buyandhold, result_macd, result_rsi, result_rmse_model, result_quantile_model, result_gmadl_model)\n",
" # results_plot(i+1, result_buyandhold, result_macd, result_rsi, result_rmse_model, result_quantile_model, result_gmadl_model)\n",
" \n"
]
},
@ -783,20 +1050,51 @@
},
{
"cell_type": "code",
"execution_count": 2,
"execution_count": 19,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"\\begin{table}\n",
"\t\\begin{center}\n",
"\t\t\\begin{tabular}{lccccccccc}\n",
"\t\t\t\\textbf{Strategy} & \\textbf{VAL} & \\textbf{ARC} & \\textbf{ASD} & \\textbf{IR*} & \\textbf{MD} & \\textbf{IR**} & \\textbf{N} & \\textbf{LONG} & \\textbf{SHORT} \\\\\n",
"\t\t\t\\hline\n",
"\t\t\tBuy and Hold & 1.440 & 13.12\\% & 55.95\\% & 0.235 & 77.20\\% & 0.040 & 2 & 100.00\\% & 0.00\\% \\\\\n",
"\t\t\tMACD Strategy & 1.952 & 25.37\\% & 52.36\\% & 0.485 & 59.24\\% & 0.207 & 327 & 52.30\\% & 28.30\\% \\\\\n",
"\t\t\tRSI Strategy & 4.542 & 66.77\\% & 46.25\\% & 1.444 & 39.91\\% & 2.415 & 377 & 30.79\\% & 28.03\\% \\\\\n",
"\t\t\tRMSE Informer & 2.727 & 40.37\\% & 50.47\\% & 0.800 & 51.75\\% & 0.624 & 34 & 64.40\\% & 24.67\\% \\\\\n",
"\t\t\tQuantile Informer & 0.629 & -14.51\\% & 36.91\\% & -0.393 & 55.09\\% & -0.104 & 1783 & 30.24\\% & 15.27\\% \\\\\n",
"\t\t\tGMADL Informer & 2.263 & 31.79\\% & 36.70\\% & 0.866 & 53.35\\% & 0.516 & 811 & 35.51\\% & 19.59\\% \\\\\n",
"\t\t\\end{tabular}\n",
"\t\\end{center}\n",
"\\end{table}\n"
]
}
],
"source": [
"test_data = pd.concat([data_windows[0][0][-PADDING:]] + [data_window[1] for data_window in data_windows])\n",
"buy_and_hold_concat = evaluate_strategy(test_data, BuyAndHoldStrategy(), padding=PADDING, interval=INTERVAL)\n",
"macd_concat = evaluate_strategy(test_data, ConcatenatedStrategies(len(data_windows[0][1]), [s[0] for s in best_strategies['macd_strategies']], padding=PADDING), padding=PADDING, interval=INTERVAL)\n",
"rsi_concat = evaluate_strategy(test_data, ConcatenatedStrategies(len(data_windows[0][1]), [s[0] for s in best_strategies['rsi_strategies']], padding=PADDING), padding=PADDING, interval=INTERVAL)\n",
"rmse_model_concat = evaluate_strategy(test_data, ConcatenatedStrategies(len(data_windows[0][1]), [s[0] for s in best_strategies['rmse_model']], padding=PADDING), padding=PADDING, interval=INTERVAL)\n",
"quantile_model_concat = evaluate_strategy(test_data, ConcatenatedStrategies(len(data_windows[0][1]), [s[0] for s in best_strategies['quantile_model']], padding=PADDING), padding=PADDING, interval=INTERVAL)\n",
"gmadl_model_concat = evaluate_strategy(test_data, ConcatenatedStrategies(len(data_windows[0][1]), [s[0] for s in best_strategies['gmadl_model']], padding=PADDING), padding=PADDING, interval=INTERVAL)\n",
"\n",
"# v_lines=[data_window[1]['close_time'].iloc[-1] for data_window in data_windows][:-1]\n",
"\n",
"results_table(buy_and_hold_concat, macd_concat, rsi_concat, rmse_model_concat, quantile_model_concat, gmadl_model_concat)\n",
"# results_plot(0, buy_and_hold_concat, macd_concat, rsi_concat, rmse_model_concat, quantile_model_concat, gmadl_model_concat, width=1200, height=500, notitle=True)\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# test_data = pd.concat([data_windows[0][0][-PADDING:]] + [data_window[1] for data_window in data_windows])\n",
"# buy_and_hold_concat = evaluate_strategy(test_data, BuyAndHoldStrategy(), padding=PADDING, interval=INTERVAL)\n",
"# macd_concat = evaluate_strategy(test_data, ConcatenatedStrategies(len(data_windows[0][1]), [s[0] for s in best_strategies['macd_strategies']], padding=PADDING), padding=PADDING, interval=INTERVAL)\n",
"# rsi_concat = evaluate_strategy(test_data, ConcatenatedStrategies(len(data_windows[0][1]), [s[0] for s in best_strategies['rsi_strategies']], padding=PADDING), padding=PADDING, interval=INTERVAL)\n",
"# quantile_model_concat = evaluate_strategy(test_data, ConcatenatedStrategies(len(data_windows[0][1]), [s[0] for s in best_strategies['quantile_model']], padding=PADDING), padding=PADDING, interval=INTERVAL)\n",
"# gmadl_model_concat = evaluate_strategy(test_data, ConcatenatedStrategies(len(data_windows[0][1]), [s[0] for s in best_strategies['gmadl_model']], padding=PADDING), padding=PADDING, interval=INTERVAL)\n",
"\n",
"# results_table(buy_and_hold_concat, macd_concat, rsi_concat, quantile_model_concat, gmadl_model_concat)\n",
"# results_plot(0, buy_and_hold_concat, macd_concat, rsi_concat, quantile_model_concat, gmadl_model_concat, width=1200, notitle=True)\n"
]
"source": []
}
],
"metadata": {

View File

@ -2,7 +2,7 @@
"cells": [
{
"cell_type": "code",
"execution_count": 18,
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
@ -41,16 +41,17 @@
},
{
"cell_type": "code",
"execution_count": 19,
"execution_count": 2,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"\u001b[34m\u001b[1mwandb\u001b[0m: Downloading large artifact btc-usdt-5m-short:latest, 1341.36MB. 24 files... \n",
"\u001b[34m\u001b[1mwandb\u001b[0m: 24 of 24 files downloaded. \n",
"Done. 0:0:1.1\n"
"Failed to detect the name of this notebook, you can set it manually with the WANDB_NOTEBOOK_NAME environment variable to enable code saving.\n",
"\u001b[34m\u001b[1mwandb\u001b[0m: Downloading large artifact btc-usdt-5m:latest, 745.12MB. 12 files... \n",
"\u001b[34m\u001b[1mwandb\u001b[0m: 12 of 12 files downloaded. \n",
"Done. 0:0:1.4\n"
]
}
],
@ -65,7 +66,7 @@
},
{
"cell_type": "code",
"execution_count": 95,
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
@ -79,7 +80,7 @@
},
{
"cell_type": "code",
"execution_count": 5,
"execution_count": 4,
"metadata": {},
"outputs": [],
"source": [
@ -88,19 +89,19 @@
},
{
"cell_type": "code",
"execution_count": 97,
"execution_count": 5,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"100%|██████████| 3840/3840 [00:25<00:00, 148.93it/s]\n",
"100%|██████████| 3840/3840 [00:25<00:00, 149.05it/s]\n",
"100%|██████████| 3840/3840 [00:27<00:00, 138.86it/s]\n",
"100%|██████████| 3840/3840 [00:28<00:00, 133.50it/s]\n",
"100%|██████████| 3840/3840 [00:25<00:00, 152.79it/s]\n",
"100%|██████████| 3840/3840 [00:22<00:00, 168.94it/s]\n"
"100%|██████████| 3840/3840 [00:18<00:00, 206.53it/s]\n",
"100%|██████████| 3840/3840 [00:18<00:00, 205.12it/s]\n",
"100%|██████████| 3840/3840 [00:18<00:00, 205.54it/s]\n",
"100%|██████████| 3840/3840 [00:18<00:00, 204.08it/s]\n",
"100%|██████████| 3840/3840 [00:18<00:00, 202.37it/s]\n",
"100%|██████████| 3840/3840 [00:18<00:00, 202.96it/s]\n"
]
}
],
@ -136,19 +137,19 @@
},
{
"cell_type": "code",
"execution_count": 99,
"execution_count": 6,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"100%|██████████| 11088/11088 [01:14<00:00, 149.71it/s]\n",
"100%|██████████| 11088/11088 [01:18<00:00, 140.49it/s]\n",
"100%|██████████| 11088/11088 [01:14<00:00, 148.45it/s]\n",
"100%|██████████| 11088/11088 [01:15<00:00, 147.54it/s]\n",
"100%|██████████| 11088/11088 [01:09<00:00, 160.15it/s]\n",
"100%|██████████| 11088/11088 [01:10<00:00, 158.01it/s]\n"
"100%|██████████| 11088/11088 [00:51<00:00, 216.64it/s]\n",
"100%|██████████| 11088/11088 [00:52<00:00, 210.53it/s]\n",
"100%|██████████| 11088/11088 [00:52<00:00, 210.59it/s]\n",
"100%|██████████| 11088/11088 [00:52<00:00, 210.06it/s]\n",
"100%|██████████| 11088/11088 [00:52<00:00, 209.24it/s]\n",
"100%|██████████| 11088/11088 [00:52<00:00, 209.32it/s]\n"
]
}
],
@ -181,7 +182,96 @@
},
{
"cell_type": "code",
"execution_count": 101,
"execution_count": 8,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"\u001b[34m\u001b[1mwandb\u001b[0m: 2 of 2 files downloaded. \n",
"\u001b[34m\u001b[1mwandb\u001b[0m: 2 of 2 files downloaded. \n",
"\u001b[34m\u001b[1mwandb\u001b[0m: 2 of 2 files downloaded. \n",
"\u001b[34m\u001b[1mwandb\u001b[0m: 2 of 2 files downloaded. \n",
"\u001b[34m\u001b[1mwandb\u001b[0m: 2 of 2 files downloaded. \n",
"\u001b[34m\u001b[1mwandb\u001b[0m: 2 of 2 files downloaded. \n",
"\u001b[34m\u001b[1mwandb\u001b[0m: 2 of 2 files downloaded. \n",
"\u001b[34m\u001b[1mwandb\u001b[0m: 2 of 2 files downloaded. \n",
"\u001b[34m\u001b[1mwandb\u001b[0m: 2 of 2 files downloaded. \n",
"\u001b[34m\u001b[1mwandb\u001b[0m: 2 of 2 files downloaded. \n",
"\u001b[34m\u001b[1mwandb\u001b[0m: 2 of 2 files downloaded. \n",
"\u001b[34m\u001b[1mwandb\u001b[0m: 2 of 2 files downloaded. \n",
"\u001b[34m\u001b[1mwandb\u001b[0m: 2 of 2 files downloaded. \n",
"\u001b[34m\u001b[1mwandb\u001b[0m: 2 of 2 files downloaded. \n",
"\u001b[34m\u001b[1mwandb\u001b[0m: 2 of 2 files downloaded. \n",
"\u001b[34m\u001b[1mwandb\u001b[0m: 2 of 2 files downloaded. \n",
"\u001b[34m\u001b[1mwandb\u001b[0m: 2 of 2 files downloaded. \n",
"\u001b[34m\u001b[1mwandb\u001b[0m: 2 of 2 files downloaded. \n"
]
}
],
"source": [
"# Model with rmse loss\n",
"SWEEP_ID = 'filipstefaniuk/wne-masters-thesis-testing/9afp99kz'\n",
"train_pred_windows = get_sweep_window_predictions(SWEEP_ID, 'train')\n",
"valid_pred_windows = get_sweep_window_predictions(SWEEP_ID, 'valid')\n",
"test_pred_windows = get_sweep_window_predictions(SWEEP_ID, 'test')"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"100%|██████████| 1176/1176 [02:10<00:00, 9.04it/s]\n",
"100%|██████████| 1176/1176 [02:07<00:00, 9.19it/s]\n",
"100%|██████████| 1176/1176 [02:10<00:00, 9.02it/s]\n",
"100%|██████████| 1176/1176 [02:16<00:00, 8.59it/s]\n",
"100%|██████████| 1176/1176 [02:13<00:00, 8.82it/s]\n",
"100%|██████████| 1176/1176 [02:12<00:00, 8.85it/s]\n"
]
}
],
"source": [
"MODEL_RMSE_LOSS_FILTER = lambda p: (\n",
" ((p['enter_long'] is not None and (p['enter_short'] is not None or p['exit_long'] is not None))\n",
" or (p['enter_short'] is not None and (p['exit_short'] is not None or p['enter_long'] is not None)))\n",
" and (p['enter_short'] is None or p['exit_long'] is None or (p['exit_long'] > p['enter_short']))\n",
" and (p['enter_long'] is None or p['exit_short'] is None or (p['exit_short'] < p['enter_long'])))\n",
"\n",
"rmse_model_sweep_results = []\n",
"for (in_sample, _), train_preds, valid_preds, test_preds in zip(data_windows, train_pred_windows, valid_pred_windows, test_pred_windows):\n",
" data_part = int((1 - VALID_PART) * len(in_sample))\n",
" params={\n",
" 'predictions': [get_predictions_dataframe(train_preds, valid_preds, test_preds)],\n",
" 'enter_long': [None, 0.001, 0.002, 0.003, 0.004, 0.005, 0.006, 0.007],\n",
" 'exit_long': [None, -0.001, -0.002, -0.003, -0.004, -0.005, -0.006, -0.007],\n",
" 'enter_short': [None, -0.001, -0.002, -0.003, -0.004, -0.005, -0.006, -0.007],\n",
" 'exit_short': [None, 0.001, 0.002, 0.003, 0.004, 0.005, 0.006, 0.007],\n",
" # 'enter_short': [None],\n",
" # 'exit_short': [None],\n",
" }\n",
" \n",
" rmse_model_sweep_results.append(parameter_sweep(\n",
" in_sample[data_part-PADDING:],\n",
" ModelGmadlPredictionsStrategy,\n",
" params,\n",
" params_filter=MODEL_RMSE_LOSS_FILTER,\n",
" padding=PADDING,\n",
" interval=INTERVAL,\n",
" sort_by=METRIC))\n",
" \n",
"\n",
"rmse_model_best_strategies = [[strat for _, strat in results[:TOP_N]] for results in rmse_model_sweep_results]"
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {},
"outputs": [
{
@ -219,19 +309,19 @@
},
{
"cell_type": "code",
"execution_count": 102,
"execution_count": 11,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"100%|██████████| 1125/1125 [02:49<00:00, 6.65it/s]\n",
"100%|██████████| 1125/1125 [02:51<00:00, 6.55it/s]\n",
"100%|██████████| 1125/1125 [02:56<00:00, 6.36it/s]\n",
"100%|██████████| 1125/1125 [02:50<00:00, 6.61it/s]\n",
"100%|██████████| 1125/1125 [02:47<00:00, 6.72it/s]\n",
"100%|██████████| 1125/1125 [02:48<00:00, 6.66it/s]\n"
"100%|██████████| 1125/1125 [02:35<00:00, 7.23it/s]\n",
"100%|██████████| 1125/1125 [02:28<00:00, 7.56it/s]\n",
"100%|██████████| 1125/1125 [02:35<00:00, 7.22it/s]\n",
"100%|██████████| 1125/1125 [02:47<00:00, 6.71it/s]\n",
"100%|██████████| 1125/1125 [02:39<00:00, 7.06it/s]\n",
"100%|██████████| 1125/1125 [02:35<00:00, 7.25it/s]\n"
]
}
],
@ -279,25 +369,13 @@
},
{
"cell_type": "code",
"execution_count": 13,
"execution_count": 12,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"\u001b[34m\u001b[1mwandb\u001b[0m: 2 of 2 files downloaded. \n",
"\u001b[34m\u001b[1mwandb\u001b[0m: 2 of 2 files downloaded. \n",
"\u001b[34m\u001b[1mwandb\u001b[0m: 2 of 2 files downloaded. \n",
"\u001b[34m\u001b[1mwandb\u001b[0m: 2 of 2 files downloaded. \n",
"\u001b[34m\u001b[1mwandb\u001b[0m: 2 of 2 files downloaded. \n",
"\u001b[34m\u001b[1mwandb\u001b[0m: 2 of 2 files downloaded. \n",
"\u001b[34m\u001b[1mwandb\u001b[0m: 2 of 2 files downloaded. \n",
"\u001b[34m\u001b[1mwandb\u001b[0m: 2 of 2 files downloaded. \n",
"\u001b[34m\u001b[1mwandb\u001b[0m: 2 of 2 files downloaded. \n",
"\u001b[34m\u001b[1mwandb\u001b[0m: 2 of 2 files downloaded. \n",
"\u001b[34m\u001b[1mwandb\u001b[0m: 2 of 2 files downloaded. \n",
"\u001b[34m\u001b[1mwandb\u001b[0m: 2 of 2 files downloaded. \n",
"\u001b[34m\u001b[1mwandb\u001b[0m: 2 of 2 files downloaded. \n",
"\u001b[34m\u001b[1mwandb\u001b[0m: 2 of 2 files downloaded. \n",
"\u001b[34m\u001b[1mwandb\u001b[0m: 2 of 2 files downloaded. \n",
@ -324,25 +402,19 @@
},
{
"cell_type": "code",
"execution_count": 14,
"execution_count": 13,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"100%|██████████| 1176/1176 [00:41<00:00, 28.28it/s]\n",
"100%|██████████| 1176/1176 [00:42<00:00, 27.90it/s]\n",
"100%|██████████| 1176/1176 [00:42<00:00, 27.84it/s]\n",
"100%|██████████| 1176/1176 [02:09<00:00, 9.10it/s]\n",
"100%|██████████| 1176/1176 [01:07<00:00, 17.48it/s]\n",
"100%|██████████| 1176/1176 [00:42<00:00, 27.56it/s]\n",
"100%|██████████| 1176/1176 [00:42<00:00, 27.60it/s]\n",
"100%|██████████| 1176/1176 [00:42<00:00, 27.51it/s]\n",
"100%|██████████| 1176/1176 [00:42<00:00, 27.39it/s]\n",
"100%|██████████| 1176/1176 [00:42<00:00, 27.40it/s]\n",
"100%|██████████| 1176/1176 [00:43<00:00, 27.34it/s]\n",
"100%|██████████| 1176/1176 [00:43<00:00, 27.33it/s]\n"
"100%|██████████| 1176/1176 [00:58<00:00, 20.16it/s]\n",
"100%|██████████| 1176/1176 [00:55<00:00, 21.38it/s]\n",
"100%|██████████| 1176/1176 [00:54<00:00, 21.43it/s]\n",
"100%|██████████| 1176/1176 [00:54<00:00, 21.38it/s]\n",
"100%|██████████| 1176/1176 [00:55<00:00, 21.29it/s]\n",
"100%|██████████| 1176/1176 [00:55<00:00, 21.03it/s]\n"
]
}
],
@ -386,13 +458,14 @@
"# Persist best strategies, so that they don't have to be recomputed every time\n",
"best_strategies = {\n",
" 'buy_and_hold': buyandhold_best_strategies,\n",
" # 'macd_strategies': macd_best_strategies,\n",
" # 'rsi_strategies': rsi_best_strategies,\n",
" # 'quantile_model': quantile_model_best_strategies,\n",
" 'macd_strategies': macd_best_strategies,\n",
" 'rsi_strategies': rsi_best_strategies,\n",
" 'rmse_model': rmse_model_best_strategies,\n",
" 'quantile_model': quantile_model_best_strategies,\n",
" 'gmadl_model': gmadl_model_best_strategies\n",
"}\n",
"\n",
"with open('cache/5min-best-strategies-long.pkl', 'wb') as outp:\n",
"with open('cache/5min-best-strategies-v2.pkl', 'wb') as outp:\n",
" pickle.dump(best_strategies, outp, pickle.HIGHEST_PROTOCOL)"
]
},
@ -405,11 +478,11 @@
},
{
"cell_type": "code",
"execution_count": 52,
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
"with open('cache/5min-best-strategies.pkl', 'rb') as inpt:\n",
"with open('cache/5min-best-strategies-v2.pkl', 'rb') as inpt:\n",
" best_strategies = pickle.load(inpt)"
]
},
@ -523,6 +596,56 @@
"print(latextable.draw_latex(table_rsi_params))"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"\\begin{table}\n",
"\t\\begin{center}\n",
"\t\t\\begin{tabular}{lcccc}\n",
"\t\t\t\\textbf{Window} & \\textbf{\\textit{enter long}} & \\textbf{\\textit{exit Long}} & \\textbf{\\textit{enter Short}} & \\textbf{\\textit{exit Short}} \\\\\n",
"\t\t\t\\hline\n",
"\t\t\tW1-5min & 0.002 & - & -0.001 & 0.001 \\\\\n",
"\t\t\tW2-5min & - & - & -0.001 & 0.001 \\\\\n",
"\t\t\tW3-5min & - & - & -0.001 & 0.001 \\\\\n",
"\t\t\tW4-5min & - & - & -0.001 & 0.001 \\\\\n",
"\t\t\tW5-5min & - & - & -0.001 & 0.001 \\\\\n",
"\t\t\tW6-5min & - & - & -0.001 & 0.001 \\\\\n",
"\t\t\\end{tabular}\n",
"\t\\end{center}\n",
"\\end{table}\n"
]
}
],
"source": [
"table_rmse_params = Texttable()\n",
"table_rmse_params.set_deco(Texttable.HEADER)\n",
"table_rmse_params.set_cols_align([\"l\", \"c\",\"c\", \"c\", \"c\"])\n",
"table_rmse_params.header([\n",
" \"\\\\textbf{Window}\",\n",
" \"\\\\textbf{\\\\textit{enter long}}\",\n",
" \"\\\\textbf{\\\\textit{exit Long}}\",\n",
" \"\\\\textbf{\\\\textit{enter Short}}\",\n",
" \"\\\\textbf{\\\\textit{exit Short}}\",\n",
"])\n",
"\n",
"for i, rmse_strategy in enumerate(best_strategies['rmse_model']):\n",
" rmse_strategy_info = rmse_strategy[0].info()\n",
" table_rmse_params.add_row([\n",
" f\"W{i+1}-{INTERVAL}\",\n",
" rmse_strategy_info['enter_long'] or '-',\n",
" rmse_strategy_info['exit_long'] or '-',\n",
" rmse_strategy_info['enter_short'] or '-',\n",
" rmse_strategy_info['exit_short'] or '-'\n",
" ])\n",
"print(latextable.draw_latex(table_rmse_params))"
]
},
{
"cell_type": "code",
"execution_count": 56,
@ -634,19 +757,32 @@
},
{
"cell_type": "code",
"execution_count": 9,
"execution_count": 6,
"metadata": {},
"outputs": [],
"source": [
"def results_plot(idx, result_buyandhold, result_macd, result_rsi, result_quantile_model, result_gmadl_model, width=850, height=500, notitle=False):\n",
"def results_plot(idx, result_buyandhold, result_macd, result_rsi, result_rmse_model, result_quantile_model, result_gmadl_model, width=850, height=500, notitle=False, v_lines=None):\n",
"\n",
" fig = go.Figure([\n",
" go.Scatter(y=result_buyandhold['portfolio_value'], x=result_buyandhold['time'], name=\"Buy and Hold\"),\n",
" go.Scatter(y=result_macd['portfolio_value'], x=result_macd['time'], name=\"MACD Strategy\"),\n",
" go.Scatter(y=result_rsi['portfolio_value'], x=result_rsi['time'], name=\"RSI Strategy\"),\n",
" go.Scatter(y=result_rmse_model['portfolio_value'], x=result_rmse_model['time'], name='RMSE Informer Strategy'),\n",
" go.Scatter(y=result_quantile_model['portfolio_value'], x=result_quantile_model['time'], name='Quantile Informer Strategy'),\n",
" go.Scatter(y=result_gmadl_model['portfolio_value'], x=result_gmadl_model['time'], name='GMADL Informer Strategy')\n",
" ])\n",
" \n",
" if v_lines:\n",
" for v_line in v_lines:\n",
" fig.add_shape(\n",
" go.layout.Shape(type=\"line\",\n",
" yref=\"paper\",\n",
" xref=\"x\",\n",
" x0=v_line,\n",
" x1=v_line,\n",
" y0=0,\n",
" y1=1,\n",
" line=dict(dash='dash', color='rgb(140,140,140)')))\n",
" fig.update_layout(\n",
" title={\n",
" 'text': f\"W{idx}-{INTERVAL}\",\n",
@ -690,7 +826,7 @@
" fig.write_image(f\"images/eval-w{idx}-{INTERVAL}.png\")\n",
" fig.show()\n",
" \n",
"def results_table(result_buyandhold, result_macd, result_rsi, result_quantile_model, result_gmadl_model):\n",
"def results_table(result_buyandhold, result_macd, result_rsi, result_rmse_model, result_quantile_model, result_gmadl_model):\n",
" table_eval_windows = Texttable()\n",
" table_eval_windows.set_deco(Texttable.HEADER)\n",
" table_eval_windows.set_cols_align([\"l\", \"c\",\"c\", \"c\", \"c\", \"c\", \"c\", \"c\", \"c\", \"c\"])\n",
@ -713,6 +849,7 @@
" ('Buy and Hold', result_buyandhold),\n",
" ('MACD Strategy', result_macd),\n",
" ('RSI Strategy', result_rsi),\n",
" ('RMSE Informer', result_rmse_model),\n",
" ('Quantile Informer', result_quantile_model),\n",
" ('GMADL Informer', result_gmadl_model)\n",
" ]\n",
@ -720,10 +857,10 @@
" table_eval_windows.add_row([\n",
" strategy_name,\n",
" result['value'],\n",
" result['arc'],\n",
" result['asd'],\n",
" f\"{result['arc']*100:.2f}\\%\",\n",
" f\"{result['asd']*100:.2f}\\%\",\n",
" result['ir'],\n",
" result['md'],\n",
" f\"{result['md']*100:.2f}\\%\",\n",
" result['mod_ir'],\n",
" result['n_trades'],\n",
" f\"{result['long_pos']*100:.2f}\\%\",\n",
@ -735,38 +872,153 @@
},
{
"cell_type": "code",
"execution_count": 1,
"execution_count": 11,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"\\begin{table}\n",
"\t\\begin{center}\n",
"\t\t\\begin{tabular}{lccccccccc}\n",
"\t\t\t\\textbf{Strategy} & \\textbf{VAL} & \\textbf{ARC} & \\textbf{ASD} & \\textbf{IR*} & \\textbf{MD} & \\textbf{IR**} & \\textbf{N} & \\textbf{LONG} & \\textbf{SHORT} \\\\\n",
"\t\t\t\\hline\n",
"\t\t\tBuy and Hold & 0.930 & -13.76\\% & 70.24\\% & -0.196 & 51.87\\% & -0.052 & 2 & 100.00\\% & 0.00\\% \\\\\n",
"\t\t\tMACD Strategy & 0.375 & -86.35\\% & 70.71\\% & -1.221 & 71.90\\% & -1.467 & 1542 & 52.05\\% & 47.95\\% \\\\\n",
"\t\t\tRSI Strategy & 1.428 & 106.05\\% & 70.55\\% & 1.503 & 26.24\\% & 6.074 & 114 & 26.31\\% & 73.69\\% \\\\\n",
"\t\t\tRMSE Informer & 0.965 & -6.93\\% & 3.11\\% & -2.227 & 3.54\\% & -4.361 & 12 & 0.02\\% & 0.00\\% \\\\\n",
"\t\t\tQuantile Informer & 1.117 & 25.15\\% & 43.69\\% & 0.576 & 16.27\\% & 0.889 & 365 & 0.00\\% & 45.14\\% \\\\\n",
"\t\t\tGMADL Informer & 1.502 & 128.10\\% & 70.54\\% & 1.816 & 30.70\\% & 7.576 & 82 & 41.54\\% & 58.46\\% \\\\\n",
"\t\t\\end{tabular}\n",
"\t\\end{center}\n",
"\\end{table}\n",
"\\begin{table}\n",
"\t\\begin{center}\n",
"\t\t\\begin{tabular}{lccccccccc}\n",
"\t\t\t\\textbf{Strategy} & \\textbf{VAL} & \\textbf{ARC} & \\textbf{ASD} & \\textbf{IR*} & \\textbf{MD} & \\textbf{IR**} & \\textbf{N} & \\textbf{LONG} & \\textbf{SHORT} \\\\\n",
"\t\t\t\\hline\n",
"\t\t\tBuy and Hold & 0.549 & -70.37\\% & 74.61\\% & -0.943 & 63.35\\% & -1.048 & 2 & 100.00\\% & 0.00\\% \\\\\n",
"\t\t\tMACD Strategy & 0.498 & -75.63\\% & 74.63\\% & -1.013 & 62.97\\% & -1.217 & 446 & 50.72\\% & 49.28\\% \\\\\n",
"\t\t\tRSI Strategy & 1.368 & 88.76\\% & 74.58\\% & 1.190 & 27.34\\% & 3.864 & 78 & 61.40\\% & 38.60\\% \\\\\n",
"\t\t\tRMSE Informer & 1 & 0.00\\% & 0.00\\% & 0 & 0.00\\% & 0 & 0 & 0.00\\% & 0.00\\% \\\\\n",
"\t\t\tQuantile Informer & 0.941 & -11.54\\% & 74.69\\% & -0.154 & 44.84\\% & -0.040 & 990 & 50.50\\% & 49.50\\% \\\\\n",
"\t\t\tGMADL Informer & 1.635 & 170.94\\% & 74.67\\% & 2.289 & 30.47\\% & 12.844 & 522 & 20.20\\% & 79.80\\% \\\\\n",
"\t\t\\end{tabular}\n",
"\t\\end{center}\n",
"\\end{table}\n",
"\\begin{table}\n",
"\t\\begin{center}\n",
"\t\t\\begin{tabular}{lccccccccc}\n",
"\t\t\t\\textbf{Strategy} & \\textbf{VAL} & \\textbf{ARC} & \\textbf{ASD} & \\textbf{IR*} & \\textbf{MD} & \\textbf{IR**} & \\textbf{N} & \\textbf{LONG} & \\textbf{SHORT} \\\\\n",
"\t\t\t\\hline\n",
"\t\t\tBuy and Hold & 1.016 & 3.23\\% & 51.77\\% & 0.062 & 37.98\\% & 0.005 & 2 & 100.00\\% & 0.00\\% \\\\\n",
"\t\t\tMACD Strategy & 1.081 & 17.10\\% & 51.79\\% & 0.330 & 20.87\\% & 0.270 & 154 & 58.24\\% & 41.76\\% \\\\\n",
"\t\t\tRSI Strategy & 1.127 & 27.41\\% & 51.92\\% & 0.528 & 22.30\\% & 0.649 & 398 & 11.48\\% & 88.52\\% \\\\\n",
"\t\t\tRMSE Informer & 1 & 0.00\\% & 0.00\\% & 0 & 0.00\\% & 0 & 0 & 0.00\\% & 0.00\\% \\\\\n",
"\t\t\tQuantile Informer & 1.057 & 11.93\\% & 51.90\\% & 0.230 & 30.10\\% & 0.091 & 894 & 27.62\\% & 72.38\\% \\\\\n",
"\t\t\tGMADL Informer & 1.198 & 44.15\\% & 19.18\\% & 2.302 & 7.68\\% & 13.227 & 16 & 0.00\\% & 17.86\\% \\\\\n",
"\t\t\\end{tabular}\n",
"\t\\end{center}\n",
"\\end{table}\n",
"\\begin{table}\n",
"\t\\begin{center}\n",
"\t\t\\begin{tabular}{lccccccccc}\n",
"\t\t\t\\textbf{Strategy} & \\textbf{VAL} & \\textbf{ARC} & \\textbf{ASD} & \\textbf{IR*} & \\textbf{MD} & \\textbf{IR**} & \\textbf{N} & \\textbf{LONG} & \\textbf{SHORT} \\\\\n",
"\t\t\t\\hline\n",
"\t\t\tBuy and Hold & 1.231 & 52.35\\% & 45.25\\% & 1.157 & 22.29\\% & 2.718 & 2 & 100.00\\% & 0.00\\% \\\\\n",
"\t\t\tMACD Strategy & 1.612 & 163.18\\% & 45.34\\% & 3.599 & 21.23\\% & 27.660 & 190 & 44.69\\% & 55.31\\% \\\\\n",
"\t\t\tRSI Strategy & 0.866 & -25.30\\% & 19.03\\% & -1.330 & 15.65\\% & -2.150 & 205 & 23.63\\% & 0.00\\% \\\\\n",
"\t\t\tRMSE Informer & 1 & 0.00\\% & 0.00\\% & 0 & 0.00\\% & 0 & 0 & 0.00\\% & 0.00\\% \\\\\n",
"\t\t\tQuantile Informer & 0.825 & -32.24\\% & 27.88\\% & -1.156 & 22.72\\% & -1.641 & 290 & 44.45\\% & 0.00\\% \\\\\n",
"\t\t\tGMADL Informer & 1.673 & 183.80\\% & 45.26\\% & 4.061 & 24.78\\% & 30.125 & 62 & 65.14\\% & 34.86\\% \\\\\n",
"\t\t\\end{tabular}\n",
"\t\\end{center}\n",
"\\end{table}\n",
"\\begin{table}\n",
"\t\\begin{center}\n",
"\t\t\\begin{tabular}{lccccccccc}\n",
"\t\t\t\\textbf{Strategy} & \\textbf{VAL} & \\textbf{ARC} & \\textbf{ASD} & \\textbf{IR*} & \\textbf{MD} & \\textbf{IR**} & \\textbf{N} & \\textbf{LONG} & \\textbf{SHORT} \\\\\n",
"\t\t\t\\hline\n",
"\t\t\tBuy and Hold & 1.439 & 109.23\\% & 44.72\\% & 2.443 & 21.07\\% & 12.664 & 2 & 100.00\\% & 0.00\\% \\\\\n",
"\t\t\tMACD Strategy & 1.346 & 82.57\\% & 32.85\\% & 2.514 & 15.44\\% & 13.447 & 94 & 49.06\\% & 0.00\\% \\\\\n",
"\t\t\tRSI Strategy & 1.169 & 37.33\\% & 13.86\\% & 2.692 & 4.73\\% & 21.237 & 42 & 5.67\\% & 0.00\\% \\\\\n",
"\t\t\tRMSE Informer & 0.667 & -56.06\\% & 36.94\\% & -1.518 & 42.77\\% & -1.989 & 3 & 0.00\\% & 57.45\\% \\\\\n",
"\t\t\tQuantile Informer & 0.984 & -3.12\\% & 33.97\\% & -0.092 & 20.63\\% & -0.014 & 578 & 59.26\\% & 0.00\\% \\\\\n",
"\t\t\tGMADL Informer & 1.582 & 153.60\\% & 45.11\\% & 3.405 & 14.37\\% & 36.394 & 130 & 44.70\\% & 55.30\\% \\\\\n",
"\t\t\\end{tabular}\n",
"\t\\end{center}\n",
"\\end{table}\n",
"\\begin{table}\n",
"\t\\begin{center}\n",
"\t\t\\begin{tabular}{lccccccccc}\n",
"\t\t\t\\textbf{Strategy} & \\textbf{VAL} & \\textbf{ARC} & \\textbf{ASD} & \\textbf{IR*} & \\textbf{MD} & \\textbf{IR**} & \\textbf{N} & \\textbf{LONG} & \\textbf{SHORT} \\\\\n",
"\t\t\t\\hline\n",
"\t\t\tBuy and Hold & 1.560 & 146.27\\% & 52.72\\% & 2.775 & 26.96\\% & 15.054 & 2 & 100.00\\% & 0.00\\% \\\\\n",
"\t\t\tMACD Strategy & 1.179 & 39.63\\% & 34.65\\% & 1.144 & 28.87\\% & 1.570 & 111 & 47.58\\% & 0.00\\% \\\\\n",
"\t\t\tRSI Strategy & 1.507 & 129.58\\% & 38.15\\% & 3.396 & 17.97\\% & 24.493 & 7 & 41.29\\% & 0.00\\% \\\\\n",
"\t\t\tRMSE Informer & 1 & 0.00\\% & 0.00\\% & 0 & 0.00\\% & 0 & 0 & 0.00\\% & 0.00\\% \\\\\n",
"\t\t\tQuantile Informer & 1.056 & 11.76\\% & 40.73\\% & 0.289 & 30.60\\% & 0.111 & 280 & 59.60\\% & 0.00\\% \\\\\n",
"\t\t\tGMADL Informer & 1.253 & 57.92\\% & 52.71\\% & 1.099 & 32.66\\% & 1.949 & 34 & 97.21\\% & 2.79\\% \\\\\n",
"\t\t\\end{tabular}\n",
"\t\\end{center}\n",
"\\end{table}\n"
]
}
],
"source": [
"# for i, (in_sample, out_of_sample) in enumerate(data_windows):\n",
"# padded_window = pd.concat([in_sample.iloc[-PADDING:], out_of_sample])\n",
"# result_buyandhold = evaluate_strategy(padded_window, best_strategies['buy_and_hold'][i], padding=PADDING, interval=INTERVAL)\n",
"# result_macd = evaluate_strategy(padded_window, [s[0] for s in best_strategies['macd_strategies']][i], padding=PADDING, interval=INTERVAL)\n",
"# result_rsi = evaluate_strategy(padded_window, [s[0] for s in best_strategies['rsi_strategies']][i], padding=PADDING, interval=INTERVAL)\n",
"# result_quantile_model = evaluate_strategy(padded_window, [s[0] for s in best_strategies['quantile_model']][i], padding=PADDING, interval=INTERVAL)\n",
"# result_gmadl_model = evaluate_strategy(padded_window, [s[0] for s in best_strategies['gmadl_model']][i], padding=PADDING, interval=INTERVAL)\n",
"for i, (in_sample, out_of_sample) in enumerate(data_windows):\n",
" padded_window = pd.concat([in_sample.iloc[-PADDING:], out_of_sample])\n",
" result_buyandhold = evaluate_strategy(padded_window, best_strategies['buy_and_hold'][i], padding=PADDING, interval=INTERVAL)\n",
" result_macd = evaluate_strategy(padded_window, [s[0] for s in best_strategies['macd_strategies']][i], padding=PADDING, interval=INTERVAL)\n",
" result_rsi = evaluate_strategy(padded_window, [s[0] for s in best_strategies['rsi_strategies']][i], padding=PADDING, interval=INTERVAL)\n",
" result_rmse_model = evaluate_strategy(padded_window, [s[0] for s in best_strategies['rmse_model']][i], padding=PADDING, interval=INTERVAL)\n",
" result_quantile_model = evaluate_strategy(padded_window, [s[0] for s in best_strategies['quantile_model']][i], padding=PADDING, interval=INTERVAL)\n",
" result_gmadl_model = evaluate_strategy(padded_window, [s[0] for s in best_strategies['gmadl_model']][i], padding=PADDING, interval=INTERVAL)\n",
"\n",
" # results_table(result_buyandhold, result_macd, result_rsi, result_quantile_model, result_gmadl_model)\n",
" # results_plot(i+1, result_buyandhold, None, None, None, result_gmadl_model)\n",
" results_table(result_buyandhold, result_macd, result_rsi, result_rmse_model, result_quantile_model, result_gmadl_model)\n",
" # results_plot(i+1, result_buyandhold, result_macd, result_rsi, result_rmse_model, result_quantile_model, result_gmadl_model)\n",
" \n"
]
},
{
"cell_type": "code",
"execution_count": 2,
"execution_count": 12,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"\\begin{table}\n",
"\t\\begin{center}\n",
"\t\t\\begin{tabular}{lccccccccc}\n",
"\t\t\t\\textbf{Strategy} & \\textbf{VAL} & \\textbf{ARC} & \\textbf{ASD} & \\textbf{IR*} & \\textbf{MD} & \\textbf{IR**} & \\textbf{N} & \\textbf{LONG} & \\textbf{SHORT} \\\\\n",
"\t\t\t\\hline\n",
"\t\t\tBuy and Hold & 1.441 & 13.14\\% & 57.74\\% & 0.228 & 77.31\\% & 0.039 & 2 & 100.00\\% & 0.00\\% \\\\\n",
"\t\t\tMACD Strategy & 0.516 & -20.04\\% & 54.14\\% & -0.370 & 85.77\\% & -0.087 & 2535 & 50.39\\% & 32.38\\% \\\\\n",
"\t\t\tRSI Strategy & 3.341 & 50.34\\% & 50.41\\% & 0.999 & 29.99\\% & 1.676 & 846 & 28.29\\% & 33.47\\% \\\\\n",
"\t\t\tRMSE Informer & 0.643 & -13.88\\% & 15.13\\% & -0.917 & 44.61\\% & -0.285 & 16 & 0.00\\% & 9.58\\% \\\\\n",
"\t\t\tQuantile Informer & 0.956 & -1.52\\% & 47.91\\% & -0.032 & 53.96\\% & -0.001 & 3395 & 40.24\\% & 27.84\\% \\\\\n",
"\t\t\tGMADL Informer & 9.747 & 115.88\\% & 54.44\\% & 2.129 & 32.66\\% & 7.552 & 846 & 44.80\\% & 41.51\\% \\\\\n",
"\t\t\\end{tabular}\n",
"\t\\end{center}\n",
"\\end{table}\n"
]
}
],
"source": [
"# test_data = pd.concat([data_windows[0][0][-PADDING:]] + [data_window[1] for data_window in data_windows])\n",
"# buy_and_hold_concat = evaluate_strategy(test_data, BuyAndHoldStrategy(), padding=PADDING)\n",
"# macd_concat = evaluate_strategy(test_data, ConcatenatedStrategies(len(data_windows[0][1]), [s[0] for s in best_strategies['macd_strategies']], padding=PADDING), padding=PADDING, interval=INTERVAL)\n",
"# rsi_concat = evaluate_strategy(test_data, ConcatenatedStrategies(len(data_windows[0][1]), [s[0] for s in best_strategies['rsi_strategies']], padding=PADDING), padding=PADDING, interval=INTERVAL)\n",
"# quantile_model_concat = evaluate_strategy(test_data, ConcatenatedStrategies(len(data_windows[0][1]), [s[0] for s in best_strategies['quantile_model']], padding=PADDING), padding=PADDING, interval=INTERVAL)\n",
"# gmadl_model_concat = evaluate_strategy(test_data, ConcatenatedStrategies(len(data_windows[0][1]), [s[0] for s in best_strategies['gmadl_model']], padding=PADDING), padding=PADDING, interval=INTERVAL)\n",
"test_data = pd.concat([data_windows[0][0][-PADDING:]] + [data_window[1] for data_window in data_windows])\n",
"buy_and_hold_concat = evaluate_strategy(test_data, BuyAndHoldStrategy(), padding=PADDING)\n",
"macd_concat = evaluate_strategy(test_data, ConcatenatedStrategies(len(data_windows[0][1]), [s[0] for s in best_strategies['macd_strategies']], padding=PADDING), padding=PADDING, interval=INTERVAL)\n",
"rsi_concat = evaluate_strategy(test_data, ConcatenatedStrategies(len(data_windows[0][1]), [s[0] for s in best_strategies['rsi_strategies']], padding=PADDING), padding=PADDING, interval=INTERVAL)\n",
"rmse_model_concat = evaluate_strategy(test_data, ConcatenatedStrategies(len(data_windows[0][1]), [s[0] for s in best_strategies['rmse_model']], padding=PADDING), padding=PADDING, interval=INTERVAL)\n",
"quantile_model_concat = evaluate_strategy(test_data, ConcatenatedStrategies(len(data_windows[0][1]), [s[0] for s in best_strategies['quantile_model']], padding=PADDING), padding=PADDING, interval=INTERVAL)\n",
"gmadl_model_concat = evaluate_strategy(test_data, ConcatenatedStrategies(len(data_windows[0][1]), [s[0] for s in best_strategies['gmadl_model']], padding=PADDING), padding=PADDING, interval=INTERVAL)\n",
"\n",
"# results_table(buy_and_hold_concat, macd_concat, rsi_concat, quantile_model_concat, gmadl_model_concat)\n",
"# results_plot(0, buy_and_hold_concat, None, None, None, gmadl_model_concat, width=1200, notitle=True)\n",
"v_lines=[data_window[1]['close_time'].iloc[-1] for data_window in data_windows][:-1]\n",
"results_table(buy_and_hold_concat, macd_concat, rsi_concat, rmse_model_concat, quantile_model_concat, gmadl_model_concat)\n",
"# results_plot(0, buy_and_hold_concat, macd_concat, rsi_concat, rmse_model_concat, quantile_model_concat, gmadl_model_concat, width=1300, height=500, notitle=True)\n",
"\n"
]
},

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -52,7 +52,7 @@
"Done. 0:0:1.1\n",
"\u001b[34m\u001b[1mwandb\u001b[0m: Downloading large artifact btc-usdt-15m:latest, 248.65MB. 12 files... \n",
"\u001b[34m\u001b[1mwandb\u001b[0m: 12 of 12 files downloaded. \n",
"Done. 0:0:0.6\n",
"Done. 0:0:0.5\n",
"\u001b[34m\u001b[1mwandb\u001b[0m: Downloading large artifact btc-usdt-30m:latest, 124.19MB. 12 files... \n",
"\u001b[34m\u001b[1mwandb\u001b[0m: 12 of 12 files downloaded. \n",
"Done. 0:0:0.4\n"
@ -88,13 +88,13 @@
"metadata": {},
"outputs": [],
"source": [
"with open('cache/5min-best-strategies.pkl', 'rb') as inpt:\n",
"with open('cache/5min-best-strategies-v2.pkl', 'rb') as inpt:\n",
" best_strategies_5min = pickle.load(inpt)\n",
"\n",
"with open('cache/15min-best-strategies.pkl', 'rb') as inpt:\n",
"with open('cache/15min-best-strategies-v2.pkl', 'rb') as inpt:\n",
" best_strategies_15min = pickle.load(inpt)\n",
"\n",
"with open('cache/30min-best-strategies.pkl', 'rb') as inpt:\n",
"with open('cache/30min-best-strategies-v6.pkl', 'rb') as inpt:\n",
" best_strategies_30min = pickle.load(inpt)"
]
},
@ -107,19 +107,31 @@
},
{
"cell_type": "code",
"execution_count": 5,
"execution_count": 7,
"metadata": {},
"outputs": [],
"source": [
"def results_plot(buy_and_hold_concat, gmadl_5min_model_concat, rsi_5_min_concat, gmadl_15min_model_concat, rsi_30min_concat, macd_30min_concat, width=850, height=500, notitle=False):\n",
"def results_plot(\n",
" buy_and_hold_concat,\n",
" macd_30min_concat,\n",
" rsi_30min_concat,\n",
" rsi_5_min_concat,\n",
" rmse_30min_model_concat,\n",
" rmse_15min_model_concat,\n",
" gmadl_30min_model_concat,\n",
" gmadl_15min_model_concat,\n",
" gmadl_5min_model_concat, width=850, height=500, notitle=False):\n",
"\n",
" fig = go.Figure([\n",
" go.Scatter(y=buy_and_hold_concat['portfolio_value'], x=buy_and_hold_concat['time'], name=\"Buy and Hold\"),\n",
" go.Scatter(y=gmadl_5min_model_concat['portfolio_value'], x=gmadl_5min_model_concat['time'], name=\"GMADL Informer Strategy (5min)\"),\n",
" go.Scatter(y=rsi_5_min_concat['portfolio_value'], x=rsi_5_min_concat['time'], name=\"RSI Strategy (5min)\"),\n",
" go.Scatter(y=gmadl_15min_model_concat['portfolio_value'], x=gmadl_15min_model_concat['time'], name='GMADL Informer Strategy (15min)'),\n",
" go.Scatter(y=macd_30min_concat['portfolio_value'], x=macd_30min_concat['time'], name='MACD Strategy (30min)'),\n",
" go.Scatter(y=rsi_30min_concat['portfolio_value'], x=rsi_30min_concat['time'], name='RSI Strategy (30min)'),\n",
" go.Scatter(y=macd_30min_concat['portfolio_value'], x=macd_30min_concat['time'], name='MACD Strategy (30min)')\n",
" go.Scatter(y=rsi_5_min_concat['portfolio_value'], x=rsi_5_min_concat['time'], name=\"RSI Strategy (5min)\"),\n",
" go.Scatter(y=rmse_30min_model_concat['portfolio_value'], x=rmse_30min_model_concat['time'], name='RMSE Informer Strategy (30min)'),\n",
" go.Scatter(y=rmse_15min_model_concat['portfolio_value'], x=rmse_15min_model_concat['time'], name='RMSE Informer Strategy (15min)'),\n",
" go.Scatter(y=gmadl_30min_model_concat['portfolio_value'], x=gmadl_30min_model_concat['time'], name='GMADL Informer Strategy (30min)'),\n",
" go.Scatter(y=gmadl_15min_model_concat['portfolio_value'], x=gmadl_15min_model_concat['time'], name='GMADL Informer Strategy (15min)'),\n",
" go.Scatter(y=gmadl_5min_model_concat['portfolio_value'], x=gmadl_5min_model_concat['time'], name=\"GMADL Informer Strategy (5min)\")\n",
" ])\n",
" fig.update_layout(\n",
" # title={\n",
@ -137,7 +149,7 @@
" autosize=False,\n",
" width=width,\n",
" height=height,\n",
" margin=dict(l=20, r=20, t=20, b=20),\n",
" margin=dict(l=20, r=20, t=50, b=20),\n",
" plot_bgcolor='white',\n",
" legend=dict(\n",
" orientation=\"h\",\n",
@ -164,7 +176,17 @@
" # fig.write_image(f\"images/eval-w{idx}-{INTERVAL}.png\")\n",
" fig.show()\n",
" \n",
"def results_table(buy_and_hold_concat, gmadl_5min_model_concat, rsi_5_min_concat, gmadl_15min_model_concat, rsi_30min_concat, macd_30min_concat):\n",
"def results_table(\n",
" buy_and_hold_concat,\n",
" macd_30min_concat,\n",
" rsi_30min_concat,\n",
" rsi_5_min_concat,\n",
" rmse_30min_model_concat,\n",
" rmse_15min_model_concat,\n",
" gmadl_30min_model_concat,\n",
" gmadl_15min_model_concat,\n",
" gmadl_5min_model_concat):\n",
"\n",
" table_eval_windows = Texttable()\n",
" table_eval_windows.set_deco(Texttable.HEADER)\n",
" table_eval_windows.set_cols_align([\"l\", \"c\",\"c\", \"c\", \"c\", \"c\", \"c\", \"c\", \"c\", \"c\"])\n",
@ -185,11 +207,14 @@
"\n",
" strategy_name_result = [\n",
" ('Buy and Hold', buy_and_hold_concat),\n",
" ('GMADL Informer (5min)', gmadl_5min_model_concat),\n",
" ('RSI Strategy (5min)', rsi_5_min_concat),\n",
" ('GMADL Informer (15min)', gmadl_15min_model_concat),\n",
" ('MACD Strategy (30min)', macd_30min_concat),\n",
" ('RSI Strategy (30min)', rsi_30min_concat),\n",
" ('MACD Strategy (30min)', macd_30min_concat)\n",
" ('RSI Strategy (5min)', rsi_5_min_concat),\n",
" ('RMSE Informer (30min)', rmse_30min_model_concat),\n",
" ('RMSE Informer (15min)', rmse_15min_model_concat),\n",
" ('GMADL Informer (30min)', gmadl_30min_model_concat),\n",
" ('GMADL Informer (15min)', gmadl_15min_model_concat),\n",
" ('GMADL Informer (5min)', gmadl_5min_model_concat),\n",
" ]\n",
" for strategy_name, result in strategy_name_result:\n",
" table_eval_windows.add_row([\n",
@ -209,23 +234,70 @@
},
{
"cell_type": "code",
"execution_count": 7,
"execution_count": 9,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"\\begin{table}\n",
"\t\\begin{center}\n",
"\t\t\\begin{tabular}{lccccccccc}\n",
"\t\t\t\\textbf{Strategy} & \\textbf{VAL} & \\textbf{ARC} & \\textbf{ASD} & \\textbf{IR*} & \\textbf{MD} & \\textbf{IR**} & \\textbf{N} & \\textbf{LONG} & \\textbf{SHORT} \\\\\n",
"\t\t\t\\hline\n",
"\t\t\tBuy and Hold & 1.441 & 0.131 & 0.577 & 0.228 & 0.773 & 0.039 & 2 & 100.00\\% & 0.00\\% \\\\\n",
"\t\t\tMACD Strategy (30min) & 1.952 & 0.254 & 0.524 & 0.485 & 0.592 & 0.207 & 327 & 52.30\\% & 28.30\\% \\\\\n",
"\t\t\tRSI Strategy (30min) & 4.542 & 0.668 & 0.462 & 1.444 & 0.399 & 2.415 & 377 & 30.79\\% & 28.03\\% \\\\\n",
"\t\t\tRSI Strategy (5min) & 3.341 & 0.503 & 0.504 & 0.999 & 0.300 & 1.676 & 846 & 28.29\\% & 33.47\\% \\\\\n",
"\t\t\tRMSE Informer (30min) & 2.727 & 0.404 & 0.505 & 0.800 & 0.518 & 0.624 & 34 & 64.40\\% & 24.67\\% \\\\\n",
"\t\t\tRMSE Informer (15min) & 1.509 & 0.149 & 0.349 & 0.428 & 0.455 & 0.140 & 16 & 15.24\\% & 27.60\\% \\\\\n",
"\t\t\tGMADL Informer (30min) & 2.263 & 0.318 & 0.367 & 0.866 & 0.533 & 0.516 & 811 & 35.51\\% & 19.59\\% \\\\\n",
"\t\t\tGMADL Informer (15min) & 3.296 & 0.496 & 0.527 & 0.942 & 0.474 & 0.987 & 362 & 49.37\\% & 37.72\\% \\\\\n",
"\t\t\tGMADL Informer (5min) & 9.747 & 1.159 & 0.544 & 2.129 & 0.327 & 7.552 & 846 & 44.80\\% & 41.51\\% \\\\\n",
"\t\t\\end{tabular}\n",
"\t\\end{center}\n",
"\\end{table}\n"
]
}
],
"source": [
"# test_data_5min = pd.concat([data_windows_5min[0][0][-PADDING:]] + [data_window[1] for data_window in data_windows_5min])\n",
"# test_data_15min = pd.concat([data_windows_15min[0][0][-PADDING:]] + [data_window[1] for data_window in data_windows_15min])\n",
"# test_data_30min = pd.concat([data_windows_30min[0][0][-PADDING:]] + [data_window[1] for data_window in data_windows_30min])\n",
"test_data_5min = pd.concat([data_windows_5min[0][0][-PADDING:]] + [data_window[1] for data_window in data_windows_5min])\n",
"test_data_15min = pd.concat([data_windows_15min[0][0][-PADDING:]] + [data_window[1] for data_window in data_windows_15min])\n",
"test_data_30min = pd.concat([data_windows_30min[0][0][-PADDING:]] + [data_window[1] for data_window in data_windows_30min])\n",
"\n",
"# buy_and_hold_concat = evaluate_strategy(test_data_5min, BuyAndHoldStrategy(), padding=PADDING, interval='5min')\n",
"# gmadl_5min_model_concat = evaluate_strategy(test_data_5min, ConcatenatedStrategies(len(data_windows_5min[0][1]), [s[0] for s in best_strategies_5min['gmadl_model']], padding=PADDING), padding=PADDING, interval='5min')\n",
"# gmadl_15min_model_concat = evaluate_strategy(test_data_15min, ConcatenatedStrategies(len(data_windows_15min[0][1]), [s[0] for s in best_strategies_15min['gmadl_model']], padding=PADDING), padding=PADDING, interval='15min')\n",
"# rsi_5_min_concat = evaluate_strategy(test_data_5min, ConcatenatedStrategies(len(data_windows_5min[0][1]), [s[0] for s in best_strategies_5min['rsi_strategies']], padding=PADDING), padding=PADDING, interval='5min')\n",
"# rsi_30min_concat = evaluate_strategy(test_data_30min, ConcatenatedStrategies(len(data_windows_30min[0][1]), [s[0] for s in best_strategies_30min['rsi_strategies']], padding=PADDING), padding=PADDING, interval='30min')\n",
"# macd_30min_concat = evaluate_strategy(test_data_30min, ConcatenatedStrategies(len(data_windows_30min[0][1]), [s[0] for s in best_strategies_30min['macd_strategies']], padding=PADDING), padding=PADDING, interval='30min')\n",
"buy_and_hold_concat = evaluate_strategy(test_data_5min, BuyAndHoldStrategy(), padding=PADDING, interval='5min')\n",
"macd_30min_concat = evaluate_strategy(test_data_30min, ConcatenatedStrategies(len(data_windows_30min[0][1]), [s[0] for s in best_strategies_30min['macd_strategies']], padding=PADDING), padding=PADDING, interval='30min')\n",
"rsi_30min_concat = evaluate_strategy(test_data_30min, ConcatenatedStrategies(len(data_windows_30min[0][1]), [s[0] for s in best_strategies_30min['rsi_strategies']], padding=PADDING), padding=PADDING, interval='30min')\n",
"rsi_5_min_concat = evaluate_strategy(test_data_5min, ConcatenatedStrategies(len(data_windows_5min[0][1]), [s[0] for s in best_strategies_5min['rsi_strategies']], padding=PADDING), padding=PADDING, interval='5min')\n",
"rmse_30min_model_concat = evaluate_strategy(test_data_30min, ConcatenatedStrategies(len(data_windows_30min[0][1]), [s[0] for s in best_strategies_30min['rmse_model']], padding=PADDING), padding=PADDING, interval='30min')\n",
"rmse_15min_model_concat = evaluate_strategy(test_data_15min, ConcatenatedStrategies(len(data_windows_15min[0][1]), [s[0] for s in best_strategies_15min['rmse_model']], padding=PADDING), padding=PADDING, interval='15min')\n",
"gmadl_30min_model_concat = evaluate_strategy(test_data_30min, ConcatenatedStrategies(len(data_windows_30min[0][1]), [s[0] for s in best_strategies_30min['gmadl_model']], padding=PADDING), padding=PADDING, interval='30min')\n",
"gmadl_15min_model_concat = evaluate_strategy(test_data_15min, ConcatenatedStrategies(len(data_windows_15min[0][1]), [s[0] for s in best_strategies_15min['gmadl_model']], padding=PADDING), padding=PADDING, interval='15min')\n",
"gmadl_5min_model_concat = evaluate_strategy(test_data_5min, ConcatenatedStrategies(len(data_windows_5min[0][1]), [s[0] for s in best_strategies_5min['gmadl_model']], padding=PADDING), padding=PADDING, interval='5min')\n",
"\n",
"# results_table(buy_and_hold_concat, gmadl_5min_model_concat, rsi_5_min_concat, gmadl_15min_model_concat, rsi_30min_concat, macd_30min_concat)\n",
"# results_plot(buy_and_hold_concat, gmadl_5min_model_concat, gmadl_15min_model_concat, rsi_5_min_concat, rsi_30min_concat, macd_30min_concat, width=1200, notitle=True)"
"results_table(\n",
" buy_and_hold_concat,\n",
" macd_30min_concat,\n",
" rsi_30min_concat,\n",
" rsi_5_min_concat,\n",
" rmse_30min_model_concat,\n",
" rmse_15min_model_concat,\n",
" gmadl_30min_model_concat,\n",
" gmadl_15min_model_concat,\n",
" gmadl_5min_model_concat)\n",
"\n",
"# results_plot(\n",
"# buy_and_hold_concat,\n",
"# macd_30min_concat,\n",
"# rsi_30min_concat,\n",
"# rsi_5_min_concat,\n",
"# rmse_30min_model_concat,\n",
"# rmse_15min_model_concat,\n",
"# gmadl_30min_model_concat,\n",
"# gmadl_15min_model_concat,\n",
"# gmadl_5min_model_concat, \n",
"# width=1200, notitle=True)"
]
},
{
@ -248,27 +320,33 @@
"buy_and_hold_5min = evaluate_strategy(test_data_5min, BuyAndHoldStrategy(), padding=PADDING, interval='5min')\n",
"buy_and_hold_15min = evaluate_strategy(test_data_15min, BuyAndHoldStrategy(), padding=PADDING, interval='15min')\n",
"buy_and_hold_30min = evaluate_strategy(test_data_30min, BuyAndHoldStrategy(), padding=PADDING, interval='30min')\n",
"gmadl_5min_model_concat = evaluate_strategy(test_data_5min, ConcatenatedStrategies(len(data_windows_5min[0][1]), [s[0] for s in best_strategies_5min['gmadl_model']], padding=PADDING), padding=PADDING, interval='5min')\n",
"gmadl_15min_model_concat = evaluate_strategy(test_data_15min, ConcatenatedStrategies(len(data_windows_15min[0][1]), [s[0] for s in best_strategies_15min['gmadl_model']], padding=PADDING), padding=PADDING, interval='15min')\n",
"rsi_5_min_concat = evaluate_strategy(test_data_5min, ConcatenatedStrategies(len(data_windows_5min[0][1]), [s[0] for s in best_strategies_5min['rsi_strategies']], padding=PADDING), padding=PADDING, interval='5min')\n",
"macd_30min_concat = evaluate_strategy(test_data_30min, ConcatenatedStrategies(len(data_windows_30min[0][1]), [s[0] for s in best_strategies_30min['macd_strategies']], padding=PADDING), padding=PADDING, interval='30min')\n",
"rsi_30min_concat = evaluate_strategy(test_data_30min, ConcatenatedStrategies(len(data_windows_30min[0][1]), [s[0] for s in best_strategies_30min['rsi_strategies']], padding=PADDING), padding=PADDING, interval='30min')\n",
"macd_30min_concat = evaluate_strategy(test_data_30min, ConcatenatedStrategies(len(data_windows_30min[0][1]), [s[0] for s in best_strategies_30min['macd_strategies']], padding=PADDING), padding=PADDING, interval='30min')"
"rsi_5_min_concat = evaluate_strategy(test_data_5min, ConcatenatedStrategies(len(data_windows_5min[0][1]), [s[0] for s in best_strategies_5min['rsi_strategies']], padding=PADDING), padding=PADDING, interval='5min')\n",
"rmse_30min_model_concat = evaluate_strategy(test_data_30min, ConcatenatedStrategies(len(data_windows_30min[0][1]), [s[0] for s in best_strategies_30min['rmse_model']], padding=PADDING), padding=PADDING, interval='30min')\n",
"rmse_15min_model_concat = evaluate_strategy(test_data_15min, ConcatenatedStrategies(len(data_windows_15min[0][1]), [s[0] for s in best_strategies_15min['rmse_model']], padding=PADDING), padding=PADDING, interval='15min')\n",
"gmadl_30min_model_concat = evaluate_strategy(test_data_30min, ConcatenatedStrategies(len(data_windows_30min[0][1]), [s[0] for s in best_strategies_30min['gmadl_model']], padding=PADDING), padding=PADDING, interval='30min')\n",
"gmadl_15min_model_concat = evaluate_strategy(test_data_15min, ConcatenatedStrategies(len(data_windows_15min[0][1]), [s[0] for s in best_strategies_15min['gmadl_model']], padding=PADDING), padding=PADDING, interval='15min')\n",
"gmadl_5min_model_concat = evaluate_strategy(test_data_5min, ConcatenatedStrategies(len(data_windows_5min[0][1]), [s[0] for s in best_strategies_5min['gmadl_model']], padding=PADDING), padding=PADDING, interval='5min')"
]
},
{
"cell_type": "code",
"execution_count": 55,
"execution_count": 12,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"GMADL (5min) & 311040 & 2.820834 & 375.84 & 0.000000*** \\\\\n",
"GMADL (15 min) & 103680 & 0.558743 & 408.13 & 0.000000*** \\\\\n",
"RSI (5 min) & 311040 & 0.648741 & 662.77 & 0.000000*** \\\\\n",
"MACD (30 min) & 51840 & 0.326504 & 174.34 & 0.000000*** \\\\\n",
"RSI (30 min) & 51840 & 1.065079 & 258.49 & 0.000000*** \\\\\n",
"MACD (30 min) & 51840 & 0.326504 & 174.34 & 0.000000*** \\\\\n"
"RSI (5 min) & 311040 & 0.648741 & 662.77 & 0.000000*** \\\\\n",
"RMSE (30 min) & 51840 & 0.796647 & 161.58 & 0.000000*** \\\\\n",
"RMSE (15 min) & 103680 & 0.541611 & 115.29 & 0.000000*** \\\\\n",
"GMADL (30 min) & 51840 & 0.320689 & 448.49 & 0.000000*** \\\\\n",
"GMADL (15 min) & 103680 & 0.558743 & 408.13 & 0.000000*** \\\\\n",
"GMADL (5min) & 311040 & 2.820834 & 375.84 & 0.000000*** \\\\\n"
]
}
],
@ -285,18 +363,24 @@
"\n",
" return tt, pval, sigma, N\n",
"\n",
"gmadl_5min_ttest = ttest(buy_and_hold_5min, gmadl_5min_model_concat)\n",
"gmadl_15min_ttest = ttest(buy_and_hold_15min, gmadl_15min_model_concat)\n",
"rsi_5min_ttest = ttest(buy_and_hold_5min, rsi_5_min_concat)\n",
"rsi_30min_ttest = ttest(buy_and_hold_30min, rsi_30min_concat)\n",
"macd_30min_ttest = ttest(buy_and_hold_30min, macd_30min_concat)\n",
"rsi_30min_ttest = ttest(buy_and_hold_30min, rsi_30min_concat)\n",
"rsi_5min_ttest = ttest(buy_and_hold_5min, rsi_5_min_concat)\n",
"rmse_30min_ttest = ttest(buy_and_hold_30min, rmse_30min_model_concat)\n",
"rmse_15min_ttest = ttest(buy_and_hold_15min, rmse_15min_model_concat)\n",
"gmadl_30min_ttest = ttest(buy_and_hold_30min, gmadl_30min_model_concat)\n",
"gmadl_15min_ttest = ttest(buy_and_hold_15min, gmadl_15min_model_concat)\n",
"gmadl_5min_ttest = ttest(buy_and_hold_5min, gmadl_5min_model_concat)\n",
"\n",
"for name, result in [\n",
" (\"GMADL (5min)\", gmadl_5min_ttest),\n",
" (\"GMADL (15 min)\", gmadl_15min_ttest),\n",
" (\"RSI (5 min)\", rsi_5min_ttest),\n",
" (\"MACD (30 min)\", macd_30min_ttest),\n",
" (\"RSI (30 min)\", rsi_30min_ttest),\n",
" (\"MACD (30 min)\", macd_30min_ttest)\n",
" (\"RSI (5 min)\", rsi_5min_ttest),\n",
" (\"RMSE (30 min)\", rmse_30min_ttest),\n",
" (\"RMSE (15 min)\", rmse_15min_ttest),\n",
" (\"GMADL (30 min)\", gmadl_30min_ttest),\n",
" (\"GMADL (15 min)\", gmadl_15min_ttest),\n",
" (\"GMADL (5min)\", gmadl_5min_ttest),\n",
"]:\n",
" print(f\"{name} & {result[3]} & {result[2]:.6f} & {result[0]:.2f} & {result[1]:.6f}*** \\\\\\\\\")"
]
@ -310,52 +394,88 @@
},
{
"cell_type": "code",
"execution_count": 56,
"execution_count": 23,
"metadata": {},
"outputs": [],
"source": [
"# def results_for_strats(data_windows, best_strategies, interval='5min', top_n=10):\n",
"# test_data = pd.concat([data_windows[0][0][-PADDING:]] + [data_window[1] for data_window in data_windows])\n",
"def results_for_strats(\n",
" data_windows_5min, data_windows_15min, data_windows_30min, \n",
" best_strategies_5min, best_strategies_15min, best_strategies_30min,\n",
" top_n=10):\n",
" test_data_5min = pd.concat([data_windows_5min[0][0][-PADDING:]] + [data_window[1] for data_window in data_windows_5min])\n",
" test_data_15min = pd.concat([data_windows_15min[0][0][-PADDING:]] + [data_window[1] for data_window in data_windows_15min])\n",
" test_data_30min = pd.concat([data_windows_30min[0][0][-PADDING:]] + [data_window[1] for data_window in data_windows_30min])\n",
"\n",
" \n",
"# buy_and_hold_concat = evaluate_strategy(test_data, BuyAndHoldStrategy(), padding=PADDING, interval=interval)\n",
"# macd_concat = [evaluate_strategy(test_data, ConcatenatedStrategies(len(data_windows[0][1]), [s[x] for s in best_strategies['macd_strategies']], padding=PADDING), padding=PADDING, interval=interval) for x in range(top_n)]\n",
"# rsi_concat = [evaluate_strategy(test_data, ConcatenatedStrategies(len(data_windows[0][1]), [s[x] for s in best_strategies['rsi_strategies']], padding=PADDING), padding=PADDING, interval=interval) for x in range(top_n)]\n",
"# quantile_model_concat = [evaluate_strategy(test_data, ConcatenatedStrategies(len(data_windows[0][1]), [s[x] for s in best_strategies['quantile_model']], padding=PADDING), padding=PADDING, interval=interval) for x in range(top_n)]\n",
"# gmadl_model_concat = [evaluate_strategy(test_data, ConcatenatedStrategies(len(data_windows[0][1]), [s[x] for s in best_strategies['gmadl_model']], padding=PADDING), padding=PADDING, interval=interval) for x in range(top_n)]\n",
" buy_and_hold_concat = evaluate_strategy(test_data_5min, BuyAndHoldStrategy(), padding=PADDING, interval='5min')\n",
" macd_30min_concat = [evaluate_strategy(test_data_30min, ConcatenatedStrategies(len(data_windows_30min[0][1]), [s[x] for s in best_strategies_30min['macd_strategies']], padding=PADDING), padding=PADDING, interval='30min') for x in range(top_n)]\n",
" macd_15min_concat = [evaluate_strategy(test_data_15min, ConcatenatedStrategies(len(data_windows_15min[0][1]), [s[x] for s in best_strategies_15min['macd_strategies']], padding=PADDING), padding=PADDING, interval='15min') for x in range(top_n)]\n",
" macd_5min_concat = [evaluate_strategy(test_data_5min, ConcatenatedStrategies(len(data_windows_5min[0][1]), [s[x] for s in best_strategies_5min['macd_strategies']], padding=PADDING), padding=PADDING, interval='5min') for x in range(top_n)]\n",
" rsi_30min_concat = [evaluate_strategy(test_data_30min, ConcatenatedStrategies(len(data_windows_30min[0][1]), [s[x] for s in best_strategies_30min['rsi_strategies']], padding=PADDING), padding=PADDING, interval='30min') for x in range(top_n)]\n",
" rsi_15min_concat = [evaluate_strategy(test_data_15min, ConcatenatedStrategies(len(data_windows_15min[0][1]), [s[x] for s in best_strategies_15min['rsi_strategies']], padding=PADDING), padding=PADDING, interval='15min') for x in range(top_n)]\n",
" rsi_5_min_concat = [evaluate_strategy(test_data_5min, ConcatenatedStrategies(len(data_windows_5min[0][1]), [s[x] for s in best_strategies_5min['rsi_strategies']], padding=PADDING), padding=PADDING, interval='5min') for x in range(top_n)]\n",
" rmse_30min_model_concat = [evaluate_strategy(test_data_30min, ConcatenatedStrategies(len(data_windows_30min[0][1]), [s[x] for s in best_strategies_30min['rmse_model']], padding=PADDING), padding=PADDING, interval='30min') for x in range(top_n)]\n",
" rmse_15min_model_concat = [evaluate_strategy(test_data_15min, ConcatenatedStrategies(len(data_windows_15min[0][1]), [s[x] for s in best_strategies_15min['rmse_model']], padding=PADDING), padding=PADDING, interval='15min') for x in range(top_n)]\n",
" rmse_5min_model_concat = [evaluate_strategy(test_data_5min, ConcatenatedStrategies(len(data_windows_5min[0][1]), [s[x] for s in best_strategies_5min['rmse_model']], padding=PADDING), padding=PADDING, interval='5min') for x in range(top_n)]\n",
" quantile_30min_model_concat = [evaluate_strategy(test_data_30min, ConcatenatedStrategies(len(data_windows_30min[0][1]), [s[x] for s in best_strategies_30min['quantile_model']], padding=PADDING), padding=PADDING, interval='30min') for x in range(top_n)]\n",
" quantile_15min_model_concat = [evaluate_strategy(test_data_15min, ConcatenatedStrategies(len(data_windows_15min[0][1]), [s[x] for s in best_strategies_15min['quantile_model']], padding=PADDING), padding=PADDING, interval='15min') for x in range(top_n)]\n",
" quantile_5min_model_concat = [evaluate_strategy(test_data_5min, ConcatenatedStrategies(len(data_windows_5min[0][1]), [s[x] for s in best_strategies_5min['quantile_model']], padding=PADDING), padding=PADDING, interval='5min') for x in range(top_n)]\n",
" gmadl_30min_model_concat = [evaluate_strategy(test_data_30min, ConcatenatedStrategies(len(data_windows_30min[0][1]), [s[x] for s in best_strategies_30min['gmadl_model']], padding=PADDING), padding=PADDING, interval='30min') for x in range(top_n)]\n",
" gmadl_15min_model_concat = [evaluate_strategy(test_data_15min, ConcatenatedStrategies(len(data_windows_15min[0][1]), [s[x] for s in best_strategies_15min['gmadl_model']], padding=PADDING), padding=PADDING, interval='15min') for x in range(top_n)]\n",
" gmadl_5min_model_concat = [evaluate_strategy(test_data_5min, ConcatenatedStrategies(len(data_windows_5min[0][1]), [s[x] for s in best_strategies_5min['gmadl_model']], padding=PADDING), padding=PADDING, interval='5min') for x in range(top_n)]\n",
"\n",
"# z = list(reversed([\n",
"# list(reversed([round(buy_and_hold_concat['mod_ir'], 3)]*top_n)),\n",
"# list(reversed([round(x['mod_ir'], 3) for x in macd_concat])),\n",
"# list(reversed([round(x['mod_ir'], 3) for x in rsi_concat])),\n",
"# list(reversed([round(x['mod_ir'], 3) for x in quantile_model_concat])),\n",
"# list(reversed([round(x['mod_ir'], 3) for x in gmadl_model_concat])),\n",
"# ]))\n",
"# x = list(reversed(range(1, top_n+1)))\n",
"# y = list(reversed([\n",
"# \"Buy and Hold\",\n",
"# \"MACD Strategy\",\n",
"# \"RSI Strategy\",\n",
"# \"Quantile Informer\",\n",
"# \"Gmadl Informer\"\n",
"# ]))\n",
"# # 'Portland'\n",
"# fig = ff.create_annotated_heatmap(z, x=x, y=y, colorscale='thermal', zmid=buy_and_hold_concat['mod_ir'])\n",
"# fig.update_layout(\n",
"# margin=dict(l=20, r=20, b=20, t=20),\n",
"# width=1100,\n",
"# height=450,\n",
"# font=dict(\n",
"# # family=\"Courier New, monospace\",\n",
"# size=18, # Set the font size here\n",
"# # color=\"RebeccaPurple\"\n",
"# )\n",
"# )\n",
"# fig.show()\n",
" z = list(reversed([\n",
" list(reversed([round(buy_and_hold_concat['mod_ir'], 3)]*top_n)),\n",
" list(reversed([round(x['mod_ir'], 3) for x in macd_30min_concat])),\n",
" list(reversed([round(x['mod_ir'], 3) for x in macd_15min_concat])),\n",
" list(reversed([round(x['mod_ir'], 3) for x in macd_5min_concat])),\n",
" list(reversed([round(x['mod_ir'], 3) for x in rsi_30min_concat])),\n",
" list(reversed([round(x['mod_ir'], 3) for x in rsi_15min_concat])),\n",
" list(reversed([round(x['mod_ir'], 3) for x in rsi_5_min_concat])),\n",
" list(reversed([round(x['mod_ir'], 3) for x in rmse_30min_model_concat])),\n",
" list(reversed([round(x['mod_ir'], 3) for x in rmse_15min_model_concat])),\n",
" list(reversed([round(x['mod_ir'], 3) for x in rmse_5min_model_concat])),\n",
" list(reversed([round(x['mod_ir'], 3) for x in quantile_30min_model_concat])),\n",
" list(reversed([round(x['mod_ir'], 3) for x in quantile_15min_model_concat])),\n",
" list(reversed([round(x['mod_ir'], 3) for x in quantile_5min_model_concat])),\n",
" list(reversed([round(x['mod_ir'], 3) for x in gmadl_30min_model_concat])),\n",
" list(reversed([round(x['mod_ir'], 3) for x in gmadl_15min_model_concat])),\n",
" list(reversed([round(x['mod_ir'], 3) for x in gmadl_5min_model_concat])),\n",
" ]))\n",
" x = list(reversed(range(1, top_n+1)))\n",
" y = list(reversed([\n",
" \"Buy and Hold\",\n",
" \"MACD Strategy (30 min)\",\n",
" \"MACD Strategy (15 min)\",\n",
" \"MACD Strategy (5 min)\",\n",
" \"RSI Strategy (30 min)\",\n",
" \"RSI Strategy (15 min)\",\n",
" \"RSI Strategy (5 min)\",\n",
" \"RMSE Informer (30 min)\",\n",
" \"RMSE Informer (15 min)\",\n",
" \"RMSE Informer (5 min)\",\n",
" \"Quantile Informer (30 min)\",\n",
" \"Quantile Informer (15 min)\",\n",
" \"Quantile Informer (5 min)\",\n",
" \"Gmadl Informer (30 min)\",\n",
" \"Gmadl Informer (15 min)\",\n",
" \"Gmadl Informer (5 min)\"\n",
" ]))\n",
" # 'Portland'\n",
" fig = ff.create_annotated_heatmap(z, x=x, y=y, colorscale='thermal', zmid=buy_and_hold_concat['mod_ir'])\n",
" fig.update_layout(\n",
" margin=dict(l=20, r=20, b=20, t=20),\n",
" width=1100,\n",
" height=650,\n",
" font=dict(\n",
" # family=\"Courier New, monospace\",\n",
" size=16, # Set the font size here\n",
" # color=\"RebeccaPurple\"\n",
" )\n",
" )\n",
" fig.show()\n",
"\n",
"# results_for_strats(data_windows_5min, best_strategies_5min, interval='5min', top_n=10) \n",
"# results_for_strats(data_windows_15min, best_strategies_15min, interval='15min', top_n=10) \n",
"# results_for_strats(data_windows_30min, best_strategies_30min, interval='30min', top_n=10) \n"
"# results_for_strats(data_windows_5min, data_windows_15min, data_windows_30min,\n",
"# best_strategies_5min, best_strategies_15min, best_strategies_30min, top_n=10) "
]
},
{