Professional Documents
Culture Documents
R topics documented:
adjust_disc . .
cashflow . . . .
cft . . . . . . .
disc_cf . . . . .
find_rate . . . .
irr . . . . . . .
loan . . . . . .
npv . . . . . .
plot.rate_curve
pmt . . . . . .
rate . . . . . .
rate_curve . . .
rem . . . . . .
tvm . . . . . .
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
1
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
2
2
3
3
4
4
5
5
6
7
7
8
9
9
cashflow
xirr . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
xnpv . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
[.rate_curve . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
Index
adjust_disc
12
Description
Adjusts the discount factors by a spread
Usage
adjust_disc(fd, spread)
Arguments
fd
spread
effective spread
Examples
adjust_disc(fd = c(0.99, 0.98), spread = 0.01)
cashflow
Description
Returns the cashflow for the loan, excluding the initial inflow for the loan taker
Usage
cashflow(l)
Arguments
l
The loan
Examples
l <- loan(rate = 0.05, maturity = 10, amt = 100, type = "bullet")
cashflow(l)
cft
cft
Description
This is the IRR of the loans cashflow, after adding all the extra costs
Usage
cft(amt, maturity, rate, up_fee = 0, per_fee = 0)
Arguments
amt
maturity
rate
up_fee
per_fee
Details
It is assumed that the loan has monthly payments The CFT is returned as an effective rate of periodicty equal to that of the maturity and the rate The interest is calculated over amt + fee
Examples
cft(amt = 100, maturity = 10, rate = 0.05, up_fee = 1, per_fee = 0.1)
disc_cf
Description
Value of a discounted cashflow
Usage
disc_cf(fd, cf)
Arguments
fd
cf
Examples
disc_cf(fd = c(1, 0.99, 0.98, 0.97), cf = c(1, -0.3, -0.4, -0.6))
irr
find_rate
Description
Thru a root finding process, this function finds the rate that corresponds to a given set of discount
factors, as for the loan to have the same present value discounted with the discount factors or with
that constant rate
Usage
find_rate(m, d, loan_type, interval = c(1e-06, 2), tol = 1e-08)
Arguments
m
d
loan_type
interval
tol
Examples
find_rate(m = 3, d = c(0.99, 0.98, 0.97), loan_type = "bullet")
irr
Description
Internal Rate of Return of a periodic cashflow (IRR)
Usage
irr(cf, ts = seq(from = 0, by = 1, along.with = cf), interval = c(-1, 10),
...)
Arguments
cf
ts
interval
...
The cashflow
The times on which the cashflow ocurrs. It is assumed that cf[idx] happens at
moment ts[idx]
A length 2 vector that indicates the root finding algorithm where to search for
the irr
Other arguments to be passed on to uniroot
loan
Examples
irr(cf = c(-1, 0.5, 0.9), ts = c(0, 1, 3))
loan
Description
Creates an instance of a loan class
Usage
loan(rate, maturity, amt, type, grace_int = 0, grace_amort = grace_int)
Arguments
rate
maturity
The maturity of the loan, measured in the same units as the periodicity of the
rate
amt
type
grace_int
The number of periods that the loan doesnt pay interest and capitalizes it. Leave
in 0 for zero loans
grace_amort
Examples
loan(rate = 0.05, maturity = 10, amt = 100, type = "bullet")
npv
Description
Net Present Value of a periodic cashflow (NPV)
Usage
npv(i, cf, ts = seq(from = 0, by = 1, along.with = cf))
plot.rate_curve
Arguments
i
The rate used to discount the cashflow. It must be effective and with a periodicity
that matches that of the cashflow
cf
The cashflow
ts
The times on which the cashflow ocurrs. It is assumed that cf[idx] happens at
moment ts[idx]. If empty, assumes that cf[idx] happens at period idx - 1
Value
The net present value at
Examples
npv(i = 0.01, cf = c(-1, 0.5, 0.9), ts = c(0, 1, 3))
plot.rate_curve
Description
Plots a rate curve
Usage
## S3 method for class 'rate_curve'
plot(x, rate_type = NULL, ...)
Arguments
x
rate_type
...
Examples
r <- rate_curve(rates = c(0.1, 0.2, 0.3), rate_type = "zero_eff")
plot(r)
## Not run:
plot(r, rate_type = "german")
plot(r, rate_type = c("french", "german"))
## End(Not run)
pmt
pmt
The value of the payment of a loan with constant payments (french type
amortization)
Description
The value of the payment of a loan with constant payments (french type amortization)
Usage
pmt(amt, maturity, rate)
Arguments
amt
maturity
rate
Details
The periodicity of the maturity and the rate must match, and this will be the periodicity of the
payments
Examples
pmt(amt = 100, maturity = 10, rate = 0.05)
rate
Description
The rate of a loan with constant payments (french type amortization)
Usage
rate(amt, maturity, pmt, extrema = c(1e-04, 1e+09), tol = 1e-04)
Arguments
amt
maturity
pmt
extrema
tol
rate_curve
Details
The periodicity of the maturity and the payment must match, and this will be the periodicity of the
rate (which is returned as an effective rate)
Examples
rate(amt = 100, maturity = 10, pmt = 15)
rate_curve
Description
Creates a rate curve instance
Usage
rate_curve(rates = NULL, rate_type = "zero_eff", pers = 1:length(rates),
fun_d = NULL, fun_r = NULL, knots = seq.int(from = 1, to = max(pers), by
= 1), functor = function(x, y) splinefun(x = x, y = y, method = "monoH.FC"))
Arguments
rates
rate_type
pers
fun_d
fun_r
knots
functor
A rate vector
The rate type. Must be on of c("fut", "zero_nom", "zero_eff", "swap")
The periods the rates correspond to
A discount factor function. fun_d(x) returns the discount factor for time x, vectorized on x
A rate function. fun_r(x) returns the EPR for time x, vectorized on x
The nodes used to bootstrap the rates. This is a mandatory argument if a rate
function or discount function is provided
A function with parameters x and y, that returns a function used to interpolate
Note
Currently a rate curve can only be built from one of the following sources
1. A discount factor function
2. A rate function and a rate type from the following types: "fut", "zero_nom", "zero_eff" or
"swap"
3. A rate vector, a pers vector and a rate type as before
Examples
rate_curve(rates = c(0.1, 0.2, 0.3), rate_type = "zero_eff")
rate_curve(fun_r = function(x) rep_len(0.1, length(x)), rate_type = "swap", knots = 1:12)
rate_curve(fun_d = function(x) 1 / (1 + x), knots = 1:12)
rem
rem
Description
The amount that has to be repayed at each moment in a loan, at the end of the period
Usage
rem(cf, amt, r)
Arguments
cf
The cashflow of the loan, not including the initial inflow for the loan taker
amt
Examples
rem(cf = rep_len(0.4, 4), amt = 1, r = 0.2)
tvm
tvm
Description
Functions for managing cashflows and interest rate curves.
xirr
Description
Internal Rate of Return of an irregular cashflow (IRR)
Usage
xirr(cf, d, interval = c(-1, 10), ...)
10
[.rate_curve
Arguments
cf
The cashflow
The dates when each cashflow occurs. Same length as the cashflow
interval
A length 2 vector that indicates the root finding algorithm where to search for
the irr
...
Examples
xirr(cf = c(-1, 1.5), d = Sys.Date() + c(0, 365))
xnpv
Description
Net Present Value of an irregular cashflow (NPV)
Usage
xnpv(i, cf, d)
Arguments
i
The rate used to discount the cashflow. It must be an effective anual rate (EAR)
cf
The cashflow
The dates when each cashflow occurs. Same length as the cashflow
Examples
xnpv(i = 0.01, cf = c(-1, 0.5, 0.9), d = as.Date(c("2015-01-01", "2015-02-15", "2015-04-10")))
[.rate_curve
Description
Returns a particular rate or rates from a curve
Usage
## S3 method for class 'rate_curve'
r[rate_type = "zero_eff", x = NULL]
[.rate_curve
11
Arguments
r
rate_type
Value
If x is NULL, then returns a rate function of rate_type type. Else, it returns the rates of rate_type
type and corresponding to time x
Examples
r <- rate_curve(rates = c(0.1, 0.2, 0.3), rate_type = "zero_eff")
r["zero_eff"]
r["swap",c(1.5, 2)]
Index
[.rate_curve, 10
adjust_disc, 2
cashflow, 2
cft, 3
disc_cf, 3
find_rate, 4
irr, 4
loan, 5
npv, 5
plot.rate_curve, 6
pmt, 7
rate, 7
rate_curve, 8
rem, 9
tvm, 9
tvm-package (tvm), 9
xirr, 9
xnpv, 10
12