Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implementing Baron-Adesi Whaley approximation of black scholes formula #28

Merged
merged 1 commit into from
Mar 18, 2020

Conversation

esztermarton
Copy link
Contributor

Implementation and reference values for tests taken from paper:
https://deriscope.com/docs/Barone_Adesi_Whaley_1987.pdf

Copy link
Contributor

@cyrilchim cyrilchim left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nearly there!


_allowed_symbols = [
'adesi_whaley',
'american_option',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you want expose american_option you need
from tf_quant_finance.black_scholes.approximations import american_option

and have a separate init file for american_option
This is probably a better thing to do

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make a new directory for american_option? Super happy to make that change at some point - maybe worth waiting until we have more things in the approximation bucket so it isn't unnecessarily nested? will be a good practice to see how well i've understood these build configs now :D

Comment on lines +20 to +27
# tensorflow dep,
# numpy dep,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You don't have all the deps:
"//tf_quant_finance/black_scholes:vaniall_prices",
"//tf_quant_finance/black_scholes:implied_vol_newton_root",
"//tf_quant_finance/math"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes! I think this notation of having the specific function was what I was missing!! thanks

tf_quant_finance/black_scholes/approximations/BUILD Outdated Show resolved Hide resolved
Copy link
Contributor

@cyrilchim cyrilchim left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a few docstring comments

Comment on lines 239 to 243
""" Calculates variables q, a and the critical spot price as per reference [1]
for the american option price formula.
These are values needed to calculate the approximate american option price.
For spot prices above and below the critical spot price, the american option
price formula behaves differently.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think this is done - let me know is this is what you were thinking (i thought this one in specific could use a bit of explanation so i've saved the old doc string in case you want some of if back :) )

Comment on lines 188 to 191
# The naming convention will align variables with the variables named in
# reference [1], but made lower case, and differentiating between put and
# call option values with the suffix _put and _call.
# [1] https://deriscope.com/docs/Barone_Adesi_Whaley_1987.pdf
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess it's failing because of extra spaces here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

took those away. What was failing? Is there some kind of linter I could run to make the code consistent style? (at work we use black and it makes this a lot easier :) ) (but I do note that the style of tfqf is not the same as black so I can't user that) Do you maybe have a pylint file that could at least highlight my mistakes?

Copy link
Contributor

@cyrilchim cyrilchim left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A bunch of final stylistic comments. Will push it once fixed.
Thank you again for the efforts!

volatilities,
strikes,
expiries,
discount_rates,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

discount_rates can be None
Also, discount_factors dissapeared. Please put them back

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it hasn't disappeared... i never put it in! Seemed a little too high level for a fairly approximate formula and I didn't want to accommodate for it at the cost of making it more complicated. but i can do it now... :) Can I just accept it and calculate discount rate from it? (discount_rate = -tf.math.log(discount_factor) / expiries)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants