(8) 统 计 与 金 融
首 先 用 with 命 令 载 入 工 具 包 stats、 finance。
> restart;
> with(stats);
> with(finance);
金 融 工 具 包 ( 本 工 具 包 内 容 未 做 汉 化 )
The finance package assists you in performing financial calculations. Wi
th it, y
ou can calculate the present value and accumulated value of annuities, g
rowing a
nnuities, perpetuities, growing perpetuities and level coupon bonds. Mor
eover, i
t can also
help you compute the yield to maturity of a bond. You can construct an a
mortizat
ion table, determine the effective rate of interest for a given compound
interes
t rate, and find the present value and future value of a fixed quantity
for a gi
ven
compound interest rate.
Note: all examples use dollars ($) and interest rates are in terms of pe
rcent (%
). Moreover, the default setting for floating point precision is 10. Rou
nd up ea
ch answer that Maple finds to the nearest cent.
Amortization Method
The most common method of repaying interest-bearing loans is the amortiz
ation me
thod . This procedure is used to liquidate an interest-bearing debt by a
series
of periodic payments, usually equal, at a given interest rate. You may u
se Maple
to
determine how many payments are required to pay off the loan, using the
amortiza
tion command. You can also create amortization tables.
A debt of $100 with interest at 10% per annum is to be amortized by paym
ents of
$50 at the end of each year for as long as necessary.
> A:= amortization( 100, 50, );
The output from the command above is summarized in the table below. From
the res
ult we see that you must make three payments: $50, $50 and $. The l
ast resu
lt in the output, $, is the cost of the loan .
> amortization_table[n, Payment, Interest, Principal, Balance] = matrix(
A[1]);
The first column of the matrix refers to the payment number. The second
column s
hows the payment per time period. The third column is how much of the pa
yment go
es towards paying off the interest. The fourth refers to how much goes t
o pay of
f the
principal per payment. The last column is the outstanding balance of the
debt.
Annuities
Maple can find the present value of ordinary simple annuities.
Suppose you want to find the present value of an annuity paying $100 per
annum,
for 5 years, starting in 1 year from now, at an annual interest rate of
10 %.
> annuity( 100, , 5 );
Consider a growing (increasing) annuity that pays $100 at the end of the
first y
ear, then grows at 5 % per annum. It is a five-year annuity and the annu
al rate
of interest is 10%. Use the growingannuity command.
> growingannuity( 100, , , 5 );
If the interest rate changes to % and the growth rate is unknown (call
it ), t
hen the future value is given by the formula below.
> growingannuity( 100, g, 5*12 );
As a final example, analyze the case where the payments per time period
are not
fixed. Suppose you want to find the present value of variable revenues e
xpected
from a project. At the end of year one, the project expects $200 in reve
nue, and
$150 and
$100 in years two and three respectively. The opportunity cost of capita
l is
%.
> cashflows( [200, 150, 100], );
You may generalize the above result. If the discount rate is %, the pre
sent val
ue of the benefits earned from the project is given by the cashflows com
mand.
> cashflows( [200, 150, 100], r );
Bonds
When a corporation or government needs to borrow a large sum of money fo
r a reas
onably long period of time, they issue bonds which they sell to investor
s.
A $1000 bond that pays interest at % (bond rate) is redeemable at par a
t the en
d of five years. Suppose you want to find the purchase price of the bond
to yiel
d an investor 14% compounded semi-annually. (Note: the yield rate always
comes b
efore the
coupon rate).
> levelcoupon( 1000, .14/2, .10/2, 5*2 );
The result shows that the bond is purchased at a discount , since the op
portunit
y cost of capital is higher than the bond rate.
Suppose you want to find the yield rate to maturity of a bond. Suppose a
large c
orporation issues a 15-year bond that has a face value of $10 000 000, a
nd pays
interest at a rate of %. If the purchase price of the bond is $11 729 2
, t
he yield to
maturity for the bond is found by the yieldtomaturity command.
> yieldtomaturity( , , .10/2, 30 );
That is, approximately 4% per half-year, or % .
Effective Interest Rates
For a given nominal rate of interest compounded times per year, the an
nual eff
ective rate of interest is the rate j which, if compounded annually, wil
l produc
e the same amount of interest per year.
Compute the annual effective rate of interest to %
effectiverate( .1325, 365 );
The annual effective rate works out to be about %.
The effective annual rate of interest corresponding to % is calculated
as follo
ws.
> effectiverate( r, m );
As another example, to find the rate equivalent to %, enter the follow
ing comm
and.
> 4*effectiverate( .10/4, 2/4 );
The annual effective rate is approximately %.
Recall that is the annual interest rate that is compounded m times per
annum. T
he continuous compound rate is the nominal interest rate that is compoun
ded with
out limit, or continuously. Typical notation for this is . For instance
, the an
nual
effective rate of interest equivalent to =15 % is computed as follows.
> effectiverate( .15, infinity );
Interest Formulas
If is the principal at the beginning of the first interest period, is
the accu
mulated value at the end of periods, and is the interest rate per time
period,
then
.
Use the futurevalue command to find and the presentvalue command to det
ermine
.
Suppose you deposit $100 in the bank and earn interest at 10% per annum.
The fol
lowing command finds the accumulated value at the end of four years.
> futurevalue( 100, .10, 4 );
If you want $ in four years from now, how much money must you inve
st now a
t an interest rate of 10%?
> presentvalue( , .10, 4 );
You can extend the first example to the fundamental compound interest fo
rmula .
If is the principal at the beginning of the first interest period, is
the accu
mulated value at the end of periods, and is the interest rate per conv
ersion p
eriod, then
.
Again you can use the futurevalue and presentvalue command, but you must
modify
the arguments for compound interest.
Going back to the first example, suppose you invest $100 at an annual in
terest r
ate of 10% compounded monthly for 4 years.
This means that for each compound period, the interest is (conventional
ly writt
en as %).
Since the number of compound periods per year is 12, the total number of
periods
is (4)(12).
The following command finds the accumulated value.
> futurevalue( 100, .10/12, 4*12 );
Perpetuities
A perpetuity is an annuity whose payments begin on a fixed date and cont
inue for
ever.
Suppose that you want to establish a scholarship fund paying scholarship
s of $15
00 each year. How much money must you invest at an annual interest rate
of 9% if
the endowment is to pay its first scholarship one year from now?
> perpetuity(1500, );
Just like simple annuities, perpetuities can grow. Suppose you buy some
shares f
or a company. You expect the first dividend payment to be $235 one year
from now
, and these payments are expected to grow at % per annum, continuing in
definite
ly. The
money is worth %. The following command determines the present value
of these
payments.
> growingperpetuity( 235, , g );
统 计 工 具 包
Maple V Release 5 的 工 具 包 stats 含 有 各 种 数 据 处 理 必 须 的 工 具
。
最 小 二 乘 逼 近
统 计 工 具 包 的 子 包 fit 包 含 各 种 用 于 数 据 拟 和 的 工 具 ( 如
leastsq
uare 命 令 ) 。 使 用 with(fit)命 令 载 入 它 。
> with(fit);
建 立 如 下 数 字 列 表 :
> Xvalues := [1, 2, 3, 4];
> Yvalues := [0, 6, 14, 24];
我 们 使 用 二 次 模 型 来 拟 和 这 组 数 据 , 得 到 系 数 a,b,c.
> leastsquare[ [x, y], y=a*x^2+b*x+c, {a, b, c} ]([Xvalues, Yvalues]);
均 值 、 中 值 、 均 差 、 标 准 差
参 见 : 概 率 分 布
例 如 以 下 数 据 列 表 :
> data := [, , , , , 5, , ];
我 们 载 入 描 述 统 计 子 包 ,
> with(describe);
计 算 例 中 数 据 的 均 值 、 中 值 、 均 差 、 标 准 差 。
> my_mean := mean(data);
> median(data);
> variance(data);
> my_sdev := standarddeviation(data);
概 率 分 布
统 计 工 具 包 stats 支 持 各 种 用 途 广 泛 的 概 率 分 布 , 包 括 : 正
态 分
布 ( normal) 、 卡 方 分 布 ( chi-squared) 、 t 分 布 ( student t)
、 F 分
布 ( F) 、 指 数 分 布 ( exponential) 等 。 这 些 函 数 摆 脱 了 人
们 对 数
学 用 表 的
依 赖 。 例 如 函 数 normald 计 算 随 即 变 量 的 正 态 分 布 。
使 用 上 节 数 据 计 算 概 率 :
> pr1 := statevalf[ cdf, normald[my_mean, my_sdev] ]();
计 算 概 率 : .
> pr2 := statevalf[ cdf, normald[my_mean, my_sdev] ](10) - pr1;
统 计
stats 还 带 有 子 包 statplots ,它 内 置 许 多 表 达 统 计 操 作 的 绘 图
命 令
。
> with(statplots);
下 例 生 成 一 组 数 据 的 散 点 图 以 及 用 于 诠 释 数 据 的 其 他 图
形 元 素
。
> Xdata := [, , , , , , , ,
2,
2, , , , , , , , , , ]
;
> Ydata := [, , , , , , , ,
13,
0, , , , , , , , , ,
05];
命 令 scatterplot 生 成 散 点 图
> scatterplot( Xdata, Ydata, color=black );
plots 工 具 包 的 命 令 display 允 许 我 们 同 时 显 示 多 图 。
> with(plots):
> display( { scatterplot( Xdata, Ydata, color=black),
boxplot[15]( Ydata, color=green ), xyexchange(
boxplot[12]( Xdata, color=blue , format=notched) ) },
view=[0..17, -4..14], axes=frame );