rl-pricing 0.5.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (55) hide show
  1. rl/__init__.py +0 -0
  2. rl/autotrain/__init__.py +0 -0
  3. rl/autotrain/r1.py +124 -0
  4. rl/autotrain/training.py +933 -0
  5. rl/bench/__init__.py +5 -0
  6. rl/bench/cli.py +272 -0
  7. rl/bench/data.py +383 -0
  8. rl/bench/engine.py +173 -0
  9. rl/bench/features.py +114 -0
  10. rl/bench/figures.py +104 -0
  11. rl/bench/gym_env.py +125 -0
  12. rl/bench/leaderboard.py +424 -0
  13. rl/bench/ledger.py +607 -0
  14. rl/bench/market.py +178 -0
  15. rl/bench/monthly.py +387 -0
  16. rl/bench/policies/__init__.py +1 -0
  17. rl/bench/policies/baselines.py +290 -0
  18. rl/bench/policies/forecast.py +212 -0
  19. rl/bench/policies/sb3.py +337 -0
  20. rl/bench/policies/tradingagents.py +364 -0
  21. rl/bench/policy.py +53 -0
  22. rl/bench/runner.py +408 -0
  23. rl/bench/scoring.py +279 -0
  24. rl/bench/submission.py +124 -0
  25. rl/bench/sweep.py +561 -0
  26. rl/bench/tasks.py +206 -0
  27. rl/bench/verdicts.py +265 -0
  28. rl/cli.py +299 -0
  29. rl/config/__init__.py +0 -0
  30. rl/config/config.py +91 -0
  31. rl/env/__init__.py +0 -0
  32. rl/env/env_portfolio.py +261 -0
  33. rl/env/env_stocktrading.py +406 -0
  34. rl/forecast/__init__.py +0 -0
  35. rl/forecast/lstm.py +238 -0
  36. rl/marketdata/__init__.py +0 -0
  37. rl/marketdata/sharadar.py +204 -0
  38. rl/marketdata/synthetic.py +77 -0
  39. rl/marketdata/yahoodownloader.py +130 -0
  40. rl/model/__init__.py +0 -0
  41. rl/model/models.py +584 -0
  42. rl/preprocessing/__init__.py +0 -0
  43. rl/preprocessing/data.py +26 -0
  44. rl/preprocessing/preprocessors.py +248 -0
  45. rl/trade/__init__.py +0 -0
  46. rl/trade/backtest.py +93 -0
  47. rl/trade/baselines.py +229 -0
  48. rl/trade/execution.py +48 -0
  49. rl/trade/metrics.py +154 -0
  50. rl_pricing-0.5.0.dist-info/METADATA +86 -0
  51. rl_pricing-0.5.0.dist-info/RECORD +55 -0
  52. rl_pricing-0.5.0.dist-info/WHEEL +5 -0
  53. rl_pricing-0.5.0.dist-info/entry_points.txt +2 -0
  54. rl_pricing-0.5.0.dist-info/licenses/LICENSE +21 -0
  55. rl_pricing-0.5.0.dist-info/top_level.txt +1 -0
rl/__init__.py ADDED
File without changes
File without changes
rl/autotrain/r1.py ADDED
@@ -0,0 +1,124 @@
1
+ """Driver for the R1 runs: the toolkit's ensemble with the FinRL authors' recipe.
2
+
3
+ Sets what the toolkit lets us match from Yang, Liu, Zhong and Walid (ICAIF
4
+ 2020): the four indicators (``macd``, ``rsi_30``, ``cci_30``, ``dx_30``), the
5
+ training steps per algorithm (A2C 30,000, PPO 100,000, DDPG 10,000), PPO with
6
+ ``ent_coef`` 0.005 and 128-step rollouts in minibatches of 16 (the authors'
7
+ ``nminibatches=8``), and DDPG with Ornstein-Uhlenbeck action noise of sigma
8
+ 0.5. A2C and the rest of DDPG keep the toolkit defaults, as does everything
9
+ else (0.1% fees per side, $1,000,000, ``hmax`` 100, reward scaling 1e-4,
10
+ 63-session rebalance and validation windows, next-open fills, observation
11
+ normalisation, refit of the winner). Each algorithm also trades its own
12
+ account (``standalone_accounts``).
13
+
14
+ Prices come from a CSV in the toolkit format (``date,tic,open,high,low,close,
15
+ volume``), e.g. from :mod:`rl.marketdata.sharadar`::
16
+
17
+ python -m rl.autotrain.r1 --data-file prices.csv --seed 0 --run-name r1_a_s0
18
+ """
19
+
20
+ import argparse
21
+ import copy
22
+ import logging
23
+
24
+ from rl.autotrain.training import TrainConfig, run_ensemble
25
+ from rl.config import config
26
+
27
+ AUTHORS_INDICATORS = ("macd", "rsi_30", "cci_30", "dx_30")
28
+ AUTHORS_TIMESTEPS = {"a2c": 30_000, "ppo": 100_000, "ddpg": 10_000}
29
+ AUTHORS_DDPG_NOISE_SIGMA = 0.5
30
+
31
+
32
+ def authors_model_kwargs(ddpg_noise_sigma=AUTHORS_DDPG_NOISE_SIGMA):
33
+ """Per-algorithm model settings (each replaces the config.py default)."""
34
+ return {
35
+ "a2c": copy.deepcopy(config.A2C_PARAMS),
36
+ # 128 steps in 8 minibatches; every other PPO setting is stable-baselines3's default.
37
+ "ppo": {"n_steps": 128, "batch_size": 16, "ent_coef": 0.005},
38
+ "ddpg": {
39
+ **copy.deepcopy(config.DDPG_PARAMS),
40
+ "action_noise": {"type": "ornstein_uhlenbeck", "sigma": ddpg_noise_sigma},
41
+ },
42
+ }
43
+
44
+
45
+ def r1_config(
46
+ data_file,
47
+ *,
48
+ seed,
49
+ use_turbulence=True,
50
+ ticker_list=None,
51
+ start_date="2009-01-02",
52
+ start_trade_date="2016-01-04",
53
+ end_date="2026-01-01",
54
+ ddpg_noise_sigma=AUTHORS_DDPG_NOISE_SIGMA,
55
+ ensemble_timesteps=None,
56
+ standalone_accounts=True,
57
+ run_name=None,
58
+ results_dir=config.RESULTS_DIR,
59
+ **overrides,
60
+ ):
61
+ """The :class:`TrainConfig` of one R1 ensemble run.
62
+
63
+ ``end_date`` is exclusive (the default includes 2025-12-31). ``overrides``
64
+ set any other :class:`TrainConfig` field.
65
+ """
66
+ settings = dict(
67
+ agent="ensemble",
68
+ task="trading",
69
+ data_source="csv",
70
+ data_file=data_file,
71
+ ticker_list=ticker_list,
72
+ start_date=start_date,
73
+ start_trade_date=start_trade_date,
74
+ end_date=end_date,
75
+ tech_indicator_list=list(AUTHORS_INDICATORS),
76
+ use_turbulence=use_turbulence,
77
+ ensemble_timesteps=dict(AUTHORS_TIMESTEPS if ensemble_timesteps is None else ensemble_timesteps),
78
+ ensemble_model_kwargs=authors_model_kwargs(ddpg_noise_sigma),
79
+ standalone_accounts=standalone_accounts,
80
+ seed=seed,
81
+ run_name=run_name,
82
+ results_dir=results_dir,
83
+ )
84
+ settings.update(overrides)
85
+ return TrainConfig(**settings).validate()
86
+
87
+
88
+ def run_r1(data_file, *, seed, **options):
89
+ """Run the ensemble for ``seed`` (see :func:`r1_config`); returns :func:`run_ensemble`'s dict."""
90
+ return run_ensemble(r1_config(data_file, seed=seed, **options))
91
+
92
+
93
+ def main(argv=None):
94
+ parser = argparse.ArgumentParser(description=__doc__.split("\n\n")[0])
95
+ parser.add_argument("--data-file", required=True, help="CSV of date,tic,open,high,low,close,volume")
96
+ parser.add_argument("--seed", type=int, required=True)
97
+ parser.add_argument("--tickers", nargs="+", help="default: every ticker in the file")
98
+ parser.add_argument("--no-turbulence", action="store_true", help="arm B: no liquidation rule")
99
+ parser.add_argument("--start-date", default="2009-01-02")
100
+ parser.add_argument("--start-trade-date", default="2016-01-04")
101
+ parser.add_argument("--end-date", default="2026-01-01", help="exclusive")
102
+ parser.add_argument("--ddpg-noise-sigma", type=float, default=AUTHORS_DDPG_NOISE_SIGMA)
103
+ parser.add_argument("--run-name")
104
+ parser.add_argument("--results-dir", default=config.RESULTS_DIR)
105
+ options = parser.parse_args(argv)
106
+ logging.basicConfig(
107
+ level=logging.INFO, format="%(asctime)s %(levelname)s %(name)s: %(message)s"
108
+ )
109
+ return run_r1(
110
+ options.data_file,
111
+ seed=options.seed,
112
+ use_turbulence=not options.no_turbulence,
113
+ ticker_list=options.tickers,
114
+ start_date=options.start_date,
115
+ start_trade_date=options.start_trade_date,
116
+ end_date=options.end_date,
117
+ ddpg_noise_sigma=options.ddpg_noise_sigma,
118
+ run_name=options.run_name,
119
+ results_dir=options.results_dir,
120
+ )
121
+
122
+
123
+ if __name__ == "__main__":
124
+ main()