(9) Finance and Statistics
Before examining this topic, please make sure that you have read: (1) Working Through the New User's Tour.
Use the restart command to clear Maple's internal memory and get started with this page of the tour.
> restart;
To access the functions in the stats and finance packages by their short names, use the with command.
> with(stats);
> with(finance);
Finance Package
The finance package assists you in performing financial calculations. With it, you can calculate the present value and the accumulated value of annuities, growing annuities, perpetuities, growing perpetuities, and level coupon bonds. Moreover, it can also help you compute the yield to maturity of a bond. You can construct an amortization table, determine the effective rate of interest for a given compound interest rate, and find the present value and the future value of a fixed quantity for a given compound interest rate.
Note: All examples using dollars ($) and interest rates are expressed in terms of percent (%). The default setting for floating-point precision is 10.
Amortization Method
The most common method of repaying interest-bearing loans is the amortization method . This procedure is used to liquidate an interest-bearing debt by a series of periodic payments, usually equal, at a given interest rate. By using the amortization command, you can determine how many payments are required to pay off the loan. You can also create amortization tables.
Consider a debt of $100, with interest at 10% per annum, which is to be amortized by payments of $50 at the end of each year for as long as necessary. Calculate how many payments are required to pay off the debt.
> A:= amortization( 100, 50, 0.10 );
The output from the above command is summarized in the table below. From the result we see that you must make three payments: $50, $50, and $17.60. The last result in the output, $17.60, is the cost of the loan .
> amortization_table[n, Payment, Interest, Principal, Balance] = Matrix(A[1]);
The legend above the table explains what values appear in what columns.
Annuities
Maple can find the present value of ordinary simple annuities.
Suppose that you want to find the present value of an annuity paying $100 per annum for 5 years, starting 1 year from now, at an annual interest rate of 10%.
> annuity( 100, 0.10, 5 );
Consider a growing (increasing) annuity that pays $100 at the end of the first year, then grows at 5% per annum. It is a 5-year annuity and the annual rate of interest is 10%. To calculate its value, use the growingannuity command.
> growingannuity( 100, 0.1, 0.05, 5 );
If the interest rate changes to
% and the growth rate is unknown (call it
), then the future value is given by the formula below.
> growingannuity( 100, 0.1/12, g, 5*12 );
As a final example, analyze the case where the payments per time period are not fixed. Suppose that you want to find the present value of variable revenues expected from a project. The project expects $200 in revenue in year 1, $150 in year 2, and $100 in year 3. The opportunity cost of capital (or discount rate) is 7.8%.
> cashflows( [200, 150, 100], 0.078 );
You may generalize the above result. If the discount rate is
%, the present value of the benefits earned from the project is given by the
cashflows
command.
> cashflows( [200, 150, 100], r );
Bonds
When a corporation or government needs to borrow a large sum of money for a reasonably long period of time, they issue bonds which they sell to investors. The bond's yield rate is income divided by the dollar amount invested.
A $1000 bond that pays interest at
% (the bond rate) is redeemable at par at the end of five years. Suppose that you want to find the purchase price of the bond to yield an investor 14% compounded semi-annually.
(
Note:
The yield rate always comes before the coupon rate.)
> levelcoupon( 1000, .14/2, .10/2, 5*2 );
The result shows that the bond is purchased at a discount , since the opportunity cost of capital is higher than the bond rate.
Suppose that you want to find the yield rate to maturity of a bond. Suppose that a large corporation issues a 15-year bond that has a face value of $10,000,000, and pays interest at a rate of
%. If the purchase price of the bond is $11,729,203.32, the yield to maturity for the bond is found by using the
yieldtomaturity
command.
> yieldtomaturity( 11729203.32, 10000000.00, .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
annual effective rate of interest
is the rate
j
which, if compounded annually, will produce 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 14.17%.
The effective annual rate of interest corresponding to
% is calculated as follows.
> effectiverate( r, m );
As another example, to find the rate
equivalent to
%, enter the following command.
> 4*effectiverate( .10/4, 2/4 );
The annual effective rate is approximately 9.88%.
Recall that
is the annual interest rate that is compounded
m
times per annum. The
continuous compound rate
is the nominal interest rate that is compounded without limit, or continuously. Typical notation for this is
. For instance, the annual effective rate of interest equivalent to
= 15% is computed as follows.
> effectiverate( .15, infinity );
Interest Formulas
You can also calculate various interest scenarios.
If
is the principal at the beginning of the first interest period,
is the accumulated value at the end of
periods, and
is the interest rate per time period, then
.
You would use the
futurevalue
command to find
and the
presentvalue
command to determine
.
Suppose that you deposit $100 in the bank and earn interest at 10% per annum. The following command finds the accumulated value of your deposit at the end of four years.
> futurevalue( 100, .10, 4 );
If you want $146.41 four years from now, then how much money must you invest now at an interest rate of 10%?
> presentvalue( 146.41, .10, 4 );
You can extend the first example to the fundamental compound interest formula .
If
is the principal at the beginning of the first interest period,
is the accumulated value at the end of
periods, and
is the interest rate per conversion period, 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 that you invest $100 at an annual interest rate of 10% compounded monthly for 4 years.
This means that for each compound period, the interest is
(conventionally written 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 continue forever.
Suppose that you want to establish a scholarship fund paying scholarships of $1500 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, 0.09);
Just like simple annuities, perpetuities can grow. Suppose that you buy some shares for 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 indefinitely. The money is worth 7.5%. The following command determines the present value of these payments.
> growingperpetuity( 235, 0.075, g );
Statistics Package
The statistics package in Maple , stats , provides routines for streamlining many operations involved in the analysis of data.
Least Squares Approximation
The statistics package in Maple has a subpackage, fit , that contains commands (such as the leastsquare command) for fitting data with various models. To access the functions in the fit subpackage by their short names, execute the with(fit) command.
> with(fit);
As an example, define the data set as a sequence of two lists. The first list contains the
values of the data, which is a set of four data points. The second list contains the
values.
> Xvalues := [1, 2, 3, 4];
> Yvalues := [0, 6, 14, 24];
Now fit a quadratic model of the form
by determining the values of
,
, and
.
> leastsquare[ [x, y], y=a*x^2+b*x+c, {a, b, c} ]([Xvalues, Yvalues]);
Mean, Median, Variance, and Standard Deviation
You can perform simple statistical operations such as calculating the mean, median, variance, and standard deviation of a data set.
For example, consider the following data set. Notice that the data is enclosed in square brackets [] to make it a list (an ordered sequence of expressions).
> data := [1.1, 5.8, 3.4, 4.2, 3.9, 5, 0.9, 6.2];
To access the functions in the describe subpackage (which allows you to compute the mean, median, variance, and standard deviation) by their short names, execute the with(describe) command.
> with(describe);
Now you can compute the mean, median, variance, and standard deviation of the previously entered data.
> my_mean := mean(data);
> median(data);
> variance(data);
> my_sdev := standarddeviation(data);
The stats package supports a range of useful probability distributions, including normal, chi-squared, student t, F , and exponential . These functions effectively eliminate the need for cumbersome tables. For instance, you can compute various probabilities for a normally distributed continuous random variable by using the normald command. ( Note: The second argument is the standard deviation, not the variance.)
Recall that you assigned values to
and
in the previous section on
Mean, Median, Variance, and Standard Deviation
. Compute
for the previously assigned values.
> pr1 := statevalf[ cdf, normald[my_mean, my_sdev] ](2.44);
You can also compute
.
> pr2 := statevalf[ cdf, normald[my_mean, my_sdev] ](10) - pr1;
Statistical Plots
The stats package includes a subpackage, statplots , that has powerful graphing commands for creating plots that are specific to statistical operations. To access the functions in the statplots subpackage by their short names, execute the with(statplots) command.
> with(statplots);
The following command lines generate a scatter plot with additional graphic elements to aid in data interpretation.
The first two command lines define the data, as follows.
> Xdata := [4.535, 4.029, 5.407, 1.605, 5.757, 3.527, 7.890, 8.159, 6.092, 13.442, 2.845, 5.172, 3.277, 8.810, 3.657, 7.226, 3.851, 2.162, 2.668, 4.692];
> Ydata := [7.454, 4.476, 2.873, 5.476, 9.975, -1.476, 1.033, 1.140, 4.813, 0.450, -0.788, 9.389, 4.811, -3.107, 4.407, 5.534, 1.691, -0.789, 1.684, 1.605];
The scatterplot command generates a plot of your data.
> scatterplot( Xdata, Ydata, color=black );
The display command from the plots package allows you to display several plots simultaneously.
> with(plots):
Warning, the name changecoords has been redefined
>
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 );