Exemple #1
0
        public UnlTradingData CalculateWhatIf(double ivChange, int daysLeftChange)
        {
            IVChange       = ivChange;
            DaysLeftChange = daysLeftChange;
            var positionList = UnlManager.PositionsDataBuilder.PositionDataDic.Values;
            List <BnSCalculationData> bnSCalculationDataList = new List <BnSCalculationData>();
            BnSCalcHelpper            bnSCalcHelpper         = new BnSCalcHelpper();

            foreach (OptionsPositionData position in positionList)
            {
                BnSCalculationData bnSCalculationData =
                    bnSCalcHelpper.CalculateValuesByBnS(position.OptionData, DaysLeftChange, IVChange);
                bnSCalculationData.Position = position.Position;
                bnSCalculationDataList.Add(bnSCalculationData);
            }
            WhatIfPositionsSummaryData =
                new PositionsSummaryData
            {
                CostTotal     = bnSCalculationDataList.Sum(pd => pd.Cost),
                DeltaTotal    = bnSCalculationDataList.Sum(pd => pd.DeltaTotal),
                GammaTotal    = bnSCalculationDataList.Sum(pd => pd.GammaTotal),
                ThetaTotal    = bnSCalculationDataList.Sum(pd => pd.ThetaTotal),
                VegaTotal     = bnSCalculationDataList.Sum(pd => pd.VegaTotal),
                MarketValue   = bnSCalculationDataList.Sum(pd => pd.PositionPrice),
                Shorts        = bnSCalculationDataList.Where(pd => pd.Position < 0).Sum(pd => Abs(pd.Position)),
                Longs         = bnSCalculationDataList.Where(pd => pd.Position > 0).Sum(pd => pd.Position),
                IVWeightedAvg = bnSCalculationDataList.Sum(pd => pd.ImpliedVolatilitiesForCalc * pd.Quantity) /
                                bnSCalculationDataList.Sum(pd => pd.Quantity)
            };

            WhatIfUnlTradingData.PositionsSummaryData = WhatIfPositionsSummaryData;
            return(WhatIfUnlTradingData);
        }
Exemple #2
0
        /// <summary>
        /// Insert the new calculated values to the OptionData object, instead of the old values.
        /// </summary>
        /// <param name="bnSCalculationData"></param>
        /// <param name="optionData"></param>
        private void UpdateOptionData(BnSCalculationData bnSCalculationData, OptionData optionData)
        {
            optionData.ImpliedVolatility = bnSCalculationData.ImpliedVolatilitiesBase;

            optionData.Delta = bnSCalculationData.ResultDataValues.Delta;
            optionData.Gamma = bnSCalculationData.ResultDataValues.Gamma;
            optionData.Theta = bnSCalculationData.ResultDataValues.Theta;
            optionData.Vega  = bnSCalculationData.ResultDataValues.Vega;
        }
Exemple #3
0
        /// <summary>
        /// Calculate the values according the Bns calculations
        /// </summary>
        /// <param name="optionData"> </param>
        /// <param name="daysLeftChange">the change on the left daye to expiry.</param>
        /// <param name="ivChange">the change on the IV</param>
        /// <returns></returns>
        public BnSCalculationData CalculateValuesByBnS(OptionData optionData, int daysLeftChange = 0, double ivChange = 0)
        {
            //First calculate the IV according the actual prices, UNL and option price.
            var calculatedIV = CalculateIVByOptionPrice(optionData);
            //Create object for calculation and store the results:
            var parametersForCalc =
                new ParametersForCalc(optionData, daysLeftChange, ivChange)
            {
                ImpliedVolatilitiesBase = calculatedIV
            };
            var bnSCalculationData = new BnSCalculationData(parametersForCalc);

            //Do BnS calculations:
            CalculateBnSValues(bnSCalculationData);
            return(bnSCalculationData);
        }
Exemple #4
0
        /// <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;
            }
        }