Пример #1
0
        void BSUpdate(int i)
        {
            double spotPx, strikePx, optMaturity, vol;

            CheckNullInput(i);
            bool isBinary = (bool)dgv_BS.Rows[i].Cells["IsBinary"].Value;
            char optCP = dgv_BS.Rows[i].Cells["CP"].Value.ToString()[0];
            if (!Double.TryParse(textBox_Underlying.Text, out spotPx)
                || !Double.TryParse(dgv_BS.Rows[i].Cells["K"].Value.ToString(), out strikePx)
                || !Double.TryParse(dgv_BS.Rows[i].Cells["tau"].Value.ToString(), out optMaturity)
                || !Double.TryParse(dgv_BS.Rows[i].Cells["vol"].Value.ToString(), out vol)
                )
            {
                ClearBS(i);
                return;
            }

            double intR = 0.0001;
            double divYield = 0.0;

            if (isBinary)
            {
                BinaryBlackScholes bs = new BinaryBlackScholes(optCP, spotPx, strikePx, optMaturity, intR, divYield);
                dgv_BS.Rows[i].Cells["Price"].Value = bs.calPx(vol);
                dgv_BS.Rows[i].Cells["Delta"].Value = bs.calDelta(vol);
                dgv_BS.Rows[i].Cells["Gamma"].Value = bs.calGamma(vol);
                dgv_BS.Rows[i].Cells["Theta"].Value = bs.calTheta(vol);
                dgv_BS.Rows[i].Cells["Vega"].Value = bs.calVega(vol);
                dgv_BS.Rows[i].Cells["DualDelta"].Value = bs.calDualDelta(vol);
            }
            else
            {
                BlackScholes bs = new BlackScholes(optCP, spotPx, strikePx, optMaturity, intR, divYield);
                dgv_BS.Rows[i].Cells["Price"].Value = bs.calPx(vol);
                dgv_BS.Rows[i].Cells["Delta"].Value = bs.calDelta(vol);
                dgv_BS.Rows[i].Cells["Gamma"].Value = bs.calGamma(vol);
                dgv_BS.Rows[i].Cells["Theta"].Value = bs.calTheta(vol);
                dgv_BS.Rows[i].Cells["Vega"].Value = bs.calVega(vol);
                dgv_BS.Rows[i].Cells["DualDelta"].Value = bs.calDualDelta(vol);
            }
        }
Пример #2
0
        double GetGreek(string str_greek, double x, int j, string time_K)
        {
            double spotPx, strikePx, optMaturity, vol;

            CheckNullInput(j);
            bool isBinary = (bool)dgv_BS.Rows[j].Cells["IsBinary"].Value;
            char optCP = dgv_BS.Rows[j].Cells["CP"].Value.ToString()[0];
            if (!Double.TryParse(textBox_Underlying.Text, out spotPx)
                || !Double.TryParse(dgv_BS.Rows[j].Cells["K"].Value.ToString(), out strikePx)
                || !Double.TryParse(dgv_BS.Rows[j].Cells["tau"].Value.ToString(), out optMaturity)
                || !Double.TryParse(dgv_BS.Rows[j].Cells["vol"].Value.ToString(), out vol)
                )
            {
                throw new Exception();
            }

            double intR = 0.0001;
            double divYield = 0.0;

            if (time_K == "time")
            {
                if (optMaturity < x)
                {
                    double intrinsicValue = 0.0;
                    if (optCP == 'C') intrinsicValue = Math.Max(0.0, spotPx - strikePx);
                    if (optCP == 'P') intrinsicValue = Math.Max(0.0, strikePx - spotPx);
                    if (isBinary) intrinsicValue = Math.Sign(intrinsicValue);
                    return intrinsicValue;
                }
            }

            if (isBinary)
            {
                BinaryBlackScholes bs;
                if (time_K=="time")
                    bs= new BinaryBlackScholes(optCP, spotPx, strikePx, optMaturity-x, intR, divYield);
                else
                    bs= new BinaryBlackScholes(optCP, spotPx, x, optMaturity, intR, divYield);
                if (str_greek == "Price") return bs.calPx(vol);
                if (str_greek == "Delta") return bs.calDelta(vol);
                if (str_greek == "Gamma") return bs.calGamma(vol);
                if (str_greek == "Theta") return bs.calTheta(vol);
                if (str_greek == "Vega") return bs.calVega(vol);
                if (str_greek == "DualDelta") return bs.calDualDelta(vol);
            }
            else
            {
                BlackScholes bs;
                if (time_K=="time")
                    bs= new BlackScholes(optCP, spotPx, strikePx, optMaturity-x, intR, divYield);
                else
                    bs= new BlackScholes(optCP, x, strikePx, optMaturity, intR, divYield);
                if (str_greek == "Price") return bs.calPx(vol);
                if (str_greek == "Delta") return bs.calDelta(vol);
                if (str_greek == "Gamma") return bs.calGamma(vol);
                if (str_greek == "Theta") return bs.calTheta(vol);
                if (str_greek == "Vega") return bs.calVega(vol);
                if (str_greek == "DualDelta") return bs.calDualDelta(vol);
            }
            throw new Exception();
        }