示例#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);
            }
        }