diff --git a/notebooks/btcusdt_1m_evaluation.ipynb b/notebooks/btcusdt_1m_evaluation.ipynb new file mode 100644 index 0000000..a075604 --- /dev/null +++ b/notebooks/btcusdt_1m_evaluation.ipynb @@ -0,0 +1,507 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 1, + "metadata": {}, + "outputs": [], + "source": [ + "import pandas as pd\n", + "import pickle\n", + "import plotly.graph_objs as go\n", + "import latextable\n", + "from texttable import Texttable\n", + "from strategy.strategy import (\n", + " BuyAndHoldStrategy,\n", + " MACDStrategy,\n", + " RSIStrategy,\n", + " ModelQuantilePredictionsStrategy,\n", + " ModelGmadlPredictionsStrategy,\n", + " ConcatenatedStrategies\n", + ")\n", + "from strategy.util import (\n", + " get_data_windows,\n", + " get_sweep_window_predictions,\n", + " get_predictions_dataframe\n", + ")\n", + "from strategy.evaluation import (\n", + " parameter_sweep,\n", + " evaluate_strategy\n", + ")\n", + "from strategy.plotting import (\n", + " plot_sweep_results\n", + ")\n", + "\n", + "PADDING=5000\n", + "VALID_PART=0.2\n", + "INTERVAL='min'\n", + "METRIC='mod_ir'\n", + "TOP_N=10" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "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-1m:latest, 3717.80MB. 12 files... \n", + "\u001b[34m\u001b[1mwandb\u001b[0m: 12 of 12 files downloaded. \n", + "Done. 0:0:4.7\n" + ] + } + ], + "source": [ + "data_windows = get_data_windows(\n", + " 'wne-masters-thesis-testing',\n", + " 'btc-usdt-1m:latest',\n", + " min_window=0, \n", + " max_window=5\n", + ")" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [], + "source": [ + "def sweeps_on_all_windows(data_windows, strategy_class, params, **kwargs):\n", + " result = []\n", + " for in_sample, _ in data_windows:\n", + " data_part = int((1 - VALID_PART) * len(in_sample))\n", + " result.append(parameter_sweep(in_sample[data_part-PADDING:], strategy_class, params, padding=PADDING, interval=INTERVAL, **kwargs))\n", + " return result" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": {}, + "outputs": [], + "source": [ + "buyandhold_best_strategies = [BuyAndHoldStrategy() for _ in data_windows] " + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "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" + ] + } + ], + "source": [ + "# Model with gmadl loss\n", + "SWEEP_ID = 'filipstefaniuk/wne-masters-thesis-testing/s8goxcbz'\n", + "# SWEEP_ID = 'filipstefaniuk/wne-masters-thesis-testing/v3epl3qk'\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')" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "metadata": {}, + "outputs": [], + "source": [ + "# y = test_gmadl_pred_windows[0][2][:, 0, 0]\n", + "# fig = go.Figure([\n", + "# go.Scatter(y=y[::100]),\n", + "# ])\n", + "# fig.show()" + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "metadata": {}, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "100%|██████████| 1176/1176 [04:40<00:00, 4.20it/s]\n", + "100%|██████████| 1176/1176 [04:40<00:00, 4.20it/s]\n", + "100%|██████████| 1176/1176 [04:36<00:00, 4.26it/s]\n", + "100%|██████████| 1176/1176 [04:35<00:00, 4.28it/s]\n", + "100%|██████████| 1176/1176 [04:36<00:00, 4.26it/s]\n", + "100%|██████████| 1176/1176 [04:30<00:00, 4.35it/s]\n" + ] + } + ], + "source": [ + "MODEL_GMADL_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", + "gmadl_model_sweep_results = []\n", + "for (in_sample, _), valid_preds, test_preds in zip(data_windows, valid_gmadl_pred_windows, test_gmadl_pred_windows):\n", + " data_part = int((1 - VALID_PART) * len(in_sample))\n", + " params={\n", + " 'predictions': [get_predictions_dataframe(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", + " }\n", + " \n", + " gmadl_model_sweep_results.append(parameter_sweep(\n", + " in_sample[data_part-PADDING:],\n", + " ModelGmadlPredictionsStrategy,\n", + " params,\n", + " params_filter=MODEL_GMADL_LOSS_FILTER,\n", + " padding=PADDING,\n", + " interval=INTERVAL,\n", + " sort_by=METRIC))\n", + " \n", + "\n", + "gmadl_model_best_strategies = [[strat for _, strat in results[:TOP_N]] for results in gmadl_model_sweep_results]" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [ + { + "ename": "NameError", + "evalue": "name 'buyandhold_best_strategies' is not defined", + "output_type": "error", + "traceback": [ + "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[0;31mNameError\u001b[0m Traceback (most recent call last)", + "Cell \u001b[0;32mIn[3], line 3\u001b[0m\n\u001b[1;32m 1\u001b[0m \u001b[38;5;66;03m# Persist best strategies, so that they don't have to be recomputed every time\u001b[39;00m\n\u001b[1;32m 2\u001b[0m best_strategies \u001b[38;5;241m=\u001b[39m {\n\u001b[0;32m----> 3\u001b[0m \u001b[38;5;124m'\u001b[39m\u001b[38;5;124mbuy_and_hold\u001b[39m\u001b[38;5;124m'\u001b[39m: \u001b[43mbuyandhold_best_strategies\u001b[49m,\n\u001b[1;32m 4\u001b[0m \u001b[38;5;124m'\u001b[39m\u001b[38;5;124mgmadl_model\u001b[39m\u001b[38;5;124m'\u001b[39m: gmadl_model_best_strategies\n\u001b[1;32m 5\u001b[0m }\n\u001b[1;32m 7\u001b[0m \u001b[38;5;28;01mwith\u001b[39;00m \u001b[38;5;28mopen\u001b[39m(\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mcache/1min-best-strategies-v1.pkl\u001b[39m\u001b[38;5;124m'\u001b[39m, \u001b[38;5;124m'\u001b[39m\u001b[38;5;124mwb\u001b[39m\u001b[38;5;124m'\u001b[39m) \u001b[38;5;28;01mas\u001b[39;00m outp:\n\u001b[1;32m 8\u001b[0m pickle\u001b[38;5;241m.\u001b[39mdump(best_strategies, outp, pickle\u001b[38;5;241m.\u001b[39mHIGHEST_PROTOCOL)\n", + "\u001b[0;31mNameError\u001b[0m: name 'buyandhold_best_strategies' is not defined" + ] + } + ], + "source": [ + "# 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", + " 'gmadl_model': gmadl_model_best_strategies\n", + "}\n", + "\n", + "with open('cache/1min-best-strategies-v1.pkl', 'wb') as outp:\n", + " pickle.dump(best_strategies, outp, pickle.HIGHEST_PROTOCOL)" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": {}, + "outputs": [], + "source": [ + "with open('cache/1min-best-strategies-v1.pkl', 'rb') as inpt:\n", + " best_strategies = pickle.load(inpt)" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [], + "source": [ + "# plot_sweep_results(pd.DataFrame([result for result, _ in gmadl_model_sweep_results[0]]), parameters=['enter_long', 'exit_long', 'enter_short', 'exit_short'], round=5, objective='mod_ir')" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": {}, + "outputs": [], + "source": [ + "def results_plot(idx, result_buyandhold, 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_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", + " 'y':0.97,\n", + " 'x':0.5,\n", + " 'xanchor': 'center',\n", + " 'yanchor': 'top'} if not notitle else None,\n", + " yaxis_title=\"Portfolio Value\",\n", + " xaxis_title=\"Date\",\n", + " font=dict(\n", + " # family=\"Courier New, monospace\",\n", + " size=14,\n", + " ),\n", + " autosize=False,\n", + " width=width,\n", + " height=height,\n", + " margin=dict(l=20, r=20, t=20 if notitle else 110, b=20),\n", + " plot_bgcolor='white',\n", + " legend=dict(\n", + " orientation=\"h\",\n", + " yanchor=\"bottom\",\n", + " y=1.02,\n", + " xanchor=\"left\",\n", + " x=0.02\n", + " )\n", + " )\n", + " fig.update_xaxes(\n", + " mirror=True,\n", + " ticks='outside',\n", + " showline=True,\n", + " linecolor='black',\n", + " gridcolor='lightgrey'\n", + " )\n", + " fig.update_yaxes(\n", + " mirror=True,\n", + " ticks='outside',\n", + " showline=True,\n", + " linecolor='black',\n", + " gridcolor='lightgrey'\n", + " )\n", + " fig.write_image(f\"images/eval-w{idx}-{INTERVAL}.png\")\n", + " fig.show()\n", + " \n", + "def results_table(result_buyandhold, 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", + " table_eval_windows.set_precision(3)\n", + "\n", + " table_eval_windows.header([\n", + " \"\\\\textbf{Strategy}\",\n", + " \"\\\\textbf{VAL}\",\n", + " \"\\\\textbf{ARC}\",\n", + " \"\\\\textbf{ASD}\",\n", + " \"\\\\textbf{IR*}\",\n", + " \"\\\\textbf{MD}\",\n", + " \"\\\\textbf{IR**}\",\n", + " \"\\\\textbf{N}\",\n", + " \"\\\\textbf{LONG}\",\n", + " \"\\\\textbf{SHORT}\",\n", + " ])\n", + "\n", + " strategy_name_result = [\n", + " ('Buy and Hold', result_buyandhold),\n", + " ('GMADL Informer', result_gmadl_model)\n", + " ]\n", + " for strategy_name, result in strategy_name_result:\n", + " table_eval_windows.add_row([\n", + " strategy_name,\n", + " result['value'],\n", + " f\"{result['arc']*100:.2f}\\%\",\n", + " f\"{result['asd']*100:.2f}\\%\",\n", + " result['ir'],\n", + " f\"{result['md']*100:.2f}\\%\",\n", + " result['mod_ir'],\n", + " result['n_trades'],\n", + " f\"{result['long_pos']*100:.2f}\\%\",\n", + " f\"{result['short_pos']*100:.2f}\\%\",\n", + " ])\n", + " print(latextable.draw_latex(table_eval_windows))\n" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "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 & 0.929 & -13.87\\% & 69.66\\% & -0.199 & 52.09\\% & -0.053 & 2 & 100.00\\% & 0.00\\% \\\\\n", + "\t\t\tGMADL Informer & 1.306 & 71.83\\% & 69.69\\% & 1.031 & 41.57\\% & 1.781 & 50 & 7.29\\% & 92.71\\% \\\\\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.35\\% & 73.36\\% & -0.959 & 63.40\\% & -1.064 & 2 & 100.00\\% & 0.00\\% \\\\\n", + "\t\t\tGMADL Informer & 1.837 & 243.15\\% & 73.38\\% & 3.314 & 25.16\\% & 32.024 & 186 & 18.19\\% & 81.81\\% \\\\\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.33\\% & 52.45\\% & 0.064 & 38.42\\% & 0.006 & 2 & 100.00\\% & 0.00\\% \\\\\n", + "\t\t\tGMADL Informer & 0.739 & -45.82\\% & 52.21\\% & -0.878 & 42.46\\% & -0.947 & 35 & 4.70\\% & 93.05\\% \\\\\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.230 & 52.29\\% & 44.30\\% & 1.180 & 22.35\\% & 2.761 & 2 & 100.00\\% & 0.00\\% \\\\\n", + "\t\t\tGMADL Informer & 1.086 & 18.12\\% & 40.58\\% & 0.446 & 26.30\\% & 0.308 & 11 & 60.03\\% & 23.82\\% \\\\\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.31\\% & 43.75\\% & 2.498 & 21.12\\% & 12.930 & 2 & 100.00\\% & 0.00\\% \\\\\n", + "\t\t\tGMADL Informer & 1.010 & 1.98\\% & 43.47\\% & 0.046 & 31.96\\% & 0.003 & 67 & 80.24\\% & 15.37\\% \\\\\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.561 & 146.58\\% & 53.72\\% & 2.729 & 27.11\\% & 14.756 & 2 & 100.00\\% & 0.00\\% \\\\\n", + "\t\t\tGMADL Informer & 1.178 & 39.32\\% & 43.06\\% & 0.913 & 18.63\\% & 1.927 & 92 & 54.86\\% & 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_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_gmadl_model)\n", + " # results_plot(i+1, result_buyandhold, result_gmadl_model)" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "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", + "# 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", + "# results_table(buy_and_hold_concat, gmadl_model_concat)\n", + "# results_plot(0, buy_and_hold_concat, gmadl_model_concat, width=1300, height=500, notitle=True)" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [], + "source": [ + "import plotly.figure_factory as ff\n", + "\n", + "def results_for_strats(\n", + " data_windows, \n", + " best_strategies,\n", + " top_n=10):\n", + " test_data = pd.concat([data_windows[0][0][-PADDING:]] + [data_window[1] for data_window in data_windows])\n", + "\n", + " buy_and_hold_concat = evaluate_strategy(test_data, BuyAndHoldStrategy(), padding=PADDING, interval='min')\n", + " gmadl_1min_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='min') 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 gmadl_1min_model_concat])),\n", + " ]))\n", + " x = list(reversed(range(1, top_n+1)))\n", + " y = list(reversed([\n", + " \"Buy and Hold\",\n", + " \"Gmadl Informer (1 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, best_strategies, top_n=10) " + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "wnemsc", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.9.19" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/notebooks/btcusdt_5m_evaluation.ipynb b/notebooks/btcusdt_5m_evaluation.ipynb index 0ad3b02..e19fca1 100644 --- a/notebooks/btcusdt_5m_evaluation.ipynb +++ b/notebooks/btcusdt_5m_evaluation.ipynb @@ -2,7 +2,7 @@ "cells": [ { "cell_type": "code", - "execution_count": 1, + "execution_count": 2, "metadata": {}, "outputs": [], "source": [ @@ -41,7 +41,7 @@ }, { "cell_type": "code", - "execution_count": 2, + "execution_count": 3, "metadata": {}, "outputs": [ { @@ -51,7 +51,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-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" + "Done. 0:0:1.3\n" ] } ], @@ -369,13 +369,14 @@ }, { "cell_type": "code", - "execution_count": 12, + "execution_count": 2, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ + "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: 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", @@ -478,7 +479,7 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": 4, "metadata": {}, "outputs": [], "source": [ @@ -1022,6 +1023,48 @@ "\n" ] }, + { + "cell_type": "code", + "execution_count": 7, + "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.441 & 13.14\\% & 57.74\\% & 0.228 & 77.31\\% & 0.039 & 2 & 100.00\\% & 0.00\\% \\\\\n", + "\t\t\tMACD Strategy & 1.918 & 24.63\\% & 54.07\\% & 0.456 & 67.19\\% & 0.167 & 2535 & 50.39\\% & 32.38\\% \\\\\n", + "\t\t\tRSI Strategy & 5.154 & 74.05\\% & 50.37\\% & 1.470 & 26.46\\% & 4.113 & 846 & 28.29\\% & 33.47\\% \\\\\n", + "\t\t\tRMSE Informer & 0.650 & -13.53\\% & 15.13\\% & -0.894 & 44.05\\% & -0.275 & 16 & 0.00\\% & 9.58\\% \\\\\n", + "\t\t\tQuantile Informer & 5.404 & 76.86\\% & 47.83\\% & 1.607 & 37.34\\% & 3.307 & 3395 & 40.24\\% & 27.84\\% \\\\\n", + "\t\t\tGMADL Informer & 14.946 & 149.43\\% & 54.42\\% & 2.746 & 31.57\\% & 12.994 & 846 & 44.80\\% & 41.51\\% \\\\\n", + "\t\t\\end{tabular}\n", + "\t\\end{center}\n", + "\\end{table}\n" + ] + } + ], + "source": [ + "# No transaction fees\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, exchange_fee=0)\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, exchange_fee=0)\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, exchange_fee=0)\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, exchange_fee=0)\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, exchange_fee=0)\n", + "\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" + ] + }, { "cell_type": "code", "execution_count": null, diff --git a/notebooks/btcusdt_dataset.ipynb b/notebooks/btcusdt_dataset.ipynb index 147ef61..213705b 100644 --- a/notebooks/btcusdt_dataset.ipynb +++ b/notebooks/btcusdt_dataset.ipynb @@ -110,11 +110,22 @@ "metadata": {}, "outputs": [], "source": [ + "INTERVAL_1_MIN = pd.Timedelta(minutes=1)\n", "INTERVAL_5_MIN = pd.Timedelta(minutes=5)\n", "INTERVAL_15_MIN = pd.Timedelta(minutes=15)\n", "INTERVAL_30_MIN = pd.Timedelta(minutes=30)" ] }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": {}, + "outputs": [], + "source": [ + "# btc_usdt_1_min_data = load_btc_usdt_dataset('../data/raw_data/btc-usdt-1m.csv', INTERVAL_1_MIN)\n", + "# btc_usdt_1_min_data.head()" + ] + }, { "cell_type": "code", "execution_count": 3, @@ -154,7 +165,7 @@ }, { "cell_type": "code", - "execution_count": 66, + "execution_count": 7, "metadata": {}, "outputs": [], "source": [ @@ -180,6 +191,18 @@ "vix_data['date'] = pd.to_datetime(vix_data['date'])" ] }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [], + "source": [ + "# vix_1_min_data = preprocess_vix_data(btc_usdt_1_min_data, vix_data)\n", + "# btc_usdt_1_min_data[VIX_COL_NAME] = vix_1_min_data['close']\n", + "# go.Figure(go.Scatter(y=btc_usdt_1_min_data['vix_close_price'].iloc[::10], x=btc_usdt_1_min_data['close_time'].iloc[::10])).show()\n", + "# btc_usdt_1_min_data.head()" + ] + }, { "cell_type": "code", "execution_count": 4, @@ -225,7 +248,7 @@ }, { "cell_type": "code", - "execution_count": 70, + "execution_count": 9, "metadata": {}, "outputs": [], "source": [ @@ -251,6 +274,18 @@ "fed_data['date'] = pd.to_datetime(fed_data['date'])" ] }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [], + "source": [ + "# fed_1_min_data = preprocess_fed_data(btc_usdt_1_min_data, fed_data)\n", + "# btc_usdt_1_min_data[FED_COL_NAME] = fed_1_min_data['fedfunds']\n", + "# go.Figure(go.Scatter(y=btc_usdt_1_min_data['effective_rates'].iloc[::10], x=btc_usdt_1_min_data['close_time'].iloc[::10])).show()\n", + "# btc_usdt_1_min_data.head()" + ] + }, { "cell_type": "code", "execution_count": 7, @@ -296,7 +331,7 @@ }, { "cell_type": "code", - "execution_count": 74, + "execution_count": 11, "metadata": {}, "outputs": [], "source": [ @@ -323,6 +358,18 @@ "feargreed_data = feargreed_data.sort_values('timestamp').reset_index(drop=True)" ] }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": {}, + "outputs": [], + "source": [ + "# feargreed_1_min_data = preprocess_feargreed_data(btc_usdt_1_min_data, feargreed_data)\n", + "# btc_usdt_1_min_data[FEAR_GREED_COL_NAME] = feargreed_1_min_data['value']\n", + "# go.Figure(go.Scatter(y=btc_usdt_1_min_data['fear_greed_index'].iloc[::10], x=btc_usdt_1_min_data['close_time'].iloc[::10])).show()\n", + "# btc_usdt_1_min_data.head()" + ] + }, { "cell_type": "code", "execution_count": 10, @@ -369,7 +416,7 @@ }, { "cell_type": "code", - "execution_count": 91, + "execution_count": 13, "metadata": {}, "outputs": [], "source": [ @@ -448,13 +495,14 @@ }, { "cell_type": "code", - "execution_count": 92, + "execution_count": 14, "metadata": {}, "outputs": [], "source": [ - "btc_usdt_5_min_data = preprocess_augment_data(btc_usdt_5_min_data, 5)\n", - "btc_usdt_15_min_data = preprocess_augment_data(btc_usdt_15_min_data, 15)\n", - "btc_usdt_30_min_data = preprocess_augment_data(btc_usdt_30_min_data, 30)\n" + "btc_usdt_1_min_data = preprocess_augment_data(btc_usdt_1_min_data, 1)\n", + "# btc_usdt_5_min_data = preprocess_augment_data(btc_usdt_5_min_data, 5)\n", + "# btc_usdt_15_min_data = preprocess_augment_data(btc_usdt_15_min_data, 15)\n", + "# btc_usdt_30_min_data = preprocess_augment_data(btc_usdt_30_min_data, 30)\n" ] }, { @@ -466,13 +514,14 @@ }, { "cell_type": "code", - "execution_count": 93, + "execution_count": 15, "metadata": {}, "outputs": [], "source": [ - "btc_usdt_5_min_data.to_csv('../data/preprocessed_data/processed-btc-usdt-5m.csv', index=False)\n", - "btc_usdt_15_min_data.to_csv('../data/preprocessed_data/processed-btc-usdt-15m.csv', index=False)\n", - "btc_usdt_30_min_data.to_csv('../data/preprocessed_data/processed-btc-usdt-30m.csv', index=False)" + "btc_usdt_1_min_data.to_csv('../data/preprocessed_data/processed-btc-usdt-1m.csv', index=False)\n", + "# btc_usdt_5_min_data.to_csv('../data/preprocessed_data/processed-btc-usdt-5m.csv', index=False)\n", + "# btc_usdt_15_min_data.to_csv('../data/preprocessed_data/processed-btc-usdt-15m.csv', index=False)\n", + "# btc_usdt_30_min_data.to_csv('../data/preprocessed_data/processed-btc-usdt-30m.csv', index=False)" ] }, { @@ -505,6 +554,39 @@ " print(f\"Variables: {dataset.columns}\")\n" ] }, + { + "cell_type": "code", + "execution_count": 17, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "---- DATASET BTC-USDT 1 m ----\n", + "Num observations: 2941560\n", + "First observation: 2019-07-21 00:00:59.999000\n", + "Last observation: 2025-02-21 17:59:59.999000\n", + "Time span: 2042 days (5.6 years)\n", + "Variables: Index(['open_time', 'open_price', 'high_price', 'low_price', 'close_price',\n", + " 'volume', 'close_time', 'vix_close_price', 'effective_rates',\n", + " 'fear_greed_index', 'time_index', 'group_id', 'hour', 'weekday',\n", + " 'open_to_close_price', 'high_to_close_price', 'low_to_close_price',\n", + " 'high_to_low_price', 'returns', 'returns_binary', 'log_returns',\n", + " 'vol_1h', 'sma_1h_to_close_price', 'ema_1h_to_close_price', 'vol_1d',\n", + " 'sma_1d_to_close_price', 'ema_1d_to_close_price', 'vol_7d',\n", + " 'sma_7d_to_close_price', 'macd', 'macd_signal', 'rsi',\n", + " 'low_bband_to_close_price', 'up_bband_to_close_price',\n", + " 'mid_bband_to_close_price'],\n", + " dtype='object')\n" + ] + } + ], + "source": [ + "btc_usdt_1_min_data = load_dataset('../data/preprocessed_data/processed-btc-usdt-1m.csv')\n", + "print_dataset_stats(btc_usdt_1_min_data, 1)" + ] + }, { "cell_type": "code", "execution_count": 3, @@ -613,7 +695,7 @@ }, { "cell_type": "code", - "execution_count": 5, + "execution_count": 4, "metadata": {}, "outputs": [], "source": [ @@ -648,7 +730,7 @@ }, { "cell_type": "code", - "execution_count": 6, + "execution_count": 5, "metadata": {}, "outputs": [], "source": [ @@ -697,17 +779,34 @@ }, { "cell_type": "code", - "execution_count": 8, + "execution_count": 5, "metadata": {}, "outputs": [], "source": [ - "windows_5m_data = split_dataset_moving_window(\n", - " trim_number_of_observations(btc_usdt_5_min_data, limit_time=LIMIT_TIME),\n", - " NUM_MOVING_WINDOWS,\n", - " in_sample_size=(24 * 30 * 24 * (60 // 5)), # 24 months\n", - " out_of_sample_size=(6 * 30 * 24 * (60 // 5)) # 6 months\n", - ")\n", - "plot_moving_windows(btc_usdt_5_min_data, windows_5m_data)" + "# windows_1m_data = split_dataset_moving_window(\n", + "# trim_number_of_observations(btc_usdt_1_min_data, limit_time=LIMIT_TIME),\n", + "# NUM_MOVING_WINDOWS,\n", + "# in_sample_size=(24 * 30 * 24 * 60), # 24 months\n", + "# out_of_sample_size=(6 * 30 * 24 * 60) # 6 months\n", + "# )\n", + "# plot_moving_windows(btc_usdt_1_min_data, windows_1m_data)" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": {}, + "outputs": [], + "source": [ + "# windows_5m_data = split_dataset_moving_window(\n", + "# trim_number_of_observations(btc_usdt_5_min_data, limit_time=LIMIT_TIME),\n", + "# NUM_MOVING_WINDOWS,\n", + "# in_sample_size=(24 * 30 * 24 * (60 // 5)), # 24 months\n", + "# out_of_sample_size=(6 * 30 * 24 * (60 // 5)) # 6 months\n", + "# )\n", + "# plot_moving_windows(btc_usdt_5_min_data, windows_5m_data)\n", + "# for window in windows_5m_data:\n", + "# print(window[0]['open_time'][0], window[0]['open_time'].iloc[-1])" ] }, { @@ -751,7 +850,7 @@ }, { "cell_type": "code", - "execution_count": 11, + "execution_count": 21, "metadata": {}, "outputs": [], "source": [ @@ -762,7 +861,7 @@ }, { "cell_type": "code", - "execution_count": 12, + "execution_count": 22, "metadata": {}, "outputs": [], "source": [ @@ -785,156 +884,16 @@ }, { "cell_type": "code", - "execution_count": 16, + "execution_count": 7, "metadata": {}, - "outputs": [ - { - "data": { - "text/html": [ - "Finishing last run (ID:8ybedy92) before initializing another..." - ], - "text/plain": [ - "" - ] - }, - "metadata": {}, - "output_type": "display_data" - }, - { - "data": { - "text/html": [ - " View run legendary-rose-1822 at: https://wandb.ai/filipstefaniuk/wne-masters-thesis-testing/runs/8ybedy92
View project at: https://wandb.ai/filipstefaniuk/wne-masters-thesis-testing
Synced 6 W&B file(s), 0 media file(s), 6 artifact file(s) and 0 other file(s)" - ], - "text/plain": [ - "" - ] - }, - "metadata": {}, - "output_type": "display_data" - }, - { - "data": { - "text/html": [ - "Find logs at: ./wandb/run-20241101_160026-8ybedy92/logs" - ], - "text/plain": [ - "" - ] - }, - "metadata": {}, - "output_type": "display_data" - }, - { - "data": { - "text/html": [ - "The new W&B backend becomes opt-out in version 0.18.0; try it out with `wandb.require(\"core\")`! See https://wandb.me/wandb-core for more information." - ], - "text/plain": [ - "" - ] - }, - "metadata": {}, - "output_type": "display_data" - }, - { - "data": { - "text/html": [ - "Successfully finished last run (ID:8ybedy92). Initializing new run:
" - ], - "text/plain": [ - "" - ] - }, - "metadata": {}, - "output_type": "display_data" - }, - { - "data": { - "text/html": [ - "wandb version 0.18.5 is available! To upgrade, please run:\n", - " $ pip install wandb --upgrade" - ], - "text/plain": [ - "" - ] - }, - "metadata": {}, - "output_type": "display_data" - }, - { - "data": { - "text/html": [ - "Tracking run with wandb version 0.17.7" - ], - "text/plain": [ - "" - ] - }, - "metadata": {}, - "output_type": "display_data" - }, - { - "data": { - "text/html": [ - "Run data is saved locally in /Users/filipstefaniuk/Documents/wne-msc-thesis/notebooks/wandb/run-20241101_160127-dtz0yasv" - ], - "text/plain": [ - "" - ] - }, - "metadata": {}, - "output_type": "display_data" - }, - { - "data": { - "text/html": [ - "Syncing run alight-triumph-1823 to Weights & Biases (docs)
" - ], - "text/plain": [ - "" - ] - }, - "metadata": {}, - "output_type": "display_data" - }, - { - "data": { - "text/html": [ - " View project at https://wandb.ai/filipstefaniuk/wne-masters-thesis-testing" - ], - "text/plain": [ - "" - ] - }, - "metadata": {}, - "output_type": "display_data" - }, - { - "data": { - "text/html": [ - " View run at https://wandb.ai/filipstefaniuk/wne-masters-thesis-testing/runs/dtz0yasv" - ], - "text/plain": [ - "" - ] - }, - "metadata": {}, - "output_type": "display_data" - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "\u001b[34m\u001b[1mwandb\u001b[0m: Adding directory to artifact (/var/folders/pz/gkm59rg174z0867wc4h3wd000000gn/T/tmpxkxgri0n)... Done. 0.6s\n" - ] - } - ], + "outputs": [], "source": [ - "WANDB_PROJECT = 'wne-masters-thesis-testing'\n", + "# WANDB_PROJECT = 'wne-masters-thesis-testing'\n", "\n", - "upload_dataset_to_wandb(windows_5m_data, 'btc-usdt-5m', project=WANDB_PROJECT)\n", - "upload_dataset_to_wandb(windows_15m_data, 'btc-usdt-15m', project=WANDB_PROJECT)\n", - "upload_dataset_to_wandb(windows_30m_data, 'btc-usdt-30m', project=WANDB_PROJECT)\n" + "# upload_dataset_to_wandb(windows_1m_data, 'btc-usdt-1m', project=WANDB_PROJECT)\n", + "# upload_dataset_to_wandb(windows_5m_data, 'btc-usdt-5m', project=WANDB_PROJECT)\n", + "# upload_dataset_to_wandb(windows_15m_data, 'btc-usdt-15m', project=WANDB_PROJECT)\n", + "# upload_dataset_to_wandb(windows_30m_data, 'btc-usdt-30m', project=WANDB_PROJECT)\n" ] }, { diff --git a/notebooks/sensitivity_analysis.ipynb b/notebooks/sensitivity_analysis.ipynb index 9173746..80f6f58 100644 --- a/notebooks/sensitivity_analysis.ipynb +++ b/notebooks/sensitivity_analysis.ipynb @@ -39,27 +39,36 @@ }, { "cell_type": "code", - "execution_count": 2, + "execution_count": 5, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ - "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-1m:latest, 3717.80MB. 12 files... \n", + "\u001b[34m\u001b[1mwandb\u001b[0m: 12 of 12 files downloaded. \n", + "Done. 0:0:5.3\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.1\n", + "Done. 0:0:0.8\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", "\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" + "Done. 0:0:0.5\n" ] } ], "source": [ + "data_windows_1min = get_data_windows(\n", + " 'wne-masters-thesis-testing',\n", + " 'btc-usdt-1m:latest',\n", + " min_window=0, \n", + " max_window=5\n", + ")\n", + "\n", "data_windows_5min = get_data_windows(\n", " 'wne-masters-thesis-testing',\n", " 'btc-usdt-5m:latest',\n", @@ -84,10 +93,13 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": 6, "metadata": {}, "outputs": [], "source": [ + "with open('cache/1min-best-strategies-v1.pkl', 'rb') as inpt:\n", + " best_strategies_1min = pickle.load(inpt)\n", + "\n", "with open('cache/5min-best-strategies-v2.pkl', 'rb') as inpt:\n", " best_strategies_5min = pickle.load(inpt)\n", "\n", @@ -107,31 +119,34 @@ }, { "cell_type": "code", - "execution_count": 7, + "execution_count": 10, "metadata": {}, "outputs": [], "source": [ "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", + " # 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", + " gmadl_5min_model_concat, \n", + " gmadl_1min_model_concat, \n", + " 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=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=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=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=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", + " go.Scatter(y=gmadl_5min_model_concat['portfolio_value'], x=gmadl_5min_model_concat['time'], name=\"GMADL Informer Strategy (5min)\"),\n", + " go.Scatter(y=gmadl_1min_model_concat['portfolio_value'], x=gmadl_1min_model_concat['time'], name=\"GMADL Informer Strategy (1min)\")\n", " ])\n", " fig.update_layout(\n", " # title={\n", @@ -178,14 +193,16 @@ " \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", + " # 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", + " gmadl_5min_model_concat,\n", + " gmadl_1min_model_concat\n", + " ):\n", "\n", " table_eval_windows = Texttable()\n", " table_eval_windows.set_deco(Texttable.HEADER)\n", @@ -207,14 +224,15 @@ "\n", " strategy_name_result = [\n", " ('Buy and Hold', buy_and_hold_concat),\n", - " ('MACD Strategy (30min)', macd_30min_concat),\n", - " ('RSI Strategy (30min)', rsi_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", + " # ('MACD Strategy (30min)', macd_30min_concat),\n", + " # ('RSI Strategy (30min)', rsi_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", + " ('GMADL Informer (1min)', gmadl_1min_model_concat),\n", " ]\n", " for strategy_name, result in strategy_name_result:\n", " table_eval_windows.add_row([\n", @@ -234,58 +252,50 @@ }, { "cell_type": "code", - "execution_count": 9, + "execution_count": 1, "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.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" + "ename": "NameError", + "evalue": "name 'pd' is not defined", + "output_type": "error", + "traceback": [ + "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[0;31mNameError\u001b[0m Traceback (most recent call last)", + "Cell \u001b[0;32mIn[1], line 1\u001b[0m\n\u001b[0;32m----> 1\u001b[0m test_data_1min \u001b[38;5;241m=\u001b[39m \u001b[43mpd\u001b[49m\u001b[38;5;241m.\u001b[39mconcat([data_windows_1min[\u001b[38;5;241m0\u001b[39m][\u001b[38;5;241m0\u001b[39m][\u001b[38;5;241m-\u001b[39mPADDING:]] \u001b[38;5;241m+\u001b[39m [data_window[\u001b[38;5;241m1\u001b[39m] \u001b[38;5;28;01mfor\u001b[39;00m data_window \u001b[38;5;129;01min\u001b[39;00m data_windows_1min])\n\u001b[1;32m 2\u001b[0m test_data_5min \u001b[38;5;241m=\u001b[39m pd\u001b[38;5;241m.\u001b[39mconcat([data_windows_5min[\u001b[38;5;241m0\u001b[39m][\u001b[38;5;241m0\u001b[39m][\u001b[38;5;241m-\u001b[39mPADDING:]] \u001b[38;5;241m+\u001b[39m [data_window[\u001b[38;5;241m1\u001b[39m] \u001b[38;5;28;01mfor\u001b[39;00m data_window \u001b[38;5;129;01min\u001b[39;00m data_windows_5min])\n\u001b[1;32m 3\u001b[0m test_data_15min \u001b[38;5;241m=\u001b[39m pd\u001b[38;5;241m.\u001b[39mconcat([data_windows_15min[\u001b[38;5;241m0\u001b[39m][\u001b[38;5;241m0\u001b[39m][\u001b[38;5;241m-\u001b[39mPADDING:]] \u001b[38;5;241m+\u001b[39m [data_window[\u001b[38;5;241m1\u001b[39m] \u001b[38;5;28;01mfor\u001b[39;00m data_window \u001b[38;5;129;01min\u001b[39;00m data_windows_15min])\n", + "\u001b[0;31mNameError\u001b[0m: name 'pd' is not defined" ] } ], "source": [ + "test_data_1min = pd.concat([data_windows_1min[0][0][-PADDING:]] + [data_window[1] for data_window in data_windows_1min])\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", - "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", + "# 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_1min_model_concat = evaluate_strategy(test_data_1min, ConcatenatedStrategies(len(data_windows_1min[0][1]), [s[0] for s in best_strategies_1min['gmadl_model']], padding=PADDING), padding=PADDING, interval='min')\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(\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", + "# 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", + " # gmadl_1min_model_concat\n", + " # )\n", "\n", "# results_plot(\n", "# buy_and_hold_concat,\n", @@ -294,10 +304,11 @@ "# 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)" + " # gmadl_30min_model_concat,\n", + " # gmadl_15min_model_concat,\n", + " # gmadl_5min_model_concat, \n", + " # gmadl_1min_model_concat, \n", + " # width=1200, notitle=True)" ] }, {