Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<img align="center" width="30%" alt="image" src="https://github.com/AI4Finance-Foundation/FinGPT/assets/31713746/e0371951-1ce1-488e-aa25-0992dafcc139">
</div>

# FinRL: Financial Reinforcement Learning → FinRL-X
# FinRL: Financial Reinforcement Learning → FinRL-X

<div align="center">
<img align="center" src=figs/logo_transparent_background.png width="55%"/>
Expand All @@ -24,7 +24,7 @@

> [!IMPORTANT]
> **FinRL-X** is the next-generation evolution of FinRL, designed for AI-native, modular, and production-oriented quantitative trading.
>
>
> - **This repository (`FinRL`)** preserves the original end-to-end educational and research framework.
> - **For the latest architecture, live trading deployment, and production-focused development, please use [`FinRL-X / FinRL-Trading`](https://github.com/AI4Finance-Foundation/FinRL-Trading).**

Expand Down Expand Up @@ -87,7 +87,7 @@ Key contributors include:

- [**Hongyang (Bruce) Yang**](https://www.linkedin.com/in/brucehy/) – research and development on financial reinforcement learning frameworks, market environments, and quantitative trading applications
- [other contributors…]

## Overview

FinRL is the original open-source framework for financial reinforcement learning, organized around three core layers:
Expand Down
11 changes: 9 additions & 2 deletions examples/FinRL_StockTrading_2026_1_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,21 @@
Introduce how to use FinRL to fetch and process data that we need for ML/RL trading.
"""

from __future__ import annotations

import itertools

import pandas as pd
import yfinance as yf

from finrl import config_tickers
from finrl.config import INDICATORS, TRAIN_START_DATE, TRAIN_END_DATE, TRADE_START_DATE, TRADE_END_DATE
from finrl.meta.preprocessor.preprocessors import FeatureEngineer, data_split
from finrl.config import INDICATORS
from finrl.config import TRADE_END_DATE
from finrl.config import TRADE_START_DATE
from finrl.config import TRAIN_END_DATE
from finrl.config import TRAIN_START_DATE
from finrl.meta.preprocessor.preprocessors import data_split
from finrl.meta.preprocessor.preprocessors import FeatureEngineer
from finrl.meta.preprocessor.yahoodownloader import YahooDownloader

# %% Part 1. Fetch data - Single ticker
Expand Down
6 changes: 5 additions & 1 deletion examples/FinRL_StockTrading_2026_2_train.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,15 @@
Introduce how to use FinRL to make data into the gym form environment, and train DRL agents on it.
"""

from __future__ import annotations

import pandas as pd
from stable_baselines3.common.logger import configure

from finrl.agents.stablebaselines3.models import DRLAgent
from finrl.config import INDICATORS, TRAINED_MODEL_DIR, RESULTS_DIR
from finrl.config import INDICATORS
from finrl.config import RESULTS_DIR
from finrl.config import TRAINED_MODEL_DIR
from finrl.main import check_and_make_directories
from finrl.meta.env_stock_trading.env_stocktrading import StockTradingEnv

Expand Down
3 changes: 3 additions & 0 deletions examples/FinRL_StockTrading_2026_3_Backtest.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@
Mean Variance Optimization and DJIA index.
"""

from __future__ import annotations

import matplotlib

matplotlib.use("Agg")
import matplotlib.pyplot as plt
import numpy as np
Expand Down
2 changes: 1 addition & 1 deletion finrl/config_tickers.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@
"TRI",
"WBD",
"WMT",
"ZS"
"ZS",
]

# SP 500 constituents at 2019
Expand Down
13 changes: 12 additions & 1 deletion finrl/meta/env_stock_trading/env_stocktrading.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ class StockTradingEnv(gym.Env):
sell_cost_pct (float, array): Cost for selling shares, each index corresponds to each asset
turbulence_threshold (float): Maximum turbulence allowed in market for purchases to occur. If exceeded, positions are liquidated
print_verbosity(int): When iterating (step), how often to print stats about state of env
allow_short_selling (bool): If False, the agent cannot take short
positions. The action space is restricted to [0, 1] and negative
actions are clipped. Default is True for backward compatibility.
"""

metadata = {"render.modes": ["human"]}
Expand Down Expand Up @@ -55,6 +58,7 @@ def __init__(
model_name="",
mode="",
iteration="",
allow_short_selling: bool = True,
):
self.day = day
self.df = df
Expand All @@ -68,7 +72,10 @@ def __init__(
self.state_space = state_space
self.action_space = action_space
self.tech_indicator_list = tech_indicator_list
self.action_space = spaces.Box(low=-1, high=1, shape=(self.action_space,))
if self.allow_short_selling:
self.action_space = spaces.Box(low=-1, high=1, shape=(self.action_space,))
else:
self.action_space = spaces.Box(low=0, high=1, shape=(self.action_space,))
self.observation_space = spaces.Box(
low=-np.inf, high=np.inf, shape=(self.state_space,)
)
Expand All @@ -83,6 +90,7 @@ def __init__(
self.model_name = model_name
self.mode = mode
self.iteration = iteration
self.allow_short_selling = allow_short_selling
# initalize state
self.state = self._initiate_state()

Expand Down Expand Up @@ -315,6 +323,9 @@ def step(self, actions):
actions = actions.astype(
int
) # convert into integer because we can't by fraction of shares
# Prevent short selling: clip negative actions to 0
if not self.allow_short_selling:
actions = np.where(actions < 0, 0, actions)
if self.turbulence_threshold is not None:
if self.turbulence >= self.turbulence_threshold:
actions = np.array([-self.hmax] * self.stock_dim)
Expand Down