Financial Modeling in Maple

The Finance package


The Finance package is new in Maple 15. It contains many tools for advanced financial modeling, as well as accessible tools for personal finance. On the personal finance side, there are tools that can be used for computing with mortgages or retirement packages. The financial modeling tools include a wide range of stochastic processes that can be used to model option prices, such as Brownian motion, Ito processes, an SVJJ process, and more. It also includes tools to compose complex processes out of these building blocks. You can also create, manipulate, and analyze many types of financial instruments, such as American, Bermudan, and European options and swaptions and several types of bonds; short rate models; term structures of interest rates; and cash flows. The instruments can then be priced using analytic methods, lattice methods or Monte Carlo simulation  all using one of many date arithmetic conventions. Finally, the processes occurring in the package can be visualized in several ways.
> 


Personal finance



Annuities


If you would like to receive 100 units of money each year for 20 years (for, say, a retirement package), you need less than units to start with, because interest is paid (and compounds) over the sum that will be paid to you later. The amount needed can be computed by the annuity function. The following shows the result for an interest rate of 4%.
> 


(1.1.1.1) 


Interest formulas


Consider a loan of 100 units of money with a nominal annual interest rate of 4.5% where interest compounds every two months. The following command finds the accumulated value of the deposit over three years (that is, 18 periods).
> 


(1.1.2.1) 
The effective interest rate per year can be computed in the following two ways.
> 


(1.1.2.2) 
> 


(1.1.2.3) 



Stochastic processes


Many basic and more advanced stochastic processes are implemented in the Finance package. Here are a few examples.

Brownian Motion


A basic process is Brownian motion (with given initial value, drift, and diffusion).
> 

> 



Ito process


Ito processes are fairly general. Their drift and diffusion can depend on the state and time. For example, here is a process that gets much more volatile at .
> 


(1.2.2.1) 
> 



Heston process


A more advanced process is the Heston process, where the volatility is itself subject to a stochastic differential equation. This is implemented as a twodimensional process.
> 


(1.2.3.1) 
> 

You can see that some of the sample paths result in much higher volatility than others.


Composite process


Finally, you can compose multiple processes into one with a regime switching process, for example, for switching between two Brownian motion processes, one with high volatility and low drift and one with low volatility and high drift. The switching process is determined by a state transition matrix.
> 

> 




Interest rates



Term structures


The Finance package supports a number of different tools for interest rate term structures. You can define a yield curve in a number of different ways. This yield curve can be used to construct some of the more advanced short rate models described in the next section, or to compute zero rates, discount rates, or other similar rates.
> 


(1.3.1.1) 
> 


(1.3.1.2) 
> 

> 


(1.3.1.3) 
> 


(1.3.1.4) 


Short rate models


The Finance package supports a number of different short rate models. The simplest is the Vasicek model.
> 

> 


(1.3.2.1) 
> 

The CoxIngersollRoss model is more advanced. It uses a yield curve.
> 


(1.3.2.2) 
> 


(1.3.2.3) 
> 




Financial instruments: construction and pricing



Bonds


The Finance package supports bonds with a number of different types of coupons: zero coupon bonds, fixed coupon bonds, and floating rate bonds.
> 

> 


(1.4.1.1) 
> 


(1.4.1.2) 
> 

> 


(1.4.1.3) 
> 

Get the set of cash flows for your bonds.
> 


(1.4.1.4) 
Calculate the clean price and the dirty price for your bond using the fixed rate of 5% as the discount rate.
> 


(1.4.1.5) 
> 


(1.4.1.6) 
> 


(1.4.1.7) 
Calculate the bond's yield using the previous discount rate.
> 


(1.4.1.8) 
> 


(1.4.1.9) 


Options


The Finance package supports American, European and Bermudan options with arbitrary payoff functions. The option is constructed separately from the process that describes the value of the underlying asset. Consider a European strangle which pays off if the underlying asset deviates more than 20 units from 100, in either direction.
> 


(1.4.2.1) 
> 

> 

The option is priced using a BlackScholes process for the underlying asset. The initial value is 100, the riskfree rate 5% and the volatility is constant at 40%. Assume no dividend is paid and divide the time from now to six months from now into 1000 equal time steps for lattice pricing.
> 

> 


(1.4.2.2) 
You can also run a Monte Carlo pricing process.
> 

> 


(1.4.2.3) 
Or, finally, compute the price analytically.
> 


(1.4.2.4) 
You can visualize the lattice and the Monte Carlo run together, but preferably using fewer time steps and replications. This time, a trinomial tree is used.
> 


(1.4.2.5) 
> 

Here is a Bermudan put option with exercise times in four and six months and a strike price of 90.
> 

> 

> 


(1.4.2.6) 
Here is the lattice price.
> 


(1.4.2.7) 
Monte Carlo and analytical pricing are not builtin for nonEuropean options. However, if you realize that after four months, the owner of the option can either exercise the option or she effectively now has a twomonth European put option, you can still use this approach. Use the analytic approach to find the price of the European put option for two months if the current price is :
> 


(1.4.2.8) 
As an aside, you can now determine at which value it is useful to exercise the put option after four months.
> 


(1.4.2.9) 
So if the current price after four months is less than , the owner should exercise the option (she can always buy a European option for two months instead); otherwise, she should hold on to it. Either way, the value of the Bermudan option is the maximum of the exercise price and the price of the two month European option. Use this for a Monte Carlo simulation to find the current value of the Bermudan option.
> 


(1.4.2.10) 


Swaps and swaptions


Maple's Finance package can deal with interest rate swaps. You define the payment schedule and the type of interest rate.
> 

> 


(1.4.3.1) 
> 


(1.4.3.2) 
> 

> 

> 

> 

Construct an interest rate swap with fixed rate 0 and compute the fair rate. This allows you to define the atthemoney rate for the atthemoney swap you will construct after that.
> 

> 


(1.4.3.3) 
> 

The swaption can be exercised from the day after the start of the swap, until the day after the onebutlast coupon payment date for the paying leg of the swap. These dates can be found as follows.
> 


(1.4.3.4) 
> 


(1.4.3.5) 
You can now price the swaption using lattice methods.
> 

> 

> 


(1.4.3.6) 
What happens if you take a finer or a coarser time grid? Let the number of steps vary between 50 and 1600.
> 


(1.4.3.7) 
> 

> 


(1.4.3.8) 
> 

The plot gives some confidence that further refining of the time grid will not change the first three significant digits.



Legal Notice: © Maplesoft, a division of Waterloo Maple Inc. 2011. Maplesoft and Maple are trademarks of Waterloo Maple Inc. This application may contain errors and Maplesoft is not liable for any damages resulting from the use of this material. This application is intended for noncommercial, nonprofit use only. Contact Maplesoft for permission if you wish to use this application in forprofit activities.
