TaylorSeries.jl icon indicating copy to clipboard operation
TaylorSeries.jl copied to clipboard

Support for Implicitly defined functions

Open rcalxrc08 opened this issue 2 years ago • 2 comments

First thank you very much for the amazing package.

Second, let me explain the issue: assume I have a function g returning x such that f(x,p)=0. I would be interested in computing the derivatives of x with respect to p but I am struggling to do that using the current APIs.

For example in case of ForwardDiff.jl (sorry for not perfect comparison) I can just define the rules on how to compute the first derivative and all of the other orders are automatically determined by successfully applying the chain rule (I guess).

Do you think it makes sense to implement an API in order to do this? I even was looking at this but there is no support for TaylorSeries.jl.

rcalxrc08 avatar Jun 04 '22 10:06 rcalxrc08

Hi, and thanks for reaching us!

We currently do not have an API implemented to do that. But since the chain rule works, I guess we can do something, at least in some sense related to approximations with polynomials. Do you have a concrete example to begin playing with?

lbenet avatar Jun 04 '22 19:06 lbenet

In my package called FinancialToolbox there is a function called blsimpv. It is nothing else then the inverse of Black Scholes Formula (called blsprice in the package) with respect to parameter sigma keeping everything else as a constant. image.

For float numbers I simply invert the function using the Brent method, in order to do that I do the following: I define a function f(x,S0,K,r,T,d,price)=blsprice(S0,K,r,T,x,d)-price. Unfortunately blsprice is using erf for AbstractSeries but there is a tweak for the implementation of that inside FinancialToolbox.jl https://github.com/JuliaDiff/TaylorSeries.jl/issues/285. First I am interested in finding sigma (in the world of floats let's say) st: f(sigma,S0,K,r,T,d,price)=0.0 (it exists unique if parameters are feasible). Brent method (or bisection, or newton..) will return give me back the value sigma that solves that.

But when it comes to derivatives (superior to first order) everything is more challenging because of this minima relation. In case of Dual and Hyper Dual I was able to specialize the function in order to return the derivatives as well, but those functions are far from support TaylorSeries.jl as well and they are far from being that general in order to differentiate in an agnostic way with respect to any of those parameters (S0,K,r,T,d,price).

rcalxrc08 avatar Jun 05 '22 09:06 rcalxrc08