Skip to content

Commit

Permalink
fix pandas to at least 2.2.0 (#330)
Browse files Browse the repository at this point in the history
  • Loading branch information
tschm authored Jan 22, 2024
1 parent c774496 commit 7d2e98c
Show file tree
Hide file tree
Showing 3 changed files with 132 additions and 118 deletions.
21 changes: 9 additions & 12 deletions cvx/simulator/portfolio.py
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ def snapshot(
# Daily/Monthly Returns
if aggregate:
self.nav.index.name = "date"
nav = self.nav.resample("M").last()
nav = self.nav.resample("ME").last()
returns = 100 * nav.pct_change().dropna()

df = returns.to_frame("value")
Expand Down Expand Up @@ -360,13 +360,13 @@ def snapshot(
)
table.index.name = "Portfolio"

table["start"][label_strategy] = self.nav.index[0].strftime("%Y-%m-%d")
table["end"][label_strategy] = self.nav.index[-1].strftime("%Y-%m-%d")
table.loc[label_strategy, "start"] = self.nav.index[0].strftime("%Y-%m-%d")
table.loc[label_strategy, "end"] = self.nav.index[-1].strftime("%Y-%m-%d")
# table["start"][label_benchmark] = benchmark.index[0].strftime("%Y-%m-%d")
# table["end"][label_benchmark] = benchmark.index[-1].strftime("%Y-%m-%d")
table["# assets"][label_strategy] = len(self.assets)
table.loc[label_strategy, "# assets"] = len(self.assets)
# table['# assets'][label_benchmark] =
table["Sharpe ratio"][label_strategy] = sharpe(
table.loc[label_strategy, "Sharpe ratio"] = sharpe(
self.nav.pct_change().dropna()
)
# table["Sharpe ratio"][label_benchmark] = sharpe(benchmark.pct_change().dropna())
Expand All @@ -376,24 +376,21 @@ def snapshot(
index=[label_benchmark],
columns=["start", "end", "# assets", "Sharpe ratio"],
)
table_bench["start"][label_benchmark] = benchmark.index[0].strftime(
table_bench.loc[label_benchmark, "start"] = benchmark.index[0].strftime(
"%Y-%m-%d"
)
table_bench["end"][label_benchmark] = benchmark.index[-1].strftime(
table_bench.loc[label_benchmark, "end"] = benchmark.index[-1].strftime(
"%Y-%m-%d"
)
table_bench["# assets"][label_benchmark] = ""
table_bench["Sharpe ratio"][label_benchmark] = sharpe(
table_bench.loc[label_benchmark, "# assets"] = ""
table_bench.loc[label_benchmark, "Sharpe ratio"] = sharpe(
benchmark.pct_change().dropna()
)

table = pd.concat([table, table_bench], axis=0)

table = table.reset_index()

# print(table)
# assert False

# if table is not None:
fig.add_trace(
go.Table(
Expand Down
Loading

0 comments on commit 7d2e98c

Please sign in to comment.