Struct Loan
pub struct Loan {
pub currency: Currency,
pub drawdown: Leg,
pub servicing: Leg,
pub collateral: CollateralSpec,
pub issuer: Option<CreditCurveId>,
pub index: Option<String>,
}Expand description
A loan as two legs, one per direction of cash: the drawdown, and the servicing — the interest and the repayment.
Fields§
§currency: CurrencyThe loan’s currency.
drawdown: LegThe principal drawn on the first schedule date.
servicing: LegThe interest on each period and the principal repaid on the last date.
collateral: CollateralSpecThe discounting collateral.
issuer: Option<CreditCurveId>The borrower’s credit, when the servicing is valued risky: survival weights the borrower’s promises, and default recovers on the principal still outstanding. The drawdown stays risk-free.
index: Option<String>The index the interest floats on, by registry code; None for a
fixed-rate loan.
Implementations§
§impl Loan
impl Loan
pub fn new(
schedule: &Schedule,
currency: Currency,
notional: f64,
fixed_rate: f64,
day_count: DayCountFraction,
borrower: bool,
) -> Self
pub fn new( schedule: &Schedule, currency: Currency, notional: f64, fixed_rate: f64, day_count: DayCountFraction, borrower: bool, ) -> Self
A loan of notional over schedule at fixed_rate on day_count,
each period’s interest paid on its accrual end. borrower takes the
drawdown and pays the servicing; a lender the reverse.
§Panics
If schedule has fewer than two dates.
pub fn floating(
schedule: &Schedule,
currency: Currency,
notional: f64,
index_code: &str,
margin: f64,
day_count: DayCountFraction,
borrower: bool,
) -> Result<Self, String>
pub fn floating( schedule: &Schedule, currency: Currency, notional: f64, index_code: &str, margin: f64, day_count: DayCountFraction, borrower: bool, ) -> Result<Self, String>
A loan whose interest is the index index_code (a registry code, term
or overnight) plus margin: a term index projected as the IBOR leg
does, an overnight one compounded as the OIS leg does.
§Errors
An index the registry does not know, or one that is not a rate.
§Panics
If schedule has fewer than two dates.
pub fn issued_by(self, credit: CreditCurveId) -> Self
pub fn issued_by(self, credit: CreditCurveId) -> Self
Tags the loan to its borrower’s credit, whichever side books it.
pub fn with_rate(&self, rate: f64) -> Self
pub fn with_rate(&self, rate: f64) -> Self
This loan restruck at rate: every fixed coupon’s rate replaced.
pub fn with_margin(&self, margin: f64) -> Self
pub fn with_margin(&self, margin: f64) -> Self
This loan restruck at margin: every floating coupon’s spread
replaced.
fn restruck(&self, edit: impl FnMut(&mut AnyCoupon)) -> Self
pub fn outstanding(&self, date: NaiveDate) -> f64
pub fn outstanding(&self, date: NaiveDate) -> f64
The principal still owed on date: the drawdown less every repayment
paid on or before it.
pub fn amortising_straight_line(self) -> Self
pub fn amortising_straight_line(self) -> Self
This loan amortising to zero in a straight line
(Amortisation::StraightLine): over n periods, period i’s interest
accrues on N − i·N/n, and N/n is repaid at each period’s end.
§impl Loan
impl Loan
fn risky_servicing<R: Scalar>(
&self,
view: &PricingView<'_, R>,
) -> Result<R, PricingError>
fn risky_servicing<R: Scalar>( &self, view: &PricingView<'_, R>, ) -> Result<R, PricingError>
The servicing’s risky value from the booked side: the borrower’s promises, signed as the lender receives them, survival-weighted with recovery on the outstanding, then turned to the side that books it — so a lender and a borrower see one credit and exact negatives.
Trait Implementations§
§impl<R: Scalar> Priceable<R> for Loan
impl<R: Scalar> Priceable<R> for Loan
§fn npv(&self, view: &PricingView<'_, R>) -> Result<R, PricingError>
fn npv(&self, view: &PricingView<'_, R>) -> Result<R, PricingError>
The drawdown and the servicing, each leg on the discount curve; a tagged loan’s servicing survival-weighted, the drawdown risk-free.
§fn par_rate(&self, view: &PricingView<'_, R>) -> Result<R, PricingError>
fn par_rate(&self, view: &PricingView<'_, R>) -> Result<R, PricingError>
The fixed rate at which the loan, otherwise unchanged, is worth
nothing — risky when tagged. The value is affine in the rate, so two
restrikes give it exactly: −V(0) / (V(1) − V(0)).
§fn par_spread(&self, view: &PricingView<'_, R>) -> Result<R, PricingError>
fn par_spread(&self, view: &PricingView<'_, R>) -> Result<R, PricingError>
The margin over its index at which a floating loan is worth nothing, by the same two restrikes.
§impl PricingRiskFactors for Loan
impl PricingRiskFactors for Loan
§fn risk_factors(&self) -> Result<RiskFactors<'_>, PricingError>
fn risk_factors(&self) -> Result<RiskFactors<'_>, PricingError>
The collateral’s discount curve, and a floating loan’s index; a tagged loan also its borrower’s credit and a market recovery.
§impl Product for Loan
impl Product for Loan
§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_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 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.