How to Use Personae for Quantitative Trading

May 21, 2024 | Data Science

Welcome aboard the exciting journey into the realms of quantitative trading! In this article, we will explore the Personae repository, which combines the powers of Deep Reinforcement Learning (RL) and Supervised Learning (SL) in financial markets. Buckle up as we navigate through installational setups, market simulations, and algorithmic trading strategies.

Getting Started with Personae

To kick things off, you will need a few prerequisites in your tech stack:

  • Python 3.5
  • TensorFlow 1.4
  • Numpy
  • Scipy
  • Pandas
  • rqalpha
  • Scikit-learn
  • Tushare
  • Matplotlib
  • MongoEngine
  • CUDA (optional)
  • TA-Lib (optional)
  • Docker (optionally recommended)
  • PyTorch (optional)

Setting Up with Docker

If you prefer the elegance and convenience of Docker, follow these steps:

Step 1: Base Image

Fetch the required image for this repository:

Step 2: Ensure MongoDB is Running

It is essential to have stocks data in MongoDB. If you don’t have any, start a MongoDB service using a Docker container with this command:

docker run -p 27017:27017 -v datadb:datadb -d --network=your_network mongo

Step 3: Crawling Stock Data

To gather stock or future data, utilize the spiders provided within the repository. Execute:

docker run -t -v local_project_dir:docker_project_dir --network=your_network ceruleanwangpersonae spiderstock_spider.py

For future data, run:

docker run -t -v local_project_dir:docker_project_dir --network=your_network ceruleanwangpersonae spiderfuture_spider.py

Step 4: Setting Stock Codes

Remember to adjust stock or future codes in the Default Args Parser, with default values being:

  • Stock: 600036, 601328, 601998, 601398
  • Future: AU88, RB88, CU88, AL88

Step 5: Running an Algorithm

To run a model, use the following command:

docker run -t -v local_project_dir:docker_project_dir --network=your_network ceruleanwangpersonae algorithmRL or SLalgorithm_name.py

Using Conda

If Docker isn’t your cup of tea, you may also use Conda. Create an environment, install Python 3.5 along with necessary dependencies, and run the algorithm.

Remember to set the hostname in the mongoengine configuration to your own.

Training and Testing Your Models

All models in Personae are built with support for persistence. You can edit numerous parameters during training or testing, illustrated below:

env = Market(codes, start_date=2008-01-01, end_date=2018-01-01, market: market, mix_index_state: True, training_data_ratio: training_data_ratio,)

Understanding the Code: An Analogy

Imagine you are a chef preparing a gourmet dish. Each component – spices, vegetables, and proteins – is crucial, just as each model and method essential for creating a successful trading strategy in Personae. The Market class is like your cutting board where you prepare your ingredients. The Algorithm serves as your cooking instructions, guiding how to combine these elements harmoniously. Just like how different recipes require different cooking techniques, each financial model (like DDPG, Double DQN, etc.) has its own set of parameters, akin to various ingredients varying in quantity depending on the dish’s complexity.

Troubleshooting and Tips

  • If you run into issues with Docker, ensure your Docker daemon is up and running. Also, verify your networking setup to ensure connections are properly established.
  • For MongoDB issues, confirm that the service is operational by checking your MongoDB logs.
  • If stock data retrieval fails, check in the args_parser file to ensure the codes are accurately input.

If you require further assistance, for more insights, updates, or to collaborate on AI development projects, stay connected with fxis.ai.

Final Thoughts

At fxis.ai, we believe that such advancements are crucial for the future of AI, as they enable more comprehensive and effective solutions. Our team is continually exploring new methodologies to push the envelope in artificial intelligence, ensuring that our clients benefit from the latest technological innovations.

Stay Informed with the Newest F(x) Insights and Blogs

Tech News and Blog Highlights, Straight to Your Inbox