using System.Collections.Generic;
public static void Main()
double str = RevisedcalculateVolatility(.5, 10, 130, .023, 120, "C");
private static double IVIncrementor(double iv)
public static double normsdist(double x)
return 1 - normsdist(-x);
var k = 1.0 / (1.0 + 0.2316419 * x);
return 1.0 - Math.Exp(-x * x / 2.0) / Math.Sqrt(2 * Math.PI) * k * (0.31938153 + k * (-0.356563782 + k * (1.781477937 + k * (-1.821255978 + k * 1.330274429))));
public static double RevisedcalculateVolatility(double dIntRate, double doptionPrice, double dspotPrice, double dTimetomaturity, double dstrike, string optionType)
double dVolatility = 0.5;
double dTolerance = 0.02;
Dictionary<string, double> dictValidateVol = new Dictionary<string, double>();
if (dTimetomaturity == 0)
dTimetomaturity = 0.000001;
bool isvalid = ((dspotPrice > 0) && (dVolatility > 0) && (dstrike > 0) && (dTimetomaturity > 0)) ? true : false;
if (doptionPrice < dPrice)
dVolatility = Math.Round((dVolatility - IVIncrementor(dVolatility)), 2);
dVolatility = Math.Round((dVolatility + IVIncrementor(dVolatility)), 2);
double d1 = (Math.Log(dspotPrice / dstrike) + (dIntRate + (double)dVolatility * (double)dVolatility / 2.0) * dTimetomaturity) / ((double)dVolatility * Math.Sqrt(dTimetomaturity));
double d2 = d1 - (double)dVolatility * Math.Sqrt(dTimetomaturity);
double norm_d1 = (normsdist(d1));
double norm_d2 = (normsdist(d2));
double norm_d2minus = (normsdist(-d2));
double eRiskFreeYears = Math.Exp(-1 * dIntRate * dTimetomaturity);
double rootYears = Math.Sqrt(dTimetomaturity);
dPrice = Math.Round(dspotPrice * norm_d1 - dstrike * norm_d2 * eRiskFreeYears, 4);
dPrice = Math.Round(dstrike * eRiskFreeYears * norm_d2minus - dspotPrice * normsdist(-d1), 4);
if (doptionPrice > dPrice)
dMargin = Math.Round((doptionPrice - dPrice), nRoundOff);
dMargin = Math.Round((dPrice - doptionPrice), nRoundOff);
if (!dictValidateVol.ContainsKey(dPrice + "/" + dVolatility))
dictValidateVol.Add(dPrice + "/" + dVolatility, dVolatility);
while ((dMargin > dTolerance) && (dVolatility != 0) && (isvalid == true) && (dVolatility < 100));
public class ScheduleInfo
Schedules = new List<Schedule>();
public List<Schedule> Schedules
public string InternalPresenters
public string InternalPresenterIds
public string InternalPresenterNames
public string ExternalPresenters
public int MaxInPersonAttendance
public int MaxInPersonWaitlist
public bool NoAutoBumpInPersonWaitlist
public int MaxWebcastAttendance
public int MaxWebcastWaitlist
public bool NoAutoBumpWebcastWaitlist
public DateTime StartDateTime
public DateTime EndDateTime
public string WebcastEvent
public string WebcastOnly
public string WebcastRequiresReg
public string RecordingOnly
public string RecordingRequiresReg
public string RecordingUrl
public string WhenOverrideText
public string RegistrationQuestion
public bool RegistrationQuestionRequired
public string SurveyCustomQuestion
public string ResourceUrl
public bool ScheduleCancelled
public string ScheduleCancellationWebMessage
public string ScheduleCancellationEmailMessage
public System.Guid ReviewStatusId
public string ReviewStatusComments
public bool ForceNoReminder