Merge pull request #3964 from northern-64bit/hotfix/bug-#3960

Fix portfolio/summary command (issue #3960)
This commit is contained in:
James Maslek
2023-02-06 15:03:22 -05:00
committed by GitHub

View File

@@ -768,6 +768,17 @@ def get_summary(
portfolio_engine.benchmark_returns, window
)
r2_portfolio_returns = portfolio_returns.copy()
r2_benchmark_returns = benchmark_returns.copy()
if len(portfolio_returns) > len(benchmark_returns):
r2_portfolio_returns = r2_portfolio_returns[
r2_portfolio_returns.index.isin(r2_benchmark_returns.index)
]
elif len(portfolio_returns) < len(benchmark_returns):
r2_benchmark_returns = r2_benchmark_returns[
r2_benchmark_returns.index.isin(r2_portfolio_returns.index)
]
metrics = {
"Volatility": [portfolio_returns.std(), benchmark_returns.std()],
"Skew": [
@@ -791,8 +802,8 @@ def get_summary(
metrics_model.sortino_ratio(benchmark_returns, risk_free_rate),
],
"R2 Score": [
r2_score(portfolio_returns, benchmark_returns),
r2_score(portfolio_returns, benchmark_returns),
r2_score(r2_portfolio_returns, r2_benchmark_returns),
r2_score(r2_portfolio_returns, r2_benchmark_returns),
],
}