Skip to content

Commit 0e8c262

Browse files
authored
355 two digits for sharpe ratio (#356)
* Update portfolio.py * two digits
1 parent b313ab5 commit 0e8c262

File tree

1 file changed

+6
-19
lines changed

1 file changed

+6
-19
lines changed

Diff for: cvx/simulator/portfolio.py

+6-19
Original file line numberDiff line numberDiff line change
@@ -271,15 +271,6 @@ def snapshot(
271271
],
272272
)
273273

274-
# fig = make_subplots(
275-
# rows=3, cols=1,
276-
# shared_xaxes=True,
277-
# vertical_spacing=0.03,
278-
# specs=[[{"type": "table"}],
279-
# [{"type": "scatter"}],
280-
# [{"type": "scatter"}]]
281-
# )
282-
283274
# display the NAV
284275
fig.add_trace(
285276
go.Scatter(x=self.nav.index, y=self.nav, name=label_strategy), row=2, col=1
@@ -363,14 +354,10 @@ def snapshot(
363354

364355
table.loc[label_strategy, "start"] = self.nav.index[0].strftime("%Y-%m-%d")
365356
table.loc[label_strategy, "end"] = self.nav.index[-1].strftime("%Y-%m-%d")
366-
# table["start"][label_benchmark] = benchmark.index[0].strftime("%Y-%m-%d")
367-
# table["end"][label_benchmark] = benchmark.index[-1].strftime("%Y-%m-%d")
368357
table.loc[label_strategy, "# assets"] = len(self.assets)
369-
# table['# assets'][label_benchmark] =
370-
table.loc[label_strategy, "Sharpe ratio"] = sharpe(
371-
self.nav.pct_change().dropna()
372-
)
373-
# table["Sharpe ratio"][label_benchmark] = sharpe(benchmark.pct_change().dropna())
358+
359+
s = sharpe(self.nav.pct_change().dropna())
360+
table.loc[label_strategy, "Sharpe ratio"] = f"{s:.2f}"
374361

375362
if benchmark is not None:
376363
table_bench = pd.DataFrame(
@@ -384,9 +371,9 @@ def snapshot(
384371
"%Y-%m-%d"
385372
)
386373
table_bench.loc[label_benchmark, "# assets"] = ""
387-
table_bench.loc[label_benchmark, "Sharpe ratio"] = sharpe(
388-
benchmark.pct_change().dropna()
389-
)
374+
table_bench.loc[
375+
label_benchmark, "Sharpe ratio"
376+
] = f"{sharpe(benchmark.pct_change().dropna()):.2f}"
390377

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

0 commit comments

Comments
 (0)