/// <summary> /// Gets the theta. /// </summary> /// <returns></returns> public double GetTheta() { double spot = Tree.Underlying(0, 0); double _tau = Tree.Time; int n1 = _divdays.Length; int n2 = _ratedays.Length; BinomialTreePricer lhs1 = new BinomialTreePricer(spot, Strike, Payoff.ToLower()[0] == 'p', _tau, _vol, Tree.Columns, _flatFlag, Style, Smoothing, _ratedays, _rateamts, _divdays, _divamts, _treeType); int[] _divdays1 = new int[n1]; for (int idx = 0; idx < n1; idx++) { _divdays1[idx] = Math.Max(_divdays[idx] - 1, 0); } int[] _ratedays1 = new int[n2]; for (int idx = 0; idx < n2; idx++) { _ratedays1[idx] = Math.Max(_ratedays[idx] - 1, 0); } BinomialTreePricer lhs2 = new BinomialTreePricer(spot, Strike, Payoff.ToLower()[0] == 'p', _tau - 1.0 / 365.0, _vol, Tree.Columns, _flatFlag, Style, Smoothing, _ratedays1, _rateamts, _divdays1, _divamts, _treeType); double p1 = lhs1.GetPrice(); double p2 = lhs2.GetPrice(); double theta = lhs2.GetPrice() - lhs1.GetPrice(); return(theta); }
/// <summary> /// Gets the vega. /// </summary> /// <returns></returns> public double GetVega() { double spot = Tree.Underlying(0, 0); double _tau = Tree.Time; BinomialTreePricer lhs1 = new BinomialTreePricer(spot, Strike, Payoff.ToLower()[0] == 'p', _tau, 0.99 * _vol, Tree.Columns, _flatFlag, Style, Smoothing, _ratedays, _rateamts, _divdays, _divamts, _treeType); BinomialTreePricer lhs2 = new BinomialTreePricer(spot, Strike, Payoff.ToLower()[0] == 'p', _tau, 1.01 * _vol, Tree.Columns, _flatFlag, Style, Smoothing, _ratedays, _rateamts, _divdays, _divamts, _treeType); double P1 = lhs1.GetPrice(); double P2 = lhs2.GetPrice(); double vega = 0.0; if (_vol != 0) { vega = 0.01 * (P2 - P1) / (2 * 0.01 * _vol); } return(vega); }
/// <summary> /// Gets the gamma. /// </summary> /// <returns></returns> public double GetGamma() { double spot = Tree.Underlying(0, 0); int steps = Tree.Columns + 2; double tau = Tree.Time * (1 + 2 / steps); BinomialTreePricer clone = new BinomialTreePricer(spot, Strike, Payoff.ToLower()[0] == 'p', tau, _vol, steps, _flatFlag, Style, Smoothing, _ratedays, _rateamts, _divdays, _divamts, _treeType); double[] S = new double[3]; double[] C = new double[3]; for (int i = 0; i <= 2; ++i) { S[i] = clone.Tree.Underlying(2, i); C[i] = clone.GetPriceMatrix(2, i); } double gamma = 2 * (S[0] * (C[1] - C[2]) + S[1] * (C[2] - C[0]) + S[2] * (C[0] - C[1])) / (S[1] - S[0]) / (S[2] - S[0]) / (S[2] - S[1]); return(gamma); }