/// <summary> /// /// </summary> /// <param name="spotT"></param> /// <param name="priceT"></param> /// <param name="myZero"></param> /// <param name="myDiv"></param> public void MakeTheta(ITree spotT, Pricer priceT, ZeroCurve myZero, DivList myDiv) { SetParam(spotT, priceT); var type = spotT.GetType(); ITree t1 = (ITree)Activator.CreateInstance(type); ITree t2 = (ITree)Activator.CreateInstance(type); t1.Tau = Tau; t1.Gridsteps = Gridsteps; t1.Sig = Sig; t1.Spot = Spot; t1.MakeGrid(myZero, myDiv); priceT.MakeGrid(t1); double p1 = priceT.Price(); DivList shiftDiv = new DivList { Divpoints = myDiv.Divpoints }; shiftDiv.MakeArrays(); for (int idx = 0; idx < myDiv.Divpoints; idx++) { shiftDiv.SetD(idx, myDiv.GetD(idx), myDiv.GetT(idx) - 1 / 365.0); } double t = Tau - 1.00 / 365.00; t2.Tau = t; t2.Gridsteps = Gridsteps; t2.Sig = Sig; t2.Spot = Spot; t2.MakeGrid(myZero, shiftDiv); priceT.MakeGrid(t2); double p2 = priceT.Price(); Theta = (p2 - p1); }
/// <summary> /// /// </summary> /// <param name="today"></param> /// <param name="expiry"></param> /// <param name="dates"></param> /// <param name="amts"></param> /// <returns></returns> /// <exception cref="Exception"></exception> public DivList UnpackDiv(DateTime today, DateTime expiry, DateTime[] dates, double[] amts) { int n1 = dates.Length; int n2 = dates.Length; double timetoexp = expiry.Subtract(today).Days / 365.0; if (n1 != n2) { throw new Exception("Rate ranges must be of the same length"); } var dl = new DivList { Divpoints = n1 }; dl.MakeArrays(); for (int idx = 0; idx < n1; idx++) { double time = dates[idx].Subtract(today).Days / 365.0; double rate = amts[idx]; if (time > 0 & time <= timetoexp) { dl.SetD(_kdx, rate, time); _kdx++; } } return(dl); }