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 -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionintbarsHeld()intReturns the value of theentryIndexrecord component.doubleReturns the value of theentryPricerecord component.longReturns the value of theentryTimerecord component.final booleanIndicates whether some other object is "equal to" this one.intReturns the value of theexitIndexrecord component.doubleReturns the value of theexitPricerecord component.Returns the value of theexitReasonrecord component.longexitTime()Returns the value of theexitTimerecord component.final inthashCode()Returns a hash code value for this object.booleanisWin()doublepnl()Returns the value of thepnlrecord component.doublequantity()Returns the value of thequantityrecord component.doubleReturns the value of thereturnPctrecord component.symbol()Returns the value of thesymbolrecord component.final StringtoString()Returns a string representation of this record class.
-
Field Details
-
REASON_SIGNAL
- See Also:
-
REASON_STOP_LOSS
- See Also:
-
REASON_TAKE_PROFIT
- See Also:
-
REASON_END_OF_DATA
- See Also:
-
-
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 aTraderecord class.- Parameters:
symbol- the value for thesymbolrecord componententryIndex- the value for theentryIndexrecord componentexitIndex- the value for theexitIndexrecord componententryTime- the value for theentryTimerecord componentexitTime- the value for theexitTimerecord componententryPrice- the value for theentryPricerecord componentexitPrice- the value for theexitPricerecord componentquantity- the value for thequantityrecord componentpnl- the value for thepnlrecord componentreturnPct- the value for thereturnPctrecord componentexitReason- the value for theexitReasonrecord component
-
-
Method Details
-
isWin
public boolean isWin() -
barsHeld
public int barsHeld() -
toString
-
hashCode
-
equals
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 withObjects::equals(Object,Object); primitive components are compared with thecomparemethod from their corresponding wrapper classes. -
symbol
Returns the value of thesymbolrecord component.- Returns:
- the value of the
symbolrecord component
-
entryIndex
public int entryIndex()Returns the value of theentryIndexrecord component.- Returns:
- the value of the
entryIndexrecord component
-
exitIndex
public int exitIndex()Returns the value of theexitIndexrecord component.- Returns:
- the value of the
exitIndexrecord component
-
entryTime
public long entryTime()Returns the value of theentryTimerecord component.- Returns:
- the value of the
entryTimerecord component
-
exitTime
public long exitTime()Returns the value of theexitTimerecord component.- Returns:
- the value of the
exitTimerecord component
-
entryPrice
public double entryPrice()Returns the value of theentryPricerecord component.- Returns:
- the value of the
entryPricerecord component
-
exitPrice
public double exitPrice()Returns the value of theexitPricerecord component.- Returns:
- the value of the
exitPricerecord component
-
quantity
public double quantity()Returns the value of thequantityrecord component.- Returns:
- the value of the
quantityrecord component
-
pnl
public double pnl()Returns the value of thepnlrecord component.- Returns:
- the value of the
pnlrecord component
-
returnPct
public double returnPct()Returns the value of thereturnPctrecord component.- Returns:
- the value of the
returnPctrecord component
-
exitReason
Returns the value of theexitReasonrecord component.- Returns:
- the value of the
exitReasonrecord component
-