You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
While calculating day_returns the Data is resampled to Day, but for Monthly and Weekly data the value is not correct and provides incorrect values wherever day_returns or annual_trading_days is used.
if isinstance(index, pd.DatetimeIndex):
day_returns = equity_df['Equity'].resample('D').last().dropna().pct_change()
gmean_day_return = geometric_mean(day_returns)
annual_trading_days = float(
365 if index.dayofweek.to_series().between(5, 6).mean() > 2/7 * .6 else
252)
# Annualized return and risk metrics are computed based on the (mostly correct)
# assumption that the returns are compounded. See: https://dx.doi.org/10.2139/ssrn.3054517
# Our annualized return matches `empyrical.annual_return(day_returns)` whereas
# our risk doesn't; they use the simpler approach below.
annualized_return = (1 + gmean_day_return)**annual_trading_days - 1
s.loc['Return (Ann.) [%]'] = annualized_return * 100
s.loc['Volatility (Ann.) [%]'] = np.sqrt((day_returns.var(ddof=int(bool(day_returns.shape))) + (1 + gmean_day_return)**2)**annual_trading_days - (1 + gmean_day_return)**(2*annual_trading_days)) * 100 # noqa: E501
I tried to figure out it like this:
annual_trading_days = annual_trading_days /12 ##in case of month
annual_trading_days = annual_trading_days /52 ##in case of week
Let me know if this can be implemented if it's correct or some better way to solve this.
The text was updated successfully, but these errors were encountered:
While calculating day_returns the Data is resampled to Day, but for Monthly and Weekly data the value is not correct and provides incorrect values wherever day_returns or annual_trading_days is used.
I tried to figure out it like this:
Let me know if this can be implemented if it's correct or some better way to solve this.
The text was updated successfully, but these errors were encountered: