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

call_iv() shouldn't panic if the implied volatility can't be found #2

Closed
dgbustos opened this issue Mar 21, 2019 · 3 comments
Closed

Comments

@dgbustos
Copy link

In call_iv(), if there is no volatility which matches the price, then nrfind::find_root() in call_iv_guess() will return Result.Err and unwrap() will panic.

call_iv() and the like should probably return Result<f64> instead of f64.

@dgbustos dgbustos changed the title call_iv() shouldn't panic if the implied volatility can't be found call_iv() shouldn't panic if the implied volatility can't be found Mar 21, 2019
@danielhstahl
Copy link
Owner

Thanks for bringing up this issue @dgbustos ! I've gone back and forth when considering the API for the implied volatility functions. With the "approximate_vol" function providing a value close to the optimum value I have not ever had a panic. In the tests I randomly simulate parameters; with no panics.

Have you actually experienced a panic when using the implied volatility functions? If so, can you provide the parameters which resulted in the panic?

Thanks!

@dgbustos
Copy link
Author

I have 500 examples from a recent file of SPY option quotes. They're all for deep-in-the-money calls. For example

black_scholes::call_iv( 50.275, 274.525, 225.000, 0.0244, 0.156 );
black_scholes::call_iv( 62.02, 274.525, 222.000, 0.0244, 1.823 );

When I encountered this in another library, I think I tracked the reason down to negative time value, and https://math.stackexchange.com/a/2959355 might be informative.

@danielhstahl
Copy link
Owner

That makes a lot of sense. I'll update the code (hopefully this weekend) and bump the crates version.

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

No branches or pull requests

2 participants