Page 1 of 1

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

Posted: February 11th, 2020, 9:28 am
by mathdude2018
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?

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

Posted: February 11th, 2020, 2:45 pm
by DavidJN

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

Posted: February 11th, 2020, 5:15 pm
by Cuchulainn
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?

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

Posted: February 11th, 2020, 7:51 pm
by FaridMoussaoui
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.

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

Posted: February 11th, 2020, 8:34 pm
by Cuchulainn
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/

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

Posted: February 12th, 2020, 2:48 am
by katastrofa
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.