It's very easy, but you still need two functions defined elsewhere called option_price_call_black_scholes and fabs. The rest of the code is like this:

Public Function option_price_implied_volatility_call_black_scholes_bisections(ByVal S As Double, ByVal X As Double, ByVal r As Double, ByVal time As Double, ByVal option_price As Double) As Double

Const ACCURACY As Double = 0.00001 ' make this smaller for higher accuracy

Const MAX_ITERATIONS As Integer = 100

Const HIGH_VALUE As Double = 10000000000.0

Const ERRORVALUE As Double = -1.0E+40

' check for arbitrage violations:

' if price at almost zero volatility greater than price, return 0

Dim sigma_low As Double = 0.0001

Dim price As Double = option_price_call_black_scholes(S, X, r, sigma_low, time)

Dim i As Integer

If (price > option_price) Then Return 0.0

' simple binomial search for the implied volatility.

' relies on the value of the option increasing in volatility

' want to bracket sigma. first find a maximum sigma by finding a sigma

' with a estimated price higher than the actual price.

Dim sigma_high As Double = 0.3

price = option_price_call_black_scholes(S, X, r, sigma_high, time)

While (price < option_price)

sigma_high = 2.0 * sigma_high ' keep doubling.

price = option_price_call_black_scholes(S, X, r, sigma_high, time)

If (sigma_high > HIGH_VALUE) Then Return ERRORVALUE ' panic, something wrong.

End While

For i = 0 To MAX_ITERATIONS

Dim sigma As Double = (sigma_low + sigma_high) * 0.5

price = option_price_call_black_scholes(S, X, r, sigma, time)

Dim test As Double = (price - option_price)

If (fabs(test) < ACCURACY) Then Return sigma

If (test < 0.0) Then

sigma_low = sigma

Else

sigma_high = sigma

End If

Next

Return ERRORVALUE

End Function

It's obvious that the stile of the code is terrible but that's how was the original ...

Ask me for more if you need it.

SoMoS

Public Function option_price_implied_volat

Const ACCURACY As Double = 0.00001 ' make this smaller for higher accuracy

Const MAX_ITERATIONS As Integer = 100

Const HIGH_VALUE As Double = 10000000000.0

Const ERRORVALUE As Double = -1.0E+40

' check for arbitrage violations:

' if price at almost zero volatility greater than price, return 0

Dim sigma_low As Double = 0.0001

Dim price As Double = option_price_call_black_sc

Dim i As Integer

If (price > option_price) Then Return 0.0

' simple binomial search for the implied volatility.

' relies on the value of the option increasing in volatility

' want to bracket sigma. first find a maximum sigma by finding a sigma

' with a estimated price higher than the actual price.

Dim sigma_high As Double = 0.3

price = option_price_call_black_sc

While (price < option_price)

sigma_high = 2.0 * sigma_high ' keep doubling.

price = option_price_call_black_sc

If (sigma_high > HIGH_VALUE) Then Return ERRORVALUE ' panic, something wrong.

End While

For i = 0 To MAX_ITERATIONS

Dim sigma As Double = (sigma_low + sigma_high) * 0.5

price = option_price_call_black_sc

Dim test As Double = (price - option_price)

If (fabs(test) < ACCURACY) Then Return sigma

If (test < 0.0) Then

sigma_low = sigma

Else

sigma_high = sigma

End If

Next

Return ERRORVALUE

End Function

It's obvious that the stile of the code is terrible but that's how was the original ...

Ask me for more if you need it.

SoMoS