Search Framework:
BrokerPosition
Namespace: WealthLab.Backtest
Parent: Object

The BrokerPosition class represents a Position held in a BrokerAccount. It contains the Position's symbol, type, quantity, basis price, current price, security type, Strategy association, and values used by WealthLab's Live Position and Portfolio Sync processing.

Constructors
BrokerPosition
public BrokerPosition(BrokerAccount ba)

Creates a BrokerPosition associated with the supplied BrokerAccount.



Derived Properties
Profit
public double Profit

Returns the current profit or loss of the Position based on CurrentPrice, BasisPrice, Quantity, PositionType, and the security's point-value multiplier. For Long Positions, profit is based on CurrentPrice - BasisPrice. For Short Positions, it is based on BasisPrice - CurrentPrice.


ProfitPct
public double ProfitPct

Returns the current profit or loss as a percentage of BasisValue. Returns zero if Value is zero.


Value
public double Value

Returns the current value of the Position. WealthLab calculates the value from Quantity and BasisPrice and then applies the Position's Profit. Options use a multiplier of 100.



Display Properties
BasisPriceDisplay
public string BasisPriceDisplay

Returns BasisPrice formatted using the appropriate number of decimal places for the Symbol and Broker.


CurrentPriceDisplay
public string CurrentPriceDisplay

Returns CurrentPrice formatted using the appropriate number of decimal places for the Symbol and Broker.


EntryDateDisplay
public string EntryDateDisplay

Returns EntryDate formatted as a short date string. Returns an empty string if EntryDate is null.


QuantityDisplay
public string QuantityDisplay

Returns Quantity formatted using the number of decimal places appropriate for the Symbol and Broker. If the Quantity itself contains more decimal places than the configured quantity precision, WealthLab preserves those additional decimal places.


StrategyDisplay
public string StrategyDisplay

Returns the associated Strategy's QualifiedName. Returns an empty string if Strategy is null.



Live Position Information
EntryDate
public DateTime? EntryDate

Gets or sets the Position's entry date. WealthLab uses this property when maintaining Live Positions and Strategy Positions for Portfolio Sync.


ExitDate
public DateTime? ExitDate

Gets or sets the Position's exit date. WealthLab uses this property when maintaining Live Positions for Portfolio Sync.


ExitPrice
public double? ExitPrice

Gets or sets the Position's exit price. A null ExitPrice indicates that the Position is still open.


IsOpen
public bool IsOpen

Returns true when ExitPrice is null, indicating that the Position is still open.



Members
Account
public BrokerAccount Account

Gets or sets the BrokerAccount associated with this Position.


BasisPrice
public double BasisPrice

Gets or sets the Position's basis price, representing the price at which the shares or contracts were acquired.


BasisValue
public double BasisValue

Returns the total basis value of the Position, calculated from BasisPrice, Quantity, and the security's point-value multiplier.


CancelationCode
public int? CancelationCode

Gets or sets an optional cancellation code associated with the Position. WealthLab uses this value when processing certain orphan Position exits.


CurrentAndBasisPrice
public double CurrentAndBasisPrice

Returns CurrentPrice when CurrentPrice is zero; otherwise returns BasisPrice. WealthLab uses this property for display and visibility purposes.


CurrentPrice
public double CurrentPrice

Gets or sets the most recent price of the Position's underlying Symbol as reported by the Broker. The default value is Double.NaN.


PositionType
public PositionType PositionType

Gets or sets the Position type, typically PositionType.Long or PositionType.Short. Possible values are:

  • Long
  • Short

Quantity
public double Quantity

Gets or sets the number of shares, contracts, or other units held in the Position.


SecurityType
public SecurityType SecurityType

Gets or sets the security type represented by the Position. Possible values are:

  • Stock
  • ETF
  • Index
  • Fund
  • Future
  • Option
  • Forex
  • Crypto
  • Bond
  • SSF
  • CFD
  • ContinuousFuture
  • FuturesOption
  • Unknown
  • Combo

SignalDate
public DateTime SignalDate

Gets or sets the Signal Date associated with the Position. WealthLab uses this value when processing certain orphan Position exits.


Strategy
public Strategy Strategy

Gets or sets the Strategy associated with the Position. Strategy Positions maintained internally by WealthLab use this property to identify the Strategy responsible for the Position.


Symbol
public string Symbol

Gets or sets the Position's symbol. When assigned, WealthLab determines applicable security information for the symbol. Option symbols are assigned a SecurityType of Option and a multiplier of 100. When SymbolInfo is available, the security's PointValue and SecurityType are used for Position calculations.



Persistence
Clone
public BrokerPosition Clone()

Creates and returns a copy of the BrokerPosition using its persisted representation. The cloned Position remains associated with the same BrokerAccount.


Parse
public static BrokerPosition Parse(string s, BrokerAccount ba)

Creates and returns a BrokerPosition from the persisted string s, associating it with the BrokerAccount ba. The method restores the Position's Symbol, PositionType, Quantity, BasisPrice, CurrentPrice, EntryDate, and Strategy association when available.


Persist
public string Persist()

Returns a persisted representation of the BrokerPosition. The persisted data includes Symbol, PositionType, Quantity, BasisPrice, CurrentPrice, EntryDate, and the associated Strategy's QualifiedName when a Strategy is assigned.



Utility Methods
FormatPrice
public string FormatPrice(double price)

Returns price formatted using the appropriate number of decimal places for the Position's Symbol and Broker.


ToString
public override string ToString()

Returns a string representation containing the PositionType, Quantity, Symbol, and SignalDate.