Struct ProductBuilder
pub struct ProductBuilder {Show 22 fields
family: ProductFamily,
currency: Currency,
effective: NaiveDate,
termination: NaiveDate,
notional: f64,
rate: Option<f64>,
day_count: DayCountFraction,
schedule: ScheduleConventions,
index: String,
entity: Option<CreditCurveId>,
recovery: Option<f64>,
collateral: Option<CollateralSpec>,
payment: PaymentRule,
float_payment: Option<PaymentRule>,
pays_fixed: bool,
float_day_count: Option<DayCountFraction>,
fixed_frequency: Option<Period>,
fixed_business_day: Option<BusinessDayConvention>,
accumulation: AccrualCompounding,
float_reset: Option<Period>,
par_coupons: bool,
dated_from: Option<TenorDating>,
}Expand description
Assembles one product from its terms.
Every field is passive. There is no R here and there never will be: a trade
is data, and the builder that materialises one is data handling.
Fields§
§family: ProductFamily§currency: Currency§effective: NaiveDate§termination: NaiveDate§notional: f64§rate: Option<f64>The fixed rate, once stated. A swap builds only with one; a credit trade’s premium reads it as zero until set, as it always has.
day_count: DayCountFraction§schedule: ScheduleConventions§index: String§entity: Option<CreditCurveId>§recovery: Option<f64>§collateral: Option<CollateralSpec>§payment: PaymentRule§float_payment: Option<PaymentRule>The floating leg’s own payment rule, where that side pays under a
different market’s agreement. None — every product built before this
existed, and every one whose two sides agree — means the same rule the
fixed leg uses, so a single payment still serves both.
pays_fixed: bool§float_day_count: Option<DayCountFraction>The floating leg’s accrual day count, where it differs from the fixed
leg’s. None means both legs accrue under day_count.
fixed_frequency: Option<Period>The fixed leg’s coupon frequency, where it differs from the schedule’s.
None means both legs share one schedule.
fixed_business_day: Option<BusinessDayConvention>The fixed leg’s schedule convention, where it differs from the
schedule’s. None means both legs roll alike.
accumulation: AccrualCompoundingHow an overnight floating leg accumulates its daily prints. Ignored by every other family — a term fixing has nothing to accumulate.
float_reset: Option<Period>A floating leg resetting more often than it pays: every tenor, the
resets compounded straight within each period.
par_coupons: boolWhether a term floating leg’s coupons forward over their own accrual periods (par coupons) rather than their index’s window.
dated_from: Option<TenorDating>The trade date a draft was opened on and the template’s spot rule, kept
so a tenor given to with_termination can re-date the
swap from the template’s spot. Absent on a builder dated by explicit dates.
Implementations§
§impl ProductBuilder
impl ProductBuilder
pub fn new(
family: ProductFamily,
currency: Currency,
effective: NaiveDate,
termination: NaiveDate,
schedule: ScheduleConventions,
) -> Self
pub fn new( family: ProductFamily, currency: Currency, effective: NaiveDate, termination: NaiveDate, schedule: ScheduleConventions, ) -> Self
A builder for family, between two dates.
pub fn fixed_frequency(self, frequency: Period) -> Self
pub fn fixed_frequency(self, frequency: Period) -> Self
Sets the fixed leg’s coupon frequency, where it differs from the schedule’s — an annual fixed leg against a quarterly float, the shape most vanilla swap conventions take.
pub fn with_notional(self, notional: f64) -> Self
pub fn with_notional(self, notional: f64) -> Self
This draft on notional.
pub fn with_fixed_rate(self, rate: f64) -> Self
pub fn with_fixed_rate(self, rate: f64) -> Self
This draft at rate: the fixed rate, or a CDS’s running spread.
pub fn with_termination(
self,
end: impl Into<Termination>,
) -> Result<Self, CurveError>
pub fn with_termination( self, end: impl Into<Termination>, ) -> Result<Self, CurveError>
This draft ending at end: a stated date, or a forward tenor re-dating
both the effective and the termination date from the draft’s trade date
and its template’s spot, as the one-shot tenor form dates them.
with_maturity is the same verb under the desk’s word.
§Errors
CurveError::Malformed for a tenor on a builder that was dated by
explicit dates and so has no trade date to read it from; otherwise as
swap_dates_from_tenor.
pub fn with_maturity(
self,
end: impl Into<Termination>,
) -> Result<Self, CurveError>
pub fn with_maturity( self, end: impl Into<Termination>, ) -> Result<Self, CurveError>
with_termination under the desk’s word: one verb, two
spellings, by decision.
§Errors
As with_termination.
pub fn terms(&self) -> Vec<(&'static str, String)>
pub fn terms(&self) -> Vec<(&'static str, String)>
The draft’s own terms as (name, value) rows: notional, fixed_rate
(unset until stated) and side (payer or receiver). The
conventions the template decided are conventions.
pub fn at_par(
&self,
market: &MarketContext,
) -> Result<AnyInstrument, PricingError>
pub fn at_par( &self, market: &MarketContext, ) -> Result<AnyInstrument, PricingError>
The draft struck at the par rate market implies on its own dates: the
instrument built at that rate, worth nothing on market to the par
solve’s precision, and indistinguishable from the same draft with the
rate stated.
§Errors
PricingError::Curve where the draft does not build; otherwise what a
par-rate reading of the built swap on market refuses with — a missing
curve, an unpublished fixing.
pub fn day_count(self, day_count: DayCountFraction) -> Self
pub fn day_count(self, day_count: DayCountFraction) -> Self
Sets the accrual day count. Both legs accrue under it unless
float_day_count says otherwise.
pub fn float_day_count(self, day_count: DayCountFraction) -> Self
pub fn float_day_count(self, day_count: DayCountFraction) -> Self
Sets the floating leg’s own accrual day count, where the market quotes the two legs on different bases (EUR vanilla: 30E/360 fixed, Act/360 float).
pub fn accumulating(self, accumulation: AccrualCompounding) -> Self
pub fn accumulating(self, accumulation: AccrualCompounding) -> Self
Sets how an overnight floating leg accumulates its daily prints.
Only an overnight leg reads this. Templates set it from their own convention, so a caller reaching for this is departing from one deliberately — a compounded EFFR leg against an averaged one, say.
pub fn resetting_every(self, tenor: Period) -> Self
pub fn resetting_every(self, tenor: Period) -> Self
This draft’s floating leg resetting every tenor and compounding the
resets straight within each payment period — the template’s
float_reset, read for a term index only.
fn with_float_reset(self, reset: Option<Period>) -> Self
fn with_float_reset(self, reset: Option<Period>) -> Self
This draft’s floating reset tenor as a template states it: None
resets once per period.
pub fn with_par_coupons(self, par: bool) -> Self
pub fn with_par_coupons(self, par: bool) -> Self
This draft’s term floating coupons forwarding over their own accrual periods (par coupons) rather than their index’s window.
pub fn with_fixed_business_day(
self,
convention: Option<BusinessDayConvention>,
) -> Self
pub fn with_fixed_business_day( self, convention: Option<BusinessDayConvention>, ) -> Self
This draft’s fixed leg rolling its schedule under convention rather
than the schedule’s, where the two legs follow different rules.
pub fn conventions(&self) -> Vec<(&'static str, String)>
pub fn conventions(&self) -> Vec<(&'static str, String)>
The conventions this builder will book with, as (field, value)
rows: what a template or an index resolves to before a trade is
built on it. Each value is the spelling the field’s own vocabulary
parses back, a calendar by its name and a payment lag as
<offset> <unit> <convention> on <calendar>.
pub fn entity(self, credit: CreditCurveId) -> Self
pub fn entity(self, credit: CreditCurveId) -> Self
Sets the credit the trade is valued on — a reference entity in a currency, or an index.
pub fn recovery(self, recovery: f64) -> Self
pub fn recovery(self, recovery: f64) -> Self
Fixes the recovery. Absent means the contract needs the market’s.
pub fn with_discount_key(self, collateral: CollateralSpec) -> Self
pub fn with_discount_key(self, collateral: CollateralSpec) -> Self
This draft discounting under collateral, overriding the family’s
default. The collateral is the last stated: this, or a counterparty’s
CSA through with_counterparty, whichever
came later.
pub fn with_csa(self, currency: Currency) -> Self
pub fn with_csa(self, currency: Currency) -> Self
This draft under a CSA posting currency: its own key where that is
the draft’s currency, the draft’s currency under currency otherwise —
with_csa(EUR) on a USD draft discounts on USD-CSA-EUR. The desk’s
spelling of with_discount_key; the last stated
wins.
pub fn with_counterparty(self, counterparty: &Counterparty) -> Self
pub fn with_counterparty(self, counterparty: &Counterparty) -> Self
This draft facing counterparty: collateralised under its CSA, so a
USD draft facing a EUR-CSA counterparty discounts on USD-CSA-EUR and
one facing a USD-CSA counterparty on USD. The collateral is the last
stated, as with_discount_key says.
pub fn payment(self, payment: PaymentRule) -> Self
pub fn payment(self, payment: PaymentRule) -> Self
Sets the payment rule, for both legs unless
float_payment names one for the floating side.
pub fn float_payment(self, payment: PaymentRule) -> Self
pub fn float_payment(self, payment: PaymentRule) -> Self
Sets the floating leg’s payment rule, leaving the fixed leg on the shared one.
The seam is the one float_day_count already
established: a floating leg differs from the fixed one in what it is
told, not in how it is built.
pub fn with_side(self, side: Side) -> Self
pub fn with_side(self, side: Side) -> Self
This draft on side: a Side::Payer pays fixed, a
Side::Receiver receives it — the default, restated.
pub fn family(&self) -> ProductFamily
pub fn family(&self) -> ProductFamily
The family this builder assembles. A caller setting a convention only one family reads needs to know which one it got from the registry.
fn leg_terms(&self, direction: Direction, floating: bool) -> LegTerms
fn leg_terms(&self, direction: Direction, floating: bool) -> LegTerms
One leg’s terms: the shared ones, and for the floating side its own day count and payment rule where it has been given them.
A floating leg differs from a fixed one in what it is told, not in how it is built, so the two are one function with a flag rather than two that could drift apart.
fn stated_rate(&self) -> Result<f64, CurveError>
fn stated_rate(&self) -> Result<f64, CurveError>
The rate the instrument is built at. A swap builds only with a stated rate; a credit trade’s premium reads an unset rate as zero, as it always has.
fn term_floating_leg(
&self,
sched: &Schedule,
terms: &LegTerms,
) -> Result<Leg, CurveError>
fn term_floating_leg( &self, sched: &Schedule, terms: &LegTerms, ) -> Result<Leg, CurveError>
A term-index floating leg over sched: a registered term index
projects over its own window — resetting every float_reset and
compounding straight where the draft resets more often than it pays —
and a name the registry does not know as a term index projects over the
accrual period.
fn schedules(&self) -> Result<(Schedule, Schedule), CurveError>
fn schedules(&self) -> Result<(Schedule, Schedule), CurveError>
The floating and fixed schedules: the fixed leg on its own frequency
when one is set, the schedule’s otherwise. Same calendar, convention,
roll and stub either way. Infallible once the term is checked, which
build does first.
pub fn build(&self) -> Result<AnyInstrument, CurveError>
pub fn build(&self) -> Result<AnyInstrument, CurveError>
Materialises the instrument.
§Errors
CurveError::Malformed if the terms do not describe the family — a
swap with no index, or a credit trade with no entity.
CurveError::InvertedDates if the effective date is not strictly
before the termination date, checked here so the draft’s own typed
error names both dates rather than the schedule’s.
CurveError::NoFixedRate for a swap whose rate was never stated, and
CurveError::Malformed for a notional or rate that is not finite.
Trait Implementations§
§impl Clone for ProductBuilder
impl Clone for ProductBuilder
§fn clone(&self) -> ProductBuilder
fn clone(&self) -> ProductBuilder
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more