class_docstr: Motivation:
      PortfolioMetrics is for supporting portfolio related metrics.
  
  Implementation:
  
      daily portfolio metrics of the account
      contain those followings: return, cost, turnover, account, cash, bench, value
      For each step(bar/day/minute), each column represents
      - return: the return of the portfolio generated by strategy **without transaction fee**.
      - cost: the transaction fee and slippage.
      - account: the total value of assets(cash and securities are both included) in user account based on the close price of each step.
      - cash: the amount of cash in user's account.
      - bench: the return of the benchmark
      - value: the total value of securities/stocks/instruments (cash is excluded).
  
      update report
class_docstr_tok: ["Motivation",":","PortfolioMetrics","is","for","supporting","portfolio","related","metrics",".","Implementation",":","daily","portfolio","metrics","of","the","account","contain","those","followings",":","return",",","cost",",","turnover",",","account",",","cash",",","bench",",","value","For","each","step","(","bar\/day\/minute",")",",","each","column","represents","-","return",":","the","return","of","the","portfolio","generated","by","strategy","*","*","without","transaction","fee","*","*",".","-","cost",":","the","transaction","fee","and","slippage",".","-","account",":","the","total","value","of","assets","(","cash","and","securities","are","both","included",")","in","user","account","based","on","the","close","price","of","each","step",".","-","cash",":","the","amount","of","cash","in","user","'s","account",".","-","bench",":","the","return","of","the","benchmark","-","value",":","the","total","value","of","securities\/stocks\/instruments","(","cash","is","excluded",")",".","update","report"]
docstr: Parameters
  ----------
  freq : str
      frequency of trading bar, used for updating hold count of trading bar
  benchmark_config : dict
      config of benchmark, may including the following arguments:
      - benchmark : Union[str, list, pd.Series]
          - If `benchmark` is pd.Series, `index` is trading date; the value T is the change from T-1 to T.
              example:
                  print(
                      D.features(D.instruments('csi500'),
                      ['$close/Ref($close, 1)-1'])['$close/Ref($close, 1)-1'].head()
                  )
                      2017-01-04    0.011693
                      2017-01-05    0.000721
                      2017-01-06   -0.004322
                      2017-01-09    0.006874
                      2017-01-10   -0.003350
          - If `benchmark` is list, will use the daily average change of the stock pool in the list as the
              'bench'.
          - If `benchmark` is str, will use the daily change as the 'bench'.
          benchmark code, default is SH000300 CSI300
      - start_time : Union[str, pd.Timestamp], optional
          - If `benchmark` is pd.Series, it will be ignored
          - Else, it represent start time of benchmark, by default None
      - end_time : Union[str, pd.Timestamp], optional
          - If `benchmark` is pd.Series, it will be ignored
          - Else, it represent end time of benchmark, by default None
docstr_tok: ["Parameters","--","--","--","--","--","freq",":","str","frequency","of","trading","bar",",","used","for","updating","hold","count","of","trading","bar","benchmark_config",":","dict","config","of","benchmark",",","may","including","the","following","arguments",":","-","benchmark",":","Union","[","str",",","list",",","pd.Series","]","-","If","`","benchmark","`","is","pd.Series",",","`","index","`","is","trading","date",";","the","value","T","is","the","change","from","T-1","to","T.","example",":","print","(","D.features","(","D.instruments","(","'csi500","'",")",",","[","'","$","close\/Ref","(","$","close",",","1",")","-1","'","]",")","[","'","$","close\/Ref","(","$","close",",","1",")","-1","'","]",".head","(",")",")","2017-01-04","0.011693","2017-01-05","0.000721","2017-01-06","-0.004322","2017-01-09","0.006874","2017-01-10","-0.003350","-","If","`","benchmark","`","is","list",",","will","use","the","daily","average","change","of","the","stock","pool","in","the","list","as","the","'bench","'",".","-","If","`","benchmark","`","is","str",",","will","use","the","daily","change","as","the","'bench","'",".","benchmark","code",",","default","is","SH000300","CSI300","-","start_time",":","Union","[","str",",","pd.Timestamp","]",",","optional","-","If","`","benchmark","`","is","pd.Series",",","it","will","be","ignored","-","Else",",","it","represent","start","time","of","benchmark",",","by","default","None","-","end_time",":","Union","[","str",",","pd.Timestamp","]",",","optional","-","If","`","benchmark","`","is","pd.Series",",","it","will","be","ignored","-","Else",",","it","represent","end","time","of","benchmark",",","by","default","None"]
code: def __init__(
      self, freq: str = "day", benchmark_config: dict = {}
  ) -> None:
      """
      Parameters
      ----------
      freq : str
          frequency of trading bar, used for updating hold count of trading bar
      benchmark_config : dict
          config of benchmark, may including the following arguments:
          - benchmark : Union[str, list, pd.Series]
              - If `benchmark` is pd.Series, `index` is trading date; the value T is the change from T-1 to T.
                  example:
                      print(
                          D.features(D.instruments('csi500'),
                          ['$close/Ref($close, 1)-1'])['$close/Ref($close, 1)-1'].head()
                      )
                          2017-01-04    0.011693
                          2017-01-05    0.000721
                          2017-01-06   -0.004322
                          2017-01-09    0.006874
                          2017-01-10   -0.003350
              - If `benchmark` is list, will use the daily average change of the stock pool in the list as the
                  'bench'.
              - If `benchmark` is str, will use the daily change as the 'bench'.
              benchmark code, default is SH000300 CSI300
          - start_time : Union[str, pd.Timestamp], optional
              - If `benchmark` is pd.Series, it will be ignored
              - Else, it represent start time of benchmark, by default None
          - end_time : Union[str, pd.Timestamp], optional
              - If `benchmark` is pd.Series, it will be ignored
              - Else, it represent end time of benchmark, by default None
  
      """
  
      self.init_vars()
      self.init_bench(freq=freq, benchmark_config=benchmark_config)
  
imports: from __future__ import annotations
  import pathlib
  from collections import OrderedDict
  from typing import Any, Dict, List, Optional, Text, Tuple, Type, Union, cast
  import numpy
  import pandas
  import qlib.utils.index_data
  from qlib.backtest.decision import BaseTradeDecision, Order, OrderDir
  from qlib.backtest.exchange import Exchange
  from ..tests.config import CSI300_BENCH
  from ..utils.resam import get_higher_eq_freq_feature, resam_ts_data
  from .high_performance_ds import BaseOrderIndicator, BaseSingleMetric, NumpyOrderIndicator
label_desc: Use image node_id 1 to create a new PortfolioMetrics object  with example: obj = PortfolioMetrics(freq, benchmark_config)