pybroker.config module

Contains configuration options.

class StrategyConfig(initial_cash: float = 100000, fee_mode: FeeMode | Callable[[FeeInfo], Decimal] | None = None, fee_amount: float = 0, subtract_fees: bool = False, enable_fractional_shares: bool = False, round_fill_price: bool = True, max_long_positions: int | None = None, max_short_positions: int | None = None, buy_delay: int = 1, sell_delay: int = 1, bootstrap_samples: int = 10000, bootstrap_sample_size: int = 1000, exit_on_last_bar: bool = False, exit_cover_fill_price: PriceType | Callable[[str, BarData], int | float | Decimal] = PriceType.MIDDLE, exit_sell_fill_price: PriceType | Callable[[str, BarData], int | float | Decimal] = PriceType.MIDDLE, bars_per_year: int | None = None, return_signals: bool = False, round_test_result: bool = True)[source]

Bases: object

Configuration options for pybroker.strategy.Strategy.

initial_cash

Starting cash of strategy.

Type:

float

fee_mode

pybroker.common.FeeMode for calculating brokerage fees. Supports one of:

  • ORDER_PERCENT: Fee is a percentage of order amount.

  • PER_ORDER: Fee is a constant amount per order.

  • PER_SHARE: Fee is a constant amount per share in order.

  • Callable[[FeeInfo], Decimal]: Fees are calculated using a

    custom Callable that is passed pybroker.common.FeeInfo.

  • None: Fees are disabled (default).

Type:

pybroker.common.FeeMode | Callable[[pybroker.common.FeeInfo], decimal.Decimal] | None

fee_amount

Brokerage fee amount.

Type:

float

subtract_fees

Whether to subtract fees from the cash balance after an order is filled. Defaults to False.

Type:

bool

enable_fractional_shares

Whether to enable trading fractional shares. Set to True for crypto trading. Defaults to False.

Type:

bool

round_fill_price

Whether to round fill prices to the nearest cent. Defaults to True.

Type:

bool

max_long_positions

Maximum number of long positions that can be held at any time in pybroker.portfolio.Portfolio. Unlimited when None. Defaults to None.

Type:

int | None

max_short_positions

Maximum number of short positions that can be held at any time in pybroker.portfolio.Portfolio. Unlimited when None. Defaults to None.

Type:

int | None

buy_delay

Number of bars before placing an order for a buy signal. The default value of 1 places a buy order on the next bar. Must be > 0.

Type:

int

sell_delay

Number of bars before placing an order for a sell signal. The default value of 1 places a sell order on the next bar. Must be > 0.

Type:

int

bootstrap_samples

Number of samples used to compute boostrap metrics. Defaults to 10_000.

Type:

int

bootstrap_sample_size

Size of each random sample used to compute bootstrap metrics. Defaults to 1_000.

Type:

int

exit_on_last_bar

Whether to automatically exit any open positions on the last bar of data available for a symbol. Defaults to False.

Type:

bool

exit_cover_fill_price

Fill price for covering an open short position when exit_on_last_bar is True. Defaults to pybroker.common.PriceType.MIDDLE.

Type:

pybroker.common.PriceType | Callable[[str, pybroker.common.BarData], int | float | decimal.Decimal]

exit_sell_fill_price

Fill price for selling an open long position when exit_on_last_bar is True. Defaults to pybroker.common.PriceType.MIDDLE.

Type:

pybroker.common.PriceType | Callable[[str, pybroker.common.BarData], int | float | decimal.Decimal]

bars_per_year

Number of observations per year that will be used to annualize evaluation metrics. For example, a value of 252 would be used to annualize the Sharpe Ratio for daily returns.

Type:

int | None

return_signals

When True then bar data, indicator data, and model predictions are returned with pybroker.strategy.TestResult. Defaults to False.

Type:

bool

round_test_result

When True, round values in pybroker.strategy.TestResult up to the nearest cent. Defaults to True.

Type:

bool