SlideShare a Scribd company logo
1 of 46
Numerical & Simulation
Techniques in Finance
FRE 6251
Chapter I
Edward D. Weinberger, Ph.D, F.R.M.
Adjunct Assoc. Professor
NYU Tandon School of Engineering
edw@wpq-inc.com
Copyright 2018 Weinberger
Post-Quantitative, Inc.
THE PURPOSE OF
COMPUTING IS INSIGHT,
NOT NUMBERS…
--- R. W. Hamming
Copyright 2018 Weinberger
Post-Quantitative, Inc.
COURSE OBJECTIVES
•To familiarize students with
•what makes a “good” method
•some important methods
•EXCEL/VBA
•To teach the “informed use” of
numerical methods in packages
Copyright 2018 Weinberger
Post-Quantitative, Inc.
COURSE
ORGANIZATION
Grade based on
• Two algorithm implementations (50%
each)
• Required texts:
• Numerical Methods in C(++) by Frank Press, et. al.
(available free at http://www.nrbook.com/a/bookcpdf.php
• Options, Futures and Other Derivatives
`
Copyright 2018 Weinberger
Post-Quantitative, Inc.
TOPIC SCHEDULE
(Approximate!)
I. Root finding in 1 or more dim
II. Ordinary Differential Eqns.
(ODE’s)
III. Partial Differential Eqns. (PDE’s)
IV. Numerical Integration
V. Interpolation
VI. A Survey of Optimization
Copyright 2018 Weinberger
Post-Quantitative, Inc.
OUTLINE
Chapter I
• VBA survey for programmers
• “Machine numbers”
• 1 dim root finding methods
• bisection
• secant method
• Newton’s method
• Newton’s method in >1 dim
• ODE solvers
Copyright 2018 Weinberger
Post-Quantitative, Inc.
VBA for Programmers
• VBA NOT “industrial strength”,
unlike C++ (VBA not really OO)
• Visual Basic for Applications (VBA)
is macro language for all MS Office
• Built-in references to relevant
“objects”
• EXCEL/VBA has “Range”, “Cell”,
“Worksheet” objects (see HELP)
Copyright 2018 Weinberger
Post-Quantitative, Inc.
More VBA for
Programmers
• EXCEL functions accessible in VBA,
Applications.WorksheetFunction.min()
• “Immediate” window
• Integrated development environment
• “Record Macro” to get hints
Copyright 2018 Weinberger
Post-Quantitative, Inc.
“MACHINE NUMBERS” AS
SUBSETS OF R
• Integers represented in binary using 1
(“char”), 2 (“short”), 4 (“float”), or 8
(“long”) bytes
• Floating point numbers represented in
4 (“float”) or 8 (“double”) bytes
• Implications:
•Integer/floating point overflow
•Tests like (x == 0.25) may not work
•Cancellation (see example)
Copyright 2018 Weinberger
Post-Quantitative, Inc.
“MACHINE EPSILON”
• Smallest absolute value of non-zero
mantissa representable on machine
• Different for different machines and
different applications
• For EXCEL/VBA on my machine:
•1.19 x 10-7 for single precision
•9.31 x 10-10 for double precision
Copyright 2018 Weinberger
Post-Quantitative, Inc.
RELATIVE SPEED
ESTIMATION
• Want machine independent estimates
• Addition/Subtraction/branching fast
• Multiplication/Division slow
• Function calls slowest
• Use O(N ) notation
Copyright 2018 Weinberger
Post-Quantitative, Inc.
FIRST PROBLEM
Compute implied volatility of
European call option (e.g. one
dimensional root finding)
Copyright 2018 Weinberger
Post-Quantitative, Inc.
BISECTION METHOD
LO HIMID
If f(MID) ≥ 0
HI = MID
Else
LO = MID
Copyright 2018 Weinberger
Post-Quantitative, Inc.
SECANT METHOD
xn-2 xn-1xn
     
1
21
21
11



 








nn
nn
nnn
xx
xfxf
xfxx
Copyright 2018 Weinberger
Post-Quantitative, Inc.
NEWTON’S METHOD
xn-1 xn
xn-2
 
 










1
1
1
n
n
nn
xf
xf
xx
Copyright 2018 Weinberger
Post-Quantitative, Inc.
ROOT FINDER TRADE-
OFFS
METHOD ADVANTAGE DISADVANTAGE
Bisection Always converges Very slow (lots of fct evaluations)
Secant Fast (few fct evaluations)
Need not code separate
derivative
calculation
Can get lost
Newton Fastest Need code for derivative calculation
Can get lost
Brent Almost as fast as secant, but
doesn’t get lost.
Complex!
Copyright 2018 Weinberger
Post-Quantitative, Inc.
Desiderata
“Read user’s mind” regarding
what user wants, finding a
solution
• correctly and reliably (lever
expert knowledge, e.g. Brent)
• quickly and cheaply
• in a user friendly way,
consistent with how users think
Copyright 2018 Weinberger
Post-Quantitative, Inc.
THE STATE OF THE ART
• Numerical Libraries (Numerical
Recipes)
• Batch processing for numerical
calculation (GAMS)
• Interactive processing for numerical
calculation (MatLab)
• Symbolic calculation (Macsyma,
Maple, Mathematica, esp integrator)
Copyright 2018 Weinberger
Post-Quantitative, Inc.
THE STATE OF THE ART
• Numerical Integration of Block Diagrams
(SimuLink)
See also Wikipedia entry
http://en.wikipedia.org/wiki/
Comparison_of_numerical_
analysis_software
Copyright 2018 Weinberger
Post-Quantitative, Inc.
Types of Calculations
• Statistical Analysis
EXCEL, SAS, S+, R, GAMS, MatLab/Octave
• Matrix Manipulation
EXCEL, MatLab/Octave
• Optimization
EXCEL, MatLab/Octave, GAMS
• Differential Equations (ODE, PDE)
MatLab/OctaveCopyright 2018 Weinberger
Post-Quantitative, Inc.
Types of Calculations
• Special Functions
EXCEL (Normal Dist.), MatLab/Octave
• Fast Fourier Transform (FFT)
EXCEL, MatLab/Octave
• Root Finding
EXCEL (Solver), MatLab/Octave
• Numerical Integration
MatLab/OctaveCopyright 2018 Weinberger
Post-Quantitative, Inc.
NEWTON’S METHOD IN >1
DIMENSION
GOAL: Solve f (x) = 0, for “smooth” f by
iteration: Given xn, improve it to xn+1 = xn + δ
f (xn + δ) = f (xn) + J δ + O (|| δ ||2),
where
J = [∂ fi / ∂ xj ]
Copyright 2018 Weinberger
Post-Quantitative, Inc.
NEWTON’S METHOD IN >1
DIMENSION (cont)
Using f (xn + δ) = 0
0 ≈ f (xn) + J δ
so
- J -1 f (x) ≈ δ
and
xn = xn-1 + δ
Copyright 2018 Weinberger
Post-Quantitative, Inc.
SECOND PROBLEM
Compute numerical solution to
an ordinary differential
equation
Copyright 2018 Weinberger
Post-Quantitative, Inc.
HOW DO WE KNOW A
SOLUTION EXISTS?
ODE with no real solution:
12
2






x
dt
dx
Copyright 2018 Weinberger
Post-Quantitative, Inc.
ODE’S IN STANDARD
FORM
Almost any ODE or system of ODE’s can be written
in the form
dx1/dt = f1(x1, x2 … xN , t)
dxN /dt = fN (x1, x2 … xN , t)
}dx(t) /dt = f (x, t)
Copyright 2018 Weinberger
Post-Quantitative, Inc.
PICARD EXISTENCE
THEOREM
THEOREM: The initial value problem
dx/dt = f (x,t)
with initial condition x(0) = x0 has a unique real solution in the
appropriate region if f satisfies a “Lipschitz condition”, i.e.
|| f (y, t) - f (x, t) || ≤ const X || y - x ||
for all relevant t.
Copyright 2018 Weinberger
Post-Quantitative, Inc.
EULER’S METHOD
By definition,
     
        hohttxftxhtx
h
txhtx
dt
tdx
h





,
lim
0
Copyright 2018 Weinberger
Post-Quantitative, Inc.
xn+1 = xn+ h f (xn , tn)
EXAMPLE: SIMPLE
HARMONIC MOTION
d x1/dt = x2
d 2 x/dt2 = -4π2 k 2x
d x2/dt = -4π2 k2 x1
x1(t + h) = x1 (t) + x2(t) h
x2(t + h) = x2 (t) – 4π2 k 2 x1(t) h
Copyright 2018 Weinberger
Post-Quantitative, Inc.
EULER’S IMPLICIT
METHOD
In one dimension, use
x(t + h) = x(t) + f (x (t + h), t + h) h.
so
x(t + h) - f (x (t + h), t + h) h = x(t).
Copyright 2018 Weinberger
Post-Quantitative, Inc.
xn+1 = xn+ h f (xn+1 , tn+1)
EXAMPLE: SIMPLE
HARMONIC MOTION
x1(t + h) – x2(t + h) h = x1 (t)
x2(t + h) + 4π2 k2 x1(t + h) h = x2 (t)
x1(t + h) = [x1(t) + x2(t) h] / [1 + 4π2 k2 h]
x2(t + h) = [- 4π2k2h x1(t) + x2(t)] / [1 + 4π2k2h]
Copyright 2018 Weinberger
Post-Quantitative, Inc.
STABILITY ANALYSIS:
EULER’S (EXPLICIT) METHOD
Consider: dx/dt = - ax, a > 0
x(t + h) = x(t)[1 - ah]
x(t + nh) = x(t)[1 - ah]n
so we must have |1 – ah| < 1, or h < 2/a for
convergence
Copyright 2018 Weinberger
Post-Quantitative, Inc.
STABILITY ANALYSIS:
EULER’S (IMPLICIT) METHOD
Consider: dx/dt = - ax
x(t + h) = x(t) - ah x(t + h)
x(t + h) = x(t) /[1 + ah]
x(t + nh) = x(t) /[1 + ah]n
Much better convergence properties!!
Copyright 2018 Weinberger
Post-Quantitative, Inc.
MIDPOINT METHOD
For any function g(t), Taylor series expansion is
Copyright 2018 Weinberger
Post-Quantitative, Inc.
     
     
     2
32
2
2
2
1
32
2
2
2
1
2
hO
dt
dg
h
htghtg
hOh
dt
gd
h
dt
dg
tghtg
hOh
dt
gd
h
dt
dg
tghtg
n
nn
nn
tt
nn
ttttnn
ttttnn







MIDPOINT METHOD
In the present case
Copyright 2018 Weinberger
Post-Quantitative, Inc.
   
 
    
        
        .,2/
But.2/,2/
so,2/,2/
2/2
2
2
1
3
2
hOhttxftxhtx
hOhhthtxftxhtx
hOhthtxf
h
txhtx




MIDPOINT METHOD
HENCE
xn +1 = xn + h f (xn + k1/2, tn + h/2) + O(h 3)
k1 = h f (xn , tn)
if stepsize = h
OR
xn +1 = xn -1 + 2h f (xn, tn) + O(h 3)
if stepsize = 2h
Copyright 2018 Weinberger
Post-Quantitative, Inc.
MIDPOINT METHOD
xn xn+ h
xn+ h/2
f(xn+ h/2, yn)
Copyright 2018 Weinberger
Post-Quantitative, Inc.
CONSISTENCY: NECESSARY
BUT NOT SUFFICIENT
A method is consistent if its order of
accuracy is at least 1, i.e. truncation error
is O(h2)
Explicit Euler, Implicit Euler, and the
Midpoint method are all consistent.
Copyright 2018 Weinberger
Post-Quantitative, Inc.
WHAT WE REALLY WANT IS
CONVERGENCE
A method is convergent if
Max | xj – x(tj) | 0
as h 0
Copyright 2018 Weinberger
Post-Quantitative, Inc.
MULTI-STEP METHODS
Why not generalize midpoint method to
xn+1 = a0 xn + a1 xn-1 + a2 xn-2 + …
+ h [b0 f(xn , tn) + b1 f(xn-1 , tn-1) + …]
as long as formula is consistent?
Copyright 2018 Weinberger
Post-Quantitative, Inc.
MULTI-STEP METHODS
Answer: Not always stable
xn+1 = -4 xn + 5xn-1 + h [4 f(xn , tn) + 2 f(xn-1 , tn-1)]
is unstable for any h!
Copyright 2018 Weinberger
Post-Quantitative, Inc.
DAHLQUIST EQIVALENCE
THEOREM
Theorem: A multi-step method for solving an ODE
is consistent and stable if and only if it is convergent
(stay tuned for more on this)
Copyright 2018 Weinberger
Post-Quantitative, Inc.
RUNGE KUTTA
(4th Order)
k1 = h f (xn , yn)
k2 = h f (xn + h/2, yn + k1/2)
k3 = h f (xn + h/2, yn + k2/2)
k4 = h f (xn + h, yn + k3)
yn +1 = yn + k1/ 6+ k2/ 3+ k3/ 3+ k4/ 6 + O(h5)
Copyright 2018 Weinberger
Post-Quantitative, Inc.
RUNGE KUTTA
Adaptive Step Size
x = True solution
xh = RK solution with step size h
x2h = RK solution with step size 2h
x(t + 2h) = xh(t + 2h) + 2h 5φ + O(h6)
x(t + 2h) = x2h(t + 2h) + (2h) 5φ + O(h6)
Copyright 2018 Weinberger
Post-Quantitative, Inc.
RUNGE KUTTA
Adaptive Step Size
Δ =x2h(t + 2h) - xh(t + 2h) = 30h 5φ + O(h6)
If |Δ| > Tol1 then
replace h with h/2
else if |Δ| < Tol2 then
replace h with 2h
end if
Copyright 2018 Weinberger
Post-Quantitative, Inc.
SUMMARY
Chapter I
• VBA highlights
• “Machine numbers”
• 1 dim root finding methods
• bisection
• secant method
• Newton’s method
• Newton’s method in >1 dim
• ODE solvers
Copyright 2018 Weinberger
Post-Quantitative, Inc.

More Related Content

What's hot

What's hot (20)

Unit 3-Greedy Method
Unit 3-Greedy MethodUnit 3-Greedy Method
Unit 3-Greedy Method
 
Mathematical Analysis of Recursive Algorithm.
Mathematical Analysis of Recursive Algorithm.Mathematical Analysis of Recursive Algorithm.
Mathematical Analysis of Recursive Algorithm.
 
Design and Analysis of Algorithms
Design and Analysis of AlgorithmsDesign and Analysis of Algorithms
Design and Analysis of Algorithms
 
Integer Linear Programming
Integer Linear ProgrammingInteger Linear Programming
Integer Linear Programming
 
Slide2
Slide2Slide2
Slide2
 
Integer programming
Integer programmingInteger programming
Integer programming
 
Analysis of algorithm
Analysis of algorithmAnalysis of algorithm
Analysis of algorithm
 
Online Algorithms - An Introduction
Online Algorithms - An IntroductionOnline Algorithms - An Introduction
Online Algorithms - An Introduction
 
Data Structures and Algorithm Analysis
Data Structures  and  Algorithm AnalysisData Structures  and  Algorithm Analysis
Data Structures and Algorithm Analysis
 
Global optimization
Global optimizationGlobal optimization
Global optimization
 
Lec7
Lec7Lec7
Lec7
 
Daa notes 2
Daa notes 2Daa notes 2
Daa notes 2
 
Divide and Conquer - Part 1
Divide and Conquer - Part 1Divide and Conquer - Part 1
Divide and Conquer - Part 1
 
Analysis of algorithms
Analysis of algorithmsAnalysis of algorithms
Analysis of algorithms
 
Anlysis and design of algorithms part 1
Anlysis and design of algorithms part 1Anlysis and design of algorithms part 1
Anlysis and design of algorithms part 1
 
Dynamic programming
Dynamic programmingDynamic programming
Dynamic programming
 
Design and analysis of Algorithm By Dr. B. J. Mohite
Design and analysis of Algorithm By Dr. B. J. MohiteDesign and analysis of Algorithm By Dr. B. J. Mohite
Design and analysis of Algorithm By Dr. B. J. Mohite
 
Boyd 4.6, 4.7
Boyd 4.6, 4.7Boyd 4.6, 4.7
Boyd 4.6, 4.7
 
Algorithm analysis (All in one)
Algorithm analysis (All in one)Algorithm analysis (All in one)
Algorithm analysis (All in one)
 
CS8461 - Design and Analysis of Algorithms
CS8461 - Design and Analysis of AlgorithmsCS8461 - Design and Analysis of Algorithms
CS8461 - Design and Analysis of Algorithms
 

Similar to First part of my NYU Tandon course "Numerical and Simulation Techniques in Finance"

Approximate Dynamic Programming: A New Paradigm for Process Control & Optimiz...
Approximate Dynamic Programming: A New Paradigm for Process Control & Optimiz...Approximate Dynamic Programming: A New Paradigm for Process Control & Optimiz...
Approximate Dynamic Programming: A New Paradigm for Process Control & Optimiz...
height
 

Similar to First part of my NYU Tandon course "Numerical and Simulation Techniques in Finance" (20)

Research internship on optimal stochastic theory with financial application u...
Research internship on optimal stochastic theory with financial application u...Research internship on optimal stochastic theory with financial application u...
Research internship on optimal stochastic theory with financial application u...
 
Compositional Program Analysis using Max-SMT
Compositional Program Analysis using Max-SMTCompositional Program Analysis using Max-SMT
Compositional Program Analysis using Max-SMT
 
CH1.ppt
CH1.pptCH1.ppt
CH1.ppt
 
Practical data analysis with wine
Practical data analysis with winePractical data analysis with wine
Practical data analysis with wine
 
IRJET- Solving Quadratic Equations using C++ Application Program
IRJET-  	  Solving Quadratic Equations using C++ Application ProgramIRJET-  	  Solving Quadratic Equations using C++ Application Program
IRJET- Solving Quadratic Equations using C++ Application Program
 
Massive Matrix Factorization : Applications to collaborative filtering
Massive Matrix Factorization : Applications to collaborative filteringMassive Matrix Factorization : Applications to collaborative filtering
Massive Matrix Factorization : Applications to collaborative filtering
 
Dictionary Learning for Massive Matrix Factorization
Dictionary Learning for Massive Matrix FactorizationDictionary Learning for Massive Matrix Factorization
Dictionary Learning for Massive Matrix Factorization
 
Hierarchical Deterministic Quadrature Methods for Option Pricing under the Ro...
Hierarchical Deterministic Quadrature Methods for Option Pricing under the Ro...Hierarchical Deterministic Quadrature Methods for Option Pricing under the Ro...
Hierarchical Deterministic Quadrature Methods for Option Pricing under the Ro...
 
OR_Hamdy_taha.ppt
OR_Hamdy_taha.pptOR_Hamdy_taha.ppt
OR_Hamdy_taha.ppt
 
OR_Hamdy_taha.ppt
OR_Hamdy_taha.pptOR_Hamdy_taha.ppt
OR_Hamdy_taha.ppt
 
Determination of Optimal Product Mix for Profit Maximization using Linear Pro...
Determination of Optimal Product Mix for Profit Maximization using Linear Pro...Determination of Optimal Product Mix for Profit Maximization using Linear Pro...
Determination of Optimal Product Mix for Profit Maximization using Linear Pro...
 
Determination of Optimal Product Mix for Profit Maximization using Linear Pro...
Determination of Optimal Product Mix for Profit Maximization using Linear Pro...Determination of Optimal Product Mix for Profit Maximization using Linear Pro...
Determination of Optimal Product Mix for Profit Maximization using Linear Pro...
 
Design and Analysis of Algorithm Brute Force 1.ppt
Design and Analysis of Algorithm Brute Force 1.pptDesign and Analysis of Algorithm Brute Force 1.ppt
Design and Analysis of Algorithm Brute Force 1.ppt
 
AINL 2016: Strijov
AINL 2016: StrijovAINL 2016: Strijov
AINL 2016: Strijov
 
Convex optmization in communications
Convex optmization in communicationsConvex optmization in communications
Convex optmization in communications
 
Digital Signal Processing[ECEG-3171]-Ch1_L07
Digital Signal Processing[ECEG-3171]-Ch1_L07Digital Signal Processing[ECEG-3171]-Ch1_L07
Digital Signal Processing[ECEG-3171]-Ch1_L07
 
Approximate Dynamic Programming: A New Paradigm for Process Control & Optimiz...
Approximate Dynamic Programming: A New Paradigm for Process Control & Optimiz...Approximate Dynamic Programming: A New Paradigm for Process Control & Optimiz...
Approximate Dynamic Programming: A New Paradigm for Process Control & Optimiz...
 
Data Structure: Algorithm and analysis
Data Structure: Algorithm and analysisData Structure: Algorithm and analysis
Data Structure: Algorithm and analysis
 
Recursion in Java
Recursion in JavaRecursion in Java
Recursion in Java
 
Reject Inference in Credit Scoring
Reject Inference in Credit ScoringReject Inference in Credit Scoring
Reject Inference in Credit Scoring
 

Recently uploaded

The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
heathfieldcps1
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
QucHHunhnh
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptx
negromaestrong
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
PECB
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
heathfieldcps1
 

Recently uploaded (20)

The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdf
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptx
 
Class 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfClass 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdf
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
psychiatric nursing HISTORY COLLECTION .docx
psychiatric  nursing HISTORY  COLLECTION  .docxpsychiatric  nursing HISTORY  COLLECTION  .docx
psychiatric nursing HISTORY COLLECTION .docx
 
Asian American Pacific Islander Month DDSD 2024.pptx
Asian American Pacific Islander Month DDSD 2024.pptxAsian American Pacific Islander Month DDSD 2024.pptx
Asian American Pacific Islander Month DDSD 2024.pptx
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 

First part of my NYU Tandon course "Numerical and Simulation Techniques in Finance"

  • 1. Numerical & Simulation Techniques in Finance FRE 6251 Chapter I Edward D. Weinberger, Ph.D, F.R.M. Adjunct Assoc. Professor NYU Tandon School of Engineering edw@wpq-inc.com Copyright 2018 Weinberger Post-Quantitative, Inc.
  • 2. THE PURPOSE OF COMPUTING IS INSIGHT, NOT NUMBERS… --- R. W. Hamming Copyright 2018 Weinberger Post-Quantitative, Inc.
  • 3. COURSE OBJECTIVES •To familiarize students with •what makes a “good” method •some important methods •EXCEL/VBA •To teach the “informed use” of numerical methods in packages Copyright 2018 Weinberger Post-Quantitative, Inc.
  • 4. COURSE ORGANIZATION Grade based on • Two algorithm implementations (50% each) • Required texts: • Numerical Methods in C(++) by Frank Press, et. al. (available free at http://www.nrbook.com/a/bookcpdf.php • Options, Futures and Other Derivatives ` Copyright 2018 Weinberger Post-Quantitative, Inc.
  • 5. TOPIC SCHEDULE (Approximate!) I. Root finding in 1 or more dim II. Ordinary Differential Eqns. (ODE’s) III. Partial Differential Eqns. (PDE’s) IV. Numerical Integration V. Interpolation VI. A Survey of Optimization Copyright 2018 Weinberger Post-Quantitative, Inc.
  • 6. OUTLINE Chapter I • VBA survey for programmers • “Machine numbers” • 1 dim root finding methods • bisection • secant method • Newton’s method • Newton’s method in >1 dim • ODE solvers Copyright 2018 Weinberger Post-Quantitative, Inc.
  • 7. VBA for Programmers • VBA NOT “industrial strength”, unlike C++ (VBA not really OO) • Visual Basic for Applications (VBA) is macro language for all MS Office • Built-in references to relevant “objects” • EXCEL/VBA has “Range”, “Cell”, “Worksheet” objects (see HELP) Copyright 2018 Weinberger Post-Quantitative, Inc.
  • 8. More VBA for Programmers • EXCEL functions accessible in VBA, Applications.WorksheetFunction.min() • “Immediate” window • Integrated development environment • “Record Macro” to get hints Copyright 2018 Weinberger Post-Quantitative, Inc.
  • 9. “MACHINE NUMBERS” AS SUBSETS OF R • Integers represented in binary using 1 (“char”), 2 (“short”), 4 (“float”), or 8 (“long”) bytes • Floating point numbers represented in 4 (“float”) or 8 (“double”) bytes • Implications: •Integer/floating point overflow •Tests like (x == 0.25) may not work •Cancellation (see example) Copyright 2018 Weinberger Post-Quantitative, Inc.
  • 10. “MACHINE EPSILON” • Smallest absolute value of non-zero mantissa representable on machine • Different for different machines and different applications • For EXCEL/VBA on my machine: •1.19 x 10-7 for single precision •9.31 x 10-10 for double precision Copyright 2018 Weinberger Post-Quantitative, Inc.
  • 11. RELATIVE SPEED ESTIMATION • Want machine independent estimates • Addition/Subtraction/branching fast • Multiplication/Division slow • Function calls slowest • Use O(N ) notation Copyright 2018 Weinberger Post-Quantitative, Inc.
  • 12. FIRST PROBLEM Compute implied volatility of European call option (e.g. one dimensional root finding) Copyright 2018 Weinberger Post-Quantitative, Inc.
  • 13. BISECTION METHOD LO HIMID If f(MID) ≥ 0 HI = MID Else LO = MID Copyright 2018 Weinberger Post-Quantitative, Inc.
  • 14. SECANT METHOD xn-2 xn-1xn       1 21 21 11              nn nn nnn xx xfxf xfxx Copyright 2018 Weinberger Post-Quantitative, Inc.
  • 15. NEWTON’S METHOD xn-1 xn xn-2               1 1 1 n n nn xf xf xx Copyright 2018 Weinberger Post-Quantitative, Inc.
  • 16. ROOT FINDER TRADE- OFFS METHOD ADVANTAGE DISADVANTAGE Bisection Always converges Very slow (lots of fct evaluations) Secant Fast (few fct evaluations) Need not code separate derivative calculation Can get lost Newton Fastest Need code for derivative calculation Can get lost Brent Almost as fast as secant, but doesn’t get lost. Complex! Copyright 2018 Weinberger Post-Quantitative, Inc.
  • 17. Desiderata “Read user’s mind” regarding what user wants, finding a solution • correctly and reliably (lever expert knowledge, e.g. Brent) • quickly and cheaply • in a user friendly way, consistent with how users think Copyright 2018 Weinberger Post-Quantitative, Inc.
  • 18. THE STATE OF THE ART • Numerical Libraries (Numerical Recipes) • Batch processing for numerical calculation (GAMS) • Interactive processing for numerical calculation (MatLab) • Symbolic calculation (Macsyma, Maple, Mathematica, esp integrator) Copyright 2018 Weinberger Post-Quantitative, Inc.
  • 19. THE STATE OF THE ART • Numerical Integration of Block Diagrams (SimuLink) See also Wikipedia entry http://en.wikipedia.org/wiki/ Comparison_of_numerical_ analysis_software Copyright 2018 Weinberger Post-Quantitative, Inc.
  • 20. Types of Calculations • Statistical Analysis EXCEL, SAS, S+, R, GAMS, MatLab/Octave • Matrix Manipulation EXCEL, MatLab/Octave • Optimization EXCEL, MatLab/Octave, GAMS • Differential Equations (ODE, PDE) MatLab/OctaveCopyright 2018 Weinberger Post-Quantitative, Inc.
  • 21. Types of Calculations • Special Functions EXCEL (Normal Dist.), MatLab/Octave • Fast Fourier Transform (FFT) EXCEL, MatLab/Octave • Root Finding EXCEL (Solver), MatLab/Octave • Numerical Integration MatLab/OctaveCopyright 2018 Weinberger Post-Quantitative, Inc.
  • 22. NEWTON’S METHOD IN >1 DIMENSION GOAL: Solve f (x) = 0, for “smooth” f by iteration: Given xn, improve it to xn+1 = xn + δ f (xn + δ) = f (xn) + J δ + O (|| δ ||2), where J = [∂ fi / ∂ xj ] Copyright 2018 Weinberger Post-Quantitative, Inc.
  • 23. NEWTON’S METHOD IN >1 DIMENSION (cont) Using f (xn + δ) = 0 0 ≈ f (xn) + J δ so - J -1 f (x) ≈ δ and xn = xn-1 + δ Copyright 2018 Weinberger Post-Quantitative, Inc.
  • 24. SECOND PROBLEM Compute numerical solution to an ordinary differential equation Copyright 2018 Weinberger Post-Quantitative, Inc.
  • 25. HOW DO WE KNOW A SOLUTION EXISTS? ODE with no real solution: 12 2       x dt dx Copyright 2018 Weinberger Post-Quantitative, Inc.
  • 26. ODE’S IN STANDARD FORM Almost any ODE or system of ODE’s can be written in the form dx1/dt = f1(x1, x2 … xN , t) dxN /dt = fN (x1, x2 … xN , t) }dx(t) /dt = f (x, t) Copyright 2018 Weinberger Post-Quantitative, Inc.
  • 27. PICARD EXISTENCE THEOREM THEOREM: The initial value problem dx/dt = f (x,t) with initial condition x(0) = x0 has a unique real solution in the appropriate region if f satisfies a “Lipschitz condition”, i.e. || f (y, t) - f (x, t) || ≤ const X || y - x || for all relevant t. Copyright 2018 Weinberger Post-Quantitative, Inc.
  • 28. EULER’S METHOD By definition,               hohttxftxhtx h txhtx dt tdx h      , lim 0 Copyright 2018 Weinberger Post-Quantitative, Inc. xn+1 = xn+ h f (xn , tn)
  • 29. EXAMPLE: SIMPLE HARMONIC MOTION d x1/dt = x2 d 2 x/dt2 = -4π2 k 2x d x2/dt = -4π2 k2 x1 x1(t + h) = x1 (t) + x2(t) h x2(t + h) = x2 (t) – 4π2 k 2 x1(t) h Copyright 2018 Weinberger Post-Quantitative, Inc.
  • 30. EULER’S IMPLICIT METHOD In one dimension, use x(t + h) = x(t) + f (x (t + h), t + h) h. so x(t + h) - f (x (t + h), t + h) h = x(t). Copyright 2018 Weinberger Post-Quantitative, Inc. xn+1 = xn+ h f (xn+1 , tn+1)
  • 31. EXAMPLE: SIMPLE HARMONIC MOTION x1(t + h) – x2(t + h) h = x1 (t) x2(t + h) + 4π2 k2 x1(t + h) h = x2 (t) x1(t + h) = [x1(t) + x2(t) h] / [1 + 4π2 k2 h] x2(t + h) = [- 4π2k2h x1(t) + x2(t)] / [1 + 4π2k2h] Copyright 2018 Weinberger Post-Quantitative, Inc.
  • 32. STABILITY ANALYSIS: EULER’S (EXPLICIT) METHOD Consider: dx/dt = - ax, a > 0 x(t + h) = x(t)[1 - ah] x(t + nh) = x(t)[1 - ah]n so we must have |1 – ah| < 1, or h < 2/a for convergence Copyright 2018 Weinberger Post-Quantitative, Inc.
  • 33. STABILITY ANALYSIS: EULER’S (IMPLICIT) METHOD Consider: dx/dt = - ax x(t + h) = x(t) - ah x(t + h) x(t + h) = x(t) /[1 + ah] x(t + nh) = x(t) /[1 + ah]n Much better convergence properties!! Copyright 2018 Weinberger Post-Quantitative, Inc.
  • 34. MIDPOINT METHOD For any function g(t), Taylor series expansion is Copyright 2018 Weinberger Post-Quantitative, Inc.                  2 32 2 2 2 1 32 2 2 2 1 2 hO dt dg h htghtg hOh dt gd h dt dg tghtg hOh dt gd h dt dg tghtg n nn nn tt nn ttttnn ttttnn       
  • 35. MIDPOINT METHOD In the present case Copyright 2018 Weinberger Post-Quantitative, Inc.                             .,2/ But.2/,2/ so,2/,2/ 2/2 2 2 1 3 2 hOhttxftxhtx hOhhthtxftxhtx hOhthtxf h txhtx    
  • 36. MIDPOINT METHOD HENCE xn +1 = xn + h f (xn + k1/2, tn + h/2) + O(h 3) k1 = h f (xn , tn) if stepsize = h OR xn +1 = xn -1 + 2h f (xn, tn) + O(h 3) if stepsize = 2h Copyright 2018 Weinberger Post-Quantitative, Inc.
  • 37. MIDPOINT METHOD xn xn+ h xn+ h/2 f(xn+ h/2, yn) Copyright 2018 Weinberger Post-Quantitative, Inc.
  • 38. CONSISTENCY: NECESSARY BUT NOT SUFFICIENT A method is consistent if its order of accuracy is at least 1, i.e. truncation error is O(h2) Explicit Euler, Implicit Euler, and the Midpoint method are all consistent. Copyright 2018 Weinberger Post-Quantitative, Inc.
  • 39. WHAT WE REALLY WANT IS CONVERGENCE A method is convergent if Max | xj – x(tj) | 0 as h 0 Copyright 2018 Weinberger Post-Quantitative, Inc.
  • 40. MULTI-STEP METHODS Why not generalize midpoint method to xn+1 = a0 xn + a1 xn-1 + a2 xn-2 + … + h [b0 f(xn , tn) + b1 f(xn-1 , tn-1) + …] as long as formula is consistent? Copyright 2018 Weinberger Post-Quantitative, Inc.
  • 41. MULTI-STEP METHODS Answer: Not always stable xn+1 = -4 xn + 5xn-1 + h [4 f(xn , tn) + 2 f(xn-1 , tn-1)] is unstable for any h! Copyright 2018 Weinberger Post-Quantitative, Inc.
  • 42. DAHLQUIST EQIVALENCE THEOREM Theorem: A multi-step method for solving an ODE is consistent and stable if and only if it is convergent (stay tuned for more on this) Copyright 2018 Weinberger Post-Quantitative, Inc.
  • 43. RUNGE KUTTA (4th Order) k1 = h f (xn , yn) k2 = h f (xn + h/2, yn + k1/2) k3 = h f (xn + h/2, yn + k2/2) k4 = h f (xn + h, yn + k3) yn +1 = yn + k1/ 6+ k2/ 3+ k3/ 3+ k4/ 6 + O(h5) Copyright 2018 Weinberger Post-Quantitative, Inc.
  • 44. RUNGE KUTTA Adaptive Step Size x = True solution xh = RK solution with step size h x2h = RK solution with step size 2h x(t + 2h) = xh(t + 2h) + 2h 5φ + O(h6) x(t + 2h) = x2h(t + 2h) + (2h) 5φ + O(h6) Copyright 2018 Weinberger Post-Quantitative, Inc.
  • 45. RUNGE KUTTA Adaptive Step Size Δ =x2h(t + 2h) - xh(t + 2h) = 30h 5φ + O(h6) If |Δ| > Tol1 then replace h with h/2 else if |Δ| < Tol2 then replace h with 2h end if Copyright 2018 Weinberger Post-Quantitative, Inc.
  • 46. SUMMARY Chapter I • VBA highlights • “Machine numbers” • 1 dim root finding methods • bisection • secant method • Newton’s method • Newton’s method in >1 dim • ODE solvers Copyright 2018 Weinberger Post-Quantitative, Inc.