From 8cad43b5b360c903afe94876ae429ba599a00b56 Mon Sep 17 00:00:00 2001 From: Zhang Hong <242528979+shuxue6662-a11y@users.noreply.github.com> Date: Tue, 18 Aug 2026 19:22:06 +0800 Subject: [PATCH] fix(benchmark): use total-return DJIA baseline (DIA) for comparison --- README.md | 2 +- examples/FinRL_StockTrading_2026_3_Backtest.py | 7 ++++++- finrl/plot.py | 5 ++++- 3 files changed, 11 insertions(+), 3 deletions(-) mode change 100755 => 100644 README.md diff --git a/README.md b/README.md old mode 100755 new mode 100644 index ccdb6882b9..2fd74db019 --- a/README.md +++ b/README.md @@ -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 diff --git a/examples/FinRL_StockTrading_2026_3_Backtest.py b/examples/FinRL_StockTrading_2026_3_Backtest.py index f3e8b25c34..7a3e7bb0dc 100644 --- a/examples/FinRL_StockTrading_2026_3_Backtest.py +++ b/examples/FinRL_StockTrading_2026_3_Backtest.py @@ -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) diff --git a/finrl/plot.py b/finrl/plot.py index ab27173b2f..29a8102dbb 100644 --- a/finrl/plot.py +++ b/finrl/plot.py @@ -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) @@ -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()