Skip to content

Commit

Permalink
修复bug及遗漏点
Browse files Browse the repository at this point in the history
  • Loading branch information
Lin-Dongzhao committed May 15, 2024
1 parent d9fcd71 commit 451ff33
Show file tree
Hide file tree
Showing 7 changed files with 101 additions and 123 deletions.
67 changes: 21 additions & 46 deletions messages.pot
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PROJECT VERSION\n"
"Report-Msgid-Bugs-To: EMAIL@ADDRESS\n"
"POT-Creation-Date: 2024-04-24 13:56+0800\n"
"POT-Creation-Date: 2024-05-15 14:39+0800\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
Expand Down Expand Up @@ -73,8 +73,8 @@ msgstr ""
#: rqalpha/apis/api_base.py:173
#: rqalpha/mod/rqalpha_mod_sys_accounts/api/api_future.py:66
#: rqalpha/mod/rqalpha_mod_sys_accounts/api/api_stock.py:103
#: rqalpha/mod/rqalpha_mod_sys_accounts/api/api_stock.py:140
#: rqalpha/mod/rqalpha_mod_sys_accounts/api/api_stock.py:343
#: rqalpha/mod/rqalpha_mod_sys_accounts/api/api_stock.py:141
#: rqalpha/mod/rqalpha_mod_sys_accounts/api/api_stock.py:344
msgid "Order Creation Failed: [{order_book_id}] No market data"
msgstr ""

Expand Down Expand Up @@ -247,41 +247,16 @@ msgstr ""
msgid "deprecated parameter[bar_dict] in before_trading function."
msgstr ""

#: rqalpha/data/bundle.py:460
msgid ""
"RQAlpha already supports backtesting using futures historical margins and"
" rates, please upgrade RQDatac to version 2.11.12 and above to use it"
msgstr ""

#: rqalpha/data/bundle.py:470 rqalpha/data/bundle.py:531
msgid ""
"Futures historical trading parameters data is being updated, please "
"wait......"
msgstr ""

#: rqalpha/data/bundle.py:522 rqalpha/data/bundle.py:706
#: rqalpha/data/bundle.py:522
msgid ""
"File {} update failed, if it is using, please update later, or you can "
"delete then update again"
msgstr ""

#: rqalpha/data/base_data_source/data_source.py:140
msgid ""
"RQDatac is not installed, "
"\"config.base.futures_time_series_trading_parameters\" will be disabled."
msgstr ""

#: rqalpha/data/base_data_source/data_source.py:145
msgid ""
"RQDatac does not have permission to obtain futures histrical trading "
"parameters, \"config.base.futures_time_series_trading_parameters\" will "
"be disabled."
msgstr ""

#: rqalpha/data/base_data_source/storages.py:81
msgid ""
"Your bundle data is too old, please use 'rqalpha update-bundle' or "
"'rqalpha download-bundle' to update it to lastest before using"
"The bundle data you are using is too old, please update it to lastest "
"before using"
msgstr ""

#: rqalpha/data/base_data_source/storages.py:97
Expand Down Expand Up @@ -337,8 +312,8 @@ msgid ""
msgstr ""

#: rqalpha/mod/rqalpha_mod_sys_accounts/api/api_future.py:50
#: rqalpha/mod/rqalpha_mod_sys_accounts/api/api_stock.py:112
#: rqalpha/mod/rqalpha_mod_sys_accounts/api/api_stock.py:157
#: rqalpha/mod/rqalpha_mod_sys_accounts/api/api_stock.py:113
#: rqalpha/mod/rqalpha_mod_sys_accounts/api/api_stock.py:158
msgid "Order Creation Failed: 0 order quantity, order_book_id={order_book_id}"
msgstr ""

Expand Down Expand Up @@ -371,39 +346,39 @@ msgid ""
"again!"
msgstr ""

#: rqalpha/mod/rqalpha_mod_sys_accounts/api/api_stock.py:119
#: rqalpha/mod/rqalpha_mod_sys_accounts/api/api_stock.py:120
msgid "insufficient cash, use all remaining cash({}) to create order"
msgstr ""

#: rqalpha/mod/rqalpha_mod_sys_accounts/api/api_stock.py:332
#: rqalpha/mod/rqalpha_mod_sys_accounts/api/api_stock.py:333
msgid ""
"function order_target_portfolio: invalid keys of target_portfolio, "
"expected order_book_ids or Instrument objects, got {} (type: {})"
msgstr ""

#: rqalpha/mod/rqalpha_mod_sys_accounts/api/api_stock.py:337
#: rqalpha/mod/rqalpha_mod_sys_accounts/api/api_stock.py:338
msgid ""
"function order_target_portfolio: invalid instrument type, excepted "
"CS/ETF/LOF/INDX, got {}"
msgstr ""

#: rqalpha/mod/rqalpha_mod_sys_accounts/api/api_stock.py:351
#: rqalpha/mod/rqalpha_mod_sys_accounts/api/api_stock.py:352
msgid ""
"function order_target_portfolio: invalid values of target_portfolio, "
"excepted float between 0 and 1, got {} (key: {})"
msgstr ""

#: rqalpha/mod/rqalpha_mod_sys_accounts/api/api_stock.py:360
#: rqalpha/mod/rqalpha_mod_sys_accounts/api/api_stock.py:361
msgid "total percent should be lower than 1, current: {}"
msgstr ""

#: rqalpha/mod/rqalpha_mod_sys_accounts/api/api_stock.py:380
#: rqalpha/mod/rqalpha_mod_sys_accounts/api/api_stock.py:381
msgid ""
"Adjust position of {id_or_ins} Failed: Invalid close/open price "
"{close_price}/{open_price}"
msgstr ""

#: rqalpha/mod/rqalpha_mod_sys_accounts/api/api_stock.py:693
#: rqalpha/mod/rqalpha_mod_sys_accounts/api/api_stock.py:694
msgid "in get_dividend, start_date {} is later than the previous test day {}"
msgstr ""

Expand Down Expand Up @@ -455,31 +430,31 @@ msgstr ""
msgid "[sys_analyser] Generate report from strategy output file"
msgstr ""

#: rqalpha/mod/rqalpha_mod_sys_analyser/mod.py:113
#: rqalpha/mod/rqalpha_mod_sys_analyser/mod.py:111
msgid ""
"config 'base.benchmark' is deprecated, use 'mod.sys_analyser.benchmark' "
"instead"
msgstr ""

#: rqalpha/mod/rqalpha_mod_sys_analyser/mod.py:151
#: rqalpha/mod/rqalpha_mod_sys_analyser/mod.py:149
msgid "benchmark {} not exists, please entry correct order_book_id"
msgstr ""

#: rqalpha/mod/rqalpha_mod_sys_analyser/mod.py:163
#: rqalpha/mod/rqalpha_mod_sys_analyser/mod.py:161
msgid "benchmark {} missing data between backtest start date {} and end date {}"
msgstr ""

#: rqalpha/mod/rqalpha_mod_sys_analyser/mod.py:175
#: rqalpha/mod/rqalpha_mod_sys_analyser/mod.py:173
msgid ""
"benchmark {} available data start date {} >= backtest start date {} or "
"end date {} <= backtest end date {}"
msgstr ""

#: rqalpha/mod/rqalpha_mod_sys_analyser/mod.py:243
#: rqalpha/mod/rqalpha_mod_sys_analyser/mod.py:241
msgid "invalid init benchmark {}, should be in format 'order_book_id:weight'"
msgstr ""

#: rqalpha/mod/rqalpha_mod_sys_analyser/mod.py:248
#: rqalpha/mod/rqalpha_mod_sys_analyser/mod.py:246
msgid "invalid weight for instrument {order_book_id}: {weight}"
msgstr ""

Expand Down
5 changes: 5 additions & 0 deletions rqalpha/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ base:
forced_liquidation: true
# 是否开启期货历史交易参数进行回测,默认为 False
futures_time_series_trading_parameters: false
# 是否开启在回测过程中自动下载所需的 bundle 数据
# 当前支持数据:1. 盘前集合竞价成交量;2. 期货历史交易参数
auto_update_bundle: false
# 自动下载的 bundle 文件支持单独设置存储路径,若不设置则使用 data_bundle_path 路径
auto_update_bundle_path: ~


extra:
Expand Down
5 changes: 3 additions & 2 deletions rqalpha/data/base_data_source/data_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,15 +92,16 @@ def _p(name):
self._ins_id_or_sym_type_map = {} # type: Dict[str, INSTRUMENT_TYPE]
instruments = []

env = Environment.get_instance()
with open(_p('instruments.pk'), 'rb') as f:
for i in pickle.load(f):
if i["type"] == "Future" and Instrument.is_future_continuous_contract(i["order_book_id"]):
i["listed_date"] = datetime(1990, 1, 1)
instruments.append(Instrument(
i,
lambda i: self._future_info_store.get_tick_size(i),
lambda i, dt: self.get_futures_trading_parameters(i, dt).long_margin_ratio,
lambda i, dt: self.get_futures_trading_parameters(i, dt).short_margin_ratio
# lambda i, dt: env.data_proxy.get_futures_trading_parameters(i, dt).long_margin_ratio,
# lambda i, dt: env.data_proxy.get_futures_trading_parameters(i, dt).short_margin_ratio
))
for ins_type in self.DEFAULT_INS_TYPES:
self.register_instruments_store(InstrumentStore(instruments, ins_type))
Expand Down
31 changes: 16 additions & 15 deletions rqalpha/data/bundle.py
Original file line number Diff line number Diff line change
Expand Up @@ -490,28 +490,29 @@ def _auto_update_task(self, instrument: Instrument) -> None:
try:
with self._file_lock.acquire():
h5 = h5py.File(self._file, "a")
if order_book_id in h5 and 'trading_dt' in h5[order_book_id].dtype.names:
# 需要兼容此前的旧版数据,对字段名进行更新
if len(h5[order_book_id][:]) != 0:
last_date = datetime.datetime.strptime(str(h5[order_book_id][-1]['trading_dt']), "%Y%m%d").date()
if last_date >= self._end_date:
return
start_date = self._env.data_proxy._data_source.get_next_trading_date(last_date).date()
if start_date > self._end_date:
return
if order_book_id in h5 and h5[order_book_id].dtype.names:
if 'trading_dt' in h5[order_book_id].dtype.names:
# 需要兼容此前的旧版数据,对字段名进行更新
if len(h5[order_book_id][:]) != 0:
last_date = datetime.datetime.strptime(str(h5[order_book_id][-1]['trading_dt']), "%Y%m%d").date()
if last_date >= self._end_date:
return
start_date = self._env.data_proxy._data_source.get_next_trading_date(last_date).date()
if start_date > self._end_date:
return
else:
del h5[order_book_id]

arr = self._get_array(instrument, start_date)
if arr is None:
if order_book_id not in h5:
arr = np.array([])
h5.create_dataset(order_book_id, data=arr)
else:
if order_book_id in h5:
if 'trading_dt' in h5[order_book_id].dtype.names:
data = np.array(
[tuple(i) for i in chain(h5[order_book_id][:], arr)],
dtype=h5[order_book_id].dtype)
else:
data = arr
data = np.array(
[tuple(i) for i in chain(h5[order_book_id][:], arr)],
dtype=h5[order_book_id].dtype)
del h5[order_book_id]
h5.create_dataset(order_book_id, data=data)
else:
Expand Down
15 changes: 5 additions & 10 deletions rqalpha/model/instrument.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,9 @@ def _fix_date(ds, dflt=None) -> datetime:

__repr__ = property_repr

def __init__(self, dic, futures_tick_size_getter=None, futures_long_margin_ratio_getter=None, futures_short_margin_ratio_getter=None):
# type: (Dict, Optional[Callable[[Instrument], float]], Optional[Callable[[Instrument], float]], Optional[Callable[[Instrument], float]]) -> None
def __init__(self, dic: Dict, futures_tick_size_getter: Optional[Callable] = None, *args, **kwrags) -> None:
self.__dict__ = copy.copy(dic)
self._futures_tick_size_getter = futures_tick_size_getter
self._futures_long_margin_ratio_getter = futures_long_margin_ratio_getter
self._futures_short_margin_ratio_getter = futures_short_margin_ratio_getter

if "listed_date" in dic:
self.__dict__["listed_date"] = self._fix_date(dic["listed_date"])
Expand Down Expand Up @@ -446,20 +443,18 @@ def tick_size(self):
raise NotImplementedError

@lru_cache(8)
def get_long_margin_ratio(self, dt):
# type: (datetime.date) -> float
def get_long_margin_ratio(self, dt: datetime.date) -> float:
"""
获取多头保证金率(期货专用)
"""
return self._futures_long_margin_ratio_getter(self, dt)
return Environment.get_instance().data_proxy.get_futures_trading_parameters(self.order_book_id, dt).long_margin_ratio

@lru_cache(8)
def get_short_margin_ratio(self, dt):
# type: (datetime.date) -> float
def get_short_margin_ratio(self, dt: datetime.date) -> float:
"""
获取空头保证金率(期货专用)
"""
return self._futures_short_margin_ratio_getter(self, dt)
return Environment.get_instance().data_proxy.get_futures_trading_parameters(self.order_book_id, dt).short_margin_ratio

def calc_cash_occupation(self, price, quantity, direction, dt):
# type: (float, int, POSITION_DIRECTION, datetime.date) -> float
Expand Down
Binary file modified rqalpha/utils/translations/zh_Hans_CN/LC_MESSAGES/messages.mo
Binary file not shown.

0 comments on commit 451ff33

Please sign in to comment.