Minimizing the Mean Square Error on Future Experience with BTGym

Jun 3, 2023 | Data Science

Welcome to the world of reinforcement learning applied to algorithmic trading! In this guide, we’ll explore how to minimize mean square error in future experiences using the BTGym framework. This event-driven backtesting library integrates seamlessly with OpenAI Gym and is tailored for anyone interested in exploring the depths of algorithmic trading through reinforcement learning.

Table of Contents

Installation

To get started, it is highly recommended to run BTGym in a designated virtual environment. Here’s how you can set it up:

git clone https://github.com/Kismuz/btgym.git
cd btgym
pip install -e .

To update to the latest version, run:

cd btgym
git pull
pip install --upgrade -e .

Quickstart

To create a gym environment with all parameters set to defaults, simply execute:

from btgym import BTgymEnv
MyEnvironment = BTgymEnv(filename='..examples/data/DAT_ASCII_EURUSD_M1_2016.csv')

Adding more control options is just as easy:

from gym import spaces
from btgym import BTgymEnv
MyEnvironment = BTgymEnv(
    filename='..examples/data/DAT_ASCII_EURUSD_M1_2016.csv',
    episode_duration='days: 2, hours: 23, minutes: 55',
    drawdown_call=50,
    state_shape=dict(raw=spaces.Box(low=0, high=1, shape=(30, 4))),
    port=5555,
    verbose=1,
)

Isn’t it as simple as ordering a pizza? Just like how you specify toppings and sizes for your craving, you are now customizing your trading environment!

Description

BTGym provides a flexible and integrated framework for running experiments in realistic algorithmic trading environments, specifically designed for reinforcement learning. But remember, while BTGym offers an exciting testing ground, it’s essential to note that it’s still a research-grade project.

Problem Setting

BTGym operates based on two setups: discrete and continuous actions. This flexibility is akin to having a choice between manual and automatic driving in a vehicle. You can control each pedal (discrete actions) or simply steer (continuous actions).

Discrete Actions Setup:

  • Utilizes a riskless asset as broker account cash.
  • Traded assets can include historical price records and additional exogenous data.

Continuous Actions Setup:

  • Considers real numbers for actions taken.
  • Allows for more fluid and gradual adjustments to portfolio allocations.

Data Selection Options for Backtest Agent Training:

BTGym supports different data sampling techniques:

  • Random Sampling: Training data divided into subsets that allow maximum data efficiency.
  • Sequential Sampling: Mimics real-time trading but can be less efficient.
  • Sliding Time-Window Sampling: A mixed approach that reduces overfitting risk.

Documentation and Community

For further reading and assistance, check out the following documentation:

Known Bugs and Limitations:

  • Requires Matplotlib version 2.0.2; ensure your version matches.
  • May produce backend warnings related to PyPlot; importing order matters.
  • Not fully tested under Windows OS.

Roadmap

There is a list of input features aimed for future development of BTGym. Keeping an eye on these updates can guide you in leveraging the platform to its full potential.

News and Updates

Stay informed regarding the latest improvements and changes by checking the updates outlined on the official GitHub page.

Troubleshooting

If you run into issues while using BTGym, consider the following:

  • Make sure you have the necessary versions of dependencies installed.
  • Check compatibility with the operating system you’re running on; certain setups may be unstable.
  • If encountering specific errors, look up the detailed logs, as they might provide clues.

For more insights, updates, or to collaborate on AI development projects, stay connected with fxis.ai.

At fxis.ai, we believe that such advancements are crucial for the future of AI, enabling 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