From e4d4ca262ab8c916b56bc7af0cea0d920cdb7943 Mon Sep 17 00:00:00 2001 From: Trent McConaghy Date: Mon, 26 Feb 2024 23:58:38 +0100 Subject: [PATCH] Fix #599: [Pdr bot, sim] Implement two-sided prediction (PR #670) Fix #599: - Make Aimodel do classification (not regression), where classifier outputs probabilities of up vs down - In sim_engine predictoor: model two-sided prediction - In sim_engine trader: use up/down confidence level to decide amt of $ to put in - In sim_engine trader: sell when predict down, then buy back - In sim_engine: add contour plots to visualize models, when 2 input vars (and hide plot when not 2 vars) - In predictoor_agent approach 1: stake up/down as 50/50 - In predictoor_agent approach 3: stake up=prob_up*stake_amt, down=(1-prob_up)*stake_amt - rename predictoor approach 3 --> approach 2 - predictoor.md README updated --- README.md | 1 + READMEs/predictoor.md | 45 +- READMEs/trader.md | 10 +- pdr_backend/aimodel/aimodel.py | 49 +++ pdr_backend/aimodel/aimodel_data_factory.py | 27 +- pdr_backend/aimodel/aimodel_factory.py | 52 ++- pdr_backend/aimodel/plot_model.py | 91 ++++ pdr_backend/aimodel/test/conftest.py | 2 +- pdr_backend/aimodel/test/test_aimodel.py | 1 + .../aimodel/test/test_aimodel_data_factory.py | 63 ++- .../aimodel/test/test_aimodel_factory.py | 133 +++--- pdr_backend/aimodel/test/test_plot_model.py | 1 + pdr_backend/cli/cli_module.py | 15 +- pdr_backend/cli/test/test_cli_module.py | 10 +- pdr_backend/contract/base_contract.py | 5 +- .../contract/test/test_erc721_factory.py | 5 - pdr_backend/lake/test/resources.py | 32 +- pdr_backend/ppss/aimodel_ss.py | 4 +- pdr_backend/ppss/ppss.py | 26 +- pdr_backend/ppss/predictoor_ss.py | 66 ++- pdr_backend/ppss/test/test_aimodel_ss.py | 6 +- pdr_backend/ppss/test/test_ppss.py | 10 +- pdr_backend/ppss/test/test_predictoor_ss.py | 87 +++- pdr_backend/ppss/web3_pp.py | 4 +- .../predictoor/approach1/predictoor_agent1.py | 36 -- .../predictoor/approach1/test/conftest.py | 1 - .../approach1/test/test_predictoor_agent1.py | 61 --- .../predictoor/approach3/predictoor_agent3.py | 57 --- .../predictoor/approach3/test/conftest.py | 1 - .../approach3/test/test_predictoor_agent3.py | 187 -------- .../predictoor/base_predictoor_agent.py | 164 ------- pdr_backend/predictoor/predictoor_agent.py | 302 +++++++++++++ ...predictoor_agent_runner.py => mockutil.py} | 88 +--- .../predictoor/test/test_predictoor_agent.py | 234 ++++++++++ pdr_backend/sim/sim_engine.py | 404 +++++++++++------- pdr_backend/sim/test/test_sim_engine.py | 85 ++-- pdr_backend/util/mathutil.py | 49 +-- pdr_backend/util/strutil.py | 4 +- .../util/test_noganache/test_mathutil.py | 19 +- .../util/test_noganache/test_strutil.py | 4 +- ppss.yaml | 26 +- system_tests/conftest.py | 1 + system_tests/test_predictoor_system.py | 31 +- 43 files changed, 1412 insertions(+), 1087 deletions(-) create mode 100644 pdr_backend/aimodel/aimodel.py create mode 100644 pdr_backend/aimodel/plot_model.py create mode 100644 pdr_backend/aimodel/test/test_aimodel.py create mode 100644 pdr_backend/aimodel/test/test_plot_model.py delete mode 100644 pdr_backend/predictoor/approach1/predictoor_agent1.py delete mode 100644 pdr_backend/predictoor/approach1/test/conftest.py delete mode 100644 pdr_backend/predictoor/approach1/test/test_predictoor_agent1.py delete mode 100644 pdr_backend/predictoor/approach3/predictoor_agent3.py delete mode 100644 pdr_backend/predictoor/approach3/test/conftest.py delete mode 100644 pdr_backend/predictoor/approach3/test/test_predictoor_agent3.py delete mode 100644 pdr_backend/predictoor/base_predictoor_agent.py create mode 100644 pdr_backend/predictoor/predictoor_agent.py rename pdr_backend/predictoor/test/{predictoor_agent_runner.py => mockutil.py} (50%) create mode 100644 pdr_backend/predictoor/test/test_predictoor_agent.py diff --git a/README.md b/README.md index 6c7ef979b..cfb5319d2 100644 --- a/README.md +++ b/README.md @@ -81,6 +81,7 @@ OPF-run bots & higher-level tools: - `publisher` - publish pdr data feeds - `analytics` - analytics tools - `payout` - OCEAN & ROSE payout +- `deployer` - deployer tool - `accuracy` - calculates % correct, for display in predictoor.ai webapp Mid-level building blocks: diff --git a/READMEs/predictoor.md b/READMEs/predictoor.md index a07cd53b5..def03b964 100644 --- a/READMEs/predictoor.md +++ b/READMEs/predictoor.md @@ -65,12 +65,14 @@ What it does: 1. Grab historical price data from exchanges and stores in `parquet_data/` dir. It re-uses any previously saved data. 1. Run through many 5min epochs. At each epoch: - Build a model - - Predict up/down + - Predict - Trade - - Plot total profit versus time, and more - - Log to console, and to `logs/out_