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

Why does the Qlib use 238 instead of 252 as the number of trading days per year in the \contrib\evaluate.py? #1735

Open
OzzyXu opened this issue Jan 18, 2024 · 0 comments
Labels
question Further information is requested

Comments

@OzzyXu
Copy link

OzzyXu commented Jan 18, 2024

In the risk_analysis of \contrib\evaluate.py, the function comments say

    Parameters
    ----------
    r : pandas.Series
        daily return series.
    N: int
        scaler for annualizing information_ratio (day: 252, week: 50, month: 12), at least one of `N` and `freq` should exist
    freq: str
        analysis frequency used for calculating the scaler, at least one of `N` and `freq` should exist

But inside the function, it uses 238 instead of 252 to calculate the annualized_return.

    def cal_risk_analysis_scaler(freq):
        _count, _freq = Freq.parse(freq)
        # len(D.calendar(start_time='2010-01-01', end_time='2019-12-31', freq='day')) = 2384
        _freq_scaler = {
            Freq.NORM_FREQ_MINUTE: 240 * 238,
            Freq.NORM_FREQ_DAY: 238,
            Freq.NORM_FREQ_WEEK: 50,
            Freq.NORM_FREQ_MONTH: 12,
        }
        return _freq_scaler[_freq] / _count

    if N is None and freq is None:
        raise ValueError("at least one of `N` and `freq` should exist")
    if N is not None and freq is not None:
        warnings.warn("risk_analysis freq will be ignored")
    if N is None:
        N = cal_risk_analysis_scaler(freq)

    mean = r.mean()
    std = r.std(ddof=1)
    annualized_return = mean * N

Can I ask why the _freq_scaler uses 238 instead of 252?

@OzzyXu OzzyXu added the question Further information is requested label Jan 18, 2024
@OzzyXu OzzyXu changed the title Why does the Qlib use 238 instead of 252 as the number of trading days per year in the /contrib/evaluate.py? Why does the Qlib use 238 instead of 252 as the number of trading days per year in the \contrib\evaluate.py? Jan 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

1 participant