コード例 #1
0
        private void btnCalculate_Click(object sender, EventArgs e)
        {
            try
            {
                BlackNScholesCaculator blackNScholesCaculator = new BlackNScholesCaculator()
                {
                    DayLefts            = DayLefts,
                    ImpliedVolatilities = this.ImpliedVolatilities,
                    //OptionType = EOptionTypes.Put,
                    RiskFreeInterestRate = this.RiskFreeInterestRate,
                    StockPrice           = this.StockPrice,
                    Strike = this.StrikePrice
                };
                blackNScholesCaculator.CalculateAll();
                double resValue = blackNScholesCaculator.CallValue;
                lblCallB_SValue.Text = resValue.ToString("#0.00");
                resValue             = blackNScholesCaculator.PutValue;
                lblPutB_SValue.Text  = resValue.ToString("#0.00");


                lblPutDelta.Text = blackNScholesCaculator.DeltaPut.ToString("#0.00");

                lblCallDelta.Text = blackNScholesCaculator.DeltaCall.ToString("#0.00");

                lblCallGama.Text = blackNScholesCaculator.GamaCall.ToString("#0.0000");
                lblPutGama.Text  = blackNScholesCaculator.GamaPut.ToString("#0.0000");

                lblCallTheta.Text = blackNScholesCaculator.ThetaCall.ToString("#0.00");
                lblPutTheta.Text  = blackNScholesCaculator.ThetaPut.ToString("#0.00");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
コード例 #2
0
ファイル: BnSCalcHelpper.cs プロジェクト: avneraz/IBRTrader
        /// <summary>
        /// Use BnS equation to calculate the values (Greek parameters).
        /// </summary>
        /// <param name="bnSCalculationData"></param>
        private void CalculateBnSValues(BnSCalculationData bnSCalculationData)
        {
            var blackNScholesCaculator = new BlackNScholesCaculator
            {
                DayLefts             = bnSCalculationData.DayLeftsForCalc,
                ImpliedVolatilities  = bnSCalculationData.ImpliedVolatilitiesForCalc,
                RiskFreeInterestRate = RiskFreeInterestRate,
                StockPrice           = bnSCalculationData.StockPrice,
                Strike     = bnSCalculationData.Strike,
                Multiplier = bnSCalculationData.Multiplier
            };
            int multiplier = bnSCalculationData.Multiplier;

            blackNScholesCaculator.CalculateAll();

            if (bnSCalculationData.OptionType == EOptionType.Call)
            {
                bnSCalculationData.ResultDataValues.OptionPrice = double.IsNaN(blackNScholesCaculator.CallValue)
                    ? 0
                    : blackNScholesCaculator.CallValue;
                bnSCalculationData.ResultDataValues.Delta = blackNScholesCaculator.DeltaCall / multiplier;
                bnSCalculationData.ResultDataValues.Gamma = blackNScholesCaculator.GamaCall / multiplier;
                bnSCalculationData.ResultDataValues.Theta = blackNScholesCaculator.ThetaCall / multiplier;
                bnSCalculationData.ResultDataValues.Vega  = blackNScholesCaculator.VegaCall / multiplier;
            }
            else
            {
                bnSCalculationData.ResultDataValues.OptionPrice = double.IsNaN(blackNScholesCaculator.PutValue)
                    ? 0
                    : blackNScholesCaculator.PutValue;
                bnSCalculationData.ResultDataValues.Delta = blackNScholesCaculator.DeltaPut / multiplier;
                bnSCalculationData.ResultDataValues.Gamma = blackNScholesCaculator.GamaPut / multiplier;
                bnSCalculationData.ResultDataValues.Theta = blackNScholesCaculator.ThetaPut / multiplier;
                bnSCalculationData.ResultDataValues.Vega  = blackNScholesCaculator.VegaPut / multiplier;
            }
        }