private void CalculatePrices() { if (S <= 0 || K <= 0 || r <= 0 || t <= 0 || sigma <= 0) { ErrorMsg = "Please, fill all fields with values >0"; return; } else { ErrorMsg = ""; try { var bc = new BlacksCholes { S = S, K = K, r = r, sigma = sigma, t = t }; BlacksCholesCalculator.CalculatePremium(ref bc); CallPrice = bc.Call; PutPrice = bc.Put; } catch (DivideByZeroException ex) { ErrorMsg = "if you use / make sure to add .0 to the end of the number for example 180/365.0"; return; } catch (Exception ex) { ErrorMsg = ex.Message; return; } } }
public void Calculate_d2(double S, double K, double t, double sigma, double r, double d2) { //Arrange var blacksCholes = new BlacksCholes { S = S, K = K, t = t, sigma = sigma, r = r }; //Act BlacksCholesCalculator.CalculatePremium(ref blacksCholes); //Assert Assert.AreEqual(d2, Math.Round(blacksCholes.d2, 4)); }