From 7bfcea42967b698aa8f120669cee7acbf5d34e33 Mon Sep 17 00:00:00 2001 From: devwolff <62347426+devwolff@users.noreply.github.com> Date: Thu, 20 Jan 2022 19:49:25 +1000 Subject: [PATCH] make whatif works for decrease as well (#1220) Co-authored-by: theorish --- .../stocks/backtesting/bt_view.py | 21 ++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/gamestonk_terminal/stocks/backtesting/bt_view.py b/gamestonk_terminal/stocks/backtesting/bt_view.py index 558ac03d6f9..2623da3f464 100644 --- a/gamestonk_terminal/stocks/backtesting/bt_view.py +++ b/gamestonk_terminal/stocks/backtesting/bt_view.py @@ -83,11 +83,22 @@ def display_whatif_scenario( current_shares_value = ( data[data.index > date_shares_acquired].values[-1] * num_shares_acquired ) - increase_pct = 100 * current_shares_value / initial_shares_value - console.print( - f"{these} would be worth {current_shares_value:.2f}. Which represents an increase of {increase_pct:.2f}%.", - "\n", - ) + if current_shares_value > initial_shares_value: + pct = 100 * ( + (current_shares_value - initial_shares_value) / initial_shares_value + ) + console.print( + f"{these} would be worth {current_shares_value:.2f}. Which represents an increase of {pct:.2f}%.", + "\n", + ) + else: + pct = 100 * ( + (initial_shares_value - current_shares_value) / initial_shares_value + ) + console.print( + f"{these} would be worth {current_shares_value:.2f}. Which represents an decrease of {pct:.2f}%.", + "\n", + ) def display_simple_ema(