Table of Contents

Class Position

Namespace
Balsam
Assembly
Balsam.Backtester.dll

Represents a position which can contain multiple entries and exits and even multiple legs for a spread.

public class Position : IPosition, IPortfolioHolding
Inheritance
Position
Implements
Inherited Members
Extension Methods

Constructors

Position(Trade)

Initializes a new position object using the specified trade.

public Position(Trade trade)

Parameters

trade Trade

Properties

ATR

Gets the ATR at time of entry.

public double ATR { get; }

Property Value

double

BarsSinceEntry

Gets the number of bars that have elapsed since entry. Add 1 to get the total number of bars in the trade.

public int BarsSinceEntry { get; }

Property Value

int

ClosedPnL

Gets the closed P&L.

public double ClosedPnL { get; }

Property Value

double

Commissions

Gets commissions paid in base currency.

public double Commissions { get; }

Property Value

double

Entries

Gets a collection of executions that established or added to the position.

public TradeCollection Entries { get; }

Property Value

TradeCollection

Exits

Gets a collection of executions that liquidated or reduced the position.

public TradeCollection Exits { get; }

Property Value

TradeCollection

FXRate

Gets the current exchange rate used to convert local to base currency.

public double FXRate { get; }

Property Value

double

HasVariables

Returns true if the position has variables associated with it.

public bool HasVariables { get; }

Property Value

bool

Id

Gets a unique id for this position.

public long Id { get; }

Property Value

long

InitialMargin

Gets the initial margin requirement in base currency.

public double InitialMargin { get; }

Property Value

double

InitialRisk

Gets the distance from the entry price to the initial stop if any when the position was first opened.

public double InitialRisk { get; }

Property Value

double

Instrument

Gets the instrument of the position.

public Instrument Instrument { get; }

Property Value

Instrument

IsMoneyManagerGenerated

Returns true if the position was originally created by MoneyManager logic rather than Strategy logic.

public bool IsMoneyManagerGenerated { get; }

Property Value

bool

IsOpen

Returns true if the position is open.

public bool IsOpen { get; }

Property Value

bool

IsSpread

Returns true if the position has any spread legs associated with it. Should be called before iterating through Legs to avoid instantiating an empty legs collection unnecessarily.

public bool IsSpread { get; }

Property Value

bool

Last

Gets the last price mark.

public double Last { get; }

Property Value

double

Legs

Gets a collection of positions that make up legs of the spread.

public SpreadLegCollection Legs { get; }

Property Value

SpreadLegCollection

MaxAdverseExcursion

Gets the maximum adverse excursion in points.

public double MaxAdverseExcursion { get; }

Property Value

double

MaxFavorableExcursion

Gets the maximum favorable excursion in points.

public double MaxFavorableExcursion { get; }

Property Value

double

NotionalValue

Gets the notional value of the position in base currency (for futures contracts, the acutal, not back-adjusted, price is used).

public double NotionalValue { get; }

Property Value

double

OpenPnL

Gets the P&L of the currently open quantity.

public double OpenPnL { get; }

Property Value

double

PnL

Gets the net P&L in base currency.

public double PnL { get; }

Property Value

double

PnLLocal

Gets the net P&L in local currency.

public double PnLLocal { get; }

Property Value

double

PnLPercent

Gets the percent P&L using the unadjusted price in the denominator.

public double PnLPercent { get; }

Property Value

double

Pricing

Gets the position pricing object that maintains pricing data.

public PositionPricing Pricing { get; }

Property Value

PositionPricing

Quantity

Gets the current quantity (Entries.TotalQuantity - Exits.TotalQuantity).

public double Quantity { get; }

Property Value

double

RMultiple

Gets the movement of the position in risk terms (or ATR terms if risk isn't available).

public double RMultiple { get; }

Property Value

double

Risk

Gets the distance in points from the most recent price mark to the stop or NaN if there is no stop.

public double Risk { get; }

Property Value

double

RiskValue

Gets the risk of the position (distance to stop) in base currency.

public double RiskValue { get; }

Property Value

double

Rolls

Gets a collection of rolls that took place while the position was open.

public RollCollection Rolls { get; }

Property Value

RollCollection

Side

Gets the side of the position (long or short).

public PositionSide Side { get; }

Property Value

PositionSide

Slippage

Gets slippage in base currency (decimal value multiplied by instrument point value).

public double Slippage { get; }

Property Value

double

Stop

Gets/sets a convenience field for the user to store stop loss information.

public double Stop { get; set; }

Property Value

double

StrategyName

Gets the name of the strategy that generated the position.

public string StrategyName { get; }

Property Value

string

Symbol

Gets the symbol of the position.

public string Symbol { get; }

Property Value

string

Target

Gets/sets a convenience field for the user to store profit target information.

public double Target { get; set; }

Property Value

double

TodaysPnL

Gets the daily P&L for the most recent pricing date in base currency.

public double TodaysPnL { get; }

Property Value

double

TotalCommissions

Gets the total commissions paid in base currency including any legs of a spread.

public double TotalCommissions { get; }

Property Value

double

TotalNotionalValue

Gets the total notional value in base currency including any legs of a spread.

public double TotalNotionalValue { get; }

Property Value

double

TotalPnL

Gets the total net P&L in base currency including any legs of a spread.

public double TotalPnL { get; }

Property Value

double

TotalQuantity

Gets the total current number of contracts/shares held including any legs of a spread.

public double TotalQuantity { get; }

Property Value

double

TotalRiskValue

Gets the total risk of the position in base currency including any legs of a spread.

public double TotalRiskValue { get; }

Property Value

double

TotalSlippage

Gets the total slippage incurred in base currency including any legs of a spread.

public double TotalSlippage { get; }

Property Value

double

Variables

Gets a collection of trade variables.

public VariableDictionary Variables { get; }

Property Value

VariableDictionary

Methods

AddTrade(Trade)

Adds a new trade to the position.

public void AddTrade(Trade trade)

Parameters

trade Trade

GetOffsettingOrderSide()

Returns the order side necessary to liquidate the position.

public OrderSide GetOffsettingOrderSide()

Returns

OrderSide

ToString()

Returns a string representation of this position object.

public override string ToString()

Returns

string

UpdatePricing(Bar)

Updates position pricing using the specified Bar.

public void UpdatePricing(Bar bar)

Parameters

bar Bar