An Introduction to Derivatives, Bonds, and Annuities in Mathematica

Michael Kelly

Wolfram Research Technology Consultant

GraphicsRow[{TradingChart[{"GOOG",DatePlus[-360]},{"Volume","SimpleMovingAverage","HighestHigh","RelativeStrengthIndex"},PlotLabel->"Google prices"],DateListLogPlot[FinancialData["^DJI",DatePlus[-360]],Joined->True,Filling->Bottom,PlotLabel->"Dow Jones Index"],DateListLogPlot[FinancialData["SP500",DatePlus[-360]],Joined->True,Filling->Bottom,PlotLabel->"S&P 500 Index"]},ImageSize->{870,370}]

Outline

Mathematica now has a new range of high level financial functions. These can be accessed in the help documentation at: guide/Finance

These functions can be accessed by all the other functions in Mathematica, especially the general solution functions like Solve, FindRoot, Simplify and Full Simplify. Financial Data functions, Financial Bonds and Derivatives can also be plotted using ListPlot, ListLogPlot, ListPlot3D, DateListPlot and DateListLogPlot. 

In the diagrams below we represent these functional relationships in LayeredGraphPlots using the directed edges to indicate that some functions can be used as inputs to other functions. Not all possible relations are illustrated, just the most relevant.

TimeValue computations

Annuities, AnnuitiesDue

Cashflow

EffectiveInterest

TimeValue

Labeled[Framed[LayeredGraphPlot[{EffectiveInterest->Annuity,EffectiveInterest->AnnuityDue,EffectiveInterest->Cashflow,Annuity->Cashflow,AnnuityDue->Cashflow,EffectiveInterest->TimeValue,Cashflow->TimeValue,Annuity->TimeValue,AnnuityDue->TimeValue,EffectiveInterest->Solve,Cashflow->Solve,Annuity->Solve,AnnuityDue->Solve,TimeValue->Solve,EffectiveInterest->FindRoot,Cashflow->FindRoot,Annuity->FindRoot,AnnuityDue->FindRoot,TimeValue->FindRoot,EffectiveInterest->Simplify,Cashflow->Simplify,Annuity->Simplify,AnnuityDue->Simplify,TimeValue->Simplify},VertexLabeling->True,DirectedEdges->True,ImageSize->{870,270}]],Style["Time Value Computations",Magenta,Large],Top]

Financial Instruments

FinancialBond

FinancialDerivative

CUDAFinancialDerivative

Labeled[Framed[LayeredGraphPlot[{FinancialBond->ListPlot,FinancialDerivative->ListPlot,CUDAFinancialDerivative->ListPlot,FinancialBond->ListLogPlot,FinancialDerivative->ListLogPlot,CUDAFinancialDerivative->ListLogPlot,FinancialBond->DateListPlot,FinancialDerivative->DateListPlot,CUDAFinancialDerivative->DateListPlot,FinancialBond->DateListLogPlot,FinancialDerivative->DateListLogPlot,CUDAFinancialDerivative->DateListLogPlot,FinancialBond->ListPlot3D,FinancialDerivative->ListPlot3D,CUDAFinancialDerivative->ListPlot3D},VertexLabeling->True,DirectedEdges->True,ImageSize->{850,215}]],Style["Financial Instruments",Magenta,Large],Top]

Time Value, Annuity and Cashflow Valuation

Uniform notation

syntax=Framed[Panel[Column[{
Style[HoldForm@TimeValue[amount,rate,time],25],Style[HoldForm@TimeValue[Cashflow[{(Subscript[c, 0]),(Subscript[c, 1]),(Subscript[c, 2]),…}],r,t],25],
Style[HoldForm@TimeValue[Annuity[payment,periods, time interval],r,t],25],
Style[HoldForm@TimeValue[security,EffectiveInterest[nominalrate,compounding],time],25]
}], BaseStyle->{FontFamily-> "Georgia", Medium}, Background-> LightGray], RoundingRadius-> 8, Background-> LightGray]

Present and Future values using TimeValue:

fvpv=Framed[Panel[Column[{
Row[{Style["Future Value:",25],"        ",Column[{Style[HoldForm@TimeValue[100,.05,10],25],Style[HoldForm@TimeValue[Annuity[100,10],.05,10],25]}]}],
"       ",
 Row[{Style["Present Value:",25],"       ",Column[{Style[HoldForm@TimeValue[100,.05,-10],25],Style[HoldForm@TimeValue[Annuity[100,10],.05,0],25]}]}
]}], BaseStyle->{FontFamily-> "Georgia", Medium}, Background-> Lighter@Lighter@ LightGray], RoundingRadius-> 8, Background->Lighter@ LightGray]

Time Value, Annuity and Cashflow Valuation

Overview of all the Time Value and Annuity features can be displayed in one Tab View:

TabView[{
"Syntax"->Framed[Panel[Column[{
Style[HoldForm@TimeValue[amount,rate,time],25],Style[HoldForm@TimeValue[Cashflow[{(Subscript[c, 0]),(Subscript[c, 1]),(Subscript[c, 2]),…}],r,t],25],
Style[HoldForm@TimeValue[Annuity[payment,periods],r,t],25],
Style[HoldForm@TimeValue[security,EffectiveInterest[nominalrate,compounding],time],25]
}], BaseStyle->{FontFamily-> "Georgia", Medium}, Background-> LightGray], RoundingRadius-> 8, Background-> LightGray],
"Future/present\nvalue"->Framed[Panel[Column[{
Row[{Style["Future Value:",25],"        ",Column[{Style[HoldForm@TimeValue[100,.05,10],25],Style[HoldForm@TimeValue[Annuity[100,10],.05,10],25]}]}],
"       ",
 Row[{Style["Present Value:",25],"       ",Column[{Style[HoldForm@TimeValue[100,.05,-10],25],Style[HoldForm@TimeValue[Annuity[100,10],.05,0],25]}]}
]}], BaseStyle->{FontFamily-> "Georgia", Medium}, Background-> Lighter@Lighter@ LightGray], RoundingRadius-> 8, Background->Lighter@ LightGray],
"Plot variables"->Framed[Panel[GraphicsRow[
{ann=TimeValue[Annuity[100,t],.05,t];
Plot[ann,{t,0,15},AxesLabel->{"time","annuity present value"},Filling->Bottom,AxesOrigin->{0,0},BaseStyle->{FontSize->Medium}],
bond=FinancialBond[{"FaceValue"->1000,"Coupon"->0.07,"Maturity"->10,"CouponInterval"->(1/2)},{"InterestRate"->.09,"Settlement"->t},{"FullValue","Value"}];Plot[bond,{t,0,10},Exclusions->None,AxesLabel->{"time","bond price"},GridLines->{None,{1000}},BaseStyle->{FontSize->Medium}]
},ImageSize->600], BaseStyle->{FontFamily-> "Georgia", Large}, Background-> White], RoundingRadius-> 8, Background->Lighter@ LightGray],
"Symbolic structure"->Column[{HoldForm@TimeValue[Annuity[pmt(((1+g))^(f #-1))&,n,1/f],r,s],TimeValue[Annuity[pmt(((1+g))^(f #-1))&,n,1/f],r,s]},Frame-> All, Background-> LightGray, BaseStyle->{FontFamily-> "Georgia", FontSize-> 16}, Spacings->{2,5}],
"Solve for variables"->Column[{HoldForm@Solve[TimeValue[Cashflow[{{t1,cf1},{t2,cf2},{t3,cf3}}],r,s]==5000,t3],Solve[TimeValue[Cashflow[{{t1,cf1},{t2,cf2},{t3,cf3}}],r,s]==5000,t3]},Frame-> All, Background-> LightGray, BaseStyle->{FontFamily-> "Georgia", FontSize-> 16}, Spacings->{2,5}],
"Random variates"->Column[{HoldForm@(nsp=Expectation[TimeValue[1,EffectiveInterest[r,0],-t],t\[Distributed]GompertzMakehamDistribution[a,b]] ;
Solve[
Expectation[TimeValue[AnnuityDue[premium,t],EffectiveInterest[r,0],0],t\[Distributed]GompertzMakehamDistribution[a,b]]
==nsp,premium]),nsp=Expectation[TimeValue[1,EffectiveInterest[r,0],-t],t\[Distributed]GompertzMakehamDistribution[a,b]] ;
Solve[
Expectation[TimeValue[AnnuityDue[premium,t],EffectiveInterest[r,0],0],t\[Distributed]GompertzMakehamDistribution[a,b]]
==nsp,premium]},Frame-> All, Background-> LightGray, BaseStyle->{FontFamily-> "Georgia", FontSize-> 16}, Spacings->{2,5}],
"Continuous payment flows"->Column[{HoldForm@TimeValue[Annuity[A ((Sin[#])^2)&,n,0],r,0],TimeValue[Annuity[A ((Sin[#])^2)&,n,0],r,0]},Frame-> All, Background-> LightGray, BaseStyle->{FontFamily-> "Georgia", FontSize-> 16}, Spacings->{2,5}]
},1, Alignment->{Center,Center},ControlPlacement->Left]

Time Value Instruments

Before one can evaluate Annuities it is necessary to understand that their values are time dependent and that it is necessary to be able to calculate the present discounted and future values of Annuities.
This involves the introduction of the TimeValue function. Furthermore Annuities are a special case of the more general system of cashflows. So we will also look at the Cashflow function and consider the relationship between it and the Annuity function.

TimeValue works with symbolic parameters:

TimeValue[amount,rate,periods]

EffectiveInterest works with symbolic parameters:

EffectiveInterest[r,1/f]

EffectiveInterest[{{0,(Subscript[r, 0])},{2,(Subscript[r, 2])},{3,(Subscript[r, 3])},{5,(Subscript[r, 4])},{7,(Subscript[r, 5])}},1/f]

EffectiveInterest[{(Subscript[r, 1]),(Subscript[r, 2]),(Subscript[r, 3]),(Subscript[r, 4]),(Subscript[r, 5])},1/f]

EffectiveInterest[{1->r3,2->r4,3->r5,5->r6,7->r7}]

Annuity works with symbolic parameters and can find closed-form expressions:

TimeValue[Annuity[pmt(((1+g))^(f#-1))&,n,1/f],r,t]

Cashflow works with symbolic parameters:

TimeValue[Cashflow[{{p1,c1},{p2,c2},{p3,c3}}],r,t]

Also Cashflow can convert any annuity into the corresponding sequence of cashflows:

Cashflow[Annuity[pmt +g (#-1)&,10]]

The time value of an annuity as a function of its fixed payment, interest rate and number of payments:

Manipulate[Plot[Evaluate[TimeValue[Annuity[pmt,n],r,t]],{t,0,20},AxesLabel->{"Time","Present value"},Filling->Bottom,AxesOrigin->{0,0},BaseStyle->{FontSize->Medium},PlotRange->{{0,20},{0,40}},FillingStyle->LightGreen,PlotStyle->Directive[{Thick, Red}]],
{{pmt,2,"Payment amount"},1,3},{{n,7,"Number of payments"},5,10},{{r,.07,"Interest rate"},.05,.15}]

Time Value, Annuity and Cashflow Valuation

An applet for plotting the future value of a Cashflow with varying payments and input parameters:

Manipulate[Plot[Evaluate[
TimeValue[Cashflow[Table[pmt(((1+g))^i),{i,0,numb}]],EffectiveInterest[r,1/c],n]],
{n,5,30},AxesLabel->{"time","value"},PlotRange->{0,25000},Filling->Axis],
{{pmt,150,"payment amount"},100,300},{{g,.06,"payment growth rate"},.01,.15},{{numb,5,"number of payments"},1,20},{{r,.05,"interest rate"},.01,.15},{{c,2,"compounding rate"},1,10},FrameLabel->"future value of a Cashflow with varying payments"]

An applet for plotting the future value of a Annuity with varying payments and input parameters:

Manipulate[
Plot[Evaluate[TimeValue[Annuity[pmt(((1+g))^(f#-1))&,n,1/f],EffectiveInterest[r,1/c],n]],
{n,5,30},AxesLabel->{"time","value"},PlotRange->{0,3000000},Filling->Axis],
{{pmt,150,"payment"},100,300},{{g,.10,"payment growth rate"},.01,.15},{{r,.05,"interest rate"},.01,.15},{{f,2,"payment intervals"},1,5,1},{{c,2,"compounding rate"},1,10},FrameLabel->"future value of an Annuity with varying payments"]

Bond Valuation

Annuities include bonds as a special case, which can be described by TimeValue[Annuity[{p,{0,(Subscript[p, final])}},t,q],r,0]. 
In this way a bond is the instance of an annuity where the final payment equals the principal payment and the coupon.
However the annuity structure doesn’t allow us to study the effects of different interest rate and dividend yield specifications. However the FinancialBond function caters for these additional subtleties.
FinancialBond represents a class of financial instruments involving a series of coupon payments together with a principal payment made at maturity.

All of the features for a Financial Bond can be displayed in one Tab View:

Panel[Column[{HoldForm@FinancialBond[
{"FaceValue"->par,"Coupon"->c,"Maturity"->{2020,1,1},"CouponInterval"->1/2},{"InterestRate"->r,"Settlement"->{2010,3,8},"DayCountBasis"->"Actual/365"},
Style["property",Italic]
],
"     ",
TabView[#->Column[{
FinancialBond[
{"FaceValue"->par,"Coupon"->c,"Maturity"->{2020,1,1},"CouponInterval"->1/2},{"InterestRate"->r,"Settlement"->{2010,3,8},"DayCountBasis"->"Actual/365"},
#
]}]&/@{"Value","AccruedInterest","Duration","Convexity","SettlementToCouponDays","NextCouponDate","RemainingCoupons"},1, Alignment->{Center,Center},ControlPlacement->Left]

},BaseStyle->{FontFamily-> "Georgia", 16}, Background-> Lighter@Lighter@ LightGray],  Background->Lighter@ LightGray]

Bond Valuation

An applet for pricing a Bond and its various properties with varying yield curve and input parameters:

Manipulate[
Quiet[TableForm[{FinancialBond[{"FaceValue"->FV,"Coupon"->Crate,"Maturity"->M,"CouponInterval"->CI,"RedemptionValue"->RV},{"InterestRate"->IR,"Settlement"->S,"DayCountBasis"->DCB},properties]},TableHeadings->{None,properties}]],{{FV,1000,"Face Value"},InputField},{{Crate,0.05,"Coupon"},InputField},{{M,10,"Maturity"},InputField},{{CI,1/4,"Coupon Interval"},InputField},{{RV,1000,"Redemption Value"},InputField},Delimiter,{{IR,{1->.02,2->.03,3->.04,5->.045,10->.06},"Interest Rate Yield Curve"},InputField},{{S,3/12,"Settlement"},InputField},{{DCB,"30/360","DayCountBasis"},{Automatic,"30/360","30E/360","30E/360German","30E+/360","ActualICMA","ActualISDA","Actual/365","Actual/360","Actual/365L","ActualAFB"},ControlType->PopupMenu},{{numb,6,"number of properties"},1,13,1,Appearance->"Open"},{{properties,{"Value","FullValue","AccruedInterest","Duration","ModifiedDuration","Convexity"},"Properties"},Subsets[{"Value","FullValue","AccruedInterest","Duration","ModifiedDuration","Convexity","CouponPeriodDays","CouponToSettlementDays","SettlementToCouponDays","NextCouponDate","PreviousCouponDate","RemainingCoupons","AccruedFactor"},{numb}],ControlType->PopupMenu},ControlPlacement->Top,FrameLabel->"Pricing a Bond with varying yield curve"]

FinancialDerivative

Derivatives or options as they are sometimes called are higher order financial instruments or functions of underlying assets. As such they derive their value from the distribution of future values of those assets. In this way derivatives depend upon the assumptions of the future behaviour of their underlying instruments and use probability distributions, especially the lognormal distribution to describe the range of future underlying values at maturity.

Overview

ticks[min_,max_]:=Table[{j,Round[j 50],{.04,0}},{j,min,max, 0.2}];
s4=Framed[Panel[Manipulate[Text/@FinancialDerivative[]//TableForm, ContentSize->{400,200}], BaseStyle->{FontFamily-> "Georgia", Large}, Background-> LightGray], RoundingRadius-> 8, Background-> LightGray];
s1=Framed[Panel[Column[{pmsft=FinancialData["MSFT"];Spacer[20],Manipulate[ListPlot[{#,  FinancialDerivative[{"American","Put"}, {"StrikePrice"-> 40.00, "Expiration"->3},  {"InterestRate"-> EffectiveInterest[.05,0], "Volatility" -> 0.26, "CurrentPrice"-> pmsft, "Dividend"->0.07,"ReferenceTime"->#}, "CriticalValue", "GridSize"->{xgrid,50}]}&/@Range[0,3, 0.05], Joined->True,InterpolationOrder->0, Filling->Bottom,FillingStyle->Directive[Opacity[0.7], ColorData[1,2], Specularity[White,10]],Axes->False, Frame->True, PlotRange->All, ImageSize->350, PlotLabel->"Critical Value of a put option as a function of years to expiration"], {{xgrid, 500, "size of the numerical grid"}, 100, 1000, 100}]}], BaseStyle->{FontFamily-> "Georgia", 15}, Background-> LightGray], RoundingRadius-> 8, Background-> LightGray];
s2=Framed[Panel[Column[{Spacer[20],Manipulate[ListPlot[{#,FinancialDerivative[contspec,{"Expiration"->1,"MaxSoFar"->50},{"CurrentPrice"->45,"Dividend"->0.04,"Volatility"->#,"InterestRate"->0.05},"CriticalValue"]}&/@Range[0.1, 0.5, 0.02], Filling->Axis, FillingStyle->ColorData[1,3],ImageSize->350, PlotLabel->"Critical Values of Exotics as a function of volatility"], {{contspec,"Russian", "Contract specification"} ,{"Russian"->"Russian", {"PerpetualLookback","Put"}->"Perpetual put"}}]}], BaseStyle->{FontFamily-> "Georgia", 15}, Background-> LightGray], RoundingRadius-> 8, Background-> LightGray];
s3=Framed[Column[{Style[Text["Greeks for an American call option"], Bold, 20],Spacer[20],Panel[Grid[{Take[#, 3], Take[#, -2]}&@(ListPlot[#, Ticks->{ticks, Automatic}, Epilog->Inset[Rotate[Text[Style[#2,Bold,16,Directive[Opacity[0.5]],FontFamily->"Courier"]],0]]]&@@@Transpose[{Transpose[Table[{i,#}&/@FinancialDerivative[{"American", "Call"}, {"StrikePrice"->40,"Expiration"->3},  {"InterestRate"-> 0.01,"Volatility" -> 0.2, "CurrentPrice"-> 50 i,"Dividend"->0.05,"ReferenceTime"->0.4}, "Greeks"][[All, 2]], {i,0.5,1,0.05}]], {"Delta", "Gamma", "Rho", "Theta", "Vega"}}])], BaseStyle->{FontFamily-> "Georgia", Large}, Background-> LightGray]}, Alignment->Center], RoundingRadius-> 8, Background-> LightGray];
s5=Framed[Panel[Column[{Spacer[20],Manipulate[ListLinePlot[Table[{i,FinancialDerivative[{"American","Call"}, {"StrikePrice"->40.00, "Expiration"->1, "Value"->i},  {"InterestRate"-> int,"CurrentPrice"-> 50, "Dividend"->0.05}, "ImpliedVolatility"]}, {i, 15, 25, 0.5}], PlotStyle->ColorData[1,5],Frame->True, Axes->False, FrameLabel->{"Price", "Volatility"}] , {{int,0.02, "Interest rate"}, 0.01, 0.1}]}], BaseStyle->{FontFamily-> "Georgia", 15}, Background-> LightGray], RoundingRadius-> 8, Background-> LightGray];
TabView[{"Solvers for vanillas\nand exotics"-> s4, "Control over\nnumerical evaluation"-> s1,"Computation\nof Greeks"->s3, "Compute IV"->s5, "Exotic Contracts"->  s2}, Alignment-> {Center, Center}, Appearance-> {"Limited", 6}]

Intuitive, Unified interface

FinancialDerivative[{"American","Call"},{"StrikePrice"->40,"Expiration"->1},{"CurrentPrice"->30,"Dividend"->0.05,"Volatility"->0.3,"InterestRate"->0.05}, {"Value", "CriticalValue"}]

{“American”,”Call”} contract specification

{“StrikePrice”->40,”Expiration”->1} contract parameter specification

{“CurrentPrice”->30,”Dividend”->0.05,”Volatility”->0.3,”InterestRate”->0.05} ambient parameter specification

{“Value”, “CriticalValue”} return values

A list of all the contracts:

FinancialDerivative[]

Determine the output

Grid[({Style[#, 14, Bold], Style[#2, 14, Italic, Background->LightYellow]}&@@@{{"Value","value on the reference date"},{"CriticalValue","critical value for American options"},{"Delta","derivative of the value with respect to the price"},{"Gamma","second derivative of the value with respect to the price"},{"Rho","derivative of the value with respect to the interest rate"},{"Theta","derivative of the value with respect to the time until expiration"},{"Vega","derivative of the value with respect to the volatility"},{"ImpliedVolatility","volatility implied by the contract price"}}), Frame->All, Alignment->{Left}]

Determine the parameters for a vanilla American contract:

FinancialDerivative[{"American","Put"}]

Value of a American vanilla contract:

FinancialDerivative[{"American","Put"}, {"StrikePrice"->60.00, "Expiration"->1},  {"InterestRate"-> 0.01, "Volatility" -> 0.1, "CurrentPrice"-> 50, "Dividend"->0.05}]

Value and all Greeks of an American put option:

FinancialDerivative[{"American","Put"}, {"StrikePrice"->60.00, "Expiration"->1},  {"InterestRate"-> 0.01, "Volatility" -> 0.1, "CurrentPrice"-> 50, "Dividend"->0.05}, {"Value", "Greeks"}]

Determine the parameters for a Compound contract to buy on an underlying European put option:

FinancialDerivative[{"CompoundPut","European","Call"}]

Value and all Greeks of a Compound call on an underlying European put option:

FinancialDerivative[{"CompoundPut","European","Call"},{"Expiration"->1,"ExpirationUnderlying"->2,"StrikePrice"->50,"StrikePriceUnderlying"->50},{"CurrentPrice"->50,"Dividend"->0.02,"InterestRate"->0.05,"Volatility"->0.4},"Rules"]

A manipulate GUI for a wide range of derivatives:

Manipulate[Quiet[FinancialDerivative[derivative,{"AverageSoFar"->50,"Barrier"->40,"Barriers"->{25,40},"Coupon"->10,"Expiration"->1,"ExpirationCall"->2,"ExpirationPut"->2,"ExpirationUnderlying"->2,"ExtensionFee"->3,"ExtensionPeriod"->1,"Fractions"->{0.3,0.5},"Inception"->-1,"MaxSoFar"->55,"MinSoFar"->45,"Money"->50,"NominalAmount"->50,"Rebate"->3,"StrikePrice"->50,"StrikePriceAdjusted"->50,"StrikePriceCall"->50,"StrikePricePut"->50,"StrikePriceUnderlying"->50},{"CorrelationMatrix"->0.3,"CurrentPrice"->50,"Dividend"->0.02,"ExchangeRate"->0.8,"ExchangeVolatility"->0.3,"ForeignInterestRate"->0.04,"InterestRate"->0.05,"Volatility"->0.4},"Rules",Method->Automatic,GridSize->{Automatic,Automatic},Paths->Automatic,Steps->Automatic]],{{derivative,{"American","Call"},"Financial Derivative"},FinancialDerivative[],ControlType->PopupMenu}]

Financial Derivatives

A Template for calculating and pasting Financial Derivatives with variable inputs:

Module[{derivs =FinancialDerivative[],optNames,params,ambientParams,finderiv},Manipulate[optNames=FinancialDerivative @ derivative;params=Placeholder[Symbol[#]]& /@ optNames[[1]];ambientParams=Placeholder[Symbol[#]]& /@ optNames[[2]];CopyToClipboard[finderiv=Quiet[FinancialDerivative[derivative,Thread[Rule[optNames[[1]],params]],Thread[Rule[optNames[[2]],ambientParams]],"Rules",Method->method,"GridSize"->{xGrid,tGrid},"Paths"->paths,"Steps"->steps]]];finderiv,{{derivative,derivs[[46]],"Financial Derivative"},derivs,ControlType->PopupMenu},{{method,Automatic,"Method"},{Automatic,"BlackScholes","Binomial","MonteCarlo"}},{{xGrid,Automatic,"XGrid"},100,10000,100},{{tGrid,Automatic,"TGrid"},10,1000,50},{{steps,Automatic,"Steps"},10,1000,50},{{paths,Automatic,"Paths"},100,10000,100},FrameLabel->"Template for calculating and pasting Derivatives"]]

Pasting Example

ReleaseHold[FinancialDerivative[{"ExtendibleHolder","European","Call"},{"StrikePriceAdjusted"->50,"StrikePrice"->50,"ExtensionPeriod"->1,"ExtensionFee"->3,"Expiration"->1},{"CurrentPrice"->50,"Dividend"->0.05,"Volatility"->0.3,"InterestRate"->0.05},"Rules",Method->Automatic,"GridSize"->{Automatic,Automatic},"Paths"->Automatic,"Steps"->Automatic]]

A Template for calculating Financial Derivatives with variable inputs:

Module[{derivs =FinancialDerivative[],optNames,params,ambientParams,finders,parameterNames,parameters,parameterRules,ambientParameterNames,ambientParameters,ambientParameterRules},Manipulate[optNames=FinancialDerivative @ derivative;params=Symbol[#]& /@ optNames[[1]];ambientParams=Symbol[#]& /@ optNames[[2]];finders=FinancialDerivative /@ FinancialDerivative[];parameterNames =Sort[DeleteDuplicates[Flatten[#[[1]]& /@ finders]]];parameters=Symbol[ToLowerCase[#]]& /@ parameterNames;parameterRules=Thread[Rule[parameterNames,parameters]];ambientParameterNames=Sort[DeleteDuplicates[Flatten[#[[2]]& /@ finders]]];ambientParameters = Symbol[ToLowerCase[#]]& /@ ambientParameterNames;ambientParameterRules=Thread[Rule[ambientParameterNames,ambientParameters]];ReleaseHold[Quiet[FinancialDerivative[derivative,{"AverageSoFar"->averagesofar,"Barrier"->barrier,"Barriers"->barriers,"Coupon"->coupon,"Expiration"->expiration,"ExpirationCall"->expirationcall,"ExpirationPut"->expirationput,"ExpirationUnderlying"->expirationunderlying,"ExtensionFee"->extensionfee,"ExtensionPeriod"->extensionperiod,"Fractions"->fractions,"Inception"->inception,"MaxSoFar"->maxsofar,"MinSoFar"->minsofar,"Money"->money,"NominalAmount"->nominalamount,"Rebate"->rebate,"StrikePrice"->strikeprice,"StrikePriceAdjusted"->strikepriceadjusted,"StrikePriceCall"->strikepricecall,"StrikePricePut"->strikepriceput,"StrikePriceUnderlying"->strikepriceunderlying},{"CorrelationMatrix"->correlationmatrix,"CurrentPrice"->currentprice,"Dividend"->dividend,"ExchangeRate"->exchangerate,"ExchangeVolatility"->exchangevolatility,"ForeignInterestRate"->foreigninterestrate,"InterestRate"->interestrate,"Volatility"->volatility},"Rules",Method->method,"GridSize"->{xGrid,tGrid},"Paths"->paths,"Steps"->steps]]],{{derivative,derivs[[46]],"Financial Derivative"},derivs,ControlType->PopupMenu},OpenerView[{"Parameters",Column[{Control[{{averagesofar,50,"AverageSoFar"},InputField}],Control[{{barrier,50,"Barrier"},InputField}],Control[{{barriers,{25,40},"Barriers"},InputField}],Control[{{coupon,10,"Coupon"},InputField}],Control[{{expiration,1,"Expiration"},InputField}],Control[{{expirationcall,2,"ExpirationCall"},InputField}],Control[{{expirationput,2,"ExpirationPut"},InputField}],Control[{{expirationunderlying,2,"ExpirationUnderlying"},InputField}],Control[{{extensionfee,3,"ExtensionFee"},InputField}],Control[{{extensionperiod,1,"ExtensionPeriod"},InputField}],Control[{{fractions,{0.3,0.5},"Fractions"},InputField}],Control[{{inception,-1,"Inception"},InputField}],Control[{{maxsofar,55,"MaxSoFar"},InputField}],Control[{{minsofar,45,"MinSoFar"},InputField}],Control[{{money,50,"Money"},InputField}],Control[{{nominalamount,50,"NominalAmount"},InputField}],Control[{{rebate,3,"Rebate"},InputField}],Control[{{strikeprice,50,"StrikePrice"},InputField}],Control[{{strikepriceadjusted,50,"StrikePriceAdjusted"},InputField}],Control[{{strikepricecall,50,"StrikePriceCall"},InputField}],Control[{{strikepriceput,50,"StrikePricePut"},InputField}],Control[{{strikepriceunderlying,50,"StrikePriceUnderlying"},InputField}]}]}],OpenerView[{"Ambient Parameters",Column[{Control[{{correlationmatrix,0.3,"CorrelationMatrix"},InputField}],Control[{{currentprice,50,"CurrentPrice"},InputField}],Control[{{dividend,0.02,"Dividend"},InputField}],Control[{{exchangerate,0.8,"ExchangeRate"},InputField}],Control[{{exchangevolatility,0.3,"ExchangeVolatility"},InputField}],Control[{{foreigninterestrate,0.04,"ForeignInterestRate"},InputField}],Control[{{interestrate,0.05,"InterestRate"},InputField}],Control[{{volatility,0.4,"Volatility"},InputField}]}]}],OpenerView[{"Options",Column[{Control[{{method,Automatic,"Method"},{Automatic,"BlackScholes","Binomial","MonteCarlo"}}],Control[{{xGrid,Automatic,"XGrid"},100,10000,100}],Control[{{tGrid,Automatic,"TGrid"},10,1000,50}],Control[{{steps,Automatic,"Steps"},10,1000,50}],Control[{{paths,Automatic,"Paths"},100,10000,100}]}]}],ControlPlacement -> Join[Table[Top,{23}],Table[Bottom,{13}]],FrameLabel->"Template for calculating Financial Derivatives"]]

Financial Derivatives

Dynamic evaluation of American options:

Manipulate[Plot[FinancialDerivative[{"American",type}, {"StrikePrice"-> K, "Expiration"->T},  {"InterestRate"-> r, "Volatility" ->σ, "CurrentPrice"-> S, "Dividend"->δ}], {S, 70., 140.}, AxesLabel->{"stock", "option price"},ImageSize->400,ImagePadding->{{40,50},{25,25}}], {{type,"Call","American option"}, {"Call","Put"}}, {{K, 100.,"strike price"},50.,150.}, {{r,.05,"interest rate"},.02,.1},{{δ,.004,"dividend yield"}, .002, .05},{{σ,.3, "volatility"}, .2, .5}, {{T,.1,"time to maturity"}, .001,1.}]

Dynamic evaluation of American option Greeks:

Manipulate[Plot[FinancialDerivative[{"American",type}, {"StrikePrice"-> K, "Expiration"->T},  {"InterestRate"-> r, "Volatility" ->σ, "CurrentPrice"-> S, "Dividend"->δ},greek], {S, 70., 140.}, AxesLabel->{"stock", "option Greek"},ImageSize->400,ImagePadding->{{40,50},{25,25}}], {{type,"Call","American option"}, {"Call","Put"}},{{greek,"Delta","Greeks"}, {"Delta","Gamma","Rho","Theta","Vega"}}, {{K, 100.,"strike price"},50.,150.}, {{r,.05,"interest rate"},.02,.1},{{δ,.004,"dividend yield"}, .002, .05},{{σ,.3, "volatility"}, .2, .5}, {{T,.1,"time to maturity"}, .001,1.}]

Dynamic evaluation of double-barrier knock-out options:

Manipulate[Plot[FinancialDerivative[{"DoubleBarrierKnockOut",exercise,type}, {"StrikePrice"-> K, "Expiration"->T,"Barriers"->{lb,ub}},  {"InterestRate"-> r, "Volatility" ->σ, "CurrentPrice"-> S, "Dividend"->δ}], {S, lb,ub}, AxesLabel->{"stock", "option price"},ImageSize->400,ImagePadding->{{40,50},{25,25}}], {{type,"Call","Dble Barrier KnockOut"}, {"Call","Put"}},{{exercise,"European","Exercise"}, {"European","American"}}, {{K, 70.,"strike price"},50.,150.}, {{r,.05,"interest rate"},.02,.1},{{δ,.004,"dividend yield"}, .002, .05},{{σ,.3, "volatility"}, .2, .5}, {{T,.1,"time to maturity"}, .001,1.},{{ub,lb+20,"Upper Barrier"},lb+5,150},{{lb,80,"Lower Barrier"},50,120}]

Dynamic evaluation of all Financial Derivatives:

Module[{derivs =FinancialDerivative[],optNames,params,ambientParams,finders,parameterNames,parameters,parameterRules,ambientParameterNames,ambientParameters,ambientParameterRules},Manipulate[optNames=FinancialDerivative @ derivative;params=Symbol[#]& /@ optNames[[1]];ambientParams=Symbol[#]& /@ optNames[[2]];finders=FinancialDerivative /@ FinancialDerivative[];parameterNames =Sort[DeleteDuplicates[Flatten[#[[1]]& /@ finders]]];parameters=Symbol[ToLowerCase[#]]& /@ parameterNames;parameterRules=Thread[Rule[parameterNames,parameters]];ambientParameterNames=Sort[DeleteDuplicates[Flatten[#[[2]]& /@ finders]]];ambientParameters = Symbol[ToLowerCase[#]]& /@ ambientParameterNames;ambientParameterRules=Thread[Rule[ambientParameterNames,ambientParameters]];Plot[Quiet[FinancialDerivative[derivative,{"AverageSoFar"->averagesofar,"Barrier"->barrier,"Barriers"->barriers,"Coupon"->coupon,"Expiration"->expiration,"ExpirationCall"->expirationcall,"ExpirationPut"->expirationput,"ExpirationUnderlying"->expirationunderlying,"ExtensionFee"->extensionfee,"ExtensionPeriod"->extensionperiod,"Fractions"->fractions,"Inception"->inception,"MaxSoFar"->maxsofar,"MinSoFar"->minsofar,"Money"->money,"NominalAmount"->nominalamount,"Rebate"->rebate,"StrikePrice"->strikeprice,"StrikePriceAdjusted"->strikepriceadjusted,"StrikePriceCall"->strikepricecall,"StrikePricePut"->strikepriceput,"StrikePriceUnderlying"->strikepriceunderlying},{"CorrelationMatrix"->correlationmatrix,"CurrentPrice"->currentprice,"Dividend"->dividend,"ExchangeRate"->exchangerate,"ExchangeVolatility"->exchangevolatility,"ForeignInterestRate"->foreigninterestrate,"InterestRate"->interestrate,"Volatility"->volatility},Method->method,"GridSize"->{xGrid,tGrid},"Paths"->paths,"Steps"->steps]],{currentprice,30,150}],{{derivative,derivs[[46]],"Financial Derivative"},derivs,ControlType->PopupMenu},OpenerView[{"Parameters",Column[{Control[{{averagesofar,50,"AverageSoFar"},InputField}],Control[{{barrier,50,"Barrier"},InputField}],Control[{{barriers,{25,40},"Barriers"},InputField}],Control[{{coupon,10,"Coupon"},InputField}],Control[{{expiration,1,"Expiration"},InputField}],Control[{{expirationcall,2,"ExpirationCall"},InputField}],Control[{{expirationput,2,"ExpirationPut"},InputField}],Control[{{expirationunderlying,2,"ExpirationUnderlying"},InputField}],Control[{{extensionfee,3,"ExtensionFee"},InputField}],Control[{{extensionperiod,1,"ExtensionPeriod"},InputField}],Control[{{fractions,{0.3,0.5},"Fractions"},InputField}],Control[{{inception,-1,"Inception"},InputField}],Control[{{maxsofar,55,"MaxSoFar"},InputField}],Control[{{minsofar,45,"MinSoFar"},InputField}],Control[{{money,50,"Money"},InputField}],Control[{{nominalamount,50,"NominalAmount"},InputField}],Control[{{rebate,3,"Rebate"},InputField}],Control[{{strikeprice,50,"StrikePrice"},InputField}],Control[{{strikepriceadjusted,50,"StrikePriceAdjusted"},InputField}],Control[{{strikepricecall,50,"StrikePriceCall"},InputField}],Control[{{strikepriceput,50,"StrikePricePut"},InputField}],Control[{{strikepriceunderlying,50,"StrikePriceUnderlying"},InputField}]}]}],OpenerView[{"Ambient Parameters",Column[{Control[{{correlationmatrix,0.3,"CorrelationMatrix"},InputField}],Control[{{dividend,0.02,"Dividend"},InputField}],Control[{{exchangerate,0.8,"ExchangeRate"},InputField}],Control[{{exchangevolatility,0.3,"ExchangeVolatility"},InputField}],Control[{{foreigninterestrate,0.04,"ForeignInterestRate"},InputField}],Control[{{interestrate,0.05,"InterestRate"},InputField}],Control[{{volatility,0.4,"Volatility"},InputField}]}]}],OpenerView[{"Options",Column[{Control[{{method,Automatic,"Method"},{Automatic,"BlackScholes","Binomial","MonteCarlo"}}],Control[{{xGrid,Automatic,"XGrid"},100,10000,100}],Control[{{tGrid,Automatic,"TGrid"},10,1000,50}],Control[{{steps,Automatic,"Steps"},10,1000,50}],Control[{{paths,Automatic,"Paths"},100,10000,100}]}]}],ControlPlacement -> Join[Table[Top,{23}],Table[Bottom,{13}]],FrameLabel->"Template for plotting Financial Derivatives"]]

Dynamic evaluation of all Financial Derivative Greeks:

Module[{derivs =FinancialDerivative[],optNames,params,ambientParams,finders,parameterNames,parameters,parameterRules,ambientParameterNames,ambientParameters,ambientParameterRules},Manipulate[optNames=FinancialDerivative @ derivative;params=Symbol[#]& /@ optNames[[1]];ambientParams=Symbol[#]& /@ optNames[[2]];finders=FinancialDerivative /@ FinancialDerivative[];parameterNames =Sort[DeleteDuplicates[Flatten[#[[1]]& /@ finders]]];parameters=Symbol[ToLowerCase[#]]& /@ parameterNames;parameterRules=Thread[Rule[parameterNames,parameters]];ambientParameterNames=Sort[DeleteDuplicates[Flatten[#[[2]]& /@ finders]]];ambientParameters = Symbol[ToLowerCase[#]]& /@ ambientParameterNames;ambientParameterRules=Thread[Rule[ambientParameterNames,ambientParameters]];Plot[Quiet[FinancialDerivative[derivative,{"AverageSoFar"->averagesofar,"Barrier"->barrier,"Barriers"->barriers,"Coupon"->coupon,"Expiration"->expiration,"ExpirationCall"->expirationcall,"ExpirationPut"->expirationput,"ExpirationUnderlying"->expirationunderlying,"ExtensionFee"->extensionfee,"ExtensionPeriod"->extensionperiod,"Fractions"->fractions,"Inception"->inception,"MaxSoFar"->maxsofar,"MinSoFar"->minsofar,"Money"->money,"NominalAmount"->nominalamount,"Rebate"->rebate,"StrikePrice"->strikeprice,"StrikePriceAdjusted"->strikepriceadjusted,"StrikePriceCall"->strikepricecall,"StrikePricePut"->strikepriceput,"StrikePriceUnderlying"->strikepriceunderlying},{"CorrelationMatrix"->correlationmatrix,"CurrentPrice"->currentprice,"Dividend"->dividend,"ExchangeRate"->exchangerate,"ExchangeVolatility"->exchangevolatility,"ForeignInterestRate"->foreigninterestrate,"InterestRate"->interestrate,"Volatility"->volatility},greek,Method->method,"GridSize"->{xGrid,tGrid},"Paths"->paths,"Steps"->steps]],{currentprice,30,150}],{{derivative,derivs[[46]],"Financial Derivative"},derivs,ControlType->PopupMenu},{{greek,"Delta","Greeks"}, {"Delta","Gamma","Rho","Theta","Vega"}},OpenerView[{"Parameters",Column[{Control[{{averagesofar,50,"AverageSoFar"},InputField}],Control[{{barrier,50,"Barrier"},InputField}],Control[{{barriers,{25,40},"Barriers"},InputField}],Control[{{coupon,10,"Coupon"},InputField}],Control[{{expiration,1,"Expiration"},InputField}],Control[{{expirationcall,2,"ExpirationCall"},InputField}],Control[{{expirationput,2,"ExpirationPut"},InputField}],Control[{{expirationunderlying,2,"ExpirationUnderlying"},InputField}],Control[{{extensionfee,3,"ExtensionFee"},InputField}],Control[{{extensionperiod,1,"ExtensionPeriod"},InputField}],Control[{{fractions,{0.3,0.5},"Fractions"},InputField}],Control[{{inception,-1,"Inception"},InputField}],Control[{{maxsofar,55,"MaxSoFar"},InputField}],Control[{{minsofar,45,"MinSoFar"},InputField}],Control[{{money,50,"Money"},InputField}],Control[{{nominalamount,50,"NominalAmount"},InputField}],Control[{{rebate,3,"Rebate"},InputField}],Control[{{strikeprice,50,"StrikePrice"},InputField}],Control[{{strikepriceadjusted,50,"StrikePriceAdjusted"},InputField}],Control[{{strikepricecall,50,"StrikePriceCall"},InputField}],Control[{{strikepriceput,50,"StrikePricePut"},InputField}],Control[{{strikepriceunderlying,50,"StrikePriceUnderlying"},InputField}]}]}],OpenerView[{"Ambient Parameters",Column[{Control[{{correlationmatrix,0.3,"CorrelationMatrix"},InputField}],Control[{{dividend,0.02,"Dividend"},InputField}],Control[{{exchangerate,0.8,"ExchangeRate"},InputField}],Control[{{exchangevolatility,0.3,"ExchangeVolatility"},InputField}],Control[{{foreigninterestrate,0.04,"ForeignInterestRate"},InputField}],Control[{{interestrate,0.05,"InterestRate"},InputField}],Control[{{volatility,0.4,"Volatility"},InputField}]}]}],OpenerView[{"Options",Column[{Control[{{method,Automatic,"Method"},{Automatic,"BlackScholes","Binomial","MonteCarlo"}}],Control[{{xGrid,Automatic,"XGrid"},100,10000,100}],Control[{{tGrid,Automatic,"TGrid"},10,1000,50}],Control[{{steps,Automatic,"Steps"},10,1000,50}],Control[{{paths,Automatic,"Paths"},100,10000,100}]}]}],ControlPlacement -> Join[Table[Top,{24}],Table[Bottom,{13}]],FrameLabel->"Template for plotting Financial Derivative Greeks"]]

Follow up Contact and Financial Consulting

If further questions, explanations or financial examples are required then please contact me at:

Dr Michael Kelly
Wolfram Technology (Finance) Consultant 
mkelly@wolfram.com
217-398-0700 ext. 5545