qlib icon indicating copy to clipboard operation
qlib copied to clipboard

Transaction reveal of normal modes

Open Imbernoulli opened this issue 2 years ago • 3 comments

🌟 Feature Description

In some modes, transaction detail will be showed as output, like: [I 2017-03-08 00:00:00]: buy SH601919,price 0.38,amount 5516124.0033530545.deal amount 5516124.0083530545.factor 0.06366799771785736.value 2114227.46.cash 20360177.33.

However, in the most general modes, daily trade in deep learning mode, it is not showed.

Actually, this is not because these things are not generated in this nodes, in the following codes, if I delete the if and always run the following code, above items will be in the output.

if self.verbose: print( "[I {:%Y-%m-%d %H:%M:%S}]: {} {}, price {:.2f}, amount {}, deal_amount {}, factor {}, " "value {:.2f}, cash {:.2f}.".format( trade_start_time, "sell" if order.direction == Order.SELL else "buy", order.stock_id, trade_price, order.amount, order.deal_amount, order.factor, trade_val, self.trade_account.get_cash(), ), )

However, in the config file, there is no choice to control whether these will be in the output. We can't beautifully config whether this will be shown in the output, or be saved in other format. If these details is saved, it will add a lot to the reliability of the analysis.

Imbernoulli avatar Sep 23 '23 02:09 Imbernoulli

Maybe you can try setting the executor parameter verbose to True. code reference

port_analysis_config = {
    "executor": {
        "class": "SimulatorExecutor",
        "module_path": "qlib.backtest.executor",
        "kwargs": {
            "time_per_step": "day",
            "generate_portfolio_metrics": True,
            "verbose": True,
        },
    },
    "strategy": {
        ...
    },
    "backtest": {
        ...
    },
}

dmnsn7 avatar Sep 24 '23 15:09 dmnsn7

usage in config file (.yaml)


---
qlib_init:
  ...
task:
  model:
    ...
  dataset:
    ...
  record:
    - class: SignalRecord
      module_path: qlib.workflow.record_temp
      kwargs:
        ...
    - class: PortAnaRecord
      module_path: qlib.workflow.record_temp
      kwargs:
        config:
          executor:
            class: SimulatorExecutor
            module_path: qlib.backtest.executor
            kwargs:
              time_per_step: day
              generate_portfolio_metrics: True
              verbose: True
          strategy:
            ...
          backtest:
            ...

dmnsn7 avatar Sep 24 '23 15:09 dmnsn7

Thank you for your reply. I add executor: class: SimulatorExecutor module_path: qlib.backtest.executor kwargs: time_per_step: day generate_portfolio_metrics: True verbose: True to port_analysis_config: &port_analysis_config and it works.

Imbernoulli avatar Sep 24 '23 16:09 Imbernoulli