{"id":13460777,"url":"https://github.com/Ceruleanacg/Personae","last_synced_at":"2025-03-24T19:32:55.556Z","repository":{"id":45725742,"uuid":"124648869","full_name":"Ceruleanacg/Personae","owner":"Ceruleanacg","description":"📈 Personae is a repo of implements and environment of Deep Reinforcement Learning \u0026 Supervised Learning for Quantitative Trading.","archived":false,"fork":false,"pushed_at":"2018-11-29T17:06:12.000Z","size":32611,"stargazers_count":1334,"open_issues_count":9,"forks_count":336,"subscribers_count":123,"default_branch":"master","last_synced_at":"2024-08-24T14:36:13.811Z","etag":null,"topics":["paper","reinforcement-learning","stock","stock-data","stock-price-prediction","supervised-learning","time-series-prediction","trading"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Ceruleanacg.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":"2018-03-10T11:22:00.000Z","updated_at":"2024-08-24T10:06:54.000Z","dependencies_parsed_at":"2022-09-05T05:01:00.022Z","dependency_job_id":null,"html_url":"https://github.com/Ceruleanacg/Personae","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/Ceruleanacg%2FPersonae","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Ceruleanacg%2FPersonae/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Ceruleanacg%2FPersonae/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Ceruleanacg%2FPersonae/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Ceruleanacg","download_url":"https://codeload.github.com/Ceruleanacg/Personae/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":222004304,"owners_count":16914876,"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":["paper","reinforcement-learning","stock","stock-data","stock-price-prediction","supervised-learning","time-series-prediction","trading"],"created_at":"2024-07-31T10:00:48.633Z","updated_at":"2024-10-29T06:30:51.743Z","avatar_url":"https://github.com/Ceruleanacg.png","language":"Python","funding_links":[],"categories":["Strategies \u0026 Research","Environments","Python","时间序列"],"sub_categories":["Time Series Data","AI","网络服务_其他"],"readme":"[![License](https://img.shields.io/badge/License-MIT-blue.svg)](/LICENSE)\n[![Platform](https://img.shields.io/badge/Platform-Tensorflow-orange.svg)](https://www.tensorflow.org/)\n[![Python](https://img.shields.io/badge/Python-3.5-green.svg)]()\n[![Docker](https://img.shields.io/badge/Docker-Available-FF69B4.svg)](https://hub.docker.com/r/ceruleanwang/personae/)\n\n# Personae - RL \u0026 SL Methods and Envs For Quantitative Trading\n\nPersonae is a repo that implements papers proposed methods in Deep Reinforcement Learning \u0026 Supervised Learning and applies them to Financial Market.\n\nNow Personae includes 4 RL \u0026 3 SL implements and a simulate Financial Market supporting Stock and Future. (Short Sale is still implementing)\n\nMore RL \u0026 SL methods are updating!\n\n# WARNING\n\nThis repo is being reconstructing,\n\nIt will start from 2018-08-24 to ~2018-09-01~ a timestamp that I successfully found a job.\n\n\n\n# Attentions  \n\n- The features as inputs are naive.   \n- Day frequency is clearly not enough.  \n- It's recommended that you could replace the features here to your own.   \n\n# Contents\n\n+ [Deep Deterministic Policy Gradient (DDPG)](algorithm/RL/DDPG.py)   \nImplement of DDPG with TensorFlow.\n    \u003e arXiv:1509.02971: [Continuous control with deep reinforcement learning](https://arxiv.org/abs/1509.02971)\n\n+ [Double DQN](algorithm/RL/DoubleDQN.py)    \nImplement of Double-DQN with TensorFlow.   \n    \u003e arXiv:1509.06461: [Deep Reinforcement Learning with Double Q-learning](https://arxiv.org/abs/1509.06461)\n    \n+ [Dueling-DQN](algorithm/RL/DuelingDQN.py)     \nImplement of Dueling-DQN with TensorFlow.    \n    \u003e arXiv:1511.06581: [Dueling Network Architectures for Deep Reinforcement Learning](https://arxiv.org/abs/1511.06581)     \n\n+ [Policy Gradient](algorithm/RL/PolicyGradient.py)   \nImplement of Policy Gradient with TensorFlow.\n    \u003e NIPS. Vol. 99. 1999: [Policy gradient methods for reinforcement learning with function approximation](https://papers.nips.cc/paper/1713-policy-gradient-methods-for-reinforcement-learning-with-function-approximation.pdf)\n\n+ [DA-RNN (DualAttnRNN)](algorithm/SL/DualAttnRNN.py)      \nImplement of arXiv:1704.02971, DA-RNN with TensorFlow.\n    \u003e arXiv:1704.02971: [A Dual-Stage Attention-Based Recurrent Neural Network for Time Series Prediction](https://arxiv.org/abs/1704.02971)\n\n+ [TreNet (HNN)](algorithm/SL/TreNet.py)     \nImplement of TreNet with TensorFlow.    \n    \u003e IJCAI 2017. [Hybrid Neural Networks for Learning the Trend in Time Series](https://www.ijcai.org/proceedings/2017/0316.pdf)\n\n+ [Naive-LSTM (LSTM)](algorithm/SL/NaiveLSTM.py)    \nImplement of simple LSTM based model with TensorFlow.    \n    \u003e arXiv:1506.02078: [Visualizing and Understanding Recurrent Networks](https://arxiv.org/abs/1506.02078)     \n\n# Environment\n\nA basic simulate environment of Financial Market is implemented.\n\n- [Market](base/env/market.py)   \nImplement of Market, Trader, Positions as a gym env (gym is not required), which can give a env for regression or sequence data generating for RL or SL model.  \nFor now, Market support Stock Data and Future Data.\n\nAlso, more functions are updating.\n\n# Experiments\n\n+ [Deep Deterministic Policy Gradient (DDPG)](algorithm/SL/DualAttnRNN.py)\n+ [Double-DQN](algorithm/RL/DoubleDQN.py)    \n+ [Dueling-DQN](algorithm/RL/DuelingDQN.py)\n+ [Policy Gradient (PG)](algorithm/RL/PolicyGradient.py)     \nTrain a Agent to trade in stock market, using stock data set from 2012-01-01 to 2018-01-01 where 70% are training data, 30% are testing data.\n\n\u003cp align='center'\u003e\n  \u003cimg src='static/images/Profits.jpg'\u003e\n   \u003cem\u003eTotal Profits and Baseline Profits. (Test Set)\u003c/em\u003e\n\u003c/p\u003e\n\n+ [DA-RNN (DualAttnRNN)](algorithm/SL/DualAttnRNN.py)   \n+ [Naive-LSTM (LSTM)](algorithm/SL/NaiveLSTM.py)      \n+ [TreNet (HNN)](algorithm/SL/TreNet.py)     \nTrain a Predictor to predict stock prices, using stock data set from 2008-01-01 to 2018-01-01, where 70% are training data, 30% are testing data.\n\n\u003cp align='center'\u003e\n  \u003cimg src='static/images/Prices.jpg'\u003e\n   \u003cem\u003ePrices Prediction Experiments on 4 Bank Stocks. (Test Set)\u003c/em\u003e\n\u003c/p\u003e\n\n\n# Requirements\n\nBefore you start testing, following requirements are needed.\n\n- Python3.5\n- TensorFlow1.4\n- numpy\n- scipy\n- pandas\n- rqalpha\n- sklearn\n- tushare\n- matplotlib\n- mongoengine\n- CUDA (option)\n- ta-lib (option)\n- Docker (option)\n- PyTorch (option)\n\nIt's best that if you are a Docker user, so that you can run the whole project without installing those dependencies manually.\n \nAnd you can also use [Ansible](http://www.ansible.com.cn/) to run [CUDA-Playbook](playbook/cuda-playbook.yml) and [Docker-Playbook](playbook/docker-playbook.yml) to install CUDA and [Nvidia-Docker](https://github.com/NVIDIA/nvidia-docker) if you want to run tests in a Docker Container.\n\n# How to Use\n\n### If you use Docker\n\n#### About base image\nMy image for this repo is [ceruleanwang/personae](https://hub.docker.com/r/ceruleanwang/personae/), and personae is inherited from [ceruleanwang/quant-base](https://hub.docker.com/r/ceruleanwang/quant-base/).    \n   \nThe image [ceruleanwang/quant-base](https://hub.docker.com/r/ceruleanwang/quant-base/) is inherited from [nvidia/cuda:8.0-cudnn6-runtime](https://hub.docker.com/r/nvidia/cuda/). So please make sure your CUDA version and cuDNN version are correct. \n\n#### Instructions\nFirst you should make sure you have stocks data in your mongodb.   \n\nIf you don't have, you can use a spider writen in this repo to crawl stock or future data, but before you start, you should make sure a mongodb service is running.  \n\nIf you don't have mongodb service running, you can also use a mongodb container (option) by following code:\n```\ndocker run -p 27017:27017 -v /data/db:/data/db -d --network=your_network mongo\n``` \nThen, you can use spiders to crawl stock data by following code:   \n```\ndocker run -t -v local_project_dir:docker_project_dir --network=your_network ceruleanwang/personae spider/stock_spider.py\n```\nAlso, you can crawl future data by following code:\n```\ndocker run -t -v local_project_dir:docker_project_dir --network=your_network ceruleanwang/personae spider/future_spider.py\n```\nBut remember to set stock or future codes that you want to crawl, the default stock codes are:\n```\nstock_codes = [\"600036\", \"601328\", \"601998\", \"601398\"]\n```\nAnd the default future codes are:\n```\nfuture_codes = [\"AU88\", \"RB88\", \"CU88\", \"AL88\"]\n```\nAnd they can be modified in:   \n+ [Default Args Parser](helper/args_parser.py)\n\nThen you can just run a model by:\n```\ndocker run -t -v local_project_dir:docker_project_dir --network=yuor_network ceruleanwang/personae algorithm/RL or SL/algorithm_name.py\n```\n\n### If you use Conda\nYou can create an env yourself, and install Python3.5 and all dependencies required, then just run algorithm in your way.   \n\nOne thing should be noticed is that the hostname in [mongoengine](/base/model/__init__.py) config should be your own.\n\n### About training \u0026 testing \nFor now, all models implemented with TensorFlow support persistence. You can edit many parameters when you are training or testing a model.   \nFor example, following codes show some parameters that could be edited.\n```\nenv = Market(codes, start_date=\"2008-01-01\", end_date=\"2018-01-01\", **{\n    \"market\": market,\n    \"mix_index_state\": True,\n    \"training_data_ratio\": training_data_ratio,\n})\n\nalgorithm = Algorithm(tf.Session(config=config), env, env.trader.action_space, env.data_dim, **{\n    \"mode\": mode,\n    \"episodes\": episode,\n    \"enable_saver\": True,\n    \"enable_summary_writer\": True,\n    \"save_path\": os.path.join(CHECKPOINTS_DIR, \"RL\", model_name, market, \"model\"),\n    \"summary_path\": os.path.join(CHECKPOINTS_DIR, \"RL\", model_name, market, \"summary\"),\n})\n```\n# TODO\n- More Implementations of Papers.\n- More High-Frequency Stocks Data.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FCeruleanacg%2FPersonae","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FCeruleanacg%2FPersonae","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FCeruleanacg%2FPersonae/lists"}