以下是VBA的程序:
Function dOne(Stock, Exercise, Time, Interest, Dividend, sigma) dOne = (Log(Stock / Exercise) + (Interest - Dividend) * Time) / (sigma * Sqr(Time)) _ + 0.5 * sigma * Sqr(Time) End Function
Function CallOption(Stock, Exercise, Time, Interest, Dividend, sigma) CallOption = Stock * Exp(-Dividend * Time) * _ Application.NormSDist(dOne(Stock, Exercise, Time, Interest, Dividend, sigma)) _ - Exercise * Exp(-Time * Interest) * _ Application.NormSDist(dOne(Stock, Exercise, Time, Interest, Dividend, sigma) _ - sigma * Sqr(Time)) End Function Function CallVolatility(Stock, Exercise, Time, Interest, Dividend, Target) High = 2 Low = 0 Do While (High - Low) > 0.0001 If CallOption(Stock, Exercise, Time, Interest, Dividend, (High + Low) / 2) > _ Target Then High = (High + Low) / 2 Else: Low = (High + Low) / 2 End If Loop CallVolatility = (High + Low) / 2 End Function