Skip to content

A simple interface for constructing, manipulating, and using yield curves for modeling purposes.

License

Notifications You must be signed in to change notification settings

kasperrisager/Yields.jl

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Yields.jl

Stable Dev Build Status Coverage lifecycle

Yields provides a simple interface for constructing, manipulating, and using yield curves for modeling purposes.

It's intended to provide common functionality around modeling interest rates, spreads, and miscellaneous yields across the JuliaActuary ecosystem (though not limited to use in JuliaActuary packages).

QuickStart

using Yields

riskfree_maturities = [0.5, 1.0, 1.5, 2.0]
riskfree    = [5.0, 5.8, 6.4, 6.8] ./ 100     #spot rates, annual effective if unspecified

spread_maturities = [0.5, 1.0, 1.5, 3.0]      # different maturities
spread    = [1.0, 1.8, 1.4, 1.8] ./ 100       # spot spreads

rf_curve = Yields.Zero(riskfree,riskfree_maturities)
spread_curve = Yields.Zero(spread,spread_maturities)


yield = rf_curve + spread_curve               # additive combination of the two curves

discount(yield,1.5) # 1 / (1 + 0.064 + 0.014) ^ 1.5

Usage

Rates

Rates are types that wrap scalar values to provide information about how to determine discount and accumulation factors.

There are two CompoundingFrequency types:

  • Yields.Periodic(m) for rates that compound m times per period (e.g. m times per year if working with annual rates).
  • Yields.Continuous() for continuously compounding rates.

Examples

Yields.Continuous(0.05)       # 5% continuously compounded
Yields.Periodic(0.05,2)       # 5% compounded twice per period

These are both subtypes of the parent Rate type and are instantiated as:

Yields.Rate(0.05,Continuous())       # 5% continuously compounded
Yields.Rate(0.05,Periodic(2))        # 5% compounded twice per period

Broadcast over a vector to create Rates with the given compounding:

Yields.Periodic.([0.02,0.03,0.04],2) 
Yields.Continuous.([0.02,0.03,0.04]) 

Yields

There are a several ways to construct a yield curve object.

Bootstrapping Methods

rates can be a vector of Rates described above, or will assume Yields.Periodic(1) if the functions are given Real number values

  • Yields.Zero(rates,maturities) using a vector of zero, or spot, rates
  • Yields.Forward(rates,maturities) using a vector of one-period (or periods-long) forward rates
  • Yields.Constant(rate) takes a single constant rate for all times
  • Yields.Step(rates,maturities) doesn't interpolate - the rate is flat up to the corresponding time in times
  • Yields.Par(rates,maturities) takes a series of yields for securities priced at par.Assumes that maturities <= 1 year do not pay coupons and that after one year, pays coupons with frequency equal to the CompoundingFrequency of the corresponding rate.
  • Yields.CMT(rates,maturities) takes the most commonly presented rate data (e.g. Treasury.gov) and bootstraps the curve given the combination of bills and bonds.
  • Yields.OIS(rates,maturities) takes the most commonly presented rate data for overnight swaps and bootstraps the curve.

Kernel Methods

  • Yields.SmithWilson curve (used for discounting in the EU Solvency II framework) can be constructed either directly by specifying its inner representation or by calibrating to a set of cashflows with known prices.
    • These cashflows can conveniently be constructed with a Vector of Yields.ZeroCouponQuotes, Yields.SwapQuotes, or Yields.BulletBondQuotes.

Functions

Most of the above yields have the following defined (goal is to have them all):

  • discount(curve,from,to) or discount(curve,to) gives the discount factor
  • accumulation(curve,from,to) or accumulation(curve,to) gives the accumulation factor
  • forward(curve,from,to) gives the average rate between the two given times
  • zero(curve,time) or zero(curve,time,CompoundingFrequency) gives the zero-coupon spot rate for the given time.

Combinations

Different yield objects can be combined with addition or subtraction. See the Quickstart for an example.

When adding a Yields.AbstractYield with a scalar or vector, that scalar or vector will be promoted to a yield type via Yield(). For example:

y1 = Yields.Constant(0.05)
y2 = y1 + 0.01                # y2 is a yield of 0.06

Forward Starting Curves

Constructed curves can be shifted so that a future timepoint becomes the effective time-zero for a said curve.

julia> zero = [5.0, 5.8, 6.4, 6.8] ./ 100
julia> maturity = [0.5, 1.0, 1.5, 2.0]
julia> curve = Yields.Zero(zero, maturity)
julia> fwd = Yields.ForwardStarting(curve, 1.0)

julia> discount(curve,1,2)
0.9275624570410582

julia> discount(fwd,1) # `curve` has effectively been reindexed to `1.0`
0.9275624570410582

Conversion

Convert rates between different types with convert. E.g.:

r = Rate(Yields.Periodic(12),0.01)             # rate that compounds 12 times per rate period (ie monthly)

convert(Yields.Periodic(1),r)                  # convert monthly rate to annual effective
convert(Yields.Continuous(),r)          # convert monthly rate to continuous

Internals

For time-variant yields (ie yield curves), the inputs are converted to spot rates and interpolated using cubic splines by default (see documentation for alternatives, such as linear interpolations.

Combination Implementation

Combinations track two different curve objects and are not combined into a single underlying data structure. This means that you may achieve better performance if you combine the rates before constructing a Yields representation. The exception to this is Constant curves, which do get combined into a single structure that is as performant as pre-combined rate structure.

Related Packages

  • InterestRates.jl specializes in fast rate calculations aimed at valuing fixed income contracts, with business-day-level accuracy.
    • Comparative comments: Yields.jl does not try to provide as precise controls over the timing, structure, and interpolation of the curve. Instead, Yields.jl provides a minimal, but flexible and intuitive interface for common modeling needs.

About

A simple interface for constructing, manipulating, and using yield curves for modeling purposes.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Julia 100.0%