From 78334d7c3a3f96427313a202e5df83af3a5f788c Mon Sep 17 00:00:00 2001 From: EricWang Date: Sat, 24 Jun 2017 15:55:53 +0800 Subject: [PATCH] https://github.com/ricequant/rqalpha/issues/166 --- .../mod/rqalpha_mod_sys_accounts/__init__.py | 20 +++++++++++++++++++ rqalpha/mod/rqalpha_mod_sys_accounts/mod.py | 2 ++ .../position_model/stock_position.py | 4 ++-- 3 files changed, 24 insertions(+), 2 deletions(-) diff --git a/rqalpha/mod/rqalpha_mod_sys_accounts/__init__.py b/rqalpha/mod/rqalpha_mod_sys_accounts/__init__.py index 96320e4a2..a59ca1928 100644 --- a/rqalpha/mod/rqalpha_mod_sys_accounts/__init__.py +++ b/rqalpha/mod/rqalpha_mod_sys_accounts/__init__.py @@ -14,7 +14,27 @@ # See the License for the specific language governing permissions and # limitations under the License. +import click +from rqalpha import cli + + +__config__ = { + # 开启/关闭 股票 T+1, 默认开启 + "stock_t1": True +} + def load_mod(): from .mod import AccountMod return AccountMod() + + +cli_prefix = "mod__sys_accounts__" + +cli.commands['run'].params.append( + click.Option( + ('--stock-t1/--no-stock-t1', cli_prefix + "stock_t1"), + default=None, + help="[sys_accounts] enable/disable stock T+1" + ) +) \ No newline at end of file diff --git a/rqalpha/mod/rqalpha_mod_sys_accounts/mod.py b/rqalpha/mod/rqalpha_mod_sys_accounts/mod.py index 4c1fa81ac..7eceb1ece 100644 --- a/rqalpha/mod/rqalpha_mod_sys_accounts/mod.py +++ b/rqalpha/mod/rqalpha_mod_sys_accounts/mod.py @@ -28,6 +28,8 @@ class AccountMod(AbstractMod): def start_up(self, env, mod_config): + StockPosition.stock_t1 = mod_config.stock_t1 + # 注入 Account env.set_account_model(DEFAULT_ACCOUNT_TYPE.STOCK.name, StockAccount) env.set_account_model(DEFAULT_ACCOUNT_TYPE.FUTURE.name, FutureAccount) diff --git a/rqalpha/mod/rqalpha_mod_sys_accounts/position_model/stock_position.py b/rqalpha/mod/rqalpha_mod_sys_accounts/position_model/stock_position.py index 16780af1f..b1ebb07bb 100644 --- a/rqalpha/mod/rqalpha_mod_sys_accounts/position_model/stock_position.py +++ b/rqalpha/mod/rqalpha_mod_sys_accounts/position_model/stock_position.py @@ -30,6 +30,7 @@ class StockPosition(BasePosition): "sold_value", "average_cost" ] + stock_t1 = True def __init__(self, order_book_id): super(StockPosition, self).__init__(order_book_id) @@ -63,8 +64,7 @@ def apply_trade(self, trade): self._avg_price = (self._avg_price * self._quantity + trade.last_quantity * trade.last_price) / ( self._quantity + trade.last_quantity) self._quantity += trade.last_quantity - - if self._order_book_id not in {'510900.XSHG', '513030.XSHG', '513100.XSHG', '513500.XSHG'}: + if self.stock_t1 and self._order_book_id not in {'510900.XSHG', '513030.XSHG', '513100.XSHG', '513500.XSHG'}: # 除了上述 T+0 基金,其他都是 T+1 self._non_closable += trade.last_quantity else: