pybroker.config module
Contains configuration options.
- class StrategyConfig(initial_cash: float = 100000, fee_mode: FeeMode | Callable[[FeeInfo], Decimal] | None = None, fee_amount: float = 0, enable_fractional_shares: bool = False, round_fill_price: bool = True, position_mode: PositionMode = PositionMode.DEFAULT, max_long_positions: int | None = None, max_short_positions: int | None = None, buy_delay: int = 1, sell_delay: int = 1, bootstrap_samples: int = 10000, 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, return_stops: bool = False, round_test_result: bool = True, leverage: float = 1.0, interest_rate: float = 0.0, record_portfolio_bars: bool = False, record_position_bars: bool = False)[source]
Bases:
objectConfiguration options for
pybroker.strategy.Strategy.- fee_mode
pybroker.common.FeeModefor 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 acustom
Callablethat is passedpybroker.common.FeeInfo.
None: Fees are disabled (default).
- Type:
pybroker.common.FeeMode | Callable[[pybroker.common.FeeInfo], decimal.Decimal] | None
Whether to enable trading fractional shares. Set to
Truefor crypto trading. Defaults toFalse.- Type:
- position_mode
Position mode for
pybroker.strategy.Strategy. Supports one of:DEFAULT: Long and short positions.LONG_ONLY: Long-only positions.SHORT_ONLY: Short-only positions.
- buy_delay
Number of bars before placing an order for a buy signal. The default value of
1places a buy order on the next bar. Must be >0.- Type:
- sell_delay
Number of bars before placing an order for a sell signal. The default value of
1places a sell order on the next bar. Must be >0.- Type:
- bootstrap_samples
Number of samples used to compute boostrap metrics. Defaults to
10_000.- Type:
- 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:
- exit_cover_fill_price
Fill price for covering an open short position when
exit_on_last_barisTrue. Defaults topybroker.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_barisTrue. Defaults topybroker.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
252would be used to annualize the Sharpe Ratio for daily returns. Also sets the accrual period forinterest_rate, and is therefore required wheninterest_rateis set.- Type:
int | None
- return_signals
When
True, then bar data, indicator data, and model predictions are returned withpybroker.strategy.TestResult. Signals contain base-timeframe values only; an interval-bound indicator or model appears only when'base'is included in its binding. Defaults toFalse.- Type:
- return_stops
When
True, then stop values are returned withpybroker.strategy.TestResult. Defaults toFalse.- Type:
- round_test_result
When
True, round values inpybroker.strategy.TestResultup to the nearest cent. Defaults toTrue.- Type:
- leverage
Account leverage multiplier for buying power on long and short positions. Default
1.0uses cash-only buying.2.0allows positions up to 2x equity. Must be>= 1.0.- Type:
- interest_rate
Annual interest rate, in percent, applied to net cash balance (
cash - margin_loan). Charges interest when net cash is negative and credits interest when net cash is positive. Accrues once per bar atinterest_rate / bars_per_year, sobars_per_yearis required when this is set. Defaults to0(disabled).- Type:
- record_portfolio_bars
When
True, append fullpybroker.portfolio.PortfolioBarsnapshots topybroker.portfolio.Portfolio.barson every bar. WhenFalse(default), per-bar metrics are stored in a compact buffer used forpybroker.strategy.TestResultandpybroker.eval.EvalMetrics.- Type:
- record_position_bars
When
True, append fullpybroker.portfolio.PositionBarsnapshots topybroker.portfolio.Portfolio.position_barson every bar. WhenFalse(default),pybroker.strategy.TestResult.positionsis empty.- Type: