From d29b9463f6d0fa4efc15bbee5d79e8e9dd67fabc Mon Sep 17 00:00:00 2001 From: wjb75 <178544132+wjb75@users.noreply.github.com> Date: Sat, 16 Aug 2025 11:04:13 +0800 Subject: [PATCH] Remove np.log preprocessing from individual return series MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This commit strips out the np.log transformation on rets_1, rets_2, and rets_3, switching them to raw arithmetic returns via `.pct_change().dropna()` in line with conventional portfolio return, volatility, and Sharpe ratio calculations. No downstream functions were altered—they will now consume raw returns directly. Note: log‐returns are still valuable for their multiplicative additivity. In future updates, np.log should only be applied once to the AGGREGATED portfolio return (i.e. after the dot‐product of weights and raw returns) to avoid nonlinear distortions at the per‐asset level. Solves #393 --- doc/workshops/financial-analysis.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/doc/workshops/financial-analysis.py b/doc/workshops/financial-analysis.py index a4795d650..61ae31900 100755 --- a/doc/workshops/financial-analysis.py +++ b/doc/workshops/financial-analysis.py @@ -87,7 +87,7 @@ # %% Returns per day -rets_1 = np.log(close_data_1/close_data_1.shift(1)).dropna() +rets_1 = (close_data_1/close_data_1.shift(1)).dropna() weights_1 = [0.2, 0.2, 0.2, 0.2, 0.2] @@ -224,7 +224,7 @@ def exp_real_rets(returns, opt_weights, symbols, start_year, end_year): # %% Plot daily timeline -rets_2 = np.log(close_data_2[SYMBOLS_2] / +rets_2 = (close_data_2[SYMBOLS_2] / close_data_2[SYMBOLS_2].shift(1)).dropna() (close_data_2[SYMBOLS_2] / @@ -342,7 +342,7 @@ def exp_real_rets(returns, opt_weights, symbols, start_year, end_year): # %% Returns per day -rets_3 = np.log(crypto_hist[SYMBOLS_3] / +rets_3 = (crypto_hist[SYMBOLS_3] / crypto_hist[SYMBOLS_3].shift(1)).dropna()