SERVING THE QUANTITATIVE FINANCE COMMUNITY

mathdude2018
Topic Author
Posts: 11
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: 1744
Joined: July 14th, 2002, 3:00 am

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

Cuchulainn
Posts: 61143
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?
http://www.datasimfinancial.com
http://www.datasim.nl

Every Time We Teach a Child Something, We Keep Him from Inventing It Himself
Jean Piaget

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: 61143
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/
http://www.datasimfinancial.com
http://www.datasim.nl

Every Time We Teach a Child Something, We Keep Him from Inventing It Himself
Jean Piaget

katastrofa
Posts: 8754
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.