PortfolioCalc

vecxt_re.PortfolioCalc
object PortfolioCalc

Portfolio level calculations over a collection of positions.

Positions are record-like views over a Map[String, Any], exposing typed fields via scala.Selectable. Callers need not construct them directly: the public entry points accept any named tuple carrying the required fields (see NamedRecord).

Attributes

Graph
Supertypes
class Object
trait Matchable
class Any
Self type

Members list

Type members

Classlikes

class PositionT0(values: Map[String, Any]) extends Selectable

A holding as observed at the valuation date (day 0).

A holding as observed at the valuation date (day 0).

Normally built from a named tuple by day0MarketValues; constructing one directly from a Map is unchecked, and a missing key or a wrongly typed value only surfaces when the field is accessed.

Attributes

Supertypes
trait Selectable
class Object
trait Matchable
class Any
class PositionT1(values: Map[String, Any]) extends Selectable

A holding for forward-looking (e.g. P&L) calculations.

A holding for forward-looking (e.g. P&L) calculations.

Attributes

Note

Fields are currently identical to PositionT0; kept separate as the two are expected to diverge.

Supertypes
trait Selectable
class Object
trait Matchable
class Any

Value members

Concrete methods

inline def day0MarketValues[N <: Tuple, V <: Tuple](positions: List[NamedTuple[N, V]], portfolioCurrency: Ccy, xcRates: Map[Ccy, Double]): Array[Double]

The day 0 market value of each position, in the portfolio currency.

The day 0 market value of each position, in the portfolio currency.

For each position the value is xcRate(notional.ccy) * notional * price, where the price is taken in canonical units (so Price(102, Pts) contributes a factor of 1.02).

Positions may be supplied as any named tuple holding the fields of PositionT0.Fields, in any order; extra fields are ignored. A missing or mistyped field is a compile error. All elements of the list must share one field order, as the list has a single element type.

day0MarketValues(
 List((id = "1", name = "Bond A", price = Price(102, PriceUnit.Pts), notional = CurrencyAmount(1, Mn, USD))),
 portfolioCurrency = Ccy.CHF,
 xcRates = Map(Ccy.USD -> 0.9)
) // Array(918000.0)

Value parameters

portfolioCurrency

the currency results are expressed in. Positions already in this currency use a rate of 1.0 and need no entry in xcRates.

positions

the holdings to value

xcRates

units of portfolioCurrency per one unit of the keyed currency. Entries for currencies no position uses are ignored.

Attributes

Returns

one value per position, in input order

Throws
IllegalArgumentException

if any position's currency has no FX rate. All such positions are reported together, one per line, each with its id and name.

def day0MarketValuesOf(positions: List[PositionT0], portfolioCurrency: Ccy, xcRates: Map[Ccy, Double]): Array[Double]

As day0MarketValues, for positions already built as PositionT0.

As day0MarketValues, for positions already built as PositionT0.

Attributes

Throws
IllegalArgumentException

if any position's currency has no FX rate; see day0MarketValues

def marketValueForecast1Year(holdings: IndexedSeq[PositionT1], lossMatrix: Matrix[Double], t0Date: LocalDate, xcRates: Map[Ccy, Double], portfolioCurrency: Ccy): Matrix[Double]
def relativeReturn1Year(holdings: IndexedSeq[PositionT1], lossMatrix: Matrix[Double], t0Date: LocalDate): Matrix[Double]

The one year relative return of each position in each loss scenario, in canonical units (0.05 is 5%).

The one year relative return of each position in each loss scenario, in canonical units (0.05 is 5%).

The return is measured against the day 0 market value notional * price:

r(i, j) = (priceT1(j) + riskFree(j) + spread(j) - loss(i, j)) / price(j) - 1

i.e. marketValueForecast1Year divided by the day 0 market value, minus one. Notional and FX cancel (both are taken at the day 0 rate), so no FX rates are needed.

Value parameters

lossMatrix

one row per scenario, one column per holding; positive losses in canonical units of notional

Attributes

Returns

a lossMatrix.rows x holdings.length matrix of canonical relative returns

Throws
IllegalArgumentException

if the column count does not match the holdings, or any holding has a non-positive price (all such holdings are reported together, one per line)