Skip to content

Commit 701f1bb

Browse files
committed
Remove redundant subtract_fees config option
1 parent b615898 commit 701f1bb

File tree

6 files changed

+12
-14
lines changed

6 files changed

+12
-14
lines changed

src/pybroker/config.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,6 @@ class StrategyConfig:
8484
default=None
8585
)
8686
fee_amount: float = field(default=0)
87-
subtract_fees: bool = field(default=False)
8887
enable_fractional_shares: bool = field(default=False)
8988
round_fill_price: bool = field(default=True)
9089
position_mode: PositionMode = field(default=PositionMode.DEFAULT)

src/pybroker/indicator.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,15 @@ def _to_bar_data(df: pd.DataFrame) -> BarData:
4747
f"DataFrame is missing required column: {col.value}"
4848
)
4949
return BarData(
50-
**{col.value: df[col.value].to_numpy(copy=True) for col in required_cols},
50+
**{
51+
col.value: df[col.value].to_numpy(copy=True)
52+
for col in required_cols
53+
},
5154
**{
5255
col.value: (
53-
df[col.value].to_numpy(copy=True) if col.value in df.columns else None
56+
df[col.value].to_numpy(copy=True)
57+
if col.value in df.columns
58+
else None
5459
)
5560
for col in (DataCol.VOLUME, DataCol.VWAP)
5661
}, # type: ignore[arg-type]

src/pybroker/portfolio.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -340,8 +340,6 @@ class Portfolio:
340340
cash: Starting cash balance.
341341
fee_mode: Brokerage fee mode.
342342
fee_amount: Brokerage fee amount.
343-
subtract_fees: Whether to subtract fees from the cash balance after an
344-
order is filled.
345343
enable_fractional_shares: Whether to enable trading fractional shares.
346344
position_mode: Position mode for :class:`.Portfolio`.
347345
max_long_positions: Maximum number of long :class:`.Position`\ s that
@@ -358,7 +356,6 @@ class Portfolio:
358356
with the unrealized PnL of all open short positions.
359357
fees: Current brokerage fees.
360358
fee_amount: Brokerage fee amount.
361-
subtract_fees: Whether to subtract fees from the cash balance.
362359
enable_fractional_shares: Whether to enable trading fractional shares.
363360
orders: ``deque`` of all filled orders, sorted in ascending
364361
chronological order.
@@ -384,7 +381,6 @@ def __init__(
384381
Union[FeeMode, Callable[[FeeInfo], Decimal], None]
385382
] = None,
386383
fee_amount: Optional[float] = None,
387-
subtract_fees: bool = False,
388384
enable_fractional_shares: bool = False,
389385
position_mode: PositionMode = PositionMode.DEFAULT,
390386
max_long_positions: Optional[int] = None,
@@ -397,7 +393,6 @@ def __init__(
397393
self._fee_amount: Optional[Decimal] = (
398394
None if fee_amount is None else to_decimal(fee_amount)
399395
)
400-
self._subtract_fees = subtract_fees
401396
self._enable_fractional_shares = enable_fractional_shares
402397
self._position_mode = position_mode
403398
self.equity: Decimal = self.cash
@@ -513,7 +508,7 @@ def _add_order(
513508
)
514509
self.orders.append(order)
515510
self.fees += fees
516-
if self._subtract_fees:
511+
if self._fee_mode is not None:
517512
self.cash -= fees
518513
return order
519514

src/pybroker/scope.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,9 @@ def fetch(
363363
if ind_sym not in self._indicator_data:
364364
raise ValueError(f"Indicator {name!r} not found for {symbol}.")
365365
ind_series = self._indicator_data[ind_sym]
366-
ind_data = ind_series[ind_series.index.isin(self._filter_dates)].to_numpy(copy=True)
366+
ind_data = ind_series[
367+
ind_series.index.isin(self._filter_dates)
368+
].to_numpy(copy=True)
367369
self._sym_inds[ind_sym] = ind_data
368370
return ind_data[:end_index]
369371

src/pybroker/strategy.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1249,7 +1249,6 @@ def walkforward(
12491249
self._config.initial_cash,
12501250
self._config.fee_mode,
12511251
self._config.fee_amount,
1252-
self._config.subtract_fees,
12531252
self._fractional_shares_enabled(),
12541253
self._config.position_mode,
12551254
self._config.max_long_positions,

tests/test_portfolio.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -808,9 +808,7 @@ def test_buy_and_sell_when_fees(
808808

809809

810810
def test_subtract_fees():
811-
portfolio = Portfolio(
812-
3, FeeMode.PER_ORDER, fee_amount=1, subtract_fees=True
813-
)
811+
portfolio = Portfolio(3, FeeMode.PER_ORDER, fee_amount=1)
814812
order = portfolio.buy(DATE_1, SYMBOL_1, shares=1, fill_price=1)
815813
assert_order(
816814
order=order,

0 commit comments

Comments
 (0)