newuser,topic09

(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);

[anova, describe, fit, importdata, random, stateval...

> with(finance);

[amortization, annuity, blackscholes, cashflows, ef...
[amortization, annuity, blackscholes, cashflows, ef...
[amortization, annuity, blackscholes, cashflows, ef...

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 );

A := [[0, 0, 0, -100, 100], [1, 50, 10.00, 40.00, 6...
A := [[0, 0, 0, -100, 100], [1, 50, 10.00, 40.00, 6...
A := [[0, 0, 0, -100, 100], [1, 50, 10.00, 40.00, 6...

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]);

amortization_table[n,Payment,Interest,Principal,Bal...
amortization_table[n,Payment,Interest,Principal,Bal...

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 );

379.0786769

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 );

415.0591276

If the interest rate changes to j[12] = 10 % and the growth rate is unknown (call it g ), then the future value is given by the formula below.

> growingannuity( 100, 0.1/12, g, 5*12 );

100*(1-(.9917355375+.9917355375*g)^60)/(.8333333333...

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 );

394.4330862

You may generalize the above result. If the discount rate is r %, the present value of the benefits earned from the project is given by the cashflows command.

> cashflows( [200, 150, 100], r );

200*1/(1+r)+150/((1+r)^2)+100/((1+r)^3)

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 j[2] = 10 % (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 );

859.5283693

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 j[2] = 10 %. 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 );

.4000000005e-1

That is, approximately 4% per half-year, or j[2] = 8 %.

Effective Interest Rates

For a given nominal rate of interest j[m] compounded m 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 j[365] = 13.25 %.

effectiverate( .1325, 365 );

.141651692

The annual effective rate works out to be about 14.17%.

The effective annual rate of interest corresponding to j[m] = r % is calculated as follows.

> effectiverate( r, m );

(1+r/m)^m-1

As another example, to find the rate j[4] equivalent to j[2] = 10 %, enter the following command.

> 4*effectiverate( .10/4, 2/4 );

.98780308e-1

The annual effective rate is approximately 9.88%.

Recall that j[m] 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 j[infinity] . For instance, the annual effective rate of interest equivalent to j[infinity] = 15% is computed as follows.

> effectiverate( .15, infinity );

.161834243

Interest Formulas

You can also calculate various interest scenarios.

If P is the principal at the beginning of the first interest period, S is the accumulated value at the end of t periods, and r is the interest rate per time period, then

S = P(1+r)^t .

You would use the futurevalue command to find S and the presentvalue command to determine P .

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 );

146.4100000

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 );

100.0000000

You can extend the first example to the fundamental compound interest formula .

If P is the principal at the beginning of the first interest period, S is the accumulated value at the end of n periods, and i is the interest rate per conversion period, then

S = P(1+i)^n .

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 .10/12 (conventionally written as j[12] = 10 %).

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 );

148.9354075

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);

16666.66667

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 g % 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 );

235*1/(.75e-1-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);

[leastmediansquare, leastsquare]

As an example, define the data set as a sequence of two lists. The first list contains the x values of the data, which is a set of four data points. The second list contains the y values.

> Xvalues := [1, 2, 3, 4];

Xvalues := [1, 2, 3, 4]

> Yvalues := [0, 6, 14, 24];

Yvalues := [0, 6, 14, 24]

Now fit a quadratic model of the form a*x^2+b*x+c by determining the values of a , b , and c .

> leastsquare[ [x, y], y=a*x^2+b*x+c, {a, b, c} ]([Xvalues, Yvalues]);

y = x^2+3*x-4

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];

data := [1.1, 5.8, 3.4, 4.2, 3.9, 5, .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);

[coefficientofvariation, count, countmissing, covar...
[coefficientofvariation, count, countmissing, covar...
[coefficientofvariation, count, countmissing, covar...
[coefficientofvariation, count, countmissing, covar...

Now you can compute the mean, median, variance, and standard deviation of the previously entered data.

> my_mean := mean(data);

my_mean := 3.812500000

> median(data);

4.050000000

> variance(data);

3.403593750

> my_sdev := standarddeviation(data);

my_sdev := 1.844883126

Probability Distributions

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 my_mean and my_sdev in the previous section on Mean, Median, Variance, and Standard Deviation . Compute Pr(x <= 2.44) for the previously assigned values.

> pr1 := statevalf[ cdf, normald[my_mean, my_sdev] ](2.44);

pr1 := .2284534938

You can also compute Pr(2.44 <= x and x <= 10) .

> pr2 := statevalf[ cdf, normald[my_mean, my_sdev] ](10) - pr1;

pr2 := .7711480586

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);

[boxplot, histogram, scatterplot, xscale, xshift, x...
[boxplot, histogram, scatterplot, xscale, xshift, x...

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];

Xdata := [4.535, 4.029, 5.407, 1.605, 5.757, 3.527,...
Xdata := [4.535, 4.029, 5.407, 1.605, 5.757, 3.527,...

> 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];

Ydata := [7.454, 4.476, 2.873, 5.476, 9.975, -1.476...
Ydata := [7.454, 4.476, 2.873, 5.476, 9.975, -1.476...

The scatterplot command generates a plot of your data.

> scatterplot( Xdata, Ydata, color=black );

[Maple Plot]

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 );

[Maple Plot]

Click here to return to the Main Menu.

© 2009 by the Rector and Visitors of the University of Virginia.

The information contained on the University of Virginia’s Department of Information Technology and Communication (ITC) website is provided as a public service with the understanding that ITC makes no representations or warranties, either expressed or implied, concerning the accuracy, completeness, reliability or suitability of the information, including warrantees of title, non-infringement of copyright or patent rights of others. These pages are expected to represent the University of Virginia community and the State of Virginia in a professional manner in accordance with the University of Virginia’s Computing Policies.