Record Class BacktestConfig

java.lang.Object
java.lang.Record
com.quantfinlib.backtest.BacktestConfig
Record Components:
fillPolicy - when a signal decided at a bar's close fills (default FillPolicy.NEXT_OPEN)

public record BacktestConfig(double initialCapital, double commissionRate, double slippageRate, double stopLossPct, double takeProfitPct, int periodsPerYear, FillPolicy fillPolicy) extends Record
Backtest execution parameters. Rates are fractions (0.001 = 10 bps). slippageRate is applied to the fill price against the trader (buys fill higher, sells lower) and stands for half-spread plus implementation shortfall; commissionRate is charged on notional. stopLossPct/takeProfitPct of 0 disable the respective check; a strategy's own stop/take-profit settings override zeros here.
  • Constructor Details

    • BacktestConfig

      public BacktestConfig(double initialCapital, double commissionRate, double slippageRate, double stopLossPct, double takeProfitPct, int periodsPerYear, FillPolicy fillPolicy)
      Creates an instance of a BacktestConfig record class.
      Parameters:
      initialCapital - the value for the initialCapital record component
      commissionRate - the value for the commissionRate record component
      slippageRate - the value for the slippageRate record component
      stopLossPct - the value for the stopLossPct record component
      takeProfitPct - the value for the takeProfitPct record component
      periodsPerYear - the value for the periodsPerYear record component
      fillPolicy - the value for the fillPolicy record component
    • BacktestConfig

      public BacktestConfig(double initialCapital, double commissionRate, double slippageRate, double stopLossPct, double takeProfitPct, int periodsPerYear)
      Next-open fills.
  • Method Details

    • defaults

      public static BacktestConfig defaults()
      Daily-bar defaults matching TradeCostModel.institutional(1, 2, 1, …) without impact: 1 bp commission, 3 bp slippage (2 bp half-spread plus 1 bp shortfall), next-open fills, 100,000 capital.
    • frictionless

      public static BacktestConfig frictionless()
      No commission, no slippage, next-open fills: for unit tests and attribution of costs.
    • withInitialCapital

      public BacktestConfig withInitialCapital(double capital)
    • withCommission

      public BacktestConfig withCommission(double rate)
    • withSlippage

      public BacktestConfig withSlippage(double rate)
    • withStopLoss

      public BacktestConfig withStopLoss(double pct)
    • withTakeProfit

      public BacktestConfig withTakeProfit(double pct)
    • withFillPolicy

      public BacktestConfig withFillPolicy(FillPolicy policy)
    • toString

      public final String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. Reference components are compared with Objects::equals(Object,Object); primitive components are compared with the compare method from their corresponding wrapper classes.
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • initialCapital

      public double initialCapital()
      Returns the value of the initialCapital record component.
      Returns:
      the value of the initialCapital record component
    • commissionRate

      public double commissionRate()
      Returns the value of the commissionRate record component.
      Returns:
      the value of the commissionRate record component
    • slippageRate

      public double slippageRate()
      Returns the value of the slippageRate record component.
      Returns:
      the value of the slippageRate record component
    • stopLossPct

      public double stopLossPct()
      Returns the value of the stopLossPct record component.
      Returns:
      the value of the stopLossPct record component
    • takeProfitPct

      public double takeProfitPct()
      Returns the value of the takeProfitPct record component.
      Returns:
      the value of the takeProfitPct record component
    • periodsPerYear

      public int periodsPerYear()
      Returns the value of the periodsPerYear record component.
      Returns:
      the value of the periodsPerYear record component
    • fillPolicy

      public FillPolicy fillPolicy()
      Returns the value of the fillPolicy record component.
      Returns:
      the value of the fillPolicy record component