MCPcopy Create free account
hub / github.com/kernc/backtesting.py / geometric_mean

Function geometric_mean

backtesting/_stats.py:30–34  ·  view source on GitHub ↗
(returns: pd.Series)

Source from the content-addressed store, hash-verified

28
29
30def geometric_mean(returns: pd.Series) -> float:
31 returns = returns.fillna(0) + 1
32 if np.any(returns <= 0):
33 return 0
34 return np.exp(np.log(returns).sum() / (len(returns) or np.nan)) - 1
35
36
37def compute_stats(

Callers 1

compute_statsFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected