Compare commits

..

10 Commits

Author SHA1 Message Date
Filip Stefaniuk
0ded87a0fb add evaluation for 1 min data 2025-04-13 09:47:33 +02:00
Filip Stefaniuk
030618f589 Add configs for 1m data gmadl 2025-02-22 10:25:24 +01:00
Filip Stefaniuk
f7485d9a2d update notebooks with new results 2025-02-09 15:32:17 +01:00
Filip Stefaniuk
96950fcf90 add experiments with RMSE 2025-01-16 12:14:59 -05:00
Filip Stefaniuk
6360d76d11 update configs 2024-11-02 15:11:45 +01:00
Filip Stefaniuk
fb731be598 update the notebooks 2024-11-02 14:53:01 +01:00
Filip Stefaniuk
eef02cbbe2 update config 2024-10-20 11:29:18 +02:00
Filip Stefaniuk
86d42759e7 Add readme 2024-10-17 21:42:03 +02:00
Filip Stefaniuk
b7c1470b08 update config 2024-10-17 21:23:30 +02:00
Filip Stefaniuk
a6aa22646a Delete generic README 2024-10-16 21:02:05 +02:00
29 changed files with 2670 additions and 1372666 deletions

1
.gitignore vendored
View File

@ -200,3 +200,4 @@ lightning_logs/
wne-masters-thesis-testing/ wne-masters-thesis-testing/
notebooks/cache/ notebooks/cache/
notebooks/images/ notebooks/images/
.DS_Store

119
README.md
View File

@ -1,93 +1,48 @@
# WNE Masters Thesis # WNE Masters Thesis
The repository contains the implementation of evaluation framework and strategies for master's thesis: "Informer In Algorithmic Investment
Strategies on High Frequency Bitcoin Data"
The implementation uses [PytorchForecasting](https://pytorch-forecasting.readthedocs.io/en/stable/) framework, and the Informer implementation is taken from the following [Github repository](https://github.com/martinwhl/Informer-PyTorch-Lightning). Experiment management is done using [Weights&Biases](https://wandb.ai/site).
## Getting started ## Repository structure
Thre repository is organized in the following way:
To make it easy for you to get started with GitLab, here's a list of recommended next steps. - `src/ml`: contains the code that implements utilities for training the machine learning models.
- `src/informer`: contains the implementation of the Informer.
Already a pro? Just edit this README.md and make it your own. Want to make it easy? [Use the template at the bottom](#editing-this-readme)! - `src/strategy`: contains the implementation of the strategies, as well as the methods for efficient evaluation and hyperparameter serach.
- `notebooks/`: contains the evaluations of various srategies and methods for generating the visualistions used in the publication.
## Add your files - `scripts/`: contains the main training script.
- `configs/`: contains configurations for different experiments of ml models, that can be passed to the main training script.
- [ ] [Create](https://docs.gitlab.com/ee/user/project/repository/web_editor.html#create-a-file) or [upload](https://docs.gitlab.com/ee/user/project/repository/web_editor.html#upload-a-file) files
- [ ] [Add files using the command line](https://docs.gitlab.com/ee/gitlab-basics/add-file.html#add-a-file-using-the-command-line) or push an existing Git repository with the following command:
```
cd existing_repo
git remote add origin https://gitlab.com/FilipStefaniuk/wne-msc-thesis.git
git branch -M main
git push -uf origin main
```
## Integrate with your tools
- [ ] [Set up project integrations](https://gitlab.com/FilipStefaniuk/wne-msc-thesis/-/settings/integrations)
## Collaborate with your team
- [ ] [Invite team members and collaborators](https://docs.gitlab.com/ee/user/project/members/)
- [ ] [Create a new merge request](https://docs.gitlab.com/ee/user/project/merge_requests/creating_merge_requests.html)
- [ ] [Automatically close issues from merge requests](https://docs.gitlab.com/ee/user/project/issues/managing_issues.html#closing-issues-automatically)
- [ ] [Enable merge request approvals](https://docs.gitlab.com/ee/user/project/merge_requests/approvals/)
- [ ] [Set auto-merge](https://docs.gitlab.com/ee/user/project/merge_requests/merge_when_pipeline_succeeds.html)
## Test and Deploy
Use the built-in continuous integration in GitLab.
- [ ] [Get started with GitLab CI/CD](https://docs.gitlab.com/ee/ci/quick_start/index.html)
- [ ] [Analyze your code for known vulnerabilities with Static Application Security Testing (SAST)](https://docs.gitlab.com/ee/user/application_security/sast/)
- [ ] [Deploy to Kubernetes, Amazon EC2, or Amazon ECS using Auto Deploy](https://docs.gitlab.com/ee/topics/autodevops/requirements.html)
- [ ] [Use pull-based deployments for improved Kubernetes management](https://docs.gitlab.com/ee/user/clusters/agent/)
- [ ] [Set up protected environments](https://docs.gitlab.com/ee/ci/environments/protected_environments.html)
***
# Editing this README
When you're ready to make this README your own, just edit this file and use the handy template below (or feel free to structure it however you want - this is just a starting point!). Thanks to [makeareadme.com](https://www.makeareadme.com/) for this template.
## Suggestions for a good README
Every project is different, so consider which of these sections apply to yours. The sections used in the template are suggestions for most open source projects. Also keep in mind that while a README can be too long and detailed, too long is better than too short. If you think your README is too long, consider utilizing another form of documentation rather than cutting out information.
## Name
Choose a self-explaining name for your project.
## Description
Let people know what your project can do specifically. Provide context and add a link to any reference visitors might be unfamiliar with. A list of Features or a Background subsection can also be added here. If there are alternatives to your project, this is a good place to list differentiating factors.
## Badges
On some READMEs, you may see small images that convey metadata, such as whether or not all the tests are passing for the project. You can use Shields to add some to your README. Many services also have instructions for adding a badge.
## Visuals
Depending on what you are making, it can be a good idea to include screenshots or even a video (you'll frequently see GIFs rather than actual videos). Tools like ttygif can help, but check out Asciinema for a more sophisticated method.
## Installation ## Installation
Within a particular ecosystem, there may be a common way of installing things, such as using Yarn, NuGet, or Homebrew. However, consider the possibility that whoever is reading your README is a novice and would like more guidance. Listing specific steps helps remove ambiguity and gets people to using your project as quickly as possible. If it only runs in a specific context like a particular programming language version or operating system or has dependencies that have to be installed manually, also add a Requirements subsection.
## Usage Install package with the following command:
Use examples liberally, and show the expected output if you can. It's helpful to have inline the smallest example of usage that you can demonstrate, while providing links to more sophisticated examples if they are too long to reasonably include in the README. ```
pip install -e .
```
## Support ## Training
Tell people where they can go to for help. It can be any combination of an issue tracker, a chat room, an email address, etc.
## Roadmap Usage of the training script:
If you have ideas for releases in the future, it is a good idea to list them in the README. ```
usage: train.py [-h] [-p PROJECT] [-l LOG_LEVEL] [-s SEED] [-n LOG_INTERVAL] [-v VAL_CHECK_INTERVAL] [-t PATIENCE] [--no-wandb] [--store-predictions] config
## Contributing positional arguments:
State if you are open to contributions and what your requirements are for accepting them. config Experiment configuration file in yaml format.
For people who want to make changes to your project, it's helpful to have some documentation on how to get started. Perhaps there is a script that they should run or some environment variables that they need to set. Make these steps explicit. These instructions could also be useful to your future self. optional arguments:
-h, --help show this help message and exit
You can also document commands to lint the code or run tests. These steps help to ensure high code quality and reduce the likelihood that the changes inadvertently break something. Having instructions for running tests is especially helpful if it requires external setup, such as starting a Selenium server for testing in a browser. -p PROJECT, --project PROJECT
W&B project name. (default: wne-masters-thesis-testing)
## Authors and acknowledgment -l LOG_LEVEL, --log-level LOG_LEVEL
Show your appreciation to those who have contributed to the project. Sets the log level. (default: 20)
-s SEED, --seed SEED Random seed for the training. (default: 42)
## License -n LOG_INTERVAL, --log-interval LOG_INTERVAL
For open source projects, say how it is licensed. Log every n steps. (default: 100)
-v VAL_CHECK_INTERVAL, --val-check-interval VAL_CHECK_INTERVAL
## Project status Run validation every n batches. (default: 300)
If you have run out of energy or time for your project, put a note at the top of the README saying that development has slowed down or stopped completely. Someone may choose to fork your project or volunteer to step in as a maintainer or owner, allowing your project to keep going. You can also make an explicit request for maintainers. -t PATIENCE, --patience PATIENCE
Patience for early stopping. (default: 5)
--no-wandb Disables wandb, for testing. (default: False)
--store-predictions Whether to store predictions of the best run. (default: False)
```

View File

@ -1,11 +1,11 @@
program: ./scripts/train.py program: ./scripts/train.py
name: informer-btcusdt-15m-gmadl-eval name: informer-btcusdt-15m-rmse-eval
project: wne-masters-thesis-testing project: wne-masters-thesis-testing
command: command:
- ${env} - ${env}
- ${interpreter} - ${interpreter}
- ${program} - ${program}
- "./configs/experiments/informer-btcusdt-15m-gmadl2.yaml" - "./configs/experiments/informer-btcusdt-15m-rmse.yaml"
- "--patience" - "--patience"
- "20" - "20"
- "--store-predictions" - "--store-predictions"

View File

@ -0,0 +1,25 @@
program: ./scripts/train.py
name: informer-btcusdt-1m-gmadl-eval
project: wne-masters-thesis-testing
command:
- ${env}
- ${interpreter}
- ${program}
- "./configs/experiments/informer-btcusdt-1m-gmadl.yaml"
- "--patience"
- "20"
- "--store-predictions"
method: grid
metric:
goal: minimize
name: val_loss
parameters:
data:
parameters:
dataset:
value: "btc-usdt-1m:latest"
validation:
value: 0.2
sliding_window:
min: 0
max: 5

View File

@ -1,11 +1,11 @@
program: ./scripts/train.py program: ./scripts/train.py
name: informer-btcusdt-30m-gmadl-eval name: informer-btcusdt-30m-rmse-eval
project: wne-masters-thesis-testing project: wne-masters-thesis-testing
command: command:
- ${env} - ${env}
- ${interpreter} - ${interpreter}
- ${program} - ${program}
- "./configs/experiments/informer-btcusdt-30m-gmadl2.yaml" - "./configs/experiments/informer-btcusdt-30m-rmse.yaml"
- "--patience" - "--patience"
- "20" - "20"
- "--store-predictions" - "--store-predictions"

View File

@ -1,11 +1,11 @@
program: ./scripts/train.py program: ./scripts/train.py
name: informer-btcusdt-5m-quantile-eval name: informer-btcusdt-5m-rmse-eval
project: wne-masters-thesis-testing project: wne-masters-thesis-testing
command: command:
- ${env} - ${env}
- ${interpreter} - ${interpreter}
- ${program} - ${program}
- "./configs/experiments/informer-btcusdt-5m-quantile-returns.yaml" - "./configs/experiments/informer-btcusdt-5m-rmse.yaml"
- "--patience" - "--patience"
- "20" - "20"
- "--store-predictions" - "--store-predictions"

View File

@ -22,12 +22,31 @@ fields:
- "open_price" - "open_price"
- "close_price" - "close_price"
- "volume" - "volume"
- "open_to_close_price"
- "high_to_close_price"
- "low_to_close_price"
- "high_to_low_price"
- "returns" - "returns"
- "log_returns"
- "vol_1h"
- "macd"
- "macd_signal"
- "rsi"
- "low_bband_to_close_price"
- "up_bband_to_close_price"
- "mid_bband_to_close_price"
- "sma_1h_to_close_price"
- "sma_1d_to_close_price"
- "sma_7d_to_close_price"
- "ema_1h_to_close_price"
- "ema_1d_to_close_price"
dynamic_unknown_cat: [] dynamic_unknown_cat: []
dynamic_known_real: dynamic_known_real:
- "effective_rates" - "effective_rates"
- "vix_close_price" - "vix_close_price"
- "fear_greed_index" - "fear_greed_index"
- "vol_1d"
- "vol_7d"
dynamic_known_cat: dynamic_known_cat:
- "hour" - "hour"
- "weekday" - "weekday"

View File

@ -14,7 +14,7 @@ data:
fields: fields:
value: value:
time_index: "time_index" time_index: "time_index"
target: "close_price" target: "returns"
group_ids: ["group_id"] group_ids: ["group_id"]
dynamic_unknown_real: dynamic_unknown_real:
- "high_price" - "high_price"

View File

@ -0,0 +1,68 @@
future_window:
value: 2
past_window:
value: 110
batch_size:
value: 64
max_epochs:
value: 30
data:
value:
dataset: "btc-usdt-15m:latest"
sliding_window: 0
validation: 0.2
fields:
value:
time_index: "time_index"
target: "returns"
group_ids: ["group_id"]
dynamic_unknown_real:
- "high_price"
- "low_price"
- "open_price"
- "close_price"
- "volume"
- "open_to_close_price"
- "high_to_close_price"
- "low_to_close_price"
- "high_to_low_price"
- "returns"
- "log_returns"
- "vol_1h"
- "macd"
- "macd_signal"
- "rsi"
- "low_bband_to_close_price"
- "up_bband_to_close_price"
- "mid_bband_to_close_price"
- "sma_1h_to_close_price"
- "sma_1d_to_close_price"
- "sma_7d_to_close_price"
- "ema_1h_to_close_price"
- "ema_1d_to_close_price"
dynamic_unknown_cat: []
dynamic_known_real:
- "effective_rates"
- "vix_close_price"
- "fear_greed_index"
- "vol_1d"
- "vol_7d"
dynamic_known_cat:
- "hour"
- "weekday"
static_real: []
static_cat: []
loss:
value:
name: "RMSE"
model:
value:
name: "Informer"
d_model: 512
d_fully_connected: 256
n_attention_heads: 4
dropout: 0.1
n_encoder_layers: 3
n_decoder_layers: 2
learning_rate: 0.0005
optimizer: "Adam"

View File

@ -1,14 +1,14 @@
future_window: future_window:
value: 2 value: 2
past_window: past_window:
value: 30 value: 28
batch_size: batch_size:
value: 128 value: 256
max_epochs: max_epochs:
value: 40 value: 40
data: data:
value: value:
dataset: "btc-usdt-15m:latest" dataset: "btc-usdt-1m:latest"
sliding_window: 0 sliding_window: 0
validation: 0.2 validation: 0.2
fields: fields:
@ -63,8 +63,8 @@ model:
d_model: 256 d_model: 256
d_fully_connected: 256 d_fully_connected: 256
n_attention_heads: 2 n_attention_heads: 2
dropout: 0.1 dropout: 0.01
n_encoder_layers: 2 n_encoder_layers: 1
n_decoder_layers: 1 n_decoder_layers: 3
learning_rate: 0.0001 learning_rate: 0.0001
optimizer: "Adam" optimizer: "Adam"

View File

@ -14,7 +14,7 @@ data:
fields: fields:
value: value:
time_index: "time_index" time_index: "time_index"
target: "close_price" target: "returns"
group_ids: ["group_id"] group_ids: ["group_id"]
dynamic_unknown_real: dynamic_unknown_real:
- "high_price" - "high_price"

View File

@ -1,11 +1,11 @@
future_window: future_window:
value: 2 value: 2
past_window: past_window:
value: 26 value: 115
batch_size: batch_size:
value: 128 value: 64
max_epochs: max_epochs:
value: 40 value: 50
data: data:
value: value:
dataset: "btc-usdt-30m:latest" dataset: "btc-usdt-30m:latest"
@ -54,17 +54,15 @@ fields:
static_cat: [] static_cat: []
loss: loss:
value: value:
name: "GMADL" name: "RMSE"
a: 1000
b: 2
model: model:
value: value:
name: "Informer" name: "Informer"
d_model: 256 d_model: 256
d_fully_connected: 256 d_fully_connected: 512
n_attention_heads: 4 n_attention_heads: 2
dropout: 0.1 dropout: 0.2
n_encoder_layers: 2 n_encoder_layers: 2
n_decoder_layers: 1 n_decoder_layers: 2
learning_rate: 0.001 learning_rate: 0.0005
optimizer: "Adam" optimizer: "Adam"

View File

@ -22,12 +22,31 @@ fields:
- "open_price" - "open_price"
- "close_price" - "close_price"
- "volume" - "volume"
- "open_to_close_price"
- "high_to_close_price"
- "low_to_close_price"
- "high_to_low_price"
- "returns" - "returns"
- "log_returns"
- "vol_1h"
- "macd"
- "macd_signal"
- "rsi"
- "low_bband_to_close_price"
- "up_bband_to_close_price"
- "mid_bband_to_close_price"
- "sma_1h_to_close_price"
- "sma_1d_to_close_price"
- "sma_7d_to_close_price"
- "ema_1h_to_close_price"
- "ema_1d_to_close_price"
dynamic_unknown_cat: [] dynamic_unknown_cat: []
dynamic_known_real: dynamic_known_real:
- "effective_rates" - "effective_rates"
- "vix_close_price" - "vix_close_price"
- "fear_greed_index" - "fear_greed_index"
- "vol_1d"
- "vol_7d"
dynamic_known_cat: dynamic_known_cat:
- "hour" - "hour"
- "weekday" - "weekday"

View File

@ -14,7 +14,7 @@ data:
fields: fields:
value: value:
time_index: "time_index" time_index: "time_index"
target: "close_price" target: "returns"
group_ids: ["group_id"] group_ids: ["group_id"]
dynamic_unknown_real: dynamic_unknown_real:
- "high_price" - "high_price"

View File

@ -0,0 +1,68 @@
future_window:
value: 2
past_window:
value: 102
batch_size:
value: 64
max_epochs:
value: 30
data:
value:
dataset: "btc-usdt-5m:latest"
sliding_window: 0
validation: 0.2
fields:
value:
time_index: "time_index"
target: "returns"
group_ids: ["group_id"]
dynamic_unknown_real:
- "high_price"
- "low_price"
- "open_price"
- "close_price"
- "volume"
- "open_to_close_price"
- "high_to_close_price"
- "low_to_close_price"
- "high_to_low_price"
- "returns"
- "log_returns"
- "vol_1h"
- "macd"
- "macd_signal"
- "rsi"
- "low_bband_to_close_price"
- "up_bband_to_close_price"
- "mid_bband_to_close_price"
- "sma_1h_to_close_price"
- "sma_1d_to_close_price"
- "sma_7d_to_close_price"
- "ema_1h_to_close_price"
- "ema_1d_to_close_price"
dynamic_unknown_cat: []
dynamic_known_real:
- "effective_rates"
- "vix_close_price"
- "fear_greed_index"
- "vol_1d"
- "vol_7d"
dynamic_known_cat:
- "hour"
- "weekday"
static_real: []
static_cat: []
loss:
value:
name: "RMSE"
model:
value:
name: "Informer"
d_model: 512
d_fully_connected: 512
n_attention_heads: 4
dropout: 0.3
n_encoder_layers: 2
n_decoder_layers: 3
learning_rate: 0.0005
optimizer: "Adam"

View File

@ -0,0 +1,41 @@
program: ./scripts/train.py
name: informer-btcusdt-15m-rmse-sweep
project: wne-masters-thesis-testing
command:
- ${env}
- ${interpreter}
- ${program}
- "./configs/experiments/informer-btcusdt-15m-rmse.yaml"
- "--patience"
- "15"
method: random
metric:
goal: minimize
name: val_loss
parameters:
past_window:
distribution: int_uniform
min: 20
max: 120
batch_size:
values: [64, 128, 256]
model:
parameters:
name:
value: "Informer"
d_model:
values: [256, 512, 1024]
d_fully_connected:
values: [256, 512, 1024]
n_attention_heads:
values: [1, 2, 4]
dropout:
values: [0.05, 0.1, 0.2, 0.3]
n_encoder_layers:
values: [1, 2, 3]
n_decoder_layers:
values: [1, 2, 3]
learning_rate:
values: [0.001, 0.0005, 0.0001]
optimizer:
value: "Adam"

View File

@ -0,0 +1,43 @@
program: ./scripts/train.py
name: informer-btcusdt-30m-rmse-sweep
project: wne-masters-thesis-testing
command:
- ${env}
- ${interpreter}
- ${program}
- "./configs/experiments/informer-btcusdt-30m-rmse.yaml"
- "--patience"
- "15"
- "--val-check-interval"
- "100"
method: random
metric:
goal: minimize
name: val_loss
parameters:
past_window:
distribution: int_uniform
min: 20
max: 120
batch_size:
values: [64, 128, 256]
model:
parameters:
name:
value: "Informer"
d_model:
values: [256, 512, 1024]
d_fully_connected:
values: [256, 512, 1024]
n_attention_heads:
values: [1, 2, 4]
dropout:
values: [0.05, 0.1, 0.2, 0.3]
n_encoder_layers:
values: [1, 2, 3]
n_decoder_layers:
values: [1, 2, 3]
learning_rate:
values: [0.001, 0.0005, 0.0001]
optimizer:
value: "Adam"

View File

@ -0,0 +1,41 @@
program: ./scripts/train.py
name: informer-btcusdt-5m-rmse-sweep
project: wne-masters-thesis-testing
command:
- ${env}
- ${interpreter}
- ${program}
- "./configs/experiments/informer-btcusdt-5m-rmse.yaml"
- "--patience"
- "15"
method: random
metric:
goal: minimize
name: val_loss
parameters:
past_window:
distribution: int_uniform
min: 20
max: 120
batch_size:
values: [64, 128, 256]
model:
parameters:
name:
value: "Informer"
d_model:
values: [256, 512, 1024]
d_fully_connected:
values: [256, 512, 1024]
n_attention_heads:
values: [1, 2, 4]
dropout:
values: [0.05, 0.1, 0.2, 0.3]
n_encoder_layers:
values: [1, 2, 3]
n_decoder_layers:
values: [1, 2, 3]
learning_rate:
values: [0.001, 0.0005, 0.0001]
optimizer:
value: "Adam"

View File

@ -1,38 +0,0 @@
program: ./scripts/train.py
project: wne-masters-thesis-testing
command:
- ${env}
- ${interpreter}
- ${program}
- "./configs/experiments/temporal-fusion-btcusdt-gmadl.yaml"
- "--patience"
- "10"
method: random
metric:
goal: minimize
name: val_loss
parameters:
past_window:
distribution: int_uniform
min: 20
max: 100
batch_size:
values: [64, 128, 256]
model:
parameters:
name:
value: "TemporalFusionTransformer"
share_single_variable_networks:
value: false
hidden_size:
values: [128, 256, 512, 1024]
dropout:
values: [0.0, 0.1, 0.2, 0.3]
attention_head_size:
values: [1, 2, 4, 6]
hidden_continuous_size:
values: [4, 8, 16, 32]
learning_rate:
value: 0.001
optimizer:
value: "Adam"

View File

@ -1,36 +0,0 @@
program: ./scripts/train.py
project: wne-masters-thesis-testing
command:
- ${env}
- ${interpreter}
- ${program}
- "./configs/experiments/temporal-fusion-btcusdt-quantile.yaml"
method: random
metric:
goal: minimize
name: val_loss
parameters:
past_window:
distribution: int_uniform
min: 5
max: 100
batch_size:
values: [64, 128, 256]
model:
parameters:
name:
value: "TemporalFusionTransformer"
share_single_variable_networks:
value: false
hidden_size:
values: [128, 256, 512, 1024]
dropout:
values: [0.0, 0.1, 0.2, 0.3, 0.4]
attention_head_size:
values: [1, 2, 4, 6]
hidden_continuous_size:
values: [4, 8, 16, 32]
learning_rate:
values: [0.01, 0.001, 0.0005, 0.0001]
optimizer:
values: ["Adam", "RMSProp", "Adagrad"]

View File

@ -2,7 +2,7 @@
"cells": [ "cells": [
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 2, "execution_count": 1,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
@ -42,7 +42,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 3, "execution_count": 2,
"metadata": {}, "metadata": {},
"outputs": [ "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", "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: Downloading large artifact btc-usdt-15m:latest, 248.65MB. 12 files... \n",
"\u001b[34m\u001b[1mwandb\u001b[0m: 12 of 12 files downloaded. \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", "cell_type": "code",
"execution_count": 4, "execution_count": 3,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
@ -81,7 +81,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 5, "execution_count": 4,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
@ -90,19 +90,19 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 6, "execution_count": 5,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
"name": "stderr", "name": "stderr",
"output_type": "stream", "output_type": "stream",
"text": [ "text": [
"100%|██████████| 3840/3840 [00:06<00:00, 614.41it/s]\n", "100%|██████████| 3840/3840 [00:06<00:00, 639.58it/s]\n",
"100%|██████████| 3840/3840 [00:08<00:00, 479.05it/s]\n", "100%|██████████| 3840/3840 [00:05<00:00, 658.38it/s]\n",
"100%|██████████| 3840/3840 [00:06<00:00, 554.94it/s]\n", "100%|██████████| 3840/3840 [00:06<00:00, 624.58it/s]\n",
"100%|██████████| 3840/3840 [00:06<00:00, 575.21it/s]\n", "100%|██████████| 3840/3840 [00:05<00:00, 649.63it/s]\n",
"100%|██████████| 3840/3840 [00:06<00:00, 571.03it/s]\n", "100%|██████████| 3840/3840 [00:06<00:00, 627.23it/s]\n",
"100%|██████████| 3840/3840 [00:06<00:00, 576.86it/s]\n" "100%|██████████| 3840/3840 [00:06<00:00, 633.46it/s]\n"
] ]
} }
], ],
@ -136,19 +136,19 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 7, "execution_count": 6,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
"name": "stderr", "name": "stderr",
"output_type": "stream", "output_type": "stream",
"text": [ "text": [
"100%|██████████| 11088/11088 [00:19<00:00, 580.54it/s]\n", "100%|██████████| 11088/11088 [00:19<00:00, 560.36it/s]\n",
"100%|██████████| 11088/11088 [00:17<00:00, 627.38it/s]\n", "100%|██████████| 11088/11088 [00:22<00:00, 495.98it/s]\n",
"100%|██████████| 11088/11088 [00:17<00:00, 624.72it/s]\n", "100%|██████████| 11088/11088 [00:19<00:00, 556.67it/s]\n",
"100%|██████████| 11088/11088 [00:18<00:00, 586.62it/s]\n", "100%|██████████| 11088/11088 [00:19<00:00, 554.79it/s]\n",
"100%|██████████| 11088/11088 [00:17<00:00, 618.44it/s]\n", "100%|██████████| 11088/11088 [00:18<00:00, 590.13it/s]\n",
"100%|██████████| 11088/11088 [00:18<00:00, 597.40it/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())" "# 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", "cell_type": "markdown",
"metadata": {}, "metadata": {},
@ -186,7 +275,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 8, "execution_count": 9,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
@ -231,12 +320,12 @@
"name": "stderr", "name": "stderr",
"output_type": "stream", "output_type": "stream",
"text": [ "text": [
"100%|██████████| 1125/1125 [00:21<00:00, 51.66it/s]\n", "100%|██████████| 1125/1125 [00:25<00:00, 44.03it/s]\n",
"100%|██████████| 1125/1125 [00:20<00:00, 53.98it/s]\n", "100%|██████████| 1125/1125 [00:20<00:00, 53.68it/s]\n",
"100%|██████████| 1125/1125 [00:22<00:00, 49.63it/s]\n", "100%|██████████| 1125/1125 [00:20<00:00, 54.38it/s]\n",
"100%|██████████| 1125/1125 [00:24<00:00, 45.57it/s]\n", "100%|██████████| 1125/1125 [00:20<00:00, 54.70it/s]\n",
"100%|██████████| 1125/1125 [00:23<00:00, 47.76it/s]\n", "100%|██████████| 1125/1125 [00:20<00:00, 54.23it/s]\n",
"100%|██████████| 1125/1125 [00:24<00:00, 46.33it/s]\n" "100%|██████████| 1125/1125 [00:21<00:00, 53.31it/s]\n"
] ]
} }
], ],
@ -323,19 +412,19 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 13, "execution_count": 12,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
"name": "stderr", "name": "stderr",
"output_type": "stream", "output_type": "stream",
"text": [ "text": [
"100%|██████████| 1176/1176 [00:19<00:00, 60.00it/s]\n", "100%|██████████| 1176/1176 [00:22<00:00, 53.42it/s]\n",
"100%|██████████| 1176/1176 [00:19<00:00, 61.63it/s]\n", "100%|██████████| 1176/1176 [00:19<00:00, 59.87it/s]\n",
"100%|██████████| 1176/1176 [00:16<00:00, 69.59it/s]\n", "100%|██████████| 1176/1176 [00:17<00:00, 66.89it/s]\n",
"100%|██████████| 1176/1176 [00:17<00:00, 65.37it/s]\n", "100%|██████████| 1176/1176 [00:17<00:00, 65.52it/s]\n",
"100%|██████████| 1176/1176 [00:17<00:00, 66.33it/s]\n", "100%|██████████| 1176/1176 [00:17<00:00, 67.44it/s]\n",
"100%|██████████| 1176/1176 [00:17<00:00, 67.86it/s]\n" "100%|██████████| 1176/1176 [00:17<00:00, 67.15it/s]\n"
] ]
} }
], ],
@ -372,7 +461,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 14, "execution_count": 13,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
@ -381,11 +470,12 @@
" 'buy_and_hold': buyandhold_best_strategies,\n", " 'buy_and_hold': buyandhold_best_strategies,\n",
" 'macd_strategies': macd_best_strategies,\n", " 'macd_strategies': macd_best_strategies,\n",
" 'rsi_strategies': rsi_best_strategies,\n", " 'rsi_strategies': rsi_best_strategies,\n",
" 'rmse_model': rmse_model_best_strategies,\n",
" 'quantile_model': quantile_model_best_strategies,\n", " 'quantile_model': quantile_model_best_strategies,\n",
" 'gmadl_model': gmadl_model_best_strategies\n", " 'gmadl_model': gmadl_model_best_strategies\n",
"}\n", "}\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)" " pickle.dump(best_strategies, outp, pickle.HIGHEST_PROTOCOL)"
] ]
}, },
@ -398,11 +488,11 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 15, "execution_count": 3,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "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)" " best_strategies = pickle.load(inpt)"
] ]
}, },
@ -516,6 +606,56 @@
"print(latextable.draw_latex(table_rsi_params))" "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", "cell_type": "code",
"execution_count": 18, "execution_count": 18,
@ -627,19 +767,32 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 29, "execution_count": 5,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "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", "\n",
" fig = go.Figure([\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_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_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_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_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", " go.Scatter(y=result_gmadl_model['portfolio_value'], x=result_gmadl_model['time'], name='GMADL Informer Strategy')\n",
" ])\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", " fig.update_layout(\n",
" title={\n", " title={\n",
" 'text': f\"W{idx}-{INTERVAL}\",\n", " 'text': f\"W{idx}-{INTERVAL}\",\n",
@ -683,7 +836,7 @@
" fig.write_image(f\"images/eval-w{idx}-{INTERVAL}.png\")\n", " fig.write_image(f\"images/eval-w{idx}-{INTERVAL}.png\")\n",
" fig.show()\n", " fig.show()\n",
" \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 = Texttable()\n",
" table_eval_windows.set_deco(Texttable.HEADER)\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_cols_align([\"l\", \"c\",\"c\", \"c\", \"c\", \"c\", \"c\", \"c\", \"c\", \"c\"])\n",
@ -706,6 +859,7 @@
" ('Buy and Hold', result_buyandhold),\n", " ('Buy and Hold', result_buyandhold),\n",
" ('MACD Strategy', result_macd),\n", " ('MACD Strategy', result_macd),\n",
" ('RSI Strategy', result_rsi),\n", " ('RSI Strategy', result_rsi),\n",
" ('RMSE Informer', result_rmse_model),\n",
" ('Quantile Informer', result_quantile_model),\n", " ('Quantile Informer', result_quantile_model),\n",
" ('GMADL Informer', result_gmadl_model)\n", " ('GMADL Informer', result_gmadl_model)\n",
" ]\n", " ]\n",
@ -713,10 +867,10 @@
" table_eval_windows.add_row([\n", " table_eval_windows.add_row([\n",
" strategy_name,\n", " strategy_name,\n",
" result['value'],\n", " result['value'],\n",
" result['arc'],\n", " f\"{result['arc']*100:.2f}\\%\",\n",
" result['asd'],\n", " f\"{result['asd']*100:.2f}\\%\",\n",
" result['ir'],\n", " result['ir'],\n",
" result['md'],\n", " f\"{result['md']*100:.2f}\\%\",\n",
" result['mod_ir'],\n", " result['mod_ir'],\n",
" result['n_trades'],\n", " result['n_trades'],\n",
" f\"{result['long_pos']*100:.2f}\\%\",\n", " f\"{result['long_pos']*100:.2f}\\%\",\n",
@ -728,61 +882,154 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 1, "execution_count": 11,
"metadata": {}, "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": [ "source": [
"# for i, (in_sample, out_of_sample) in enumerate(data_windows):\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", " 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_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_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_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_rmse_model = evaluate_strategy(padded_window, [s[0] for s in best_strategies['rmse_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", " 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", "\n",
"# results_table(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_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", "cell_type": "code",
"execution_count": 2, "execution_count": 12,
"metadata": {}, "metadata": {},
"outputs": [], "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"
]
},
{ {
"cell_type": "code", "name": "stdout",
"execution_count": 23, "output_type": "stream",
"metadata": {}, "text": [
"outputs": [], "\\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": [ "source": [
"# for i, (in_sample, out_of_sample) in enumerate(data_windows):\n", "test_data = pd.concat([data_windows[0][0][-PADDING:]] + [data_window[1] for data_window in data_windows])\n",
"# padded_window = pd.concat([in_sample.iloc[-PADDING:], out_of_sample])\n", "buy_and_hold_concat = evaluate_strategy(test_data, BuyAndHoldStrategy(), padding=PADDING, interval=INTERVAL)\n",
"# result_buyandhold = evaluate_strategy(padded_window, buyandhold_best_strategies[i], padding=PADDING, interval='15min')\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",
"# result_macd = evaluate_strategy(padded_window, macd_best_strategies[i], padding=PADDING, interval='15min')\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",
"# result_rsi = evaluate_strategy(padded_window, rsi_best_strategies[i], padding=PADDING, interval='15min')\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",
"# result_quantile_model = evaluate_strategy(padded_window, quantile_model_best_strategies[i], padding=PADDING, interval='15min')\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",
"# result_gmadl_model = evaluate_strategy(padded_window, gmadl_model_best_strategies[i], padding=PADDING, interval='15min')\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", "\n",
"# go.Figure([\n", "# v_lines=[data_window[1]['close_time'].iloc[-1] for data_window in data_windows][:-1]\n",
"# go.Scatter(y=result_buyandhold['portfolio_value'], x=result_buyandhold['time'], name=result_buyandhold['strategy_name']),\n", "\n",
"# go.Scatter(y=result_macd['portfolio_value'], x=result_macd['time'], name=result_macd['strategy_name']),\n", "results_table(buy_and_hold_concat, macd_concat, rsi_concat, rmse_model_concat, quantile_model_concat, gmadl_model_concat)\n",
"# go.Scatter(y=result_rsi['portfolio_value'], x=result_rsi['time'], name=result_rsi['strategy_name']),\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"
"# 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()"
] ]
}, },
{ {

View File

@ -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
}

View File

@ -2,7 +2,7 @@
"cells": [ "cells": [
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 107, "execution_count": 1,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
@ -34,7 +34,7 @@
")\n", ")\n",
"\n", "\n",
"PADDING=5000\n", "PADDING=5000\n",
"VALID_PART=0.4\n", "VALID_PART=0.2\n",
"INTERVAL='30min'\n", "INTERVAL='30min'\n",
"METRIC='mod_ir'\n", "METRIC='mod_ir'\n",
"TOP_N=10" "TOP_N=10"
@ -42,16 +42,17 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 101, "execution_count": 2,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
"name": "stderr", "name": "stderr",
"output_type": "stream", "output_type": "stream",
"text": [ "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-30m:latest, 124.19MB. 12 files... \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", "\u001b[34m\u001b[1mwandb\u001b[0m: 12 of 12 files downloaded. \n",
"Done. 0:0:0.6\n" "Done. 0:0:0.5\n"
] ]
} }
], ],
@ -66,7 +67,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 40, "execution_count": 3,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
@ -80,7 +81,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 41, "execution_count": 4,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
@ -89,19 +90,19 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 44, "execution_count": 5,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
"name": "stderr", "name": "stderr",
"output_type": "stream", "output_type": "stream",
"text": [ "text": [
"100%|██████████| 3840/3840 [00:04<00:00, 769.13it/s]\n", "100%|██████████| 3840/3840 [00:05<00:00, 762.16it/s] \n",
"100%|██████████| 3840/3840 [00:04<00:00, 779.61it/s]\n", "100%|██████████| 3840/3840 [00:04<00:00, 937.71it/s] \n",
"100%|██████████| 3840/3840 [00:05<00:00, 754.69it/s]\n", "100%|██████████| 3840/3840 [00:03<00:00, 990.52it/s] \n",
"100%|██████████| 3840/3840 [00:06<00:00, 579.24it/s]\n", "100%|██████████| 3840/3840 [00:04<00:00, 956.93it/s] \n",
"100%|██████████| 3840/3840 [00:04<00:00, 777.65it/s]\n", "100%|██████████| 3840/3840 [00:04<00:00, 931.01it/s] \n",
"100%|██████████| 3840/3840 [00:04<00:00, 782.54it/s]\n" "100%|██████████| 3840/3840 [00:04<00:00, 951.89it/s] \n"
] ]
} }
], ],
@ -126,7 +127,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 14, "execution_count": 6,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
@ -135,19 +136,19 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 108, "execution_count": 7,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
"name": "stderr", "name": "stderr",
"output_type": "stream", "output_type": "stream",
"text": [ "text": [
"100%|██████████| 11088/11088 [00:18<00:00, 611.54it/s]\n", "100%|██████████| 11088/11088 [00:13<00:00, 838.13it/s]\n",
"100%|██████████| 11088/11088 [00:17<00:00, 644.30it/s]\n", "100%|██████████| 11088/11088 [00:10<00:00, 1054.57it/s]\n",
"100%|██████████| 11088/11088 [00:16<00:00, 653.15it/s]\n", "100%|██████████| 11088/11088 [00:10<00:00, 1032.31it/s]\n",
"100%|██████████| 11088/11088 [00:17<00:00, 640.80it/s]\n", "100%|██████████| 11088/11088 [00:11<00:00, 967.27it/s] \n",
"100%|██████████| 11088/11088 [00:14<00:00, 762.97it/s]\n", "100%|██████████| 11088/11088 [00:11<00:00, 995.52it/s] \n",
"100%|██████████| 11088/11088 [00:15<00:00, 737.06it/s]\n" "100%|██████████| 11088/11088 [00:10<00:00, 1023.57it/s]\n"
] ]
} }
], ],
@ -173,7 +174,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 89, "execution_count": 8,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
@ -195,7 +196,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 90, "execution_count": 9,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
@ -204,7 +205,105 @@
}, },
{ {
"cell_type": "code", "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": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
@ -242,19 +341,19 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 48, "execution_count": 13,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
"name": "stderr", "name": "stderr",
"output_type": "stream", "output_type": "stream",
"text": [ "text": [
"100%|██████████| 1125/1125 [00:28<00:00, 40.16it/s]\n", "100%|██████████| 1125/1125 [00:23<00:00, 47.74it/s]\n",
"100%|██████████| 1125/1125 [00:27<00:00, 41.37it/s]\n", "100%|██████████| 1125/1125 [00:23<00:00, 48.10it/s]\n",
"100%|██████████| 1125/1125 [00:27<00:00, 41.47it/s]\n", "100%|██████████| 1125/1125 [00:23<00:00, 47.79it/s]\n",
"100%|██████████| 1125/1125 [00:27<00:00, 40.47it/s]\n", "100%|██████████| 1125/1125 [00:23<00:00, 47.27it/s]\n",
"100%|██████████| 1125/1125 [00:25<00:00, 44.84it/s]\n", "100%|██████████| 1125/1125 [00:23<00:00, 47.82it/s]\n",
"100%|██████████| 1125/1125 [00:25<00:00, 44.11it/s]\n" "100%|██████████| 1125/1125 [00:23<00:00, 47.74it/s]\n"
] ]
} }
], ],
@ -296,7 +395,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 12, "execution_count": 14,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
@ -305,7 +404,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 50, "execution_count": 5,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
@ -336,7 +435,9 @@
"source": [ "source": [
"# Model with gmadl loss\n", "# Model with gmadl loss\n",
"# SWEEP_ID = 'filipstefaniuk/wne-masters-thesis-testing/tmqx4epx'\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", "train_gmadl_pred_windows = get_sweep_window_predictions(SWEEP_ID, 'train')\n",
"valid_gmadl_pred_windows = get_sweep_window_predictions(SWEEP_ID, 'valid')\n", "valid_gmadl_pred_windows = get_sweep_window_predictions(SWEEP_ID, 'valid')\n",
"test_gmadl_pred_windows = get_sweep_window_predictions(SWEEP_ID, 'test')" "test_gmadl_pred_windows = get_sweep_window_predictions(SWEEP_ID, 'test')"
@ -344,19 +445,19 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 51, "execution_count": 6,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
"name": "stderr", "name": "stderr",
"output_type": "stream", "output_type": "stream",
"text": [ "text": [
"100%|██████████| 1176/1176 [00:22<00:00, 51.45it/s]\n", "100%|██████████| 1176/1176 [00:20<00:00, 58.39it/s]\n",
"100%|██████████| 1176/1176 [00:24<00:00, 48.45it/s]\n", "100%|██████████| 1176/1176 [00:20<00:00, 57.42it/s]\n",
"100%|██████████| 1176/1176 [00:21<00:00, 53.53it/s]\n", "100%|██████████| 1176/1176 [00:20<00:00, 57.34it/s]\n",
"100%|██████████| 1176/1176 [00:24<00:00, 48.36it/s]\n", "100%|██████████| 1176/1176 [00:20<00:00, 57.48it/s]\n",
"100%|██████████| 1176/1176 [00:22<00:00, 51.90it/s]\n", "100%|██████████| 1176/1176 [00:20<00:00, 58.43it/s]\n",
"100%|██████████| 1176/1176 [00:21<00:00, 54.04it/s]\n" "100%|██████████| 1176/1176 [00:20<00:00, 57.45it/s]\n"
] ]
} }
], ],
@ -404,20 +505,21 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 109, "execution_count": 7,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
"# Persist best strategies, so that they don't have to be recomputed every time\n", "# Persist best strategies, so that they don't have to be recomputed every time\n",
"best_strategies = {\n", "best_strategies = {\n",
" # 'buy_and_hold': buyandhold_best_strategies,\n", " 'buy_and_hold': buyandhold_best_strategies,\n",
" # 'macd_strategies': macd_best_strategies,\n", " 'macd_strategies': macd_best_strategies,\n",
" 'rsi_strategies': rsi_best_strategies,\n", " 'rsi_strategies': rsi_best_strategies,\n",
" # 'quantile_model': quantile_model_best_strategies,\n", " 'rmse_model': rmse_model_best_strategies,\n",
" # 'gmadl_model': gmadl_model_best_strategies\n", " 'quantile_model': quantile_model_best_strategies,\n",
" 'gmadl_model': gmadl_model_best_strategies\n",
"}\n", "}\n",
"\n", "\n",
"with open('cache/30min-best-strategies-04.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)" " pickle.dump(best_strategies, outp, pickle.HIGHEST_PROTOCOL)"
] ]
}, },
@ -430,12 +532,18 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 53, "execution_count": 3,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
"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 = pickle.load(inpt)" " 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']"
] ]
}, },
{ {
@ -602,7 +710,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 60, "execution_count": 4,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
@ -614,12 +722,62 @@
"\t\t\\begin{tabular}{lcccc}\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\\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\t\\hline\n",
"\t\t\tW1-30min & 0.007 & - & -0.001 & - \\\\\n", "\t\t\tW1-30min & 0.002 & - & -0.003 & - \\\\\n",
"\t\t\tW2-30min & 0.003 & - & -0.007 & - \\\\\n", "\t\t\tW2-30min & - & - & -0.002 & 0.001 \\\\\n",
"\t\t\tW3-30min & - & - & -0.001 & 0.005 \\\\\n", "\t\t\tW3-30min & - & - & -0.001 & 0.002 \\\\\n",
"\t\t\tW4-30min & 0.002 & - & -0.006 & - \\\\\n", "\t\t\tW4-30min & 0.001 & - & -0.002 & - \\\\\n",
"\t\t\tW5-30min & 0.005 & -0.001 & - & - \\\\\n", "\t\t\tW5-30min & 0.001 & - & -0.002 & - \\\\\n",
"\t\t\tW6-30min & 0.003 & - & -0.004 & - \\\\\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\t\\end{tabular}\n",
"\t\\end{center}\n", "\t\\end{center}\n",
"\\end{table}\n" "\\end{table}\n"
@ -659,19 +817,32 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 98, "execution_count": 12,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "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", "\n",
" fig = go.Figure([\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_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_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_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_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", " go.Scatter(y=result_gmadl_model['portfolio_value'], x=result_gmadl_model['time'], name='GMADL Informer Strategy')\n",
" ])\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", " fig.update_layout(\n",
" title={\n", " title={\n",
" 'text': f\"W{idx}-{INTERVAL}\",\n", " 'text': f\"W{idx}-{INTERVAL}\",\n",
@ -715,7 +886,7 @@
" fig.write_image(f\"images/eval-w{idx}-{INTERVAL}.png\")\n", " fig.write_image(f\"images/eval-w{idx}-{INTERVAL}.png\")\n",
" fig.show()\n", " fig.show()\n",
" \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 = Texttable()\n",
" table_eval_windows.set_deco(Texttable.HEADER)\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_cols_align([\"l\", \"c\",\"c\", \"c\", \"c\", \"c\", \"c\", \"c\", \"c\", \"c\"])\n",
@ -738,6 +909,7 @@
" ('Buy and Hold', result_buyandhold),\n", " ('Buy and Hold', result_buyandhold),\n",
" ('MACD Strategy', result_macd),\n", " ('MACD Strategy', result_macd),\n",
" ('RSI Strategy', result_rsi),\n", " ('RSI Strategy', result_rsi),\n",
" ('RMSE Informer', result_rmse_model),\n",
" ('Quantile Informer', result_quantile_model),\n", " ('Quantile Informer', result_quantile_model),\n",
" ('GMADL Informer', result_gmadl_model)\n", " ('GMADL Informer', result_gmadl_model)\n",
" ]\n", " ]\n",
@ -745,10 +917,10 @@
" table_eval_windows.add_row([\n", " table_eval_windows.add_row([\n",
" strategy_name,\n", " strategy_name,\n",
" result['value'],\n", " result['value'],\n",
" result['arc'],\n", " f\"{result['arc']*100:.2f}\\%\",\n",
" result['asd'],\n", " f\"{result['asd']*100:.2f}\\%\",\n",
" result['ir'],\n", " result['ir'],\n",
" result['md'],\n", " f\"{result['md']*100:.2f}\\%\",\n",
" result['mod_ir'],\n", " result['mod_ir'],\n",
" result['n_trades'],\n", " result['n_trades'],\n",
" f\"{result['long_pos']*100:.2f}\\%\",\n", " f\"{result['long_pos']*100:.2f}\\%\",\n",
@ -760,20 +932,112 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 1, "execution_count": 18,
"metadata": {}, "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": [ "source": [
"# for i, (in_sample, out_of_sample) in enumerate(data_windows):\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", " 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_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_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_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_rmse_model = evaluate_strategy(padded_window, [s[0] for s in best_strategies['rmse_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", " 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", "\n",
"# results_table(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_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" " \n"
] ]
}, },
@ -786,20 +1050,51 @@
}, },
{ {
"cell_type": "code", "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": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "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"
]
} }
], ],
"metadata": { "metadata": {

View File

@ -2,7 +2,7 @@
"cells": [ "cells": [
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 109, "execution_count": 2,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
@ -33,7 +33,7 @@
")\n", ")\n",
"\n", "\n",
"PADDING=5000\n", "PADDING=5000\n",
"VALID_PART=0.4\n", "VALID_PART=0.2\n",
"INTERVAL='5min'\n", "INTERVAL='5min'\n",
"METRIC='mod_ir'\n", "METRIC='mod_ir'\n",
"TOP_N=10" "TOP_N=10"
@ -41,16 +41,17 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 94, "execution_count": 3,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
"name": "stderr", "name": "stderr",
"output_type": "stream", "output_type": "stream",
"text": [ "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-5m:latest, 745.12MB. 12 files... \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", "\u001b[34m\u001b[1mwandb\u001b[0m: 12 of 12 files downloaded. \n",
"Done. 0:0:0.8\n" "Done. 0:0:1.3\n"
] ]
} }
], ],
@ -65,7 +66,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 95, "execution_count": 3,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
@ -79,7 +80,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 96, "execution_count": 4,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
@ -88,19 +89,19 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 97, "execution_count": 5,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
"name": "stderr", "name": "stderr",
"output_type": "stream", "output_type": "stream",
"text": [ "text": [
"100%|██████████| 3840/3840 [00:25<00:00, 148.93it/s]\n", "100%|██████████| 3840/3840 [00:18<00:00, 206.53it/s]\n",
"100%|██████████| 3840/3840 [00:25<00:00, 149.05it/s]\n", "100%|██████████| 3840/3840 [00:18<00:00, 205.12it/s]\n",
"100%|██████████| 3840/3840 [00:27<00:00, 138.86it/s]\n", "100%|██████████| 3840/3840 [00:18<00:00, 205.54it/s]\n",
"100%|██████████| 3840/3840 [00:28<00:00, 133.50it/s]\n", "100%|██████████| 3840/3840 [00:18<00:00, 204.08it/s]\n",
"100%|██████████| 3840/3840 [00:25<00:00, 152.79it/s]\n", "100%|██████████| 3840/3840 [00:18<00:00, 202.37it/s]\n",
"100%|██████████| 3840/3840 [00:22<00:00, 168.94it/s]\n" "100%|██████████| 3840/3840 [00:18<00:00, 202.96it/s]\n"
] ]
} }
], ],
@ -136,19 +137,19 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 99, "execution_count": 6,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
"name": "stderr", "name": "stderr",
"output_type": "stream", "output_type": "stream",
"text": [ "text": [
"100%|██████████| 11088/11088 [01:14<00:00, 149.71it/s]\n", "100%|██████████| 11088/11088 [00:51<00:00, 216.64it/s]\n",
"100%|██████████| 11088/11088 [01:18<00:00, 140.49it/s]\n", "100%|██████████| 11088/11088 [00:52<00:00, 210.53it/s]\n",
"100%|██████████| 11088/11088 [01:14<00:00, 148.45it/s]\n", "100%|██████████| 11088/11088 [00:52<00:00, 210.59it/s]\n",
"100%|██████████| 11088/11088 [01:15<00:00, 147.54it/s]\n", "100%|██████████| 11088/11088 [00:52<00:00, 210.06it/s]\n",
"100%|██████████| 11088/11088 [01:09<00:00, 160.15it/s]\n", "100%|██████████| 11088/11088 [00:52<00:00, 209.24it/s]\n",
"100%|██████████| 11088/11088 [01:10<00:00, 158.01it/s]\n" "100%|██████████| 11088/11088 [00:52<00:00, 209.32it/s]\n"
] ]
} }
], ],
@ -181,7 +182,96 @@
}, },
{ {
"cell_type": "code", "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": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
@ -219,19 +309,19 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 102, "execution_count": 11,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
"name": "stderr", "name": "stderr",
"output_type": "stream", "output_type": "stream",
"text": [ "text": [
"100%|██████████| 1125/1125 [02:49<00:00, 6.65it/s]\n", "100%|██████████| 1125/1125 [02:35<00:00, 7.23it/s]\n",
"100%|██████████| 1125/1125 [02:51<00:00, 6.55it/s]\n", "100%|██████████| 1125/1125 [02:28<00:00, 7.56it/s]\n",
"100%|██████████| 1125/1125 [02:56<00:00, 6.36it/s]\n", "100%|██████████| 1125/1125 [02:35<00:00, 7.22it/s]\n",
"100%|██████████| 1125/1125 [02:50<00:00, 6.61it/s]\n", "100%|██████████| 1125/1125 [02:47<00:00, 6.71it/s]\n",
"100%|██████████| 1125/1125 [02:47<00:00, 6.72it/s]\n", "100%|██████████| 1125/1125 [02:39<00:00, 7.06it/s]\n",
"100%|██████████| 1125/1125 [02:48<00:00, 6.66it/s]\n" "100%|██████████| 1125/1125 [02:35<00:00, 7.25it/s]\n"
] ]
} }
], ],
@ -279,19 +369,14 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 104, "execution_count": 2,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
"name": "stderr", "name": "stderr",
"output_type": "stream", "output_type": "stream",
"text": [ "text": [
"\u001b[34m\u001b[1mwandb\u001b[0m: 2 of 2 files downloaded. \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: 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",
@ -310,26 +395,27 @@
"source": [ "source": [
"# Model with gmadl loss\n", "# Model with gmadl loss\n",
"SWEEP_ID = 'filipstefaniuk/wne-masters-thesis-testing/0pro3i5i'\n", "SWEEP_ID = 'filipstefaniuk/wne-masters-thesis-testing/0pro3i5i'\n",
"train_gmadl_pred_windows = get_sweep_window_predictions(SWEEP_ID, 'train')\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", "valid_gmadl_pred_windows = get_sweep_window_predictions(SWEEP_ID, 'valid')\n",
"test_gmadl_pred_windows = get_sweep_window_predictions(SWEEP_ID, 'test')" "test_gmadl_pred_windows = get_sweep_window_predictions(SWEEP_ID, 'test')"
] ]
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 110, "execution_count": 13,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
"name": "stderr", "name": "stderr",
"output_type": "stream", "output_type": "stream",
"text": [ "text": [
"100%|██████████| 1176/1176 [02:30<00:00, 7.82it/s]\n", "100%|██████████| 1176/1176 [00:58<00:00, 20.16it/s]\n",
"100%|██████████| 1176/1176 [02:31<00:00, 7.78it/s]\n", "100%|██████████| 1176/1176 [00:55<00:00, 21.38it/s]\n",
"100%|██████████| 1176/1176 [02:31<00:00, 7.77it/s]\n", "100%|██████████| 1176/1176 [00:54<00:00, 21.43it/s]\n",
"100%|██████████| 1176/1176 [02:32<00:00, 7.72it/s]\n", "100%|██████████| 1176/1176 [00:54<00:00, 21.38it/s]\n",
"100%|██████████| 1176/1176 [02:30<00:00, 7.84it/s]\n", "100%|██████████| 1176/1176 [00:55<00:00, 21.29it/s]\n",
"100%|██████████| 1176/1176 [02:30<00:00, 7.80it/s]\n" "100%|██████████| 1176/1176 [00:55<00:00, 21.03it/s]\n"
] ]
} }
], ],
@ -341,10 +427,10 @@
" and (p['enter_long'] is None or p['exit_short'] is None or (p['exit_short'] < p['enter_long'])))\n", " and (p['enter_long'] is None or p['exit_short'] is None or (p['exit_short'] < p['enter_long'])))\n",
"\n", "\n",
"gmadl_model_sweep_results = []\n", "gmadl_model_sweep_results = []\n",
"for (in_sample, _), train_preds, valid_preds, test_preds in zip(data_windows, train_gmadl_pred_windows, valid_gmadl_pred_windows, test_gmadl_pred_windows):\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", " data_part = int((1 - VALID_PART) * len(in_sample))\n",
" params={\n", " params={\n",
" 'predictions': [get_predictions_dataframe(train_preds, valid_preds, test_preds)],\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", " '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", " '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", " 'enter_short': [None, -0.001, -0.002, -0.003, -0.004, -0.005, -0.006, -0.007],\n",
@ -366,7 +452,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 111, "execution_count": 15,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
@ -375,11 +461,12 @@
" 'buy_and_hold': buyandhold_best_strategies,\n", " 'buy_and_hold': buyandhold_best_strategies,\n",
" 'macd_strategies': macd_best_strategies,\n", " 'macd_strategies': macd_best_strategies,\n",
" 'rsi_strategies': rsi_best_strategies,\n", " 'rsi_strategies': rsi_best_strategies,\n",
" 'rmse_model': rmse_model_best_strategies,\n",
" 'quantile_model': quantile_model_best_strategies,\n", " 'quantile_model': quantile_model_best_strategies,\n",
" 'gmadl_model': gmadl_model_best_strategies\n", " 'gmadl_model': gmadl_model_best_strategies\n",
"}\n", "}\n",
"\n", "\n",
"with open('cache/5min-best-strategies-04.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)" " pickle.dump(best_strategies, outp, pickle.HIGHEST_PROTOCOL)"
] ]
}, },
@ -392,11 +479,11 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 52, "execution_count": 4,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "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)" " best_strategies = pickle.load(inpt)"
] ]
}, },
@ -510,6 +597,56 @@
"print(latextable.draw_latex(table_rsi_params))" "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", "cell_type": "code",
"execution_count": 56, "execution_count": 56,
@ -621,19 +758,32 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 61, "execution_count": 6,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "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", "\n",
" fig = go.Figure([\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_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_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_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_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", " go.Scatter(y=result_gmadl_model['portfolio_value'], x=result_gmadl_model['time'], name='GMADL Informer Strategy')\n",
" ])\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", " fig.update_layout(\n",
" title={\n", " title={\n",
" 'text': f\"W{idx}-{INTERVAL}\",\n", " 'text': f\"W{idx}-{INTERVAL}\",\n",
@ -677,7 +827,7 @@
" fig.write_image(f\"images/eval-w{idx}-{INTERVAL}.png\")\n", " fig.write_image(f\"images/eval-w{idx}-{INTERVAL}.png\")\n",
" fig.show()\n", " fig.show()\n",
" \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 = Texttable()\n",
" table_eval_windows.set_deco(Texttable.HEADER)\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_cols_align([\"l\", \"c\",\"c\", \"c\", \"c\", \"c\", \"c\", \"c\", \"c\", \"c\"])\n",
@ -700,6 +850,7 @@
" ('Buy and Hold', result_buyandhold),\n", " ('Buy and Hold', result_buyandhold),\n",
" ('MACD Strategy', result_macd),\n", " ('MACD Strategy', result_macd),\n",
" ('RSI Strategy', result_rsi),\n", " ('RSI Strategy', result_rsi),\n",
" ('RMSE Informer', result_rmse_model),\n",
" ('Quantile Informer', result_quantile_model),\n", " ('Quantile Informer', result_quantile_model),\n",
" ('GMADL Informer', result_gmadl_model)\n", " ('GMADL Informer', result_gmadl_model)\n",
" ]\n", " ]\n",
@ -707,10 +858,10 @@
" table_eval_windows.add_row([\n", " table_eval_windows.add_row([\n",
" strategy_name,\n", " strategy_name,\n",
" result['value'],\n", " result['value'],\n",
" result['arc'],\n", " f\"{result['arc']*100:.2f}\\%\",\n",
" result['asd'],\n", " f\"{result['asd']*100:.2f}\\%\",\n",
" result['ir'],\n", " result['ir'],\n",
" result['md'],\n", " f\"{result['md']*100:.2f}\\%\",\n",
" result['mod_ir'],\n", " result['mod_ir'],\n",
" result['n_trades'],\n", " result['n_trades'],\n",
" f\"{result['long_pos']*100:.2f}\\%\",\n", " f\"{result['long_pos']*100:.2f}\\%\",\n",
@ -722,38 +873,195 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 1, "execution_count": 11,
"metadata": {}, "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": [ "source": [
"# for i, (in_sample, out_of_sample) in enumerate(data_windows):\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", " 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_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_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_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_rmse_model = evaluate_strategy(padded_window, [s[0] for s in best_strategies['rmse_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", " 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", "\n",
"# results_table(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_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" " \n"
] ]
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 2, "execution_count": 12,
"metadata": {}, "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": [ "source": [
"# test_data = pd.concat([data_windows[0][0][-PADDING:]] + [data_window[1] for data_window in data_windows])\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", "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", "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", "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", "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",
"# 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", "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", "\n",
"# results_table(buy_and_hold_concat, macd_concat, rsi_concat, quantile_model_concat, gmadl_model_concat)\n", "v_lines=[data_window[1]['close_time'].iloc[-1] for data_window in data_windows][:-1]\n",
"# results_plot(0, buy_and_hold_concat, macd_concat, rsi_concat, quantile_model_concat, gmadl_model_concat, width=1200, notitle=True)\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": 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" "\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

@ -2,7 +2,7 @@
"cells": [ "cells": [
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 11, "execution_count": 1,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
@ -39,26 +39,36 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 48, "execution_count": 5,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
"name": "stderr", "name": "stderr",
"output_type": "stream", "output_type": "stream",
"text": [ "text": [
"\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: Downloading large artifact btc-usdt-5m:latest, 745.12MB. 12 files... \n",
"\u001b[34m\u001b[1mwandb\u001b[0m: 12 of 12 files downloaded. \n", "\u001b[34m\u001b[1mwandb\u001b[0m: 12 of 12 files downloaded. \n",
"Done. 0:0:0.9\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: Downloading large artifact btc-usdt-15m:latest, 248.65MB. 12 files... \n",
"\u001b[34m\u001b[1mwandb\u001b[0m: 12 of 12 files downloaded. \n", "\u001b[34m\u001b[1mwandb\u001b[0m: 12 of 12 files downloaded. \n",
"Done. 0:0:0.7\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: Downloading large artifact btc-usdt-30m:latest, 124.19MB. 12 files... \n",
"\u001b[34m\u001b[1mwandb\u001b[0m: 12 of 12 files downloaded. \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"
] ]
} }
], ],
"source": [ "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", "data_windows_5min = get_data_windows(\n",
" 'wne-masters-thesis-testing',\n", " 'wne-masters-thesis-testing',\n",
" 'btc-usdt-5m:latest',\n", " 'btc-usdt-5m:latest',\n",
@ -83,17 +93,20 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 49, "execution_count": 6,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
"with open('cache/5min-best-strategies.pkl', 'rb') as inpt:\n", "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", " best_strategies_5min = pickle.load(inpt)\n",
"\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", " best_strategies_15min = pickle.load(inpt)\n",
"\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)" " best_strategies_30min = pickle.load(inpt)"
] ]
}, },
@ -106,19 +119,34 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 23, "execution_count": 10,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "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, \n",
" gmadl_1min_model_concat, \n",
" width=850, height=500, notitle=False):\n",
"\n", "\n",
" fig = go.Figure([\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=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=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=rsi_5_min_concat['portfolio_value'], x=rsi_5_min_concat['time'], name=\"RSI Strategy (5min)\"),\n", " go.Scatter(y=gmadl_1min_model_concat['portfolio_value'], x=gmadl_1min_model_concat['time'], name=\"GMADL Informer Strategy (1min)\")\n",
" go.Scatter(y=gmadl_15min_model_concat['portfolio_value'], x=gmadl_15min_model_concat['time'], name='GNADL Informer Strategy (15min)'),\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",
" ])\n", " ])\n",
" fig.update_layout(\n", " fig.update_layout(\n",
" # title={\n", " # title={\n",
@ -136,7 +164,7 @@
" autosize=False,\n", " autosize=False,\n",
" width=width,\n", " width=width,\n",
" height=height,\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", " plot_bgcolor='white',\n",
" legend=dict(\n", " legend=dict(\n",
" orientation=\"h\",\n", " orientation=\"h\",\n",
@ -163,7 +191,19 @@
" # fig.write_image(f\"images/eval-w{idx}-{INTERVAL}.png\")\n", " # fig.write_image(f\"images/eval-w{idx}-{INTERVAL}.png\")\n",
" fig.show()\n", " fig.show()\n",
" \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",
" gmadl_1min_model_concat\n",
" ):\n",
"\n",
" table_eval_windows = Texttable()\n", " table_eval_windows = Texttable()\n",
" table_eval_windows.set_deco(Texttable.HEADER)\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_cols_align([\"l\", \"c\",\"c\", \"c\", \"c\", \"c\", \"c\", \"c\", \"c\", \"c\"])\n",
@ -184,11 +224,15 @@
"\n", "\n",
" strategy_name_result = [\n", " strategy_name_result = [\n",
" ('Buy and Hold', buy_and_hold_concat),\n", " ('Buy and Hold', buy_and_hold_concat),\n",
" ('GMADL Informer (5min)', gmadl_5min_model_concat),\n", " # ('MACD Strategy (30min)', macd_30min_concat),\n",
" ('RSI Strategy (5min)', rsi_5_min_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 (15min)', gmadl_15min_model_concat),\n",
" ('RSI Strategy (30min)', rsi_30min_concat),\n", " ('GMADL Informer (5min)', gmadl_5min_model_concat),\n",
" ('MACD Strategy (30min)', macd_30min_concat)\n", " ('GMADL Informer (1min)', gmadl_1min_model_concat),\n",
" ]\n", " ]\n",
" for strategy_name, result in strategy_name_result:\n", " for strategy_name, result in strategy_name_result:\n",
" table_eval_windows.add_row([\n", " table_eval_windows.add_row([\n",
@ -210,21 +254,146 @@
"cell_type": "code", "cell_type": "code",
"execution_count": 1, "execution_count": 1,
"metadata": {}, "metadata": {},
"outputs": [
{
"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",
"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",
" # gmadl_1min_model_concat\n",
" # )\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",
" # gmadl_1min_model_concat, \n",
" # width=1200, notitle=True)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Statistical significance"
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {},
"outputs": [], "outputs": [],
"source": [ "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_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_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_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_5min, BuyAndHoldStrategy(), padding=PADDING, interval='5min')\n", "buy_and_hold_5min = 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", "buy_and_hold_15min = evaluate_strategy(test_data_15min, BuyAndHoldStrategy(), padding=PADDING, interval='15min')\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", "buy_and_hold_30min = evaluate_strategy(test_data_30min, BuyAndHoldStrategy(), 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", "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_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", "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": 12,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"MACD (30 min) & 51840 & 0.326504 & 174.34 & 0.000000*** \\\\\n",
"RSI (30 min) & 51840 & 1.065079 & 258.49 & 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"
]
}
],
"source": [
"import numpy as np\n",
"import scipy.stats\n",
"\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", "def ttest(benchmark, strategy):\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)" " sigma = np.std(strategy['portfolio_value'] - benchmark['portfolio_value'])\n",
" N = len(strategy['strategy_returns'])\n",
" tt = (strategy['ir'] - benchmark['ir']) / (sigma / np.sqrt(N))\n",
"\n",
" pval = scipy.stats.t.sf(np.abs(tt), N-1)*2\n",
"\n",
" return tt, pval, sigma, N\n",
"\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",
" (\"MACD (30 min)\", macd_30min_ttest),\n",
" (\"RSI (30 min)\", rsi_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}*** \\\\\\\\\")"
] ]
}, },
{ {
@ -236,52 +405,88 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 2, "execution_count": 23,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
"def results_for_strats(data_windows, best_strategies, interval='5min', top_n=10):\n", "def results_for_strats(\n",
" test_data = pd.concat([data_windows[0][0][-PADDING:]] + [data_window[1] for data_window in data_windows])\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)\n", " buy_and_hold_concat = evaluate_strategy(test_data_5min, BuyAndHoldStrategy(), padding=PADDING, interval='5min')\n",
" \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_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", " 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",
" 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", " 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",
" 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", " 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",
" 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", " 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", "\n",
" z = list(reversed([\n", " z = list(reversed([\n",
" list(reversed([round(buy_and_hold_concat['mod_ir'], 3)]*top_n)),\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 macd_30min_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 macd_15min_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 macd_5min_concat])),\n",
" list(reversed([round(x['mod_ir'], 3) for x in gmadl_model_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", " ]))\n",
" x = list(reversed(range(1, top_n+1)))\n", " x = list(reversed(range(1, top_n+1)))\n",
" y = list(reversed([\n", " y = list(reversed([\n",
" \"Buy and Hold\",\n", " \"Buy and Hold\",\n",
" \"MACD Strategy\",\n", " \"MACD Strategy (30 min)\",\n",
" \"RSI Strategy\",\n", " \"MACD Strategy (15 min)\",\n",
" \"Quantile Informer\",\n", " \"MACD Strategy (5 min)\",\n",
" \"Gmadl Informer\"\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", " ]))\n",
" # 'Portland'\n", " # 'Portland'\n",
" fig = ff.create_annotated_heatmap(z, x=x, y=y, colorscale='thermal', zmid=buy_and_hold_concat['mod_ir'])\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", " fig.update_layout(\n",
" margin=dict(l=20, r=20, b=20, t=20),\n", " margin=dict(l=20, r=20, b=20, t=20),\n",
" width=1100,\n", " width=1100,\n",
" height=450,\n", " height=650,\n",
" font=dict(\n", " font=dict(\n",
" # family=\"Courier New, monospace\",\n", " # family=\"Courier New, monospace\",\n",
" size=18, # Set the font size here\n", " size=16, # Set the font size here\n",
" # color=\"RebeccaPurple\"\n", " # color=\"RebeccaPurple\"\n",
" )\n", " )\n",
" )\n", " )\n",
" fig.show()\n", " fig.show()\n",
"\n", "\n",
"# results_for_strats(data_windows_5min, best_strategies_5min, interval='5min', top_n=10) \n", "# results_for_strats(data_windows_5min, data_windows_15min, data_windows_30min,\n",
"# results_for_strats(data_windows_15min, best_strategies_15min, interval='15min', top_n=10) \n", "# best_strategies_5min, best_strategies_15min, best_strategies_30min, top_n=10) "
"# results_for_strats(data_windows_30min, best_strategies_30min, interval='30min', top_n=10) \n"
] ]
}, },
{ {
@ -331,7 +536,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 37, "execution_count": 48,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
@ -386,7 +591,7 @@
" table_eval_windows = Texttable()\n", " table_eval_windows = Texttable()\n",
" table_eval_windows.set_deco(Texttable.HEADER)\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_cols_align([\"l\", \"c\",\"c\", \"c\", \"c\", \"c\", \"c\", \"c\", \"c\", \"c\"])\n",
" table_eval_windows.set_precision(3)\n", " table_eval_windows.set_precision(2)\n",
"\n", "\n",
" table_eval_windows.header([\n", " table_eval_windows.header([\n",
" \"\\\\textbf{Strategy}\",\n", " \"\\\\textbf{Strategy}\",\n",
@ -407,21 +612,21 @@
" table_eval_windows.add_row([\n", " table_eval_windows.add_row([\n",
" strategy_name,\n", " strategy_name,\n",
" result['value'],\n", " result['value'],\n",
" result['arc'],\n", " f\"{result['arc']*100:.1f}\\%\",\n",
" result['asd'],\n", " f\"{result['asd']*100:.1f}\\%\",\n",
" result['ir'],\n", " result['ir'],\n",
" result['md'],\n", " f\"{result['md']*100:.1f}\\%\",\n",
" result['mod_ir'],\n", " result['mod_ir'],\n",
" result['n_trades'],\n", " result['n_trades'],\n",
" f\"{result['long_pos']*100:.2f}\\%\",\n", " f\"{result['long_pos']*100:.1f}\\%\",\n",
" f\"{result['short_pos']*100:.2f}\\%\",\n", " f\"{result['short_pos']*100:.1f}\\%\",\n",
" ])\n", " ])\n",
" print(latextable.draw_latex(table_eval_windows))" " print(latextable.draw_latex(table_eval_windows))"
] ]
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 46, "execution_count": 37,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
@ -503,6 +708,125 @@
"# results_plot(buy_and_hold_concat, [res], width=1200)" "# results_plot(buy_and_hold_concat, [res], width=1200)"
] ]
}, },
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Different number of test windows"
]
},
{
"cell_type": "code",
"execution_count": 36,
"metadata": {},
"outputs": [],
"source": [
"with open('cache/5min-best-strategies-short.pkl', 'rb') as inpt:\n",
" best_strategies_5min_short = pickle.load(inpt)\n",
"\n",
"with open('cache/5min-best-strategies-long.pkl', 'rb') as inpt:\n",
" best_strategies_5min_long = pickle.load(inpt)\n",
"\n",
"with open('cache/30min-best-strategies-short.pkl', 'rb') as inpt:\n",
" best_strategies_30min_short = pickle.load(inpt)\n",
"\n",
"with open('cache/30min-best-strategies-long.pkl', 'rb') as inpt:\n",
" best_strategies_30min_long = pickle.load(inpt)"
]
},
{
"cell_type": "code",
"execution_count": 39,
"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:0.7\n",
"\u001b[34m\u001b[1mwandb\u001b[0m: Downloading large artifact btc-usdt-5m-long:latest, 446.99MB. 6 files... \n",
"\u001b[34m\u001b[1mwandb\u001b[0m: 6 of 6 files downloaded. \n",
"Done. 0:0:1.1\n",
"\u001b[34m\u001b[1mwandb\u001b[0m: Downloading large artifact btc-usdt-30m-short:latest, 223.56MB. 24 files... \n",
"\u001b[34m\u001b[1mwandb\u001b[0m: 24 of 24 files downloaded. \n",
"Done. 0:0:0.7\n",
"\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"
]
}
],
"source": [
"data_windows_5min_short = get_data_windows(\n",
" 'wne-masters-thesis-testing',\n",
" 'btc-usdt-5m-short:latest',\n",
" min_window=0, \n",
" max_window=11\n",
")\n",
"\n",
"data_windows_5min_long = get_data_windows(\n",
" 'wne-masters-thesis-testing',\n",
" 'btc-usdt-5m-long:latest',\n",
" min_window=0, \n",
" max_window=2\n",
")\n",
"\n",
"data_windows_30min_short = get_data_windows(\n",
" 'wne-masters-thesis-testing',\n",
" 'btc-usdt-30m-short:latest',\n",
" min_window=0, \n",
" max_window=11\n",
")\n",
"\n",
"data_windows_30min_long = get_data_windows(\n",
" 'wne-masters-thesis-testing',\n",
" 'btc-usdt-30m-long:latest',\n",
" min_window=0, \n",
" max_window=2\n",
")"
]
},
{
"cell_type": "code",
"execution_count": 57,
"metadata": {},
"outputs": [],
"source": [
"# def results_for_strats_different_windows(buy_and_hold_data_windows, *args, interval='5min'):\n",
"# evaluation_results = []\n",
"# names = []\n",
"# buy_and_hold_data = pd.concat([buy_and_hold_data_windows[0][0][-PADDING:]] + [data_window[1] for data_window in buy_and_hold_data_windows])\n",
"# buy_and_hold_concat = evaluate_strategy(buy_and_hold_data, BuyAndHoldStrategy(), padding=PADDING, interval=interval)\n",
"# for data_windows, strategy, name in args:\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",
"# evaluation_results.append(\n",
"# evaluate_strategy(test_data, ConcatenatedStrategies(len(data_windows[0][1]), [s[0] for s in strategy], padding=PADDING), padding=PADDING, interval=interval\n",
"# ))\n",
"# names.append(name)\n",
" \n",
"# results_plot2(buy_and_hold_concat, evaluation_results, names, width=1200)\n",
"# results_table2(buy_and_hold_concat, evaluation_results, names)\n",
"\n",
"# results_for_strats_different_windows(\n",
"# data_windows_30min,\n",
"# (data_windows_30min_short, best_strategies_30min_short['rsi_strategies'], '12 windows'),\n",
"# (data_windows_30min, best_strategies_30min['rsi_strategies'], '6 windows'),\n",
"# (data_windows_30min_long, best_strategies_30min_long['rsi_strategies'], '3 windows'),\n",
"# interval='30min'\n",
"# )\n",
"\n",
"# results_for_strats_different_windows(\n",
"# data_windows_5min,\n",
"# (data_windows_5min_short, best_strategies_5min_short['gmadl_model'], '12 windows'),\n",
"# (data_windows_5min, best_strategies_5min['gmadl_model'], '6 windows'),\n",
"# (data_windows_5min_long, best_strategies_5min_long['gmadl_model'], '3 windows'),\n",
"# interval='5min'\n",
"# )"
]
},
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": null,

View File

@ -1,6 +1,6 @@
import torch import torch
from pytorch_forecasting import QuantileLoss from pytorch_forecasting import QuantileLoss, RMSE
from pytorch_forecasting.metrics.base_metrics import MultiHorizonMetric from pytorch_forecasting.metrics.base_metrics import MultiHorizonMetric
@ -16,6 +16,9 @@ def get_loss(config):
b=config['loss']['b'] b=config['loss']['b']
) )
if loss_name == 'RMSE':
return RMSE()
raise ValueError("Unknown loss") raise ValueError("Unknown loss")