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
2 changes: 1 addition & 1 deletion README.md
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ This script trains 5 DRL agents (A2C, DDPG, PPO, TD3, SAC) using Stable Baseline
python examples/FinRL_StockTrading_2026_3_Backtest.py
```

This script loads the trained agents, runs them on the trading data, and compares their performance against two baselines: Mean Variance Optimization (MVO) and the DJIA index. Results are printed to the console and a plot is saved as `backtest_result.png`.
This script loads the trained agents, runs them on the trading data, and compares their performance against two baselines: Mean Variance Optimization (MVO) and the DJIA index (total return, via the DIA ETF). Results are printed to the console and a plot is saved as `backtest_result.png`.


## File Structure
Expand Down
7 changes: 6 additions & 1 deletion examples/FinRL_StockTrading_2026_3_Backtest.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,12 @@ def StockReturnsComputing(StockPrice, Rows, Columns):

import yfinance as yf

df_dji = yf.download("^DJI", start=TRADE_START_DATE, end=TRADE_END_DATE)
# DIA is the DJIA-tracking ETF; adjusted prices include dividends, so the
# baseline uses the same total-return convention as the agent's account
# value. ^DJI is a price-return index and would understate the baseline.
df_dji = yf.download(
"DIA", start=TRADE_START_DATE, end=TRADE_END_DATE, auto_adjust=True
)
df_dji = df_dji[["Close"]].reset_index()
df_dji.columns = ["date", "close"]
df_dji["date"] = df_dji["date"].astype(str)
Expand Down
5 changes: 4 additions & 1 deletion finrl/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def backtest_plot(
account_value,
baseline_start=config.TRADE_START_DATE,
baseline_end=config.TRADE_END_DATE,
baseline_ticker="^DJI",
baseline_ticker="DIA",
value_col_name="account_value",
):
df = deepcopy(account_value)
Expand All @@ -74,6 +74,9 @@ def backtest_plot(


def get_baseline(ticker, start, end):
# DIA (a DJIA-tracking ETF) is the default baseline because the
# downloader adjusts close prices for dividends, matching the
# total-return basis of the agent's account value.
return YahooDownloader(
start_date=start, end_date=end, ticker_list=[ticker]
).fetch_data()
Expand Down