Skip to content

Wire finite difference model into EquityAmericanOption - #168

Merged
domokane merged 4 commits into
domokane:masterfrom
idorrington92:fin_diff_vanilla_option
Mar 16, 2023
Merged

domokane merged 4 commits into
domokane:masterfrom
idorrington92:fin_diff_vanilla_option

Conversation

@idorrington92

Copy link
Copy Markdown
Contributor

Following on from previous PR: #167

I've wired the finite difference model into the EquityAmericanOption. The finite difference model seems to have a lot more parameters than other models, so rather than add a lot more parameters to the BlackScholes model class, I just added a params dictionary and gave most of the parameters sensible default values.

Tests seem to give similar (i.e. to 1dp) values as the CRR tree model

… difference notebook with changes to methods signatures and output. Update Equity vanilla american style option notebook to show finite difference model gives similar results to CRR tree. Add and update tests
@domokane

domokane commented Mar 14, 2023 •

Copy link
Copy Markdown
Owner

Hi Iain
That was quick. I would expect that in the limit both CRR and FD should give the same value to a few dp, or to be more precise given option prices can range in size, the percentage difference should be less than 0.01%. Also, have you done any timings ? I wonder if using Numba will help. I will look at the code carefully and pull it as soon as I can.
Best
D

@domokane

Copy link
Copy Markdown
Owner

PS Just to be super clear - the payoffs to implement are (i) European options - this can be compared with Black Scholes analytic prices and you should see convergence. (ii) American options as you have done which should agree closely with CRR in the limit of many time steps. I think you have done this but just want to be explicit.

@domokane

Copy link
Copy Markdown
Owner

@idorrington92

Copy link
Copy Markdown
Contributor Author

Hi @domokane
I think there is some bug in C++ code I based my Python code on. The loop at line 167 here https://github.com/domokane/CompFin/blob/98f6c6ebf1b354da43bf0d2f96790a4975c7b855/Week%204/xladdin/Utility/kBlack.cpp#L167
doesn't seem to actually do anything. The reason is all the variables, in particular the array res, are reset on each interation.
As it doesn't do anything, I removed it from when converting the code to Python, but I think that that loop is supposed to iteratively improve the model, but isn't because res gets reset every time. Implementing the loop without resetting res leads to crazy big/small results. I'll read the thesis you sent and see if I can figure what is wrong with this algorithm. Do you have any thoughts about what this loop is doing? Am I missing something?

Would you like the finite difference model in EquityVanillaOption? I didn't bother as the only model it currently uses is the analytic one (which makes sense), but happy to add this model if you want.

As for timings, I've only done a little work on this when deciding where to use Numba. Most of the methods didn't play nicely with Numba, or Numba was slower. I'll look into timing and optimisation more once I'm confident the output is actually sensible :)

@domokane
domokane merged commit f929bdf into domokane:master Mar 16, 2023
@domokane

Copy link
Copy Markdown
Owner

Great! Are the results closer to the CRR Tree now ?

@idorrington92

Copy link
Copy Markdown
Contributor Author

I fixed a bug in my implementation of dx, but they're still not very close, and I'm still confused by that loop in the C++ code. Adding the loop to my Python code, it now diverges much slower, but something is still wrong. I'll keep investigating.

@domokane

domokane commented Mar 17, 2023 via email

Copy link
Copy Markdown
Owner

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants