Skip to main content

Swap

Struct Swap 

Source
pub struct Swap { /* private fields */ }
Expand description

Base swap instrument.

Holds N Legs and a per-leg multiplier (-1 paid, +1 received). A derived swap builds its legs and constructs the base whole through Swap::new; two_leg is the receiver/payer convenience for the common two-leg case.

Implementations§

Source§

impl Swap

Source

pub fn new( legs: Vec<Leg>, payer: Vec<bool>, settings: Shared<Settings<Date>>, ) -> QlResult<Swap>

Builds a multi-leg swap from its legs and their payer flags (the C++ multi-leg constructor, swap.cpp:46).

A true flag marks a paid leg, stored as the multiplier -1; a false flag a received leg, stored as +1. The swap registers with the settings evaluation date and with every flow of every leg.

§Errors

The number of payer flags must match the number of legs.

Source

pub fn two_leg( first_leg: Leg, second_leg: Leg, settings: Shared<Settings<Date>>, ) -> Swap

Builds a two-leg swap whose first leg is paid and second received (the C++ two-leg constructor, swap.cpp:30).

Source

pub fn number_of_legs(&self) -> usize

The number of legs.

Source

pub fn legs(&self) -> &[Leg]

All the swap’s legs.

Source

pub fn leg(&self, j: usize) -> QlResult<&Leg>

The j-th leg.

§Errors

The index must be within range.

Source

pub fn payer(&self, j: usize) -> QlResult<bool>

Whether the j-th leg is paid.

§Errors

The index must be within range.

Source

pub fn start_date(&self) -> QlResult<Date>

The earliest start date over the legs.

§Errors

The swap must have at least one leg, each non-empty.

Source

pub fn maturity_date(&self) -> QlResult<Date>

The latest maturity date over the legs.

§Errors

The swap must have at least one leg, each non-empty.

Source

pub fn leg_npv(&mut self, j: usize) -> QlResult<Real>

The j-th leg’s NPV.

§Errors

The index must be within range and the engine must have provided the value.

Source

pub fn leg_bps(&mut self, j: usize) -> QlResult<Real>

The j-th leg’s BPS.

§Errors

The index must be within range and the engine must have provided the value.

Source

pub fn start_discounts(&mut self, j: usize) -> QlResult<DiscountFactor>

The discount factor at the j-th leg’s start date.

§Errors

The index must be within range and the engine must have provided the value.

Source

pub fn end_discounts(&mut self, j: usize) -> QlResult<DiscountFactor>

The discount factor at the j-th leg’s end date.

§Errors

The index must be within range and the engine must have provided the value.

Source

pub fn npv_date_discount(&mut self) -> QlResult<DiscountFactor>

The discount factor at the NPV date.

§Errors

The engine must have provided the value.

Source

pub fn deep_update(&mut self)

Invalidates the cached results and notifies observers (the C++ Swap::deepUpdate).

C++ additionally walks each leg’s flows calling deepUpdate on them, to refresh coupons whose pricer caches; the crate’s cash-flow surface exposes no such hook yet, so the leg walk reduces to the update step until one lands.

Trait Implementations§

Source§

impl Instrument for Swap

Source§

fn base(&self) -> &InstrumentBase

The embedded base state.
Source§

fn base_mut(&mut self) -> &mut InstrumentBase

Mutable access to the embedded base state.
Source§

fn is_expired(&self) -> QlResult<bool>

Whether the instrument might have value greater than zero. Read more
Source§

fn setup_arguments(&self, arguments: &mut dyn Arguments) -> QlResult<()>

Fills the engine’s argument bundle ahead of a calculation; mandatory when a pricing engine is used.
Source§

fn setup_expired(&mut self)

Leaves the instrument in a consistent state when the expiration condition is met (setupExpired): zero value, cleared extras.
Source§

fn fetch_results(&mut self, results: &dyn Results) -> QlResult<()>

Reads a calculation’s outputs back from the engine’s result bundle. Read more
Source§

fn perform_calculations(&mut self) -> QlResult<()>

Runs the engine protocol (performCalculations): reset, fill and validate the arguments, calculate, fetch the results. Override only when pricing without an engine. Read more
Source§

fn calculate(&mut self) -> QlResult<()>

Recomputes the results if the cache is stale, short-circuiting expired instruments (Instrument::calculate). Read more
Source§

fn recalculate(&mut self) -> QlResult<()>

Forces a recalculation and notifies observers even on failure (LazyObject::recalculate, inherited by every C++ instrument; goes through the virtual calculate, so expired instruments short-circuit).
Source§

fn npv(&mut self) -> QlResult<Real>

The net present value of the instrument (NPV()).
Source§

fn error_estimate(&mut self) -> QlResult<Real>

The error estimate on the NPV, when available (errorEstimate()).
Source§

fn valuation_date(&mut self) -> QlResult<Date>

The date the net present value refers to (valuationDate()).
Source§

fn result<T: Any + Clone>(&mut self, tag: &str) -> QlResult<T>
where Self: Sized,

An additional named result returned by the engine (result<T>(tag)).
Source§

fn additional_results(&mut self) -> QlResult<&BTreeMap<String, Shared<dyn Any>>>

All additional results returned by the engine (additionalResults()).

Auto Trait Implementations§

§

impl !RefUnwindSafe for Swap

§

impl !Send for Swap

§

impl !Sync for Swap

§

impl !UnwindSafe for Swap

§

impl Freeze for Swap

§

impl Unpin for Swap

§

impl UnsafeUnpin for Swap

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.