Skip to content

Commit

Permalink
Portfolio controller fixes (#2610)
Browse files Browse the repository at this point in the history
* fix some bugs

* fix rf bug

* fix rf units

* black

* fix tagency not showing

Co-authored-by: minhhoang1023 <40023817+minhhoang1023@users.noreply.github.com>
  • Loading branch information
montezdesousa and minhhoang1023 authored Sep 23, 2022
1 parent d0914a8 commit 7a02f85
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 13 deletions.
24 changes: 13 additions & 11 deletions openbb_terminal/portfolio/portfolio_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,8 @@ def call_load(self, other_args: List[str]):
self.portfolio.generate_portfolio_data()

# Add in the Risk-free rate
self.portfolio.set_risk_free_rate(ns_parser.risk_free_rate)
self.portfolio.set_risk_free_rate(ns_parser.risk_free_rate / 100)
self.risk_free_rate = ns_parser.risk_free_rate / 100

# Load benchmark
self.call_bench(["-b", "SPDR S&P 500 ETF Trust (SPY)"])
Expand All @@ -350,7 +351,7 @@ def call_load(self, other_args: List[str]):
f"\n[bold][param]Portfolio:[/param][/bold] {self.portfolio_name}"
)
console.print(
f"[bold][param]Risk Free Rate:[/param][/bold] {self.portfolio.risk_free_rate}"
f"[bold][param]Risk Free Rate:[/param][/bold] {self.risk_free_rate:.2%}"
)
console.print(
f"[bold][param]Benchmark:[/param][/bold] {self.benchmark_name}\n"
Expand All @@ -371,12 +372,13 @@ def call_show(self, other_args: List[str]):
export_allowed=EXPORT_BOTH_RAW_DATA_AND_FIGURES,
limit=10,
)
portfolio_view.display_orderbook(
self.portfolio,
show_index=False,
limit=ns_parser.limit,
export=ns_parser.export,
)
if ns_parser and self.portfolio is not None:
portfolio_view.display_orderbook(
self.portfolio,
show_index=False,
limit=ns_parser.limit,
export=ns_parser.export,
)

@log_start_end(log=logger)
def call_bench(self, other_args: List[str]):
Expand Down Expand Up @@ -1025,7 +1027,7 @@ def call_rsharpe(self, other_args: List[str]):
portfolio_view.display_rolling_sharpe(
self.portfolio,
window=ns_parser.period,
risk_free_rate=ns_parser.risk_free_rate,
risk_free_rate=ns_parser.risk_free_rate / 100,
export=ns_parser.export,
)

Expand Down Expand Up @@ -1065,9 +1067,9 @@ def call_rsort(self, other_args: List[str]):
self.portfolio_name, self.benchmark_name
):
portfolio_view.display_rolling_sortino(
portfolio=self.portfolio.benchmark_returns,
portfolio=self.portfolio,
window=ns_parser.period,
risk_free_rate=ns_parser.risk_free_rate,
risk_free_rate=ns_parser.risk_free_rate / 100,
export=ns_parser.export,
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1620,8 +1620,6 @@ def get_ef(
method=method,
)

risk_free_rate = risk_free_rate / time_factor[freq.upper()]

# Building the portfolio object
port = rp.Portfolio(returns=stock_returns, alpha=alpha)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2204,6 +2204,8 @@ def display_ef(
Whether to plot the tickers for the assets
"""

risk_free_rate = risk_free_rate / time_factor[freq.upper()]

frontier, mu, cov, stock_returns, weights, X1, Y1, port = optimizer_model.get_ef(
symbols,
interval,
Expand Down

0 comments on commit 7a02f85

Please sign in to comment.