Record Class Trade

java.lang.Object
java.lang.Record
com.quantfinlib.backtest.Trade

public record Trade(String symbol, int entryIndex, int exitIndex, long entryTime, long exitTime, double entryPrice, double exitPrice, double quantity, double pnl, double returnPct, String exitReason) extends Record
A completed round-trip trade. pnl is net of commissions; returnPct is relative to capital committed at entry.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final String
     
    static final String
     
    static final String
     
    static final String
     
  • Constructor Summary

    Constructors
    Constructor
    Description
    Trade(String symbol, int entryIndex, int exitIndex, long entryTime, long exitTime, double entryPrice, double exitPrice, double quantity, double pnl, double returnPct, String exitReason)
    Creates an instance of a Trade record class.
  • Method Summary

    Modifier and Type
    Method
    Description
    int
     
    int
    Returns the value of the entryIndex record component.
    double
    Returns the value of the entryPrice record component.
    long
    Returns the value of the entryTime record component.
    final boolean
    Indicates whether some other object is "equal to" this one.
    int
    Returns the value of the exitIndex record component.
    double
    Returns the value of the exitPrice record component.
    Returns the value of the exitReason record component.
    long
    Returns the value of the exitTime record component.
    final int
    Returns a hash code value for this object.
    boolean
     
    double
    pnl()
    Returns the value of the pnl record component.
    double
    Returns the value of the quantity record component.
    double
    Returns the value of the returnPct record component.
    Returns the value of the symbol record component.
    final String
    Returns a string representation of this record class.

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Field Details

  • Constructor Details

    • Trade

      public Trade(String symbol, int entryIndex, int exitIndex, long entryTime, long exitTime, double entryPrice, double exitPrice, double quantity, double pnl, double returnPct, String exitReason)
      Creates an instance of a Trade record class.
      Parameters:
      symbol - the value for the symbol record component
      entryIndex - the value for the entryIndex record component
      exitIndex - the value for the exitIndex record component
      entryTime - the value for the entryTime record component
      exitTime - the value for the exitTime record component
      entryPrice - the value for the entryPrice record component
      exitPrice - the value for the exitPrice record component
      quantity - the value for the quantity record component
      pnl - the value for the pnl record component
      returnPct - the value for the returnPct record component
      exitReason - the value for the exitReason record component
  • Method Details

    • isWin

      public boolean isWin()
    • barsHeld

      public int barsHeld()
    • 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.
    • symbol

      public String symbol()
      Returns the value of the symbol record component.
      Returns:
      the value of the symbol record component
    • entryIndex

      public int entryIndex()
      Returns the value of the entryIndex record component.
      Returns:
      the value of the entryIndex record component
    • exitIndex

      public int exitIndex()
      Returns the value of the exitIndex record component.
      Returns:
      the value of the exitIndex record component
    • entryTime

      public long entryTime()
      Returns the value of the entryTime record component.
      Returns:
      the value of the entryTime record component
    • exitTime

      public long exitTime()
      Returns the value of the exitTime record component.
      Returns:
      the value of the exitTime record component
    • entryPrice

      public double entryPrice()
      Returns the value of the entryPrice record component.
      Returns:
      the value of the entryPrice record component
    • exitPrice

      public double exitPrice()
      Returns the value of the exitPrice record component.
      Returns:
      the value of the exitPrice record component
    • quantity

      public double quantity()
      Returns the value of the quantity record component.
      Returns:
      the value of the quantity record component
    • pnl

      public double pnl()
      Returns the value of the pnl record component.
      Returns:
      the value of the pnl record component
    • returnPct

      public double returnPct()
      Returns the value of the returnPct record component.
      Returns:
      the value of the returnPct record component
    • exitReason

      public String exitReason()
      Returns the value of the exitReason record component.
      Returns:
      the value of the exitReason record component