Skip to content

Commit

Permalink
支持使用结算价结算期货
Browse files Browse the repository at this point in the history
  • Loading branch information
Zhou-JiaJun committed Feb 21, 2023
1 parent 3c5a50a commit 9a1d319
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
12 changes: 11 additions & 1 deletion rqalpha/mod/rqalpha_mod_sys_accounts/__init__.py
Expand Up @@ -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",
}


Expand Down Expand Up @@ -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"
)
)
4 changes: 4 additions & 0 deletions rqalpha/mod/rqalpha_mod_sys_accounts/mod.py
Expand Up @@ -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
Expand Down
12 changes: 12 additions & 0 deletions rqalpha/mod/rqalpha_mod_sys_accounts/position_model.py
Expand Up @@ -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__ = (
Expand Down

0 comments on commit 9a1d319

Please sign in to comment.