Skip to content

Commit

Permalink
https://github.com/ricequant/rqalpha/issues/166
Browse files Browse the repository at this point in the history
  • Loading branch information
wh1100717 committed Jun 24, 2017
1 parent 234d207 commit 78334d7
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
20 changes: 20 additions & 0 deletions rqalpha/mod/rqalpha_mod_sys_accounts/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
)
2 changes: 2 additions & 0 deletions rqalpha/mod/rqalpha_mod_sys_accounts/mod.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit 78334d7

Please sign in to comment.