diff --git a/rqalpha/mod/rqalpha_mod_sys_accounts/__init__.py b/rqalpha/mod/rqalpha_mod_sys_accounts/__init__.py index d475788e7..9b845e5da 100644 --- a/rqalpha/mod/rqalpha_mod_sys_accounts/__init__.py +++ b/rqalpha/mod/rqalpha_mod_sys_accounts/__init__.py @@ -32,7 +32,9 @@ # 融资利率/年 "financing_rate": 0.00, # 是否开启融资可买入股票的限制 - "financing_stocks_restriction_enabled": False + "financing_stocks_restriction_enabled": False, + # 逐日盯市结算价: settlement/close + "futures_settlement_price_type": "close", } @@ -79,3 +81,11 @@ def load_mod(): help="[sys_accounts] enable stock shorting" ) ) + +cli.commands['run'].params.append( + click.Option( + ('--futures-settlement-price-type', cli_prefix + 'futures_settlement_price_type'), + default="close", + help="[sys_accounts] future settlement price" + ) +) diff --git a/rqalpha/mod/rqalpha_mod_sys_accounts/mod.py b/rqalpha/mod/rqalpha_mod_sys_accounts/mod.py index 04504919f..48901c773 100644 --- a/rqalpha/mod/rqalpha_mod_sys_accounts/mod.py +++ b/rqalpha/mod/rqalpha_mod_sys_accounts/mod.py @@ -50,6 +50,10 @@ def start_up(self, env, mod_config): elif mod_config.financing_rate < 0: raise ValueError("sys_accounts financing_rate must >= 0") + futures_settlement_price_types = ["settlement", "close"] + if mod_config.futures_settlement_price_type not in futures_settlement_price_types: + raise ValueError("sys_accounts futures_settlement_price_type in {}".format(futures_settlement_price_types)) + if DEFAULT_ACCOUNT_TYPE.FUTURE in env.config.base.accounts: # 注入期货API # noinspection PyUnresolvedReferences diff --git a/rqalpha/mod/rqalpha_mod_sys_accounts/position_model.py b/rqalpha/mod/rqalpha_mod_sys_accounts/position_model.py index 479db77ca..2df5a9465 100644 --- a/rqalpha/mod/rqalpha_mod_sys_accounts/position_model.py +++ b/rqalpha/mod/rqalpha_mod_sys_accounts/position_model.py @@ -295,9 +295,21 @@ def settlement(self, trading_date): order_book_id=self._order_book_id )) self._quantity = self._old_quantity = 0 + + if self._env.config.mod.sys_accounts.futures_settlement_price_type == "settlement": + # 逐日盯市按照结算价结算 + self._last_price = self._env.data_proxy.get_settle_price(self._order_book_id, self._env.calendar_dt) + self._prev_close = self._env.data_proxy.get_prev_settlement(self._order_book_id, self._env.calendar_dt) + self._avg_price = self.last_price return delta_cash + def before_trading(self, trading_date): + # type: (date) -> float + delta = super().before_trading(trading_date) + self._last_price = None + return delta + class StockPositionProxy(PositionProxy): __repr_properties__ = (