This project is in progress. It aims at developing an agent that will be able to autonomously trade multiple stocks, using available data on yahoo-finance.
Warning: for now, the first tested approach (DQN) is not giving satisfactory results. Further investigation and other techniques must be pursued.
-
The environment for the trading agent (
TradingEnv
), using gym's framework. It specifies:- the observations' space;
- the actions' space;
- what is done at a step from an action.
-
An implementation of the Deep Q-Learning algorithm, that allows to easily test different deep neural networks (for the Q-value function predictor).
For
With
The first column of
For now, the reward has been defined as the rate of return (RoR):
The NN model used for DQN can be defined in q_networks.py
and then
imported to be used for the RL algo.
In the following example, a default non-optimal network
has been defined as qnet1
.
from src.trading_env import DiscreteActionsTradingEnv
from src.dqn import DeepQLearning
from src.q_networks import qnet1
from src.stock_loader import get_data_stocks
stock_names = ["TSLA", "AAPL", "GOOGL"]
start_date, end_date = "2020-01-01", "2022-01-01"
data = get_data_stocks(stock_names, start_date, end_date)
observations = ["volume", "dividends", "low", "high"]
env = DiscreteActionsTradingEnv(
initial_balance=1000,
stocks_series=data,
observations=observations,
n_discretize=3,
)
model = DeepQLearning(q_network=qnet1, env=env, n_episodes=100, max_steps_episode=80)
trained_dqn = model.train()