Skip to content

Commit 128c957

Browse files
committed
modify backtest_daily's docstring
1 parent afbba28 commit 128c957

File tree

3 files changed

+35
-25
lines changed

3 files changed

+35
-25
lines changed

docs/component/strategy.rst

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,9 +111,18 @@ Usage & Example
111111
112112
113113
strategy_obj = TopkDropoutStrategy(**STRATEGY_CONFIG)
114-
analysis_df = backtest_daily(
115-
start_time="2017-01-01", end_time="2020-08-01", strategy=strategy_obj, executor=executor_obj
114+
report_normal, positions_normal = backtest_daily(
115+
start_time="2017-01-01", end_time="2020-08-01", strategy=strategy_obj
116116
)
117+
analysis = dict()
118+
analysis["excess_return_without_cost"] = risk_analysis(
119+
report_normal["return"] - report_normal["bench"], freq=analysis_freq
120+
)
121+
analysis["excess_return_with_cost"] = risk_analysis(
122+
report_normal["return"] - report_normal["bench"] - report_normal["cost"], freq=analysis_freq
123+
)
124+
125+
analysis_df = pd.concat(analysis) # type: pd.DataFrame
117126
pprint(analysis_df)
118127
119128

qlib/config.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -244,8 +244,8 @@ def set_conf_from_C(self, config_c):
244244
_default_region_config = {
245245
REG_CN: {
246246
"trade_unit": 100,
247-
"limit_threshold": 0.099,
248-
"deal_price": "vwap",
247+
"limit_threshold": 0.095,
248+
"deal_price": "close",
249249
},
250250
REG_US: {
251251
"trade_unit": 1,

qlib/contrib/evaluate.py

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
from __future__ import division
55
from __future__ import print_function
6-
from logging import warn
76

87
import numpy as np
98
import pandas as pd
@@ -130,7 +129,7 @@ def backtest_daily(
130129
benchmark: str = "SH000300",
131130
exchange_kwargs: dict = None,
132131
pos_type: str = "Position",
133-
) -> pd.DataFrame:
132+
):
134133
"""initialize the strategy and executor, then executor the backtest of daily frequency
135134
136135
Parameters
@@ -187,13 +186,28 @@ def backtest_daily(
187186
Using Account with a Position
188187
exchange_kwargs : dict
189188
the kwargs for initializing Exchange
189+
E.g.
190+
191+
.. code-block:: python
192+
193+
exchange_kwargs = {
194+
"freq": freq,
195+
"limit_threshold": None, # limit_threshold is None, using C.limit_threshold
196+
"deal_price": None, # deal_price is None, using C.deal_price
197+
"open_cost": 0.0005,
198+
"close_cost": 0.0015,
199+
"min_cost": 5,
200+
}
201+
190202
pos_type : str
191203
the type of Position.
192204
193205
Returns
194206
-------
195-
analysis_df: pd.DataFrame
196-
backtest results
207+
report_normal: pd.DataFrame
208+
backtest report
209+
positions_normal: pd.DataFrame
210+
backtest positions
197211
198212
"""
199213
freq = "day"
@@ -205,8 +219,8 @@ def backtest_daily(
205219
executor = _executor.SimulatorExecutor(**executor_config)
206220
_exchange_kwargs = {
207221
"freq": freq,
208-
"limit_threshold": 0.095,
209-
"deal_price": "close",
222+
"limit_threshold": None,
223+
"deal_price": None,
210224
"open_cost": 0.0005,
211225
"close_cost": 0.0015,
212226
"min_cost": 5,
@@ -227,16 +241,8 @@ def backtest_daily(
227241
analysis_freq = "{0}{1}".format(*Freq.parse(freq))
228242

229243
report_normal, positions_normal = portfolio_metric_dict.get(analysis_freq)
230-
analysis = dict()
231-
analysis["excess_return_without_cost"] = risk_analysis(
232-
report_normal["return"] - report_normal["bench"], freq=analysis_freq
233-
)
234-
analysis["excess_return_with_cost"] = risk_analysis(
235-
report_normal["return"] - report_normal["bench"] - report_normal["cost"], freq=analysis_freq
236-
)
237244

238-
analysis_df = pd.concat(analysis) # type: pd.DataFrame
239-
return analysis_df
245+
return report_normal, positions_normal
240246

241247

242248
def long_short_backtest(
@@ -374,12 +380,7 @@ def t_run():
374380
"n_drop": 5,
375381
"signal": pred,
376382
}
377-
portfolio_metric_dict, indicator_dict = backtest_daily(
378-
start_time="2017-01-01", end_time="2020-08-01", strategy=strategy_config
379-
)
380-
freq = "day"
381-
analysis_freq = "{0}{1}".format(*Freq.parse(freq))
382-
report_df, positions = portfolio_metric_dict.get(analysis_freq)
383+
report_df, positions = backtest_daily(start_time="2017-01-01", end_time="2020-08-01", strategy=strategy_config)
383384
print(report_df.head())
384385
print(positions.keys())
385386
print(positions[list(positions.keys())[0]])

0 commit comments

Comments
 (0)