```
Function resolve_iv(call_flag As Integer, S As Single, X As Single, a As Single, T As Single, r As Single, iv As Single, q As Single)
' q = div , T = time to expiration
' r = risk free rate . iv = volatility
' a = option price , S = stock price ; X = strike price
' ported from python routine from gary whitlock
Dim high As Single
Dim low As Single
Dim precision As Single
Dim IVTrial As Single
Dim TheoPrice As Single
high = 500
low = 0
precision = 0.0001
While ((high - low) > precision)
IVTrial = (high + low) / 2
If (IVTrial < 0.00001) Then
resolve_iv = ((high + low) / 2)
Exit Function
End If
' TheoPrice = BlackScholes(call_flag, S, X, T, r, IVTrial, q)
TheoPrice = calc_fair_value(call_flag, S, X, IVTrial, T, r)
If (TheoPrice > a) Then
high = (high + low) / 2
Else
low = (high + low) / 2
End If
Wend
resolve_iv = ((high + low) / 2)
End Function
```