InitialRiskPositionSizer

class qf_lib.backtesting.position_sizer.initial_risk_position_sizer.InitialRiskPositionSizer(broker: Broker, data_provider: DataProvider, order_factory: OrderFactory, signals_register: SignalsRegister, initial_risk: float, max_target_percentage: Optional[float] = None, tolerance_percentage: float = 0.0)[source]

Bases: PositionSizer

This PositionSizer converts signals to orders using Initial Risk value that is predefined in the position sizer. Each signal will be sized based on fraction_at_risk. position size = Initial_Risk / signal.fraction_at_risk

Parameters:
  • broker (Broker) –

  • data_provider (DataProvider) –

  • order_factory (OrderFactory) –

  • initial_risk (float) – should be set once for all signals. It corresponds to the value that we are willing to lose on single trade. For example: initial_risk = 0.02, means that we are willing to lose 2% of portfolio value in single trade

  • max_target_percentage (float) – max leverage that is accepted by the position sizer. if None, no max_target_percentage is used.

  • tolerance_percentage (float) – percentage used by OrdersFactory target_percent_orders function; it defines tolerance to the target percentages