Esempio n. 1
0
        /// <summary>
        /// Gets the theta.
        /// </summary>
        /// <returns></returns>
        public double GetTheta()
        {
            double             spot = Tree.Underlying(0, 0);
            double             tau  = Tree.Time;
            int                n1   = _dividendDays.Length;
            int                n2   = _rateDays.Length;
            BinomialTreePricer lhs1 = new BinomialTreePricer(spot, Strike, Payoff.ToLower()[0] == 'p', tau, _volatility, Tree.Columns, _flatFlag, Style, Smoothing, _rateDays, _rateAmounts, _dividendDays, _dividendAmounts, _treeType);

            int[] divDays1 = new int[n1];
            for (int idx = 0; idx < n1; idx++)
            {
                divDays1[idx] = Math.Max(_dividendDays[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, _volatility, Tree.Columns, _flatFlag, Style, Smoothing, rateDays1, _rateAmounts, divDays1, _dividendAmounts, _treeType);
            double             p1    = lhs1.GetPrice();
            double             p2    = lhs2.GetPrice();
            double             theta = lhs2.GetPrice() - lhs1.GetPrice();

            return(theta);
        }
Esempio n. 2
0
        /// <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 * _volatility, Tree.Columns, _flatFlag, Style, Smoothing, _rateDays, _rateAmounts, _dividendDays, _dividendAmounts, _treeType);
            BinomialTreePricer lhs2 = new BinomialTreePricer(spot, Strike, Payoff.ToLower()[0] == 'p', tau, 1.01 * _volatility, Tree.Columns, _flatFlag, Style, Smoothing, _rateDays, _rateAmounts, _dividendDays, _dividendAmounts, _treeType);
            double             p1   = lhs1.GetPrice();
            double             p2   = lhs2.GetPrice();
            double             vega = 0.0;

            if (_volatility != 0)
            {
                vega = 0.01 * (p2 - p1) / (2 * 0.01 * _volatility);
            }
            return(vega);
        }
Esempio n. 3
0
        /// <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, _volatility, steps, _flatFlag, Style, Smoothing, _rateDays, _rateAmounts, _dividendDays, _dividendAmounts, _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);
        }