code: def risk_analysis(r, N: int = None, freq: str = "day"):
      """Risk Analysis
      NOTE:
      The calculation of annulaized return is different from the definition of annualized return.
      It is implemented by design.
      Qlib tries to cumulated returns by summation instead of production to avoid the cumulated curve being skewed exponentially.
      All the calculation of annualized returns follows this principle in Qlib.
  
      TODO: add a parameter to enable calculating metrics with production accumulation of return.
  
      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
      """
  
      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
      information_ratio = mean / std * np.sqrt(N)
      max_drawdown = (r.cumsum() - r.cumsum().cummax()).min()
      data = {
          "mean": mean,
          "std": std,
          "annualized_return": annualized_return,
          "information_ratio": information_ratio,
          "max_drawdown": max_drawdown,
      }
      res = pd.Series(data).to_frame("risk")
      return res
  
file_path: qlib/qlib/contrib/evaluate.py
imports: from __future__ import division
  from __future__ import print_function
  import numpy
  import pandas
  import warnings
  from typing import Union
  from ..log import get_module_logger
  from ..utils import get_date_range
  from ..utils.resam import Freq
  from ..strategy.base import BaseStrategy
  from ..backtest import get_exchange, position, backtest, executor
  from ..data import D
  from ..config import C
  from ..data.dataset.utils import get_level_index
label_desc: Use image node_id 1 for calling a global function with example usage: risk_analysis(r, N, freq) and returns: res, unknown