AI4Finance-Foundation / FinRL

FinRL: Financial Reinforcement Learning. 🔥
https://ai4finance.org
MIT License
9.39k stars 2.28k forks source link

I can't get pass the imports, newbie coder #1091

Open deepspacemine opened 10 months ago

deepspacemine commented 10 months ago

Describe the bug A clear and concise description of what the bug is.

To Reproduce Steps to reproduce the behavior:

  1. Go to '...'
  2. Click on '....'
  3. Scroll down to '....'
  4. See error

Expected behavior A clear and concise description of what you expected to happen.

Screenshots If applicable, add screenshots to help explain your problem.

Desktop (please complete the following information):

Smartphone (please complete the following information):

Additional context Add any other context about the problem here.

deepspacemine commented 10 months ago

image

mmmarchetti commented 10 months ago

Describe the bug A clear and concise description of what the bug is.

To Reproduce Steps to reproduce the behavior:

  1. Go to '...'
  2. Click on '....'
  3. Scroll down to '....'
  4. See error

Expected behavior A clear and concise description of what you expected to happen.

Screenshots If applicable, add screenshots to help explain your problem.

Desktop (please complete the following information):

  • OS: [e.g. iOS]
  • Browser [e.g. chrome, safari]
  • Version [e.g. 22]

Smartphone (please complete the following information):

  • Device: [e.g. iPhone6]
  • OS: [e.g. iOS8.1]
  • Browser [e.g. stock browser, safari]
  • Version [e.g. 22]

Additional context Add any other context about the problem here.

Hello! Please fill in the fields to help us reproduce the error. Please explain which file you were testing.

deepspacemine commented 10 months ago

I'm trying to run the code to Google Colab. My Main issue in installing the imports, mainly finrl. Does anyone have issue with that pip install

PS C:\Users\Milan> pip install finrl
Collecting finrl Using cached finrl-0.3.6.tar.gz (75 kB) Installing build dependencies ... done Getting requirements to build wheel ... done Preparing metadata (pyproject.toml) ... done Discarding https://files.pythonhosted.org/packages/65/22/94fd5875e26f5bc79cc1d3250f200843052c423dd4c604cf3362d5178388/finrl-0.3.6.tar.gz (from https://pypi.org/simple/finrl/) (requires-python:>=3.7): Requested finrl from https://files.pythonhosted.org/packages/65/22/94fd5875e26f5bc79cc1d3250f200843052c423dd4c604cf3362d5178388/finrl-0.3.6.tar.gz has inconsistent version: expected '0.3.6', but metadata has '0.3.5' Using cached finrl-0.3.5-py3-none-any.whl (85 kB) Requirement already satisfied: alpaca-trade-api>=2.1.0 in c:\users\milan\appdata\local\packages\pythonsoftwarefoundation.python.3.11_qbz5n2kfra8p0\localcache\local-packages\python311\site-packages (from finrl) (3.0.2) INFO: pip is looking at multiple versions of finrl to determine which version is compatible with other requirements. This could take a while. Using cached finrl-0.3.4-py3-none-any.whl (133 kB) Requirement already satisfied: numpy>=1.17.3 in c:\users\milan\appdata\local\packages\pythonsoftwarefoundation.python.3.11_qbz5n2kfra8p0\localcache\local-packages\python311\site-packages (from finrl) (1.25.2) Requirement already satisfied: pandas>=1.1.5 in c:\users\milan\appdata\local\packages\pythonsoftwarefoundation.python.3.11_qbz5n2kfra8p0\localcache\local-packages\python311\site-packages (from finrl) (2.1.0) Collecting stockstats (from finrl) Obtaining dependency information for stockstats from https://files.pythonhosted.org/packages/15/b3/a4ae4952ff08544e7f286bc2925193077660fa80cab8f86b0a32a2a70f4d/stockstats-0.6.2-py2.py3-none-any.whl.metadata Using cached stockstats-0.6.2-py2.py3-none-any.whl.metadata (38 kB) Requirement already satisfied: yfinance in c:\users\milan\appdata\local\packages\pythonsoftwarefoundation.python.3.11_qbz5n2kfra8p0\localcache\local-packages\python311\site-packages (from finrl) (0.2.28) Collecting elegantrl (from finrl) Using cached elegantrl-0.3.6.tar.gz (168 kB) Preparing metadata (setup.py) ... done Requirement already satisfied: pyfolio in c:\users\milan\appdata\local\packages\pythonsoftwarefoundation.python.3.11_qbz5n2kfra8p0\localcache\local-packages\python311\site-packages (from finrl) (0.9.2) Requirement already satisfied: matplotlib in c:\users\milan\appdata\local\packages\pythonsoftwarefoundation.python.3.11_qbz5n2kfra8p0\localcache\local-packages\python311\site-packages (from finrl) (3.7.2) Requirement already satisfied: scikit-learn>=0.21.0 in c:\users\milan\appdata\local\packages\pythonsoftwarefoundation.python.3.11_qbz5n2kfra8p0\localcache\local-packages\python311\site-packages (from finrl) (1.3.0) Requirement already satisfied: gym>=0.17 in c:\users\milan\appdata\local\packages\pythonsoftwarefoundation.python.3.11_qbz5n2kfra8p0\localcache\local-packages\python311\site-packages (from finrl) (0.23.0) Collecting stable-baselines3[extra] (from finrl) Obtaining dependency information for stable-baselines3[extra] from https://files.pythonhosted.org/packages/5e/81/7a0fbfc45240ec36cc3fcfe8f135996ef03277e2305d941a6d9186eb14e8/stable_baselines3-2.1.0-py3-none-any.whl.metadata Using cached stable_baselines3-2.1.0-py3-none-any.whl.metadata (5.2 kB) Collecting ray[default] (from finrl) Obtaining dependency information for ray[default] from https://files.pythonhosted.org/packages/c7/31/7f76e7bce04dd52b5d63eb036363c7baa0ed43ae61857c13e1e084dc9e0a/ray-2.6.3-cp311-cp311-win_amd64.whl.metadata Using cached ray-2.6.3-cp311-cp311-win_amd64.whl.metadata (12 kB) Collecting lz4 (from finrl) Using cached lz4-4.3.2-cp311-cp311-win_amd64.whl (99 kB) Collecting tensorboardX (from finrl) Obtaining dependency information for tensorboardX from https://files.pythonhosted.org/packages/44/71/f3e7c9b2ab67e28c572ab4e9d5fa3499e0d252650f96d8a3a03e26677f53/tensorboardX-2.6.2.2-py2.py3-none-any.whl.metadata Using cached tensorboardX-2.6.2.2-py2.py3-none-any.whl.metadata (5.8 kB) Collecting gputil (from finrl) Using cached GPUtil-1.4.0.tar.gz (5.5 kB) Preparing metadata (setup.py) ... done Collecting exchange-calendars (from finrl) Obtaining dependency information for exchange-calendars from https://files.pythonhosted.org/packages/5d/b2/eb858bf3540ace8f594d9423ac1264460bf36abcd9251ee4546c956c8ec5/exchange_calendars-4.2.8-py3-none-any.whl.metadata Using cached exchange_calendars-4.2.8-py3-none-any.whl.metadata (38 kB) Collecting ccxt>=1.66.32 (from finrl) Obtaining dependency information for ccxt>=1.66.32 from https://files.pythonhosted.org/packages/37/4b/35a2b25fdc65042764c9fd43676fc00aad2e59ac6eca1e0f0328c54442c5/ccxt-4.0.83-py2.py3-none-any.whl.metadata Using cached ccxt-4.0.83-py2.py3-none-any.whl.metadata (110 kB) Collecting jqdatasdk (from finrl) Obtaining dependency information for jqdatasdk from https://files.pythonhosted.org/packages/63/6b/4bc2747558a03d006f4bdafc3413325fb59fb1dc1427ab54b3e3272fa1c1/jqdatasdk-1.9.0-py3-none-any.whl.metadata Using cached jqdatasdk-1.9.0-py3-none-any.whl.metadata (5.7 kB) Collecting wrds (from finrl) Using cached wrds-3.1.6-py3-none-any.whl (12 kB) Requirement already satisfied: pytest in c:\users\milan\appdata\local\packages\pythonsoftwarefoundation.python.3.11_qbz5n2kfra8p0\localcache\local-packages\python311\site-packages (from finrl) (7.4.1) Requirement already satisfied: setuptools>=41.4.0 in c:\users\milan\appdata\local\packages\pythonsoftwarefoundation.python.3.11_qbz5n2kfra8p0\localcache\local-packages\python311\site-packages (from finrl) (68.1.2) Requirement already satisfied: wheel>=0.33.6 in c:\users\milan\appdata\local\packages\pythonsoftwarefoundation.python.3.11_qbz5n2kfra8p0\localcache\local-packages\python311\site-packages (from finrl) (0.41.2) Collecting pre-commit (from finrl) Obtaining dependency information for pre-commit from https://files.pythonhosted.org/packages/58/56/3b24f8641c39021218ca16115a9cd88512ae16eab790513e832a36269e90/pre_commit-3.4.0-py2.py3-none-any.whl.metadata Using cached pre_commit-3.4.0-py2.py3-none-any.whl.metadata (1.3 kB) Requirement already satisfied: certifi>=2018.1.18 in c:\users\milan\appdata\local\packages\pythonsoftwarefoundation.python.3.11_qbz5n2kfra8p0\localcache\local-packages\python311\site-packages (from ccxt>=1.66.32->finrl) (2023.7.22) Requirement already satisfied: requests>=2.18.4 in c:\users\milan\appdata\local\packages\pythonsoftwarefoundation.python.3.11_qbz5n2kfra8p0\localcache\local-packages\python311\site-packages (from ccxt>=1.66.32->finrl) (2.31.0) Collecting cryptography>=2.6.1 (from ccxt>=1.66.32->finrl) Obtaining dependency information for cryptography>=2.6.1 from https://files.pythonhosted.org/packages/30/56/5f4eee57ccd577c261b516bfcbe17492838e2bc4e2e92ea93bbb57666fbd/cryptography-41.0.3-cp37-abi3-win_amd64.whl.metadata Using cached cryptography-41.0.3-cp37-abi3-win_amd64.whl.metadata (5.3 kB) Requirement already satisfied: aiohttp>=3.8 in c:\users\milan\appdata\local\packages\pythonsoftwarefoundation.python.3.11_qbz5n2kfra8p0\localcache\local-packages\python311\site-packages (from ccxt>=1.66.32->finrl) (3.8.2) Collecting aiodns>=1.1.1 (from ccxt>=1.66.32->finrl) Using cached aiodns-3.0.0-py3-none-any.whl (5.0 kB) Requirement already satisfied: yarl>=1.7.2 in c:\users\milan\appdata\local\packages\pythonsoftwarefoundation.python.3.11_qbz5n2kfra8p0\localcache\local-packages\python311\site-packages (from ccxt>=1.66.32->finrl) (1.9.2) Requirement already satisfied: cloudpickle>=1.2.0 in c:\users\milan\appdata\local\packages\pythonsoftwarefoundation.python.3.11_qbz5n2kfra8p0\localcache\local-packages\python311\site-packages (from gym>=0.17->finrl) (2.2.1) Requirement already satisfied: gym-notices>=0.0.4 in c:\users\milan\appdata\local\packages\pythonsoftwarefoundation.python.3.11_qbz5n2kfra8p0\localcache\local-packages\python311\site-packages (from gym>=0.17->finrl) (0.0.8) Requirement already satisfied: python-dateutil>=2.8.2 in c:\users\milan\appdata\local\packages\pythonsoftwarefoundation.python.3.11_qbz5n2kfra8p0\localcache\local-packages\python311\site-packages (from pandas>=1.1.5->finrl) (2.8.2) Requirement already satisfied: pytz>=2020.1 in c:\users\milan\appdata\local\packages\pythonsoftwarefoundation.python.3.11_qbz5n2kfra8p0\localcache\local-packages\python311\site-packages (from pandas>=1.1.5->finrl) (2022.7.1) Requirement already satisfied: tzdata>=2022.1 in c:\users\milan\appdata\local\packages\pythonsoftwarefoundation.python.3.11_qbz5n2kfra8p0\localcache\local-packages\python311\site-packages (from pandas>=1.1.5->finrl) (2023.3) Requirement already satisfied: scipy>=1.5.0 in c:\users\milan\appdata\local\packages\pythonsoftwarefoundation.python.3.11_qbz5n2kfra8p0\localcache\local-packages\python311\site-packages (from scikit-learn>=0.21.0->finrl) (1.11.1) Requirement already satisfied: joblib>=1.1.1 in c:\users\milan\appdata\local\packages\pythonsoftwarefoundation.python.3.11_qbz5n2kfra8p0\localcache\local-packages\python311\site-packages (from scikit-learn>=0.21.0->finrl) (1.3.1) Requirement already satisfied: threadpoolctl>=2.0.0 in c:\users\milan\appdata\local\packages\pythonsoftwarefoundation.python.3.11_qbz5n2kfra8p0\localcache\local-packages\python311\site-packages (from scikit-learn>=0.21.0->finrl) (3.2.0) Requirement already satisfied: urllib3<2,>1.24 in c:\users\milan\appdata\local\packages\pythonsoftwarefoundation.python.3.11_qbz5n2kfra8p0\localcache\local-packages\python311\site-packages (from alpaca-trade-api>=2.1.0->finrl) (1.26.16) Requirement already satisfied: websocket-client<2,>=0.56.0 in c:\users\milan\appdata\local\packages\pythonsoftwarefoundation.python.3.11_qbz5n2kfra8p0\localcache\local-packages\python311\site-packages (from alpaca-trade-api>=2.1.0->finrl) (1.6.2) Requirement already satisfied: websockets<11,>=9.0 in c:\users\milan\appdata\local\packages\pythonsoftwarefoundation.python.3.11_qbz5n2kfra8p0\localcache\local-packages\python311\site-packages (from alpaca-trade-api>=2.1.0->finrl) (10.4) Requirement already satisfied: msgpack==1.0.3 in c:\users\milan\appdata\local\packages\pythonsoftwarefoundation.python.3.11_qbz5n2kfra8p0\localcache\local-packages\python311\site-packages (from alpaca-trade-api>=2.1.0->finrl) (1.0.3) Collecting PyYAML==6.0 (from alpaca-trade-api>=2.1.0->finrl) Using cached PyYAML-6.0-cp311-cp311-win_amd64.whl (143 kB) Requirement already satisfied: deprecation==2.1.0 in c:\users\milan\appdata\local\packages\pythonsoftwarefoundation.python.3.11_qbz5n2kfra8p0\localcache\local-packages\python311\site-packages (from alpaca-trade-api>=2.1.0->finrl) (2.1.0) Requirement already satisfied: attrs>=17.3.0 in c:\users\milan\appdata\local\packages\pythonsoftwarefoundation.python.3.11_qbz5n2kfra8p0\localcache\local-packages\python311\site-packages (from aiohttp>=3.8->ccxt>=1.66.32->finrl) (23.1.0) Requirement already satisfied: charset-normalizer<3.0,>=2.0 in c:\users\milan\appdata\local\packages\pythonsoftwarefoundation.python.3.11_qbz5n2kfra8p0\localcache\local-packages\python311\site-packages (from aiohttp>=3.8->ccxt>=1.66.32->finrl) (2.1.1) Requirement already satisfied: multidict<6.0,>=4.5 in c:\users\milan\appdata\local\packages\pythonsoftwarefoundation.python.3.11_qbz5n2kfra8p0\localcache\local-packages\python311\site-packages (from aiohttp>=3.8->ccxt>=1.66.32->finrl) (5.2.0) Requirement already satisfied: async-timeout<5.0,>=4.0.0a3 in c:\users\milan\appdata\local\packages\pythonsoftwarefoundation.python.3.11_qbz5n2kfra8p0\localcache\local-packages\python311\site-packages (from aiohttp>=3.8->ccxt>=1.66.32->finrl) (4.0.3) Requirement already satisfied: frozenlist>=1.1.1 in c:\users\milan\appdata\local\packages\pythonsoftwarefoundation.python.3.11_qbz5n2kfra8p0\localcache\local-packages\python311\site-packages (from aiohttp>=3.8->ccxt>=1.66.32->finrl) (1.4.0) Requirement already satisfied: aiosignal>=1.1.2 in c:\users\milan\appdata\local\packages\pythonsoftwarefoundation.python.3.11_qbz5n2kfra8p0\localcache\local-packages\python311\site-packages (from aiohttp>=3.8->ccxt>=1.66.32->finrl) (1.3.1) Requirement already satisfied: packaging in c:\users\milan\appdata\local\packages\pythonsoftwarefoundation.python.3.11_qbz5n2kfra8p0\localcache\local-packages\python311\site-packages (from deprecation==2.1.0->alpaca-trade-api>=2.1.0->finrl) (23.0) Requirement already satisfied: torch in c:\users\milan\appdata\local\packages\pythonsoftwarefoundation.python.3.11_qbz5n2kfra8p0\localcache\local-packages\python311\site-packages (from elegantrl->finrl) (2.0.1) Collecting pyluach (from exchange-calendars->finrl) Using cached pyluach-2.2.0-py3-none-any.whl (25 kB) Collecting toolz (from exchange-calendars->finrl) Using cached toolz-0.12.0-py3-none-any.whl (55 kB) Collecting korean-lunar-calendar (from exchange-calendars->finrl) Using cached korean_lunar_calendar-0.3.1-py3-none-any.whl (9.0 kB) Requirement already satisfied: six in c:\users\milan\appdata\local\packages\pythonsoftwarefoundation.python.3.11_qbz5n2kfra8p0\localcache\local-packages\python311\site-packages (from jqdatasdk->finrl) (1.16.0) Collecting SQLAlchemy>=1.2.8 (from jqdatasdk->finrl) Obtaining dependency information for SQLAlchemy>=1.2.8 from https://files.pythonhosted.org/packages/10/81/230bec5713913a472003b71c8dd7e3572de44499e741df576fd6b39d82c8/SQLAlchemy-2.0.20-cp311-cp311-win_amd64.whl.metadata Using cached SQLAlchemy-2.0.20-cp311-cp311-win_amd64.whl.metadata (9.7 kB) Collecting thriftpy2>=0.3.9 (from jqdatasdk->finrl) Using cached thriftpy2-0.4.16.tar.gz (643 kB) Preparing metadata (setup.py) ... done Collecting pymysql>=0.7.6 (from jqdatasdk->finrl) Obtaining dependency information for pymysql>=0.7.6 from https://files.pythonhosted.org/packages/e5/30/20467e39523d0cfc2b6227902d3687a16364307260c75e6a1cb4422b0c62/PyMySQL-1.1.0-py3-none-any.whl.metadata Using cached PyMySQL-1.1.0-py3-none-any.whl.metadata (4.4 kB) Requirement already satisfied: contourpy>=1.0.1 in c:\users\milan\appdata\local\packages\pythonsoftwarefoundation.python.3.11_qbz5n2kfra8p0\localcache\local-packages\python311\site-packages (from matplotlib->finrl) (1.1.0) Requirement already satisfied: cycler>=0.10 in c:\users\milan\appdata\local\packages\pythonsoftwarefoundation.python.3.11_qbz5n2kfra8p0\localcache\local-packages\python311\site-packages (from matplotlib->finrl) (0.11.0) Requirement already satisfied: fonttools>=4.22.0 in c:\users\milan\appdata\local\packages\pythonsoftwarefoundation.python.3.11_qbz5n2kfra8p0\localcache\local-packages\python311\site-packages (from matplotlib->finrl) (4.42.1) Requirement already satisfied: kiwisolver>=1.0.1 in c:\users\milan\appdata\local\packages\pythonsoftwarefoundation.python.3.11_qbz5n2kfra8p0\localcache\local-packages\python311\site-packages (from matplotlib->finrl) (1.4.5) Requirement already satisfied: pillow>=6.2.0 in c:\users\milan\appdata\local\packages\pythonsoftwarefoundation.python.3.11_qbz5n2kfra8p0\localcache\local-packages\python311\site-packages (from matplotlib->finrl) (10.0.0) Requirement already satisfied: pyparsing<3.1,>=2.3.1 in c:\users\milan\appdata\local\packages\pythonsoftwarefoundation.python.3.11_qbz5n2kfra8p0\localcache\local-packages\python311\site-packages (from matplotlib->finrl) (3.0.9) Collecting cfgv>=2.0.0 (from pre-commit->finrl) Obtaining dependency information for cfgv>=2.0.0 from https://files.pythonhosted.org/packages/c5/55/51844dd50c4fc7a33b653bfaba4c2456f06955289ca770a5dbd5fd267374/cfgv-3.4.0-py2.py3-none-any.whl.metadata Using cached cfgv-3.4.0-py2.py3-none-any.whl.metadata (8.5 kB) Collecting identify>=1.0.0 (from pre-commit->finrl) Obtaining dependency information for identify>=1.0.0 from https://files.pythonhosted.org/packages/05/66/f65626f8e1fd835941851503f0dac65460b3f1332f7fffc85cbf548d5209/identify-2.5.27-py2.py3-none-any.whl.metadata Using cached identify-2.5.27-py2.py3-none-any.whl.metadata (4.4 kB) Collecting nodeenv>=0.11.1 (from pre-commit->finrl) Obtaining dependency information for nodeenv>=0.11.1 from https://files.pythonhosted.org/packages/1a/e6/6d2ead760a9ddb35e65740fd5a57e46aadd7b0c49861ab24f94812797a1c/nodeenv-1.8.0-py2.py3-none-any.whl.metadata Using cached nodeenv-1.8.0-py2.py3-none-any.whl.metadata (21 kB) Collecting virtualenv>=20.10.0 (from pre-commit->finrl) Obtaining dependency information for virtualenv>=20.10.0 from https://files.pythonhosted.org/packages/48/87/0ff871ebe003075d61e1abeab67c21d50edf44dbfdeabd107bef30a9e027/virtualenv-20.24.4-py3-none-any.whl.metadata Using cached virtualenv-20.24.4-py3-none-any.whl.metadata (4.5 kB) Requirement already satisfied: ipython>=3.2.3 in c:\users\milan\appdata\local\packages\pythonsoftwarefoundation.python.3.11_qbz5n2kfra8p0\localcache\local-packages\python311\site-packages (from pyfolio->finrl) (8.11.0) Requirement already satisfied: seaborn>=0.7.1 in c:\users\milan\appdata\local\packages\pythonsoftwarefoundation.python.3.11_qbz5n2kfra8p0\localcache\local-packages\python311\site-packages (from pyfolio->finrl) (0.12.2) Requirement already satisfied: empyrical>=0.5.0 in c:\users\milan\appdata\local\packages\pythonsoftwarefoundation.python.3.11_qbz5n2kfra8p0\localcache\local-packages\python311\site-packages (from pyfolio->finrl) (0.5.5) Requirement already satisfied: iniconfig in c:\users\milan\appdata\local\packages\pythonsoftwarefoundation.python.3.11_qbz5n2kfra8p0\localcache\local-packages\python311\site-packages (from pytest->finrl) (2.0.0) Requirement already satisfied: pluggy<2.0,>=0.12 in c:\users\milan\appdata\local\packages\pythonsoftwarefoundation.python.3.11_qbz5n2kfra8p0\localcache\local-packages\python311\site-packages (from pytest->finrl) (1.3.0) Requirement already satisfied: colorama in c:\users\milan\appdata\local\packages\pythonsoftwarefoundation.python.3.11_qbz5n2kfra8p0\localcache\local-packages\python311\site-packages (from pytest->finrl) (0.4.6) Collecting click>=7.0 (from ray[default]->finrl) Obtaining dependency information for click>=7.0 from https://files.pythonhosted.org/packages/00/2e/d53fa4befbf2cfa713304affc7ca780ce4fc1fd8710527771b58311a3229/click-8.1.7-py3-none-any.whl.metadata
Using cached click-8.1.7-py3-none-any.whl.metadata (3.0 kB) Requirement already satisfied: filelock in c:\users\milan\appdata\local\packages\pythonsoftwarefoundation.python.3.11_qbz5n2kfra8p0\localcache\local-packages\python311\site-packages (from ray[default]->finrl) (3.12.3) Requirement already satisfied: jsonschema in c:\users\milan\appdata\local\packages\pythonsoftwarefoundation.python.3.11_qbz5n2kfra8p0\localcache\local-packages\python311\site-packages (from ray[default]->finrl) (4.19.0) Requirement already satisfied: protobuf!=3.19.5,>=3.15.3 in c:\users\milan\appdata\local\packages\pythonsoftwarefoundation.python.3.11_qbz5n2kfra8p0\localcache\local-packages\python311\site-packages (from ray[default]->finrl) (4.23.4) Requirement already satisfied: grpcio>=1.42.0 in c:\users\milan\appdata\local\packages\pythonsoftwarefoundation.python.3.11_qbz5n2kfra8p0\localcache\local-packages\python311\site-packages (from ray[default]->finrl) (1.56.2) Collecting aiohttp-cors (from ray[default]->finrl) Using cached aiohttp_cors-0.7.0-py3-none-any.whl (27 kB) Collecting colorful (from ray[default]->finrl) Using cached colorful-0.5.5-py2.py3-none-any.whl (201 kB) Collecting py-spy>=0.2.0 (from ray[default]->finrl) Using cached py_spy-0.3.14-py2.py3-none-win_amd64.whl (1.4 MB) Collecting gpustat>=1.0.0 (from ray[default]->finrl) Using cached gpustat-1.1.1.tar.gz (98 kB) Installing build dependencies ... done Getting requirements to build wheel ... done Preparing metadata (pyproject.toml) ... done Collecting opencensus (from ray[default]->finrl) Using cached opencensus-0.11.2-py2.py3-none-any.whl (128 kB) Requirement already satisfied: pydantic<2 in c:\users\milan\appdata\local\packages\pythonsoftwarefoundation.python.3.11_qbz5n2kfra8p0\localcache\local-packages\python311\site-packages (from ray[default]->finrl) (1.10.12) Requirement already satisfied: prometheus-client>=0.7.1 in c:\users\milan\appdata\local\packages\pythonsoftwarefoundation.python.3.11_qbz5n2kfra8p0\localcache\local-packages\python311\site-packages (from ray[default]->finrl) (0.17.1) Collecting smart-open (from ray[default]->finrl) Using cached smart_open-6.3.0-py3-none-any.whl (56 kB) Collecting virtualenv>=20.10.0 (from pre-commit->finrl) Using cached virtualenv-20.21.0-py3-none-any.whl (8.7 MB) Collecting pyarrow<7.0.0,>=6.0.1 (from ray[default]->finrl) Using cached pyarrow-6.0.1.tar.gz (770 kB) Installing build dependencies ... error error: subprocess-exited-with-error

× pip subprocess to install build dependencies did not run successfully. │ exit code: 1 ╰─> [9 lines of output] Ignoring numpy: markers 'python_version < "3.8"' don't match your environment Ignoring numpy: markers 'python_version == "3.8"' don't match your environment Ignoring numpy: markers 'python_version == "3.9"' don't match your environment Collecting cython>=0.29 Obtaining dependency information for cython>=0.29 from https://files.pythonhosted.org/packages/ea/8f/216de5d7bede3e26a7131b427a8aadade032f03f9c8ee88792def02e2cf4/Cython-3.0.2-cp311-cp311-win_amd64.whl.metadata Using cached Cython-3.0.2-cp311-cp311-win_amd64.whl.metadata (3.2 kB) ERROR: Ignored the following versions that require a different python version: 1.21.2 Requires-Python >=3.7,<3.11; 1.21.3 Requires-Python >=3.7,<3.11; 1.21.4 Requires-Python >=3.7,<3.11; 1.21.5 Requires-Python >=3.7,<3.11; 1.21.6 Requires-Python >=3.7,<3.11 ERROR: Could not find a version that satisfies the requirement numpy==1.21.3 (from versions: 1.3.0, 1.4.1, 1.5.0, 1.5.1, 1.6.0, 1.6.1, 1.6.2, 1.7.0, 1.7.1, 1.7.2, 1.8.0, 1.8.1, 1.8.2, 1.9.0, 1.9.1, 1.9.2, 1.9.3, 1.10.0.post2, 1.10.1, 1.10.2, 1.10.4, 1.11.0, 1.11.1, 1.11.2, 1.11.3, 1.12.0, 1.12.1, 1.13.0, 1.13.1, 1.13.3, 1.14.0, 1.14.1, 1.14.2, 1.14.3, 1.14.4, 1.14.5, 1.14.6, 1.15.0, 1.15.1, 1.15.2, 1.15.3, 1.15.4, 1.16.0, 1.16.1, 1.16.2, 1.16.3, 1.16.4, 1.16.5, 1.16.6, 1.17.0, 1.17.1, 1.17.2, 1.17.3, 1.17.4, 1.17.5, 1.18.0, 1.18.1, 1.18.2, 1.18.3, 1.18.4, 1.18.5, 1.19.0, 1.19.1, 1.19.2, 1.19.3, 1.19.4, 1.19.5, 1.20.0, 1.20.1, 1.20.2, 1.20.3, 1.21.0, 1.21.1, 1.22.0, 1.22.1, 1.22.2, 1.22.3, 1.22.4, 1.23.0rc1, 1.23.0rc2, 1.23.0rc3, 1.23.0, 1.23.1, 1.23.2, 1.23.3, 1.23.4, 1.23.5, 1.24.0rc1, 1.24.0rc2, 1.24.0, 1.24.1, 1.24.2, 1.24.3, 1.24.4, 1.25.0rc1, 1.25.0, 1.25.1, 1.25.2, 1.26.0b1) ERROR: No matching distribution found for numpy==1.21.3 [end of output]

note: This error originates from a subprocess, and is likely not a problem with pip. error: subprocess-exited-with-error

× pip subprocess to install build dependencies did not run successfully. │ exit code: 1 ╰─> See above for output.

deepspacemine commented 10 months ago

Also here is the copy of the code..

import datetime import threading from neo_finrl.data_processors.processor_alpaca import AlpacaProcessor from elegantrl.run import * import alpaca_trade_api as tradeapi import time import pandas as pd import numpy as np import torch import sys import os import gym

class AlpacaPaperTrading():

def __init__(self,ticker_list, time_interval, drl_lib, agent, cwd, net_dim, 
             state_dim, action_dim, API_KEY, API_SECRET, 
             APCA_API_BASE_URL, tech_indicator_list, turbulence_thresh=30, 
             max_stock=1e2, latency = None):
    #load agent
    self.drl_lib = drl_lib
    if agent =='ppo':

        if drl_lib == 'elegantrl':
          from elegantrl.agent import AgentPPO
          args = Arguments(if_on_policy=True)
          args.agent = AgentPPO()
          args.agent.if_use_cri_target = True

          #load agent
          try:
              state_dim = state_dim
              action_dim = action_dim

              agent = args.agent
              net_dim = net_dim

              agent.init(net_dim, state_dim, action_dim)
              agent.save_or_load_agent(cwd=cwd, if_save=False)
              self.act = agent.act
              self.device = agent.device
          except:
              raise ValueError('Fail to load agent!')

        elif drl_lib == 'rllib':
            from ray.rllib.agents import ppo
            from ray.rllib.agents.ppo.ppo import PPOTrainer

            config = ppo.DEFAULT_CONFIG.copy()
            config['env'] = StockEnvEmpty
            config["log_level"] = "WARN"
            config['env_config'] = {'state_dim':state_dim,
                        'action_dim':action_dim,}
            trainer = PPOTrainer(env=StockEnvEmpty, config=config)
            trainer.restore(cwd)
            try:
                trainer.restore(cwd)
                self.agent = trainer
                print("Restoring from checkpoint path", cwd)
            except:
                raise ValueError('Fail to load agent!')

        elif drl_lib == 'stable_baselines3':
            from stable_baselines3 import PPO

            try:
                #load agent
                self.model = PPO.load(cwd)
                print("Successfully load model", cwd)
            except:
                raise ValueError('Fail to load agent!')

        else:
            raise ValueError('The DRL library input is NOT supported yet. Please check your input.')

    else:
        raise ValueError('Agent input is NOT supported yet.')

    #connect to Alpaca trading API
    try:
        self.alpaca = tradeapi.REST(API_KEY,API_SECRET,APCA_API_BASE_URL, 'v2')
    except:
        raise ValueError('Fail to connect Alpaca. Please check account info and internet connection.')

    #read trading time interval
    if time_interval == '1s':
        self.time_interval = 1
    elif time_interval == '5s':
        self.time_interval = 5
    elif time_interval == '1Min':
        self.time_interval = 60
    elif time_interval == '5Min':
        self.time_interval = 60 * 5
    elif time_interval == '15Min':
        self.time_interval = 60 * 15
    else:
        raise ValueError('Time interval input is NOT supported yet.')

    #read trading settings
    self.tech_indicator_list = tech_indicator_list
    self.turbulence_thresh = turbulence_thresh
    self.max_stock = max_stock 

    #initialize account
    self.stocks = np.asarray([0] * len(ticker_list)) #stocks holding
    self.stocks_cd = np.zeros_like(self.stocks) 
    self.cash = None #cash record 
    self.stocks_df = pd.DataFrame(self.stocks, columns=['stocks'], index = ticker_list)
    self.asset_list = []
    self.price = np.asarray([0] * len(ticker_list))
    self.stockUniverse = ticker_list
    self.turbulence_bool = 0
    self.equities = []

def test_latency(self, test_times = 10): 
    total_time = 0
    for i in range(0, test_times):
        time0 = time.time()
        self.get_state()
        time1 = time.time()
        temp_time = time1 - time0
        total_time += temp_time
    latency = total_time/test_times
    print('latency for data processing: ', latency)
    return latency

def run(self):
    orders = self.alpaca.list_orders(status="open")
    for order in orders:
      self.alpaca.cancel_order(order.id)

    # Wait for market to open.
    print("Waiting for market to open...")
    tAMO = threading.Thread(target=self.awaitMarketOpen)
    tAMO.start()
    tAMO.join()
    print("Market opened.")
    while True:

      # Figure out when the market will close so we can prepare to sell beforehand.
      clock = self.alpaca.get_clock()
      closingTime = clock.next_close.replace(tzinfo=datetime.timezone.utc).timestamp()
      currTime = clock.timestamp.replace(tzinfo=datetime.timezone.utc).timestamp()
      self.timeToClose = closingTime - currTime

      if(self.timeToClose < (60)):
        # Close all positions when 1 minutes til market close.
        print("Market closing soon. Stop trading.")
        break

        '''# Close all positions when 1 minutes til market close.
        print("Market closing soon.  Closing positions.")

        positions = self.alpaca.list_positions()
        for position in positions:
          if(position.side == 'long'):
            orderSide = 'sell'
          else:
            orderSide = 'buy'
          qty = abs(int(float(position.qty)))
          respSO = []
          tSubmitOrder = threading.Thread(target=self.submitOrder(qty, position.symbol, orderSide, respSO))
          tSubmitOrder.start()
          tSubmitOrder.join()

        # Run script again after market close for next trading day.
        print("Sleeping until market close (15 minutes).")
        time.sleep(60 * 15)'''

      else:
        trade = threading.Thread(target=self.trade)
        trade.start()
        trade.join()
        last_equity = float(self.alpaca.get_account().last_equity)
        cur_time = time.time()
        self.equities.append([cur_time,last_equity])
        time.sleep(self.time_interval)

def awaitMarketOpen(self):
    isOpen = self.alpaca.get_clock().is_open
    while(not isOpen):
      clock = self.alpaca.get_clock()
      openingTime = clock.next_open.replace(tzinfo=datetime.timezone.utc).timestamp()
      currTime = clock.timestamp.replace(tzinfo=datetime.timezone.utc).timestamp()
      timeToOpen = int((openingTime - currTime) / 60)
      print(str(timeToOpen) + " minutes til market open.")
      time.sleep(60)
      isOpen = self.alpaca.get_clock().is_open

def trade(self):
    state = self.get_state()

    if self.drl_lib == 'elegantrl':
        with torch.no_grad():
            s_tensor = torch.as_tensor((state,), device=self.device)
            a_tensor = self.act(s_tensor)  
            action = a_tensor.detach().cpu().numpy()[0]  

        action = (action * self.max_stock).astype(int)

    elif self.drl_lib == 'rllib':
        action = self.agent.compute_single_action(state)

    elif self.drl_lib == 'stable_baselines3':
        action = self.model.predict(state)[0]

    else:
        raise ValueError('The DRL library input is NOT supported yet. Please check your input.')

    self.stocks_cd += 1
    if self.turbulence_bool == 0:
        min_action = 10  # stock_cd
        for index in np.where(action < -min_action)[0]:  # sell_index:
            sell_num_shares = min(self.stocks[index], -action[index])
            qty =  abs(int(sell_num_shares))
            respSO = []
            tSubmitOrder = threading.Thread(target=self.submitOrder(qty, self.stockUniverse[index], 'sell', respSO))
            tSubmitOrder.start()
            tSubmitOrder.join()
            self.cash = float(self.alpaca.get_account().cash)
            self.stocks_cd[index] = 0

        for index in np.where(action > min_action)[0]:  # buy_index:
            if self.cash < 0:
                tmp_cash = 0
            else:
                tmp_cash = self.cash
            buy_num_shares = min(tmp_cash // self.price[index], abs(int(action[index])))
            qty = abs(int(buy_num_shares))
            respSO = []
            tSubmitOrder = threading.Thread(target=self.submitOrder(qty, self.stockUniverse[index], 'buy', respSO))
            tSubmitOrder.start()
            tSubmitOrder.join()
            self.cash = float(self.alpaca.get_account().cash)
            self.stocks_cd[index] = 0

    else:  # sell all when turbulence
        positions = self.alpaca.list_positions()
        for position in positions:
            if(position.side == 'long'):
                orderSide = 'sell'
            else:
                orderSide = 'buy'
            qty = abs(int(float(position.qty)))
            respSO = []
            tSubmitOrder = threading.Thread(target=self.submitOrder(qty, position.symbol, orderSide, respSO))
            tSubmitOrder.start()
            tSubmitOrder.join()

        self.stocks_cd[:] = 0

def get_state(self):
    alpaca = AlpacaProcessor(api=self.alpaca)
    price, tech, turbulence = alpaca.fetch_latest_data(ticker_list = self.stockUniverse, time_interval='1Min',
                                                 tech_indicator_list=self.tech_indicator_list)
    turbulence_bool = 1 if turbulence >= self.turbulence_thresh else 0

    turbulence = (self.sigmoid_sign(turbulence, self.turbulence_thresh) * 2 ** -5).astype(np.float32)

    tech = tech * 2 ** -7
    positions = self.alpaca.list_positions()
    stocks = [0] * len(self.stockUniverse)
    for position in positions:
        ind = self.stockUniverse.index(position.symbol)
        stocks[ind] = ( abs(int(float(position.qty))))

    stocks = np.asarray(stocks, dtype = float)
    cash = float(self.alpaca.get_account().cash)
    self.cash = cash
    self.stocks = stocks
    self.turbulence_bool = turbulence_bool 
    self.price = price

    amount = np.array(max(self.cash, 1e4) * (2 ** -12), dtype=np.float32)
    scale = np.array(2 ** -6, dtype=np.float32)
    state = np.hstack((amount,
                turbulence,
                self.turbulence_bool,
                price * scale,
                self.stocks * scale,
                self.stocks_cd,
                tech,
                )).astype(np.float32)
    print(len(self.stockUniverse))
    return state

def submitOrder(self, qty, stock, side, resp):
    if(qty > 0):
      try:
        self.alpaca.submit_order(stock, qty, side, "market", "day")
        print("Market order of | " + str(qty) + " " + stock + " " + side + " | completed.")
        resp.append(True)
      except:
        print("Order of | " + str(qty) + " " + stock + " " + side + " | did not go through.")
        resp.append(False)
    else:
      print("Quantity is 0, order of | " + str(qty) + " " + stock + " " + side + " | not completed.")
      resp.append(True)

@staticmethod
def sigmoid_sign(ary, thresh):
    def sigmoid(x):
        return 1 / (1 + np.exp(-x * np.e)) - 0.5

    return sigmoid(ary / thresh) * thresh

class StockEnvEmpty(gym.Env):

Empty Env used for loading rllib agent

def __init__(self,config):
  state_dim = config['state_dim']
  action_dim = config['action_dim']
  self.observation_space = gym.spaces.Box(low=-3000, high=3000, shape=(state_dim,), dtype=np.float32)
  self.action_space = gym.spaces.Box(low=-1, high=1, shape=(action_dim,), dtype=np.float32)

def reset(self):
    return 

def step(self, actions):
    return
deepspacemine commented 10 months ago

and maybe I'm not understanding this repo correctly i was trying to run one page of code, where this might be a more in-deep app, that i need to read more to understand

mmmarchetti commented 10 months ago

Instead of running: pip install finrl please try running: pip install git+https://github.com/AI4Finance-Foundation/FinRL.git Let me know if this solution works for you.

deepspacemine commented 10 months ago

ERROR: Package 'finrl' requires a different Python: 3.11.5 not in '<3.11,>=3.10', I might take a different path. i'm reading the FinRL details and found the training
https://finrl.readthedocs.io/en/latest/start/first_glance.html There still a new error on this page but might be better.