SERVING THE QUANTITATIVE FINANCE COMMUNITY

mathdude2018
Topic Author
Posts: 13
Joined: January 10th, 2018, 4:35 pm

### Code for closed form solution for max(S1-S2-K, 0)

For valuation of max(S1 - S2 - K, 0) when K is much larger than 0; I came across this paper (page 17-18):
http://www.cs.toronto.edu/pub/reports/na/ccc/ywchen-18-msc.pdf

I tried looking up Matlab or Python codes for this option valuation but I didn't find one. I don't want to recreate the wheel if already done so. Is anyone aware of such code?

DavidJN
Posts: 1770
Joined: July 14th, 2002, 3:00 am

### Re: Code for closed form solution for max(S1-S2-K, 0)

Cuchulainn
Posts: 63816
Joined: July 16th, 2004, 7:38 am
Location: Amsterdam
Contact:

### Re: Code for closed form solution for max(S1-S2-K, 0)

Espen Haug's book (in VBA)
You can easily port analytical solutions to Python.

For PDE solutions there are libraries in C++. PDE in Python or Matlab is torture.

All pretty standard at this stage I reckon.

BTW is that a student project?
My C++ Boost code gives
262537412640768743.999999999999250072597198185688879353856337336990862707537410378210647910118607313

http://www.datasimfinancial.com
http://www.datasim.nl

FaridMoussaoui
Posts: 507
Joined: June 20th, 2008, 10:05 am
Location: Genève, Genf, Ginevra, Geneva

### Re: Code for closed form solution for max(S1-S2-K, 0)

For PDE solutions there are libraries in C++. PDE in Python or Matlab is torture.
What are you saying Daniel, are you drunk? There is a toolbox in matlab called "Financial Instruments" where you have solvers for BSM, Heston, .... in MC or PDE.
There is also an ADI solver for 2D PDEs in "/opt/R2014a/toolbox/fininst/fininst/+internal/+fininst/adi2dcc.m", that's a Linux path but windows/macOSX are similar.

Cuchulainn
Posts: 63816
Joined: July 16th, 2004, 7:38 am
Location: Amsterdam
Contact:

### Re: Code for closed form solution for max(S1-S2-K, 0)

I don't use Matab, It's also too \$ Python is just not the language for this.
It would be anathema, like Fine Gael forming a government with Sinn Fein.
Each to his own. Depends what you want.

I see Julia as much^2 better.

https://wilmott.com/automatic-for-the-greeks/
My C++ Boost code gives
262537412640768743.999999999999250072597198185688879353856337336990862707537410378210647910118607313

http://www.datasimfinancial.com
http://www.datasim.nl

katastrofa
Posts: 9853
Joined: August 16th, 2007, 5:36 am
Location: Alpha Centauri

### Re: Code for closed form solution for max(S1-S2-K, 0)

Someone recommended iPython to me when I complained that Python is not as convenient for data visualisation as Matlab. I've just started using it, but it looks cool. And there's also Octave.

Wilmott.com has been "Serving the Quantitative Finance Community" since 2001. Continued...

 JOBS BOARD

Looking for a quant job, risk, algo trading,...? Browse jobs here...

GZIP: On