remove -p from perf (#3344)

Co-authored-by: Jeroen Bouma <jer.bouma@gmail.com>
Co-authored-by: James Maslek <jmaslek11@gmail.com>
This commit is contained in:
montezdesousa
2022-11-09 21:37:27 +00:00
committed by GitHub
parent b93671ad0b
commit 9951461df8
4 changed files with 13 additions and 38 deletions

View File

@@ -241,8 +241,6 @@ class PortfolioController(BaseController):
choices["metric"]["--rfr"] = None
choices["metric"]["-r"] = "--rfr"
choices["perf"] = {
"--period": {c: {} for c in portfolio_helper.PERIODS},
"-p": "--period",
"--show_trades": {},
"-t": "--show_trades",
}
@@ -655,17 +653,6 @@ class PortfolioController(BaseController):
dest="show_trades",
help="Whether to show performance on all trades in comparison to the benchmark.",
)
parser.add_argument(
"-p",
"--period",
type=str,
choices=portfolio_helper.PERIODS,
dest="period",
default="all",
help="The file to be loaded",
)
if other_args and "-" not in other_args[0][0]:
other_args.insert(0, "-p")
ns_parser = self.parse_known_args_and_warn(parser, other_args)
@@ -676,7 +663,6 @@ class PortfolioController(BaseController):
portfolio_view.display_performance_vs_benchmark(
self.portfolio,
ns_parser.period,
ns_parser.show_trades,
)

View File

@@ -582,7 +582,7 @@ class PortfolioModel:
"Portfolio Investment",
"Close",
"Portfolio Value",
"% Portfolio Return",
"Portfolio % Return",
"Abs Portfolio Return",
]
] = float(0)
@@ -593,7 +593,7 @@ class PortfolioModel:
self.portfolio_trades["Portfolio Value"][index] = (
self.portfolio_trades["Close"][index] * trade["Quantity"]
)
self.portfolio_trades["% Portfolio Return"][index] = (
self.portfolio_trades["Portfolio % Return"][index] = (
self.portfolio_trades["Portfolio Value"][index]
/ self.portfolio_trades["Portfolio Investment"][index]
) - 1
@@ -1577,7 +1577,6 @@ def get_rolling_beta(
@log_start_end(log=logger)
def get_performance_vs_benchmark(
portfolio: PortfolioModel,
interval: str = "all",
show_all_trades: bool = False,
) -> pd.DataFrame:
@@ -1587,8 +1586,6 @@ def get_performance_vs_benchmark(
----------
portfolio: Portfolio
Portfolio object with trades loaded
interval : str
interval to consider performance. From: mtd, qtd, ytd, 3m, 6m, 1y, 3y, 5y, 10y, all
show_all_trades: bool
Whether to also show all trades made and their performance (default is False)
Returns
@@ -1601,17 +1598,14 @@ def get_performance_vs_benchmark(
benchmark_trades = portfolio.benchmark_trades
portfolio_trades.index = pd.to_datetime(portfolio_trades["Date"].values)
portfolio_trades = portfolio_helper.filter_df_by_period(portfolio_trades, interval)
benchmark_trades.index = pd.to_datetime(benchmark_trades["Date"].values)
benchmark_trades = portfolio_helper.filter_df_by_period(benchmark_trades, interval)
if show_all_trades:
# Combine DataFrames
combined = pd.concat(
[
portfolio_trades[
["Date", "Ticker", "Portfolio Value", "% Portfolio Return"]
["Date", "Ticker", "Portfolio Value", "Portfolio % Return"]
],
benchmark_trades[["Benchmark Value", "Benchmark % Return"]],
],
@@ -1620,7 +1614,7 @@ def get_performance_vs_benchmark(
# Calculate alpha
combined["Alpha"] = (
combined["% Portfolio Return"] - combined["Benchmark % Return"]
combined["Portfolio % Return"] - combined["Benchmark % Return"]
)
combined["Date"] = pd.to_datetime(combined["Date"]).dt.date

View File

@@ -252,7 +252,6 @@ def display_category_allocation(
@log_start_end(log=logger)
def display_performance_vs_benchmark(
portfolio: portfolio_model.PortfolioModel,
interval: str = "all",
show_all_trades: bool = False,
):
"""Display portfolio performance vs the benchmark
@@ -263,20 +262,16 @@ def display_performance_vs_benchmark(
Object containing trades made within the portfolio.
benchmark_trades: pd.DataFrame
Object containing trades made within the benchmark.
interval : str
interval to consider performance. From: mtd, qtd, ytd, 3m, 6m, 1y, 3y, 5y, 10y, all
show_all_trades: bool
Whether to also show all trades made and their performance (default is False)
"""
df = portfolio_model.get_performance_vs_benchmark(
portfolio, interval, show_all_trades
)
df = portfolio_model.get_performance_vs_benchmark(portfolio, show_all_trades)
if show_all_trades:
print_rich_table(
df,
title=f"Portfolio vs. Benchmark - Individual Trades in period: {interval}",
title="Portfolio vs. Benchmark - Individual Trades in period",
headers=list(df.columns),
show_index=False,
floatfmt=[".2f", ".2f", ".2f", ".2%", ".2f", ".2%", ".2%"],
@@ -284,7 +279,7 @@ def display_performance_vs_benchmark(
else:
print_rich_table(
df,
title=f"Portfolio vs. Benchmark - Totals in period: {interval}",
title="Portfolio vs. Benchmark",
headers=list(df.columns),
show_index=True,
)

View File

@@ -1,20 +1,20 @@
```
usage: performance [-s] [-t] [-h]
usage: performance [-t] [-h]
```
Shows performance of each trade and total performance of the portfolio versus the benchmark.
```
optional arguments:
-s, --full_shares Whether to only make a trade with the benchmark when a full share can be bought (no partial shares). (default: False)
-t, --show_trades Whether to show performance on all trades in comparison to the benchmark. (default: False)
-t, --show_trades Whether to show performance on all trades in comparison to the
benchmark. (default: False)
-h, --help show this help message (default: False)
```
Example:
```
2022 May 12, 06:22 (🦋) /portfolio/ $ perf -t
Portfolio vs. Benchmark - Totals
Portfolio vs. Benchmark - Totals
┏━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━┳━━━━━━━━━━━┳━━━━━━━━━━━━┓
┃ ┃ Portfolio ┃ Benchmark ┃ Difference ┃
┡━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━╇━━━━━━━━━━━╇━━━━━━━━━━━━┩
@@ -27,7 +27,7 @@ Example:
│ Total Abs Return │ 34637.53 │ 20608.20 │ 14029.33 │
└──────────────────┴───────────┴───────────┴────────────┘
Portfolio vs. Benchmark - Individual Trades
Portfolio vs. Benchmark - Individual Trades
┏━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━┳━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━┓
┃ Date ┃ Name ┃ Portfolio Value ┃ % Portfolio Return ┃ Benchmark Value ┃ % Benchmark Return ┃ Alpha ┃
┡━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━╇━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━┩
@@ -111,4 +111,4 @@ Example:
├─────────────────────┼───────┼─────────────────┼────────────────────┼─────────────────┼────────────────────┼──────────┤
│ 2022-05-02 00:00:00 │ YUM │ 1197.90 │ -5.93% │ 1194.00 │ -6.23% │ 0.31% │
└─────────────────────┴───────┴─────────────────┴────────────────────┴─────────────────┴────────────────────┴──────────┘
```
```