-
Notifications
You must be signed in to change notification settings - Fork 564
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
Conversation
080e67a
to
323b6c9
Compare
tf_quant_finance/black_scholes/approximations/american_option.py
Outdated
Show resolved
Hide resolved
6599d08
to
43f78d8
Compare
There was a problem hiding this 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', |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
tf_quant_finance/black_scholes/approximations/american_option.py
Outdated
Show resolved
Hide resolved
# tensorflow dep, | ||
# numpy dep, |
There was a problem hiding this comment.
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"
There was a problem hiding this comment.
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/american_option.py
Outdated
Show resolved
Hide resolved
There was a problem hiding this 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
tf_quant_finance/black_scholes/approximations/american_option.py
Outdated
Show resolved
Hide resolved
tf_quant_finance/black_scholes/approximations/american_option.py
Outdated
Show resolved
Hide resolved
""" 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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as above
There was a problem hiding this comment.
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 :) )
# 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 |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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?
There was a problem hiding this 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!
tf_quant_finance/black_scholes/approximations/american_option.py
Outdated
Show resolved
Hide resolved
volatilities, | ||
strikes, | ||
expiries, | ||
discount_rates, |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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)
tf_quant_finance/black_scholes/approximations/american_option.py
Outdated
Show resolved
Hide resolved
tf_quant_finance/black_scholes/approximations/american_option.py
Outdated
Show resolved
Hide resolved
tf_quant_finance/black_scholes/approximations/american_option.py
Outdated
Show resolved
Hide resolved
tf_quant_finance/black_scholes/approximations/american_option.py
Outdated
Show resolved
Hide resolved
tf_quant_finance/black_scholes/approximations/american_option.py
Outdated
Show resolved
Hide resolved
tf_quant_finance/black_scholes/approximations/american_option.py
Outdated
Show resolved
Hide resolved
608da4f
to
9c7e09c
Compare
Implementation and reference values for tests taken from paper:
https://deriscope.com/docs/Barone_Adesi_Whaley_1987.pdf