jane
jane

Reputation: 33

Julia - find independent variable if dependent is given

I have the following function in julia that calculates the put option price given certain parameters (S,K,m,y,sigma).

formula

function OptionBlackSFs(S,K,m,y,σ,δ=0,PutIt=false)
    # Calculates Black-Scholes European call or put option price, continuous dividends of δ.
    d1 = ( log(S/K) + (y-δ+0.5*σ^2)*m ) / (σ*sqrt(m))
    d2 = d1 - σ*sqrt(m)
    c  = exp(-δ*m)*S*Φ(d1) - K*exp(-y*m)*Φ.(d2)
    if PutIt 
        price = c - exp(-δ*m)*S + exp(-y*m)*K    
    else     
        price = c
    end    
    return price      
end

Is it possible to 'reverse' the function to find out sigma given a certain price?

Thank you!

Upvotes: 2

Views: 112

Answers (1)

Michael K. Borregaard
Michael K. Borregaard

Reputation: 8044

No, that would require each price to only correspond to a single level of sigma, e.g. for your function to be monotonous. You can't guarantee that.

What you can do though is to have Julia optimise your function iteratively, so you find those values of sigma that leads to the lowest difference between the function output and your price. There are several packages in Julia for this kind of thing, take a look at Optim.jl. E.g. this page: https://julianlsolvers.github.io/Optim.jl/stable/#user/minimization/#minimizing-a-univariate-function-on-a-bounded-interval

Your function isn't univariate, but it's easy to make it so by assigning values to the variables you are not estimating:

f(σ) = OptionBlackSFs(2,3,4,5,σ,6) - input_price

and then pass to Optim, which will solve for the inputs that make the output of f as close to 0 as possible. A nicer but slightly more complex syntax might be

let S = 2, K = 3, m = 4, y = 5, δ = 6, input_price = 100
  global f(σ) = OptionBlackSFs(S,K,m,y,σ,δ) - input_price
end

Upvotes: 1

Related Questions