Projects
Blackbox Trade

Blackbox Trade

This project demonstrates the concept of blackbox trading, which involves using machine learning models for automated trading strategies.

The repository for this project is currently unavailable as the project is still in development. Video link (opens in a new tab)

Blackbox thumbnail

Environment

The environment for AI learning is implemented using a Python class. This class aims to simulate an environment similar to futures commodity trading. For each incoming price feed, three actions are available:

  1. Buy: Increases the inventory by 1 and closes all short positions, if any.
  2. Sell: Decreases the inventory by 1 and closes all long positions, if any.
  3. Wait: No action taken.

Parameters

Each position uses margin trading, and leverage is adjustable in the configuration.

The environment settings are as follows:

ParameterValue
Initial Balance1000 USD
Leverage3x
Long onlyFalse
Max drawdown50%
Funding Fee (per 8h)0.01%
Commission (per trade)0.03%
Slippage0%

Price Data

Two types of data are used to train the model:

  1. Real market data (OHLC)
  2. Random walk data

Random data is necessary to prevent overfitting to market data. Random walk data is generated using a script for each training episode. Here's a sample:

Blackbox Montecarlo

Observation Variables and Outputs

The model input consists of four indicators:

  1. Short-term delta EMA
  2. Long-term delta EMA
  3. RSI
  4. Inventory

The output activation function is sigmoid, resulting in a value between 0 and 1:

  • If the value is below 0.2, it opens short positions.
  • If the value is above 0.8, it opens long positions.
  • Otherwise, it waits.

Episode

For each episode, the environment receives new OHLC data, which is used to update the environment state and observation variables. The observations are then passed through the neural network to produce an output value.

Training

The model is trained continuously to achieve the highest possible fitness level. After multiple runs, the following results were obtained: Training Result

It appears that after 50 generations, the model begins to understand the environment but is unable to produce high-quality trades. The results remain divergent due to factors that require further investigation.

Testing

Once training is complete, the best-performing model is selected for additional testing across multiple scenarios. It was found that after 1000 steps, all episodes concluded.

Winner result

Conclusion

This project successfully produced a model that understands the core concepts of trading. However, the quality of the model is not yet suitable for production use. Further research into fitness settings and observation variables is necessary to improve performance.