Rates

We should first discuss Rates, which are reexported from FinanceCore.jl

Rates are types that wrap scalar values to provide information about how to determine discount and accumulation factors. These allow for explicit handling of rate compounding conventions which, if not explicit, is often a source of errors in practice. See Rate conventions for how FinanceModels reads a bare number and which results are Rates.

There are two Frequency types:

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

Examples

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

These construct Rate values with the chosen compounding convention, equivalently:

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

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

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

Rates can also be constructed by specifying the Frequency and then passing a scalar rate:

Periodic(1)(0.05)
Continuous()(0.05)

Conversion

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

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

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

To get the scalar value out of the Rate, use FinanceModels.rate(r):

julia> r = Rate(0.01,Periodic(12));

julia> rate(r)
0.009999999999998899

(Rates internally store the equivalent continuously compounded rate, so the nominal value returned by rate may show floating point artifacts of the round-trip conversion.)

Arithmetic

Adding, subtracting, multiplying, dividing, and comparing rates is supported.