Serving the Quantitative Finance Community

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

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

February 11th, 2020, 9:28 am

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?
 
User avatar
DavidJN
Posts: 242
Joined: July 14th, 2002, 3:00 am

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

February 11th, 2020, 2:45 pm

 
User avatar
Cuchulainn
Posts: 20253
Joined: July 16th, 2004, 7:38 am
Location: 20, 000

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

February 11th, 2020, 5:15 pm

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?
 
User avatar
FaridMoussaoui
Posts: 327
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)

February 11th, 2020, 7:51 pm

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.
 
User avatar
Cuchulainn
Posts: 20253
Joined: July 16th, 2004, 7:38 am
Location: 20, 000

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

February 11th, 2020, 8:34 pm

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/
 
User avatar
katastrofa
Posts: 7440
Joined: August 16th, 2007, 5:36 am
Location: Alpha Centauri

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

February 12th, 2020, 2:48 am

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.