Struct Repo
pub struct Repo {Show 14 fields
pub terms: RepoTerms,
pub cash: f64,
pub collateral: FixedRateBond,
pub nominal: f64,
pub repo_keys: Vec<String>,
pub coupons: CouponTreatment,
pub counterparty: Option<String>,
pub discount: CollateralSpec,
pub floating: Option<OvernightCoupon>,
pub window: Vec<WindowCoupon>,
pub interest_dates: Vec<NaiveDate>,
pub interest_strips: Vec<OvernightCoupon>,
pub fx_rate: Option<f64>,
pub collateral_discount: Option<CollateralSpec>,
}Expand description
A repo, reverse repo or buy/sell-back on one bond.
Fields§
§terms: RepoTermsThe shared terms.
cash: f64The near-leg cash amount.
collateral: FixedRateBondThe collateral bond.
nominal: f64The collateral’s face amount.
repo_keys: Vec<String>The repo keys tried in order: the security’s, its group’s, the currency’s general collateral. The first the market holds prices; a trade naming one key holds that key alone.
coupons: CouponTreatmentWhat happens to a coupon inside the term.
counterparty: Option<String>The counterparty, for reporting.
discount: CollateralSpecThe discount key the seam needs; the cash leg reads the repo curve.
floating: Option<OvernightCoupon>For a floating repo, the compounding strip over [start, end], at unit
notional and carrying the spread.
window: Vec<WindowCoupon>The collateral’s coupons paid in (start, end].
interest_dates: Vec<NaiveDate>Interim dates the cash leg pays its interest on, strictly inside the term. Empty pays it all at the far date with the principal.
interest_strips: Vec<OvernightCoupon>For a scheduled floating repo, the compounding strip of each interim
period, in order; the last period’s is floating.
fx_rate: Option<f64>For a cross-currency repo, the contract FX rate the cash and the
collateral were sized at: cash-currency units per collateral-currency
unit. None when the two share a currency.
collateral_discount: Option<CollateralSpec>For a cross-currency repo, the collateral currency’s cash collateral: the curve its bond is valued on for margin.
Implementations§
§impl Repo
impl Repo
pub fn from_cash(
terms: RepoTerms,
collateral: FixedRateBond,
cash: f64,
price: f64,
) -> Result<Self, RepoError>
pub fn from_cash( terms: RepoTerms, collateral: FixedRateBond, cash: f64, price: f64, ) -> Result<Self, RepoError>
A repo on cash, with the collateral nominal that covers it at the
margin ratio and price (per 100, on the margin basis).
§Errors
pub fn from_collateral(
terms: RepoTerms,
collateral: FixedRateBond,
nominal: f64,
price: f64,
) -> Result<Self, RepoError>
pub fn from_collateral( terms: RepoTerms, collateral: FixedRateBond, nominal: f64, price: f64, ) -> Result<Self, RepoError>
A repo on nominal face of collateral at price (per 100, on the
margin basis): cash = nominal·price/100/margin_ratio.
§Errors
RepoError::MixedCurrencies when the collateral or a floating index
is not in the cash currency; RepoError::Malformed for an end not
after the start, a non-positive amount, price or margin ratio, a
collateral maturing inside the term, or an index the registry does not
hold as an overnight index.
pub fn cross_currency_from_cash(
terms: RepoTerms,
collateral: FixedRateBond,
cash: f64,
price: f64,
fx_rate: f64,
) -> Result<Self, RepoError>
pub fn cross_currency_from_cash( terms: RepoTerms, collateral: FixedRateBond, cash: f64, price: f64, fx_rate: f64, ) -> Result<Self, RepoError>
A cross-currency repo on cash, the collateral in its own currency
covering it at the margin ratio, price (per 100, in the collateral’s
currency, on the margin basis) and the contract fx_rate (cash units
per collateral unit): nominal = cash·margin_ratio·100/(price·fx_rate).
Classic: the collateral’s coupons are manufactured in its currency.
§Errors
RepoError::Malformed for an FX rate that is not positive and
finite, a collateral in the cash currency, or as
from_collateral.
pub fn cross_currency_from_collateral(
terms: RepoTerms,
collateral: FixedRateBond,
nominal: f64,
price: f64,
fx_rate: f64,
) -> Result<Self, RepoError>
pub fn cross_currency_from_collateral( terms: RepoTerms, collateral: FixedRateBond, nominal: f64, price: f64, fx_rate: f64, ) -> Result<Self, RepoError>
A cross-currency repo on nominal face of collateral at price (per
100, in its own currency) and the contract fx_rate:
cash = nominal·price·fx_rate/100/margin_ratio.
§Errors
fn build( terms: RepoTerms, collateral: FixedRateBond, cash: f64, nominal: f64, fx_rate: Option<f64>, ) -> Result<Self, RepoError>
pub fn with_interest_dates(
self,
dates: Vec<NaiveDate>,
) -> Result<Self, RepoError>
pub fn with_interest_dates( self, dates: Vec<NaiveDate>, ) -> Result<Self, RepoError>
The same repo paying its interest on dates: each period’s cash · r · τ on its end date, the last
with the principal at the far date. A floating repo compounds its index
over each period on its own strip.
§Errors
RepoError::Malformed on a buy/sell-back (whose coupons net at the
far date), or dates not strictly ascending inside the open term.
pub fn interest_periods(&self) -> Vec<(NaiveDate, NaiveDate, f64)>
pub fn interest_periods(&self) -> Vec<(NaiveDate, NaiveDate, f64)>
The cash leg’s interest periods as (start, end, τ): one over the
whole term, or one per interim date and the last to the far date.
pub fn financed_on(self, key: impl Into<String>) -> Self
pub fn financed_on(self, key: impl Into<String>) -> Self
Financed on key alone: a missing curve under it is refused naming it.
pub fn financed_on_security(self, isin: &str, group: Option<&str>) -> Self
pub fn financed_on_security(self, isin: &str, group: Option<&str>) -> Self
Financed on the security’s own key, its repo group’s, then the currency’s general collateral — the special-to-GC cascade. A missing special prices as GC; a missing GC is refused naming it.
pub fn with_coupons(self, treatment: CouponTreatment) -> Self
pub fn with_coupons(self, treatment: CouponTreatment) -> Self
This repo with treatment for the coupons inside its term.
pub fn with_counterparty(self, counterparty: impl Into<String>) -> Self
pub fn with_counterparty(self, counterparty: impl Into<String>) -> Self
This repo facing counterparty.
pub fn year_fraction(&self) -> f64
pub fn year_fraction(&self) -> f64
The accrual over [start, end] in the repo’s day count.
pub fn accrued_strip(&self, to: NaiveDate) -> Option<OvernightCoupon>
pub fn accrued_strip(&self, to: NaiveDate) -> Option<OvernightCoupon>
For a floating repo started before to, the strip from the start to
to — what the cash has accrued by then.
§impl Repo
impl Repo
fn priced_curve<'v, 'a, R: Scalar>(
&self,
view: &'v PricingView<'a, R>,
) -> Result<(&'v ResolvedCurve<'a, R>, usize), PricingError>
fn priced_curve<'v, 'a, R: Scalar>( &self, view: &'v PricingView<'a, R>, ) -> Result<(&'v ResolvedCurve<'a, R>, usize), PricingError>
The repo curve that prices and the tier it came from, counting the cascade from the security (0) to the general collateral (last).
pub fn repo_curve_of<'v, 'a, R: Scalar>(
&self,
view: &'v PricingView<'a, R>,
) -> Result<&'v ResolvedCurve<'a, R>, PricingError>
pub fn repo_curve_of<'v, 'a, R: Scalar>( &self, view: &'v PricingView<'a, R>, ) -> Result<&'v ResolvedCurve<'a, R>, PricingError>
pub fn priced_tier<R: Scalar>(
&self,
view: &PricingView<'_, R>,
) -> Result<usize, PricingError>
pub fn priced_tier<R: Scalar>( &self, view: &PricingView<'_, R>, ) -> Result<usize, PricingError>
The tier of the cascade that prices this repo on view: the security
(0), its group (1), or the general collateral (the last).
§Errors
As Priceable::npv.
fn accrual<R: Scalar>(
&self,
from: NaiveDate,
strip: Option<&OvernightCoupon>,
view: &PricingView<'_, R>,
) -> Result<R, PricingError>
fn accrual<R: Scalar>( &self, from: NaiveDate, strip: Option<&OvernightCoupon>, view: &PricingView<'_, R>, ) -> Result<R, PricingError>
The accrual I over the strip from from to the far date: r·τ for a
fixed rate, the compounded index plus the spread times τ for a
floating one.
pub fn coupon_growth<R: Scalar>(
&self,
coupon: &WindowCoupon,
view: &PricingView<'_, R>,
) -> Result<R, PricingError>
pub fn coupon_growth<R: Scalar>( &self, coupon: &WindowCoupon, view: &PricingView<'_, R>, ) -> Result<R, PricingError>
What one unit of coupon is worth at the far date: grown at the repo’s
own rate from its payment date, 1 + I(t_c, end) — or, paid after the
far date, carried back, 1 − I(end, t_c), the simple period run in
reverse.
§Errors
As Priceable::npv.
pub fn far_amount<R: Scalar>(
&self,
view: &PricingView<'_, R>,
) -> Result<R, PricingError>
pub fn far_amount<R: Scalar>( &self, view: &PricingView<'_, R>, ) -> Result<R, PricingError>
The far amount the contract fixes: N·(1 + I), less — for a
buy/sell-back — each coupon the lender is entitled to over the term,
carried to the far date at the repo’s own rate.
§Errors
As Priceable::npv.
pub fn interim_periods<R: Scalar>(
&self,
view: &PricingView<'_, R>,
) -> Result<Vec<(NaiveDate, NaiveDate, f64, R)>, PricingError>
pub fn interim_periods<R: Scalar>( &self, view: &PricingView<'_, R>, ) -> Result<Vec<(NaiveDate, NaiveDate, f64, R)>, PricingError>
The interim periods still unpaid as (start, end, τ, rate): the fixed
rate, or the period’s compounded index plus spread on its own strip.
§Errors
Whatever the projection and fixings report.
fn interim_interest<R: Scalar>(
&self,
view: &PricingView<'_, R>,
curve: &dyn YieldCurve<R>,
) -> Result<R, PricingError>
fn interim_interest<R: Scalar>( &self, view: &PricingView<'_, R>, curve: &dyn YieldCurve<R>, ) -> Result<R, PricingError>
The interim interest payments still owed, each cash · r · τ
discounted on curve from its own date; zero on an unscheduled repo.
fn unpaid_annuity<R: Scalar>(
&self,
view: &PricingView<'_, R>,
curve: &dyn YieldCurve<R>,
) -> Result<R, PricingError>
fn unpaid_annuity<R: Scalar>( &self, view: &PricingView<'_, R>, curve: &dyn YieldCurve<R>, ) -> Result<R, PricingError>
cash · Σ DF(tᵢ) τᵢ over the periods still unpaid, the last included,
each τ the one its interest accrues on.
fn scheduled_terms(&self) -> Result<(), PricingError>
fn scheduled_terms(&self) -> Result<(), PricingError>
A schedule booked and the coupons switched to buy/sell-back after it: the far amount nets coupons a periodic leg has no place for.
fn far_slope(&self) -> f64
fn far_slope(&self) -> f64
How the far amount moves per unit of rate (fixed) or spread
(floating): N·τ less each netted coupon’s c·τ_c.
fn par_level<R: Scalar>(
&self,
view: &PricingView<'_, R>,
) -> Result<R, PricingError>
fn par_level<R: Scalar>( &self, view: &PricingView<'_, R>, ) -> Result<R, PricingError>
The rate (fixed) or spread (floating) at which the cash leg is worth nothing: the far amount that repays the cash at the repo curve’s own forward, reached from the trade’s along the far amount’s slope.
§impl Repo
impl Repo
pub fn package_value_with<R: Scalar>(
&self,
view: &PricingView<'_, R>,
) -> Result<R, PricingError>
pub fn package_value_with<R: Scalar>( &self, view: &PricingView<'_, R>, ) -> Result<R, PricingError>
The trade with its collateral: the cash leg plus the bond received, less the bond returned at its repo forward, less — classic — the coupons manufactured back. The forwards are financed and discounted on the repo curve, the spot on the trade’s discount curve. A foreign bond (a cross-currency repo) is valued in its own currency on its own discount curve — no repo curve of the cash currency finances it — and converted at spot, as its margin is.
§Errors
As Priceable::npv, and a cross-currency repo without the
collateral currency’s discount curve.
pub fn package_value(&self, market: &MarketContext) -> Result<f64, PricingError>
pub fn package_value(&self, market: &MarketContext) -> Result<f64, PricingError>
pub fn margin(&self, market: &MarketContext) -> Result<RepoMargin, PricingError>
pub fn margin(&self, market: &MarketContext) -> Result<RepoMargin, PricingError>
The margin position on market, the collateral priced off its curves
on the margin basis.
§Errors
As Priceable::npv.
pub fn margin_at(
&self,
market: &MarketContext,
price: f64,
) -> Result<RepoMargin, PricingError>
pub fn margin_at( &self, market: &MarketContext, price: f64, ) -> Result<RepoMargin, PricingError>
The margin position on market with the collateral at a quoted
price per 100 on the margin basis — a screen mark.
§Errors
As Priceable::npv.
fn margin_on( &self, view: &PricingView<'_, f64>, price: f64, ) -> Result<RepoMargin, PricingError>
fn priced_passive<T>( &self, market: &MarketContext, measure: impl FnOnce(&Self, &PricingView<'_, f64>) -> Result<T, PricingError>, ) -> Result<T, PricingError>
Trait Implementations§
§impl<R: Scalar> Priceable<R> for Repo
impl<R: Scalar> Priceable<R> for Repo
§fn npv(&self, view: &PricingView<'_, R>) -> Result<R, PricingError>
fn npv(&self, view: &PricingView<'_, R>) -> Result<R, PricingError>
sign · CashLeg on the repo curve: F·P(end) − N·P(start) before the
start, F·P(end) after it, nothing from the far date on — the
deposit’s three datings, with the far amount the contract fixes.
§fn par_rate(&self, view: &PricingView<'_, R>) -> Result<R, PricingError>
fn par_rate(&self, view: &PricingView<'_, R>) -> Result<R, PricingError>
The fixed simple rate at which this repo, under its own coupon treatment, is worth nothing. A floating repo quotes a par spread.
§fn par_spread(&self, view: &PricingView<'_, R>) -> Result<R, PricingError>
fn par_spread(&self, view: &PricingView<'_, R>) -> Result<R, PricingError>
Fixed: the trade’s rate less the par rate. Floating: the spread over the compounded index at which the repo is worth nothing.
§impl PricingRiskFactors for Repo
impl PricingRiskFactors for Repo
§fn risk_factors(&self) -> Result<RiskFactors<'_>, PricingError>
fn risk_factors(&self) -> Result<RiskFactors<'_>, PricingError>
Financed on the cascade’s last key — the currency’s general collateral, or the one key named — which must resolve, and on the tiers before it, which may be absent; discounted by its own currency for the seam; and, floating, projecting its overnight index.
§impl Product for Repo
impl Product for Repo
§fn restruck_at_rate(&self, rate: f64) -> Option<AnyInstrument>
fn restruck_at_rate(&self, rate: f64) -> Option<AnyInstrument>
rate — the scalar a par
calibration rung on it is quoted in — or None for a product that
carries no such scalar. What a quote scenario moves a rung to.§fn currency(&self) -> Currency
fn currency(&self) -> Currency
§fn contract_dates(&self) -> Vec<(&'static str, NaiveDate)>
fn contract_dates(&self) -> Vec<(&'static str, NaiveDate)>
(name, date) pairs —
exactly the dates its stated constructor takes, so a product built
through a derived form can be read back and rebuilt through the stated
one. Empty for a product with no stated form. No default: every
product states which it is — see AnyInstrument::contract_dates.§fn legs(&self) -> Option<Vec<&Leg>>
fn legs(&self) -> Option<Vec<&Leg>>
None
for a product that holds none — see AnyInstrument::legs. No
default: every product states which it is.§fn final_payment_date(&self) -> Option<NaiveDate>
fn final_payment_date(&self) -> Option<NaiveDate>
None for a product no ladder is built from.§fn restruck_at_spread(&self, _spread: f64) -> Option<AnyInstrument>
fn restruck_at_spread(&self, _spread: f64) -> Option<AnyInstrument>
spread on its spread
leg, or None for a product that quotes none.