Skip to content

Commit dd28058

Browse files
committed
Refactor position model to utilize instance variable for instrument checks, improving code clarity and consistency. Simplify order_target_portfolio_smart function call by removing unnecessary parentheses.
1 parent bcbc4cc commit dd28058

File tree

2 files changed

+3
-6
lines changed

2 files changed

+3
-6
lines changed

rqalpha/mod/rqalpha_mod_sys_accounts/api/order_target_portfolio.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -303,8 +303,7 @@ def _get_style(order_book_id) -> OrderStyle:
303303
target_weights=Series(target_weights),
304304
valuation_prices=prices,
305305
env=env
306-
)(
307-
)
306+
)()
308307

309308
orders = []
310309

rqalpha/mod/rqalpha_mod_sys_accounts/position_model.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -166,9 +166,8 @@ def settlement(self, trading_date):
166166
if self.direction != POSITION_DIRECTION.LONG:
167167
raise RuntimeError("direction of stock position {} is not supposed to be short".format(self._order_book_id))
168168
next_date = self._env.data_proxy.get_next_trading_date(trading_date, trading_calendar_type=self.calendar_type)
169-
instrument = self._env.data_proxy.instrument_not_none(self._order_book_id)
170169
delta_cash = 0
171-
if instrument.de_listed_at(next_date):
170+
if self._instrument.de_listed_at(next_date):
172171
try:
173172
transform_data = self._env.data_proxy.get_share_transformation(self._order_book_id)
174173
except NotImplementedError:
@@ -372,14 +371,13 @@ def settlement(self, trading_date):
372371
if self._quantity == 0:
373372
return delta_cash
374373
data_proxy = self._env.data_proxy
375-
instrument = data_proxy.instrument(self._order_book_id)
376374
next_date = data_proxy.get_next_trading_date(trading_date)
377375
if self._env.config.mod.sys_accounts.futures_settlement_price_type == "settlement":
378376
# 逐日盯市按照结算价结算
379377
self._last_price = self._env.data_proxy.get_settle_price(self._order_book_id, self._env.trading_dt)
380378
delta_cash += self.equity
381379
self._avg_price = self.last_price
382-
if instrument.de_listed_at(next_date):
380+
if self._instrument.de_listed_at(next_date):
383381
user_system_log.warn(_(u"{order_book_id} is expired, close all positions by system").format(
384382
order_book_id=self._order_book_id
385383
))

0 commit comments

Comments
 (0)