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

Implement exponential mode for annualized_return calculation in risk_… #1433

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

DimitarSivrev
Copy link

@DimitarSivrev DimitarSivrev commented Feb 7, 2023

My first contribution to Qlib,

Resolves #964

Description

This change allows the user to choose between accumulation mode and exponential mode when calculating the annualized_return in the risk_analysis function. The exponential mode uses the formula product of (1 + r_i) minus 1. A new parameter 'accumulation_mode' has been added to the risk_analysis function to control the mode of calculation. An error will be thrown if the parameter is not set to 'accumulation' or 'exponential'. I can resolve any issues with this change.

Types of changes

  • Fix bugs
  • Add new feature
  • Update documentation

@github-actions github-actions bot added the waiting for triage Cannot auto-triage, wait for triage. label Feb 7, 2023
@quant2008
Copy link

quant2008 commented May 14, 2023

DimitarSivrev, I tried the exponential mode, but it seems still not correct. pls see here #1512

@@ -24,16 +24,14 @@
logger = get_module_logger("Evaluate")


def risk_analysis(r, N: int = None, freq: str = "day"):
def risk_analysis(r, N: int = None, freq: str = "day", accumulation_mode = "summation"):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@@ -61,10 +61,16 @@ def cal_risk_analysis_scaler(freq):
warnings.warn("risk_analysis freq will be ignored")
if N is None:
N = cal_risk_analysis_scaler(freq)

if accumulation_mode not in ["summation", "exponential"]:
raise ValueError("Invalid value for `accumulation_mode`. Only 'summation' and 'exponential' are supported")

mean = r.mean()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be geometric mean if production is considered

if accumulation_mode == "summation":
annualized_return = mean * N
else:
annualized_return = (np.prod(1 + r) - 1)
information_ratio = mean / std * np.sqrt(N)
max_drawdown = (r.cumsum() - r.cumsum().cummax()).min()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The maxdrawdown should also be changed if production is considered

if accumulation_mode == "summation":
annualized_return = mean * N
else:
annualized_return = (np.prod(1 + r) - 1)
information_ratio = mean / std * np.sqrt(N)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if the annualized volatility should be chagned if production is considered.
But intuitively, the accumulated volatility and production vollatility is different.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
waiting for triage Cannot auto-triage, wait for triage.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Concerns about the calculation of return
3 participants