{"id":21023363,"url":"https://github.com/iusztinpaul/yacht","last_synced_at":"2025-08-11T20:31:26.732Z","repository":{"id":44603554,"uuid":"340674558","full_name":"iusztinpaul/yacht","owner":"iusztinpaul","description":"Order execution in the financial markets using Deep Reinforcement Learning.","archived":false,"fork":false,"pushed_at":"2022-12-10T08:58:34.000Z","size":75583,"stargazers_count":14,"open_issues_count":0,"forks_count":7,"subscribers_count":4,"default_branch":"main","last_synced_at":"2024-12-02T07:47:27.853Z","etag":null,"topics":["cryptocurrency","deep-learning","deep-reinforcement-learning","order-execution","pandas","pytorch","reinforcement-learning","stocks","trading","trading-bot","weights-and-biases"],"latest_commit_sha":null,"homepage":"","language":"Jupyter Notebook","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/iusztinpaul.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-02-20T14:31:38.000Z","updated_at":"2024-09-16T20:14:16.000Z","dependencies_parsed_at":"2023-01-26T05:01:56.167Z","dependency_job_id":null,"html_url":"https://github.com/iusztinpaul/yacht","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iusztinpaul%2Fyacht","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iusztinpaul%2Fyacht/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iusztinpaul%2Fyacht/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iusztinpaul%2Fyacht/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/iusztinpaul","download_url":"https://codeload.github.com/iusztinpaul/yacht/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":229589403,"owners_count":18097011,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cryptocurrency","deep-learning","deep-reinforcement-learning","order-execution","pandas","pytorch","reinforcement-learning","stocks","trading","trading-bot","weights-and-biases"],"created_at":"2024-11-19T11:17:47.317Z","updated_at":"2024-12-13T18:50:22.250Z","avatar_url":"https://github.com/iusztinpaul.png","language":"Jupyter Notebook","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cdiv align=\"center\"\u003e\n  \u003ca href=\"https://www.linkedin.com/in/pauliusztin\"\u003e\n      \u003cpicture\u003e\n        \u003csource media=\"(prefers-color-scheme: dark)\" srcset=\"./images/yacht_full_logo_white.png\"\u003e\n        \u003csource media=\"(prefers-color-scheme: light)\" srcset=\"./images/yacht_full_logo_black.png\"\u003e\n        \u003cimg alt=\"Shows a black logo in light color mode and a white one in dark color mode.\" src=\"./images/yacht_full_logo_white.png\"\u003e\n      \u003c/picture\u003e\n  \u003c/a\u003e\n\u003c/div\u003e\n\n# Yacht: Yet Another Comprehensive Trading Framework Using Deep Reinforcement Learning\nA Deep Reinforcement Learning framework for **trading** \u0026 **order execution** in financial markets. The goal of the project\nis to speed up the development \u0026 research of financial agents by building a modular and scalable codebase. The framework supports the following main features:\n* Loading \u0026 preprocessing data directly from different APIs\n* Training \u0026 evaluating deep reinforcement learning agents\n* Use specific financial metrics or quickly implement your own\n* Visualizing the performance of the agent with some intuitive graphs\n\nThe nice part is that everything is `configurable` within a config file.\n\u003cbr\u003e The code is using popular packages like:\n* pytorch\n* pandas\n* stable-baselines3\n* gym\n* wandb\n* mplfinance\n\n# Project Architecture\n![Project Architecture](images/project_architecture.png)\n\u003cbr\u003e\u003cbr\u003eThe architecture is split into 4 main categories:\n* Data\n* Environment\n* Reinforcement Learning Agents\n* Specific Task Layer\n\nThe `Specific Task Layer` is a glue code module that is used for training \u0026 backtesting.\nIt can be further be extended into the `applicaton layer`.\n\n# Visual Representations\nVisual representations of the actions taken by the agent \u0026 the current status of the agent:\n![graph1](images/graph_twap.png)\n![graph2](images/graph1_opds.png)\n![graph3](images/graph2_opds.png)\n\n----\n\n# Install\n### Requirements\n* Code tested under `Python 3.8`, `pytorch 1.13.0`, and `cuda 11.6` on `Ubuntu 20.04`\n\n1. Create a conda environment and activate it:\n```shell\nconda create --name yacht python=3.8\nconda env activate yacht\n```\n\n2. Install torch and cuda separately with `conda`:\n```shell\nconda install pytorch=1.13.0 torchvision torchaudio pytorch-cuda=11.6 -c pytorch -c nvidia\n```\n\n3. Ultimately, install other requirements with `pip`:\n```shell\npip install -r requirements.txt\n```\n\n### Config Compiler\n* The configuration system is built with `google protobuf`. If you want to recompile / change the protobuf files,\nyou should install the `protoc` compiler on your system:\n```shell\nsudo apt  install protobuf-compiler libprotobuf-dev\n```\n* Run the `compilation` command from the root folder:  \n```shell\n  protoc -I=. --python_out=. yacht/config/proto/*.proto\n  ```\n\n### Add Secret Keys\n* Create a file called `.env` at the root directory level. If you want to fully use the market APIs and\nexperiment trackers you should add the secret keys.\n* Look at `.env.default` for the supported env vars.\n* Not all `env vars` are mandatory. For example the free version of `Yahoo Finance` does not require any credentials.\n\n----------\n\n# Data APIs\n* Currently, we have support for:\n  * `Binance`\n  * `Yahoo Finance`.\n* You should set the `api keys` in the `.env` file for full support.\n\n# Datasets \u0026 Download Data\n* S\u0026P 500\n* Dow 30\n* Nasdaq 100\n* Russell 2000\n\nYou can set `tickers: ['NASDAQ100']` in the configuration file and all the tickers from the index will be expanded.\nYou can also set something like `['NASDAQ100', 'S\u0026P500', 'AAPL']` or any combination you like.\n#### Download\nThe data is stored in `h5` files.\n```shell\npython main.py download --config-file-name download_4years.config.txt --storage-dir ./storage/download_4_years --market-storage-dir ./storage\n```\n* The `--market-storage-dir` CLI argument is optional. If you add it the market will be placed\nin a different location than your `storage-dir`. This is helpful because it can be accessed by multiple\nexperiments in parallel `during training` (the `h5` file will be set in a read only mode). Otherwise, while training,\nonly one experiment can access a specific file. \n* `--market-storage-dir` should be used also during `training` \u0026 `backtesting`\n* You can use the `market_mixins: [...]` from the config file to preprocess the data before it is stored.\n\n-------\n\n# Usage\nAll the supported configs can be found at `./yacht/config/configs`. \nYou should only add the config path relative to the root directory.\n\n### Train\n```shell\npython main.py train --config-file order_execution/all/single_asset_all_universal_silent.config.txt --storage-dir ./storage/yacht --market-storage-dir ./storage\n```\n\n### Backtest\n```shell\npython main.py backtest --config-file order_execution/all/single_asset_all_universal_silent.config.txt --storage-dir ./storage/yacht --market-storage-dir ./storage\n```\n\n### Download Pretrained Weights 👇🏻\nYou can download the pretrained weights from [here](https://drive.google.com/drive/folders/1ldDB_zcE-9nNvsIsDbn5W1-5-UA_8C-k?usp=sharing).\n\n```shell\ncd /root/directory\nmkdir storage\n--\u003e place the downloaded weights in ./storage \n```\n\nSuppose you downloaded and placed the pretrained weights and data correctly as showed above. In that case, you can run the following command to resume the agent:\n```shell\npython main.py train --config-file order_execution/all/single_asset_all_universal_silent.config.txt --storage-dir ./storage/yacht --resume-from best-train --market-storage-dir ./storage\n```\nFor the parameter `--resume-from` we support the following combinations:\n* Absolute path to the checkpoint.\n* `latest-train` = resume the agent from the latest checkpoint saved during training\n* `best-train` = resume the agent from the best checkpoint saved during training\n\n**NOTE:** For the `best-train` parameter, you can choose a metric on which the agent was monitored. You\ncan do that with the `meta.metrics_to_load_best_on` parameter from the configuration file. For example, `metrics_to_load_best_on: ['PA', 'GLR']`\nwill load two agents: The agent monitored on the metric `PA` \u0026 the one who performed the best on `GLR`.\n\n# Tutorials\n* [Get started](https://medium.com/mlearning-ai/how-to-automate-your-orders-as-a-buy-and-hold-investor-84f6885015aa)\n\n------\n\n# Experiment Tracking\n### Weights \u0026 Biases\n* For now, we support `wandb` for experiment tracking and logging.\n* Just add the api key in the `.env` file. Also, in the configuration file you should add:\n```shell\nmeta: {\n  experiment_tracker: 'wandb'\n}\n```\nIf you want to add a specific `project_entity` add:\n```shell\nmeta: {\n  project_entity: 'your_project_entity'\n} \n```\n**NOTE:** Be aware that this name is unique between all the users that use wandb. For\nexample, I use `project_entity=yacht`. If you try to use it  will through an unauthorized error\nbecause you do not have access to my entity.\n\u003cbr/\u003eHere is an example of how it looks:\n![Wandb Example](images/wandb.png)\n* If you don't want to log a specific experiment on the experiment tracker just remove the config\nfield or replace it with the empty string `''`.\n\n# Hyperparameter Optimization\n### Weights \u0026 Biases\n* We support yyperparameter optimization with weights \u0026 biases sweeps.\n* Weights \u0026 biases should work as a simple experiment tracker before using this.\n* You can use any other config from `tools/tuning/configs` or generate your own.\n```shell\nwandb sweep tools/tuning/configs/single_asset_order_execution_crypto.yaml\nwandb agent id-given-by-generated-sweep\n```\n\n--------\n\n# More Resources\nFor further reading go to:\n* [Available Components](docs/components.md)\n* [Config Explanation](docs/config.md)\n* [Trading](docs/trading.md)\n* [Order Execution](docs/order_execution.md)\n* [Metrics](docs/metrics.md)\n* [Teacher-Student](docs/teacher.md)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fiusztinpaul%2Fyacht","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fiusztinpaul%2Fyacht","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fiusztinpaul%2Fyacht/lists"}