I’m going through my code and each time D1 ends up being NaN. The code looks fine to me, and I’m completely stumped…
double D1;
Data Data = new Data();
PriceSpot = 40;
Data.PriceStrike = 40;
Data.RateInterest = .03;
Data.Volatility = .3;
Data.ExpriationDays = 300;
D1 =
(
Math.Log(PriceSpot/Data.PriceStrike) +
(
(Data.RateInterest + (Math.Pow(Data.Volatility,2)/2)) *
(Data.ExpirationDays/365)
)
) /
(
Data.Volatility *
Math.Pow(Data.ExpirationDays/365,.5)
);
Data.Volatility * Math.Pow(Data.ExpirationDays/365,.5)is 0 since 300/365 as int equals to 0Assuming
ExpriationDaysproperty is of typeintindeed, it’ll make the whole expression be 0.For example:
Some comment about dividing by 0:
When dividing two 0 integers an exception will be thrown at runtime:
When dividing two 0 doubles the result will be NaN and no exception will be thrown: