Wolfram Language Paclet Repository

Community-contributed installable additions to the Wolfram Language

Primary Navigation

    • Cloud & Deployment
    • Core Language & Structure
    • Data Manipulation & Analysis
    • Engineering Data & Computation
    • External Interfaces & Connections
    • Financial Data & Computation
    • Geographic Data & Computation
    • Geometry
    • Graphs & Networks
    • Higher Mathematical Computation
    • Images
    • Knowledge Representation & Natural Language
    • Machine Learning
    • Notebook Documents & Presentation
    • Scientific and Medical Data & Computation
    • Social, Cultural & Linguistic Data
    • Strings & Text
    • Symbolic & Numeric Computation
    • System Operation & Setup
    • Time-Related Computation
    • User Interface Construction
    • Visualization & Graphics
    • Random Paclet
    • Alphabetical List
  • Using Paclets
    • Get Started
    • Download Definition Notebook
  • Learn More about Wolfram Language

Itovsn3

Guides

  • Main

Tech Notes

  • Bessel
  • BlackScholes
  • ItoArea
  • MardiaDryden
  • Reflect
  • Stochastic Integration

Symbols

  • AddDrift
  • AddFixed
  • AddQuadVar
  • Brktbydt
  • BrownBasis
  • BrownSingle
  • BSDQ
  • Drftbydt
  • Drift
  • Fixed
  • GetItoProc
  • InitialValue
  • Introduce
  • ItoD
  • ItoExpand
  • ItoInit
  • ItoIntegral
  • ItoReset
  • Itosde
  • ItoStatus
  • RandomQ
BlackScholes
Initialize and set up semimartingales
Verification of answer
Construct self-financing strategy
Solution in terms of share price S
Stochastic analysis of trading strategy
Analysis of value of option at time zero
Recast in innovation of Brownian motion
Contact Information
Further simplification using drift
Acknowledgements
Further simplification using Feynman-Kac
References
Brownian kernel and explicit solution
​
Author Information
Wilfrid S. Kendall
Statistics, University of Warwick,
Coventry CV4 7 AL, UK.
Purpose
This is a Mathematica notebook that demonstrates a derivation of the Black-Scholes formula using Itovsn3.
IMPORTANT
This notebook assumes nothing has been previously defined . Quit Mathematica and reload if this is not the case!
Load package
In[1]:=
Needs["FernandoDuarte`Itovsn3`"]
Initialize and set up semimartingales
Initialize Itovsn3 and set up a real Brownian motion W to serve as the innovation process for the share price:
In[2]:=
ItoReset
[t,dt]​​
BrownSingle
[W,0];
Out[2]//TableForm=
Itovsn3 resetting ...
Itovsn3 initialized
with time semimartingale t
and time differential dt
Now we can use this to set up a geometric Brownian motion S to model the share price, together with a bond B which evolves in an entirely deterministic manner.
In[4]:=
alfa=α;​​mu=μ;​​sigma=σ;​​SetAttributes[σ,Constant]​​SetAttributes[μ,Constant]​​SetAttributes[α,Constant]​​
Itosde
[S,dSsigmaSdW+muSdt,1]​​
AddFixed
[0,S,S0];​​
Itosde
[B,dBalfaBdt,1]​​
AddFixed
[0,B,B0];​​
ItoStatus
[];
Construct self-financing strategy
We now consider a trading strategy, holding s[t] units of the share S and b[t] units of the bond B, where s and b are allowed to vary smoothly with time but we require the strategy to be exactly self-financing. We establish a substitution rule to replace V[S,t] by this self-financing trading strategy.
In[15]:=
Strategy=s[t]S+b[t]B;​​ValueDefinition=First[Solve[V[S,t]-Strategy0,b[t]]]​​SelfFinancing=First[Solve[
∂
t
s[t]S+
∂
t
b[t]B0,
∂
t
b[t]]]
Out[16]=
b[t]
-Ss[t]+V[S,t]
B

Out[17]=

′
b
[t]-
S
′
s
[t]
B

Stochastic analysis of trading strategy
Consider then the evolution of the value V[S,t] of the trading strategy over time: we know the following stochastic differential should be zero! Notice the self-financing condition means we know how to derive b[t] once a[t] is given.
In[18]:=
sd=
ItoD
[V[S,t]-Strategy];​​SecondOrder=FirstSolve
ItoExpand
[sddW]/.SelfFinancing0,s[t]​​pde=Expand
Drift
[sd]/.SelfFinancing/.ValueDefinition/.SecondOrder
dt
0
Out[19]=
s[t]
(1,0)
V
[S,t]
Out[20]=
-αV[S,t]+
(0,1)
V
[S,t]+Sα
(1,0)
V
[S,t]+
1
2
2
S
2
σ
(2,0)
V
[S,t]0
Recast in innovation of Brownian motion
We now have a linear second-order partial differential equation in V which we must solve. In principle one could write a solver for a class of equations including this example. However it seems more illuminating to proceed by a trial-and-error method.
First observe that the argument S is constrained to be positive. This suggests we should re-cast the argument using the known solution of S in terms of its innovation W. First we check the solution (again, we could have built a solver!):
In[21]:=
SS=ExpsigmaW+mut-
2
sigma
t
2
;​​sd=
ItoD
[S-SS]/.SSS;​​Together
Drift
[sd]/.SSS0​​
ItoExpand
[
2
sd
]/.SSS0
Out[23]=
True
Out[24]=
True
Now we work through the derivation of the pde, but this time using SS not S, and viewing the value as V1[W,t] instead of V[S,t], in other words viewed as a function of W not of S:
In[25]:=
Strategy=s[t]SS+b[t]B;​​ValueDefinition=First[Solve[V1[W,t]-Strategy0,b[t]]];​​SelfFinancing=First[Solve[
∂
t
s[t]SS+
∂
t
b[t]B0,
∂
t
b[t]]];​​sd=
ItoD
[V1[W,t]-Strategy];​​SecondOrder=FirstSolve
ItoExpand
[sddW]/.SelfFinancing0,s[t];​​pde=Expand
Drift
[sd]/.SelfFinancing/.ValueDefinition/.SecondOrder
dt
0
Out[30]=
-αV1[W,t]+
(0,1)
V1
[W,t]+
α
(1,0)
V1
[W,t]
σ
-
μ
(1,0)
V1
[W,t]
σ
+
1
2
(2,0)
V1
[W,t]0
Further simplification using drift
This is a considerable improvement, as we can now recognize an orthodox heat equation hiding in there. It looks like we can improve matters still further by adding in a drift term! We work with V2[WW,t] where WW = W - ((alfa-mu)/sigma)*t, instead of V1[W,t]:
In[31]:=
WW=W-
(alfa-mu)t
sigma
​​Strategy=s[t]SS+b[t]B;​​ValueDefinition=First[Solve[V2[WW,t]-Strategy0,b[t]]];​​SelfFinancing=First[Solve[
∂
t
s[t]SS+
∂
t
b[t]B0,
∂
t
b[t]]];​​sd=
ItoD
[V2[WW,t]-Strategy];​​SecondOrder=FirstSolve
ItoExpand
[sddW]/.SelfFinancing0,s[t];​​pde=Expand
Drift
[sd]/.SelfFinancing/.ValueDefinition/.SecondOrder
dt
0
Out[31]=
W-
t(α-μ)
σ
Out[37]=
-αV2W-
t(α-μ)
σ
,t+
(0,1)
V2
W-
t(α-μ)
σ
,t+
1
2
(2,0)
V2
W-
t(α-μ)
σ
,t0
Further simplification using Feynman-Kac
It looks as if we could get an even neater answer by adding in a multiplier to take out the -alfa V2 term (this is equivalent to using the Feynman-Kac trick). Thus we now work with VV = Exp[alfa*(t-t1)]*V3[WW,t] instead of V1[W,t] (so we are discounting relative to the value of the bond at time t1):
In[38]:=
SetAttributes[t1,Constant]​​VV=Exp[alfa(t-t1)]V3[WW,t]​​Strategy=s[t]SS+b[t]B;​​ValueDefinition=First[Solve[VV-Strategy0,b[t]]];​​SelfFinancing=First[Solve[
∂
t
s[t]SS+
∂
t
b[t]B0,
∂
t
b[t]]];​​sd=
ItoD
[VV-Strategy];​​SecondOrder=FirstSolve
ItoExpand
[sddW]/.SelfFinancing0,s[t];​​pde=Expand
Drift
[sd]/.SelfFinancing/.ValueDefinition/.SecondOrder
dt
0
Brownian kernel and explicit solution
We can now recognize V3 as solving the Kolmogorov backwards differential equation solved by the well-known Brownian heat kernel. Consequently we know the general form for V3: integrals with respect to S1 and t1 of the following (and notice the option we establish so that this can be eventually rephrased in terms of the terminal share price S1 rather than the terminal innovation W1!):
Verification of answer
Substituting back shows we have got the answer:
Solution in terms of share price S
So now we know the kernel which should be integrated (as a function of W1) to yield solutions to Black-Scholes-type problems. Notice that subject to regularity conditions such an integration yields solutions whatever function of W1 is integrated against the kernel. This allows us to derive self-financing strategies delivering arbitrary functions of W1 at time t1.
Rewritten in terms of the current share price S the kernel is as follows (but note here that in Solve Mathematica warns about multiple solutions!):
Analysis of value of option at time zero
We are principally interested in the value of this at time zero:
Using integration against W1, this tells us the value of the strategy we must start with at time 0 in order to achieve value f[S1] at time t1, since integration of the kernel multiplied by a function of S1 (equivalently, W1) against W1 still yields a solution of the partial differential equation, and therefore still yields a value process achievable by a self-financing strategy. We first compute the value of W1 required to obtain S1:
Thus the value required at time 0 to achieve f[S1] at time t1 is given by
This values the option f[S1] at time t1. Here is how it works if instead we value an option on buying the share at price Soption at time t1. Firstly we calculate the value Woption of W1 for a given option level Soption (ignore the spelling warning):
Some coaching is required in the integration procedure, since Mathematica has no way of telling what is the sign of t1 and therefore fails to integrate to the limit at plus or minus Infinity! Note also that Mathematica warns again about multiple solutions.
We now have to make a careful set of simplifications so as to ensure Mathematica spots the special values of two of the Erf arguments (we also add some simplifications for tidying up the answer!).

Further Exercise

Compute the amount S of share to be held at time 0
Contact Information
Email: w.s.kendall@warwick.ac.uk
URL: http://www.warwick.ac.uk/go/WSK
Acknowledgements
The research reported here was supported by EPSRC grants GR/71677 (Stochastic calculus in AXIOM using modules of stochastic differentials) and GR/L56831 (Perfect simulation in stochastic geometry), and a joint EPSRC/BBSRC research grant (Multi-strain species modelling and control via differential algebra reductions). This Mathematica notebook was constructed on a visit to MSRI Berkeley CA during its 1997-1998 program Stochastic Analysis. Finally, it is a pleasure to express my gratitude to my friends Suzanne Scotchmer and Joseph Farrell for the generous hospitality they showed to me during my visit to MSRI.
References
Discussion of applications of symbolic Ito calculus and related software to problems in Mathematical Finance:
Derivation of Black-Scholes formula using an implementation of diffusion theory in Mathematica:
Derivation of Duffie-Richardson quadratic hedging formula using Itovsn3:

© 2025 Wolfram. All rights reserved.

  • Legal & Privacy Policy
  • Contact Us
  • WolframAlpha.com
  • WolframCloud.com