From c4c9f4a189c5e9b12833cf682740fb08b3e57a88 Mon Sep 17 00:00:00 2001 From: Chris Schneider Date: Wed, 9 Sep 2020 21:19:40 -0400 Subject: [PATCH 1/7] make entry_point executabe (via chmod +x) --- entry_point.sh | 0 1 file changed, 0 insertions(+), 0 deletions(-) mode change 100644 => 100755 entry_point.sh diff --git a/entry_point.sh b/entry_point.sh old mode 100644 new mode 100755 From b10cca57f14076f74052940019f79530c68f4d9a Mon Sep 17 00:00:00 2001 From: Chris Schneider Date: Wed, 9 Sep 2020 21:20:53 -0400 Subject: [PATCH 2/7] clean up dockerfile * move pip3 comment * update CMD to use relative path --- dockerfile | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/dockerfile b/dockerfile index afbe27bb..98879969 100644 --- a/dockerfile +++ b/dockerfile @@ -1,8 +1,11 @@ FROM python:3.8 # Setup environment -RUN cp /usr/local/bin/pip3.8 /usr/local/bin/pip3 # reenable pip3 + +# reenable pip3 +RUN cp /usr/local/bin/pip3.8 /usr/local/bin/pip3 RUN pip3 install --upgrade pip + WORKDIR /usr/src/app # Install requirements @@ -13,4 +16,4 @@ COPY . . VOLUME ["/usr/src/app"] -CMD ["/usr/src/app/entry_point.sh"] +CMD ["./entry_point.sh"] From d12cf089803429516e83e0612a075fb2f50118e4 Mon Sep 17 00:00:00 2001 From: Chris Schneider Date: Wed, 9 Sep 2020 21:21:36 -0400 Subject: [PATCH 3/7] replace docker-compose template with default file --- .gitignore | 1 - docker-compose.yml | 8 ++++++++ docker-compose.yml.template | 8 -------- 3 files changed, 8 insertions(+), 9 deletions(-) create mode 100644 docker-compose.yml delete mode 100644 docker-compose.yml.template diff --git a/.gitignore b/.gitignore index 1fda299b..e8a1fc23 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,4 @@ __pycache__/ -docker-compose.yml dictionaries/* !dictionaries/readme.txt !dictionaries/sample_dict.npy diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 00000000..3b3be65c --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,8 @@ +version: "3" + +services: + surpriver: + build: . + restart: always + volumes: + - "./:/usr/src/app" diff --git a/docker-compose.yml.template b/docker-compose.yml.template deleted file mode 100644 index 713db5ce..00000000 --- a/docker-compose.yml.template +++ /dev/null @@ -1,8 +0,0 @@ -version: "3" -services: - surpriver: - image: surpriver:latest - container_name: surpriver - restart: always - volumes: - - ":/usr/src/app" From cdaf3d118d297ae19774bce109901d7a417abe4d Mon Sep 17 00:00:00 2001 From: Chris Schneider Date: Wed, 9 Sep 2020 21:22:01 -0400 Subject: [PATCH 4/7] add .dockerignore --- .dockerignore | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 .dockerignore diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 00000000..96656349 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,10 @@ +__pycache__/ + +.dockerignore +docker-compose.yml + +dictionaries/* +!dictionaries/readme.txt +!dictionaries/sample_dict.npy + +.git* From b0715510b0f43c1cba106f2f248749443b52f18a Mon Sep 17 00:00:00 2001 From: Chris Schneider Date: Wed, 9 Sep 2020 21:22:27 -0400 Subject: [PATCH 5/7] add makefile with convienient scripts --- makefile | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 makefile diff --git a/makefile b/makefile new file mode 100644 index 00000000..5ce05e31 --- /dev/null +++ b/makefile @@ -0,0 +1,37 @@ +start: + docker-compose up -d --build + +stop: + docker-compose stop + +down: + docker-compose down + +ps: + docker-compose ps + +fresh: start + docker-compose exec surpriver \ + python detection_engine.py \ + --top_n 25 \ + --min_volume 5000 \ + --data_granularity_minutes 60 \ + --history_to_use 30 \ + --is_load_from_dictionary 0 \ + --data_dictionary_path 'dictionaries/data_dict.npy' \ + --is_save_dictionary 1 \ + --is_test 0 \ + --future_bars 0 + +history: start + docker-compose exec surpriver \ + python detection_engine.py \ + --top_n 25 \ + --min_volume 5000 \ + --data_granularity_minutes 60 \ + --history_to_use 14 \ + --is_load_from_dictionary 1 \ + --data_dictionary_path 'dictionaries/data_dict.npy' \ + --is_save_dictionary 0 \ + --is_test 0 \ + --future_bars 0 From 6e97d6d04f2e8d15c21a0550a7cd9686b8ef312c Mon Sep 17 00:00:00 2001 From: Chris Schneider Date: Thu, 12 Nov 2020 19:47:12 -0500 Subject: [PATCH 6/7] update makefile --- makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/makefile b/makefile index 5ce05e31..5715d4b6 100644 --- a/makefile +++ b/makefile @@ -1,4 +1,4 @@ -start: +start: dockerfile docker-compose.yml docker-compose up -d --build stop: @@ -10,7 +10,7 @@ down: ps: docker-compose ps -fresh: start +today: start docker-compose exec surpriver \ python detection_engine.py \ --top_n 25 \ From 4c25706b51cdd6153b6d2d48fad334348bf04009 Mon Sep 17 00:00:00 2001 From: Chris Schneider Date: Thu, 12 Nov 2020 19:48:07 -0500 Subject: [PATCH 7/7] update README with new docker instructions --- README.md | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index e5319a84..aa3c1731 100644 --- a/README.md +++ b/README.md @@ -33,22 +33,26 @@ pip install -r requirements.txt ``` ## Running with Docker + You can also use docker if you know what it is and have some knowledge on how to use it. Here are the steps to run the tool with docker. -- First you must build the container: `docker build . -t surpriver` -- Then you need to copy the contents of docker-compose.yml.template to a new file called docker-compose.yml -- Replace `` with the directory you are working in. -- Run the container by executing `docker-compose up -d` -- Execute any of the commands below by prepending `docker exec -it surpriver` to your command line. +- First you must build the container: `make` +- Execute any of the commands below by prepending `docker-compose exec surpriver` to your command line. ### Predictions for Today If you want to go ahead and directly get the most anomalous stocks for today, you can simple run the following command to get the stocks with the most unusual patterns. We will dive deeper into the command in the following sections. #### Get Most Anomalous Stocks for Today ##### When you do not have the data dictionary saved and you are running it for the first time. -``` + +```shell +make today + +# OR + python detection_engine.py --top_n 25 --min_volume 5000 --data_granularity_minutes 60 --history_to_use 14 --is_load_from_dictionary 0 --data_dictionary_path 'dictionaries/data_dict.npy' --is_save_dictionary 1 --is_test 0 --future_bars 0 ``` + This command will give you the top **25 stocks** that had the highest anomaly score in the last **14 bars** of **60 minute candles**. It will also store all the data that it used to make predictions in the **dictionaries/data_dict.npy** folder. Below is a more detailed explanation of each parameter. - **top_n**: The total number of most anomalous stocks you want to see. - **min_volume**: Filter for volume. Any stock that has an average of volume lower than this value will be ignored. @@ -61,8 +65,13 @@ This command will give you the top **25 stocks** that had the highest anomaly sc - **future_bars**: These number of bars will be saved from the recent history for testing purposes. - **output_format**: The format for results. If you pass CLI, the results will be printed to the console. If you pass JSON, a JSON file will be created with results for today's date. The default is CLI. -##### When you have the data dictionary saved, you can just run the following command. -``` +##### When you have the data dictionary saved, you can just run the following command. + +```shell +make history + +# OR + python detection_engine.py --top_n 25 --min_volume 5000 --data_granularity_minutes 60 --history_to_use 14 --is_load_from_dictionary 1 --data_dictionary_path 'dictionaries/data_dict.npy' --is_save_dictionary 0 --is_test 0 --future_bars 0 --output_format 'CLI' ``` Notice the change in **is_save_dictionary** and **is_load_from_dictionary**.