mirror of
https://github.com/OpenBB-finance/OpenBB.git
synced 2026-10-27 12:40:35 +00:00
remove cumulative returns functionalities (#2103)
Co-authored-by: Jeroen Bouma <jer.bouma@gmail.com> Co-authored-by: Theodore Aptekarev <aptekarev@gmail.com>
This commit is contained in:
@@ -44,7 +44,6 @@ class PortfolioController(BaseController):
|
||||
"bench",
|
||||
"alloc",
|
||||
"perf",
|
||||
"cret",
|
||||
"yret",
|
||||
"mret",
|
||||
"dret",
|
||||
@@ -170,7 +169,6 @@ class PortfolioController(BaseController):
|
||||
mt.add_info("_graphs_")
|
||||
mt.add_cmd("holdv", self.portfolio_name and self.benchmark_name)
|
||||
mt.add_cmd("holdp", self.portfolio_name and self.benchmark_name)
|
||||
mt.add_cmd("cret", self.portfolio_name and self.benchmark_name)
|
||||
mt.add_cmd("yret", self.portfolio_name and self.benchmark_name)
|
||||
mt.add_cmd("mret", self.portfolio_name and self.benchmark_name)
|
||||
mt.add_cmd("dret", self.portfolio_name and self.benchmark_name)
|
||||
@@ -213,7 +211,6 @@ class PortfolioController(BaseController):
|
||||
[info]Graphs:[/info]{("[unvl]", "[cmds]")[port_bench]}
|
||||
holdv holdings of assets (absolute value)
|
||||
holdp portfolio holdings of assets (in percentage)
|
||||
cret cumulative returns
|
||||
yret yearly returns
|
||||
mret monthly returns
|
||||
dret daily returns
|
||||
@@ -783,47 +780,6 @@ class PortfolioController(BaseController):
|
||||
"[red]Please first define the portfolio (via 'load')[/red]\n"
|
||||
)
|
||||
|
||||
@log_start_end(log=logger)
|
||||
def call_cret(self, other_args: List[str]):
|
||||
"""Process cret command"""
|
||||
parser = argparse.ArgumentParser(
|
||||
add_help=False,
|
||||
formatter_class=argparse.ArgumentDefaultsHelpFormatter,
|
||||
prog="cret",
|
||||
description="Graph of cumulative returns against benchmark",
|
||||
)
|
||||
parser.add_argument(
|
||||
"-p",
|
||||
"--period",
|
||||
type=str,
|
||||
dest="period",
|
||||
default="all",
|
||||
choices=list(portfolio_helper.PERIODS_DAYS.keys()),
|
||||
help="Period to select start of cumulative returns",
|
||||
)
|
||||
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,
|
||||
raw=True,
|
||||
limit=10,
|
||||
export_allowed=EXPORT_BOTH_RAW_DATA_AND_FIGURES,
|
||||
)
|
||||
|
||||
if ns_parser and self.portfolio is not None:
|
||||
if check_portfolio_benchmark_defined(
|
||||
self.portfolio_name, self.benchmark_name
|
||||
):
|
||||
portfolio_view.display_cumulative_returns(
|
||||
self.portfolio.returns,
|
||||
self.portfolio.benchmark_returns,
|
||||
ns_parser.period,
|
||||
ns_parser.raw,
|
||||
ns_parser.limit,
|
||||
ns_parser.export,
|
||||
)
|
||||
|
||||
@log_start_end(log=logger)
|
||||
def call_yret(self, other_args: List[str]):
|
||||
"""Process yret command"""
|
||||
|
||||
@@ -350,76 +350,6 @@ def display_performance_vs_benchmark(
|
||||
)
|
||||
|
||||
|
||||
@log_start_end(log=logger)
|
||||
def display_cumulative_returns(
|
||||
portfolio_returns: pd.Series,
|
||||
benchmark_returns: pd.Series,
|
||||
period: str = "all",
|
||||
raw: bool = False,
|
||||
limit: int = 10,
|
||||
export: str = "",
|
||||
external_axes: Optional[plt.Axes] = None,
|
||||
):
|
||||
"""Display portfolio returns vs benchmark
|
||||
|
||||
Parameters
|
||||
----------
|
||||
portfolio_returns : pd.Series
|
||||
Returns of the portfolio
|
||||
benchmark_returns : pd.Series
|
||||
Returns of the benchmark
|
||||
period : str
|
||||
Period to compare cumulative returns and benchmark
|
||||
raw : False
|
||||
Display raw data from cumulative return
|
||||
limit : int
|
||||
Last cumulative returns to display
|
||||
export : str
|
||||
Export certain type of data
|
||||
external_axes: plt.Axes
|
||||
Optional axes to display plot on
|
||||
"""
|
||||
|
||||
portfolio_returns = portfolio_helper.filter_df_by_period(portfolio_returns, period)
|
||||
benchmark_returns = portfolio_helper.filter_df_by_period(benchmark_returns, period)
|
||||
|
||||
cumulative_returns = 100 * portfolio_model.cumulative_returns(portfolio_returns)
|
||||
benchmark_c_returns = 100 * portfolio_model.cumulative_returns(benchmark_returns)
|
||||
|
||||
if raw:
|
||||
last_cumulative_returns = cumulative_returns.to_frame()
|
||||
last_cumulative_returns = last_cumulative_returns.join(benchmark_c_returns)
|
||||
last_cumulative_returns.index = last_cumulative_returns.index.date
|
||||
print_rich_table(
|
||||
last_cumulative_returns.tail(limit),
|
||||
title="Cumulative Portfolio and Benchmark returns",
|
||||
headers=["Portfolio [%]", "Benchmark [%]"],
|
||||
show_index=True,
|
||||
)
|
||||
else:
|
||||
if external_axes is None:
|
||||
_, ax = plt.subplots(figsize=plot_autoscale(), dpi=PLOT_DPI)
|
||||
else:
|
||||
ax = external_axes
|
||||
|
||||
ax.plot(cumulative_returns.index, cumulative_returns, label="Portfolio")
|
||||
ax.plot(benchmark_c_returns.index, benchmark_c_returns, label="Benchmark")
|
||||
|
||||
ax.legend(loc="upper left")
|
||||
ax.set_ylabel("Cumulative Returns [%]")
|
||||
theme.style_primary_axis(ax)
|
||||
|
||||
if not external_axes:
|
||||
theme.visualize_output()
|
||||
|
||||
export_data(
|
||||
export,
|
||||
os.path.dirname(os.path.abspath(__file__)),
|
||||
"cret",
|
||||
cumulative_returns.to_frame().join(benchmark_c_returns),
|
||||
)
|
||||
|
||||
|
||||
@log_start_end(log=logger)
|
||||
def display_yearly_returns(
|
||||
portfolio_returns: pd.Series,
|
||||
|
||||
@@ -16,7 +16,6 @@ Benchmark:
|
||||
Graphs:[unvl]
|
||||
holdv holdings of assets (absolute value)
|
||||
holdp portfolio holdings of assets (in percentage)
|
||||
cret cumulative returns
|
||||
yret yearly returns
|
||||
mret monthly returns
|
||||
dret daily returns
|
||||
|
||||
@@ -1,18 +0,0 @@
|
||||
```
|
||||
usage: cret [-p {3m,6m,1y,3y,5y,10y}] [-h] [--export EXPORT] [--raw] [-l LIMIT]
|
||||
```
|
||||
|
||||
Graph of cumulative returns against benchmark
|
||||
|
||||
```
|
||||
optional arguments:
|
||||
-p {3m,6m,1y,3y,5y,10y}, --period {3m,6m,1y,3y,5y,10y}
|
||||
Period to select start of cumulative returns (default: all)
|
||||
-h, --help show this help message (default: False)
|
||||
--export EXPORT Export raw data into csv, json, xlsx and figure into png, jpg, pdf, svg (default: )
|
||||
--raw Flag to display raw data (default: False)
|
||||
-l LIMIT, --limit LIMIT
|
||||
Number of entries to show in data. (default: 10)
|
||||
```
|
||||
|
||||
<img width="1426" alt="Screenshot 2022-05-18 at 00 56 10" src="https://user-images.githubusercontent.com/25267873/168930742-546ad527-62ce-4174-a037-bcf7de88bc18.png">
|
||||
2
website/data/menu/main.yml
vendored
2
website/data/menu/main.yml
vendored
@@ -1321,8 +1321,6 @@ main:
|
||||
ref: "/terminal/portfolio/holdv"
|
||||
- name: holdp
|
||||
ref: "/terminal/portfolio/holdp"
|
||||
- name: cret
|
||||
ref: "/terminal/portfolio/cret"
|
||||
- name: yret
|
||||
ref: "/terminal/portfolio/yret"
|
||||
- name: mret
|
||||
|
||||
Reference in New Issue
Block a user