Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect values of Annualised Returns and Volatility with week or Month level data #537

Open
khannavivek opened this issue Nov 19, 2021 · 0 comments

Comments

@khannavivek
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant