Esempio n. 1
0
        private OneTouchCalculator ConfigureCalculator(IOption option, IMarketCondition market, double timeIncrement = 0.0)
        {
            var trade = (BinaryOption)option;

            var exerciseDate = trade.ExerciseDates.Last();
            var maturityDate = trade.UnderlyingMaturityDate;

            var    riskFreeRate         = market.DiscountCurve.Value.ZeroRate(market.ValuationDate, exerciseDate);
            var    riskfreeDfAtExercise = market.DiscountCurve.Value.ZeroRate(market.ValuationDate, exerciseDate);
            var    spot  = market.SpotPrices.Value.Values.First();
            double sigma = AnalyticalOptionPricerUtil.pricingVol(volSurf: market.VolSurfaces.Value.Values.First(),
                                                                 exerciseDate: exerciseDate, option: option, spot: spot);

            var dividendCurveInput = market.DividendCurves.Value.Values.First().ZeroRate(market.ValuationDate, exerciseDate);
            var dividendInput      = AnalyticalOptionPricerUtil.dividendYieldOutput(dividendCurveInput, riskFreeRate,
                                                                                    option.Dividends, spot, market.ValuationDate, trade.ExerciseDates.Last(), option.DayCount);
            var dividendRate = AnalyticalOptionPricerUtil.dividenRate(trade.UnderlyingProductType, dividendInput, riskfreeDfAtExercise);

            var exerciseInYears = AnalyticalOptionPricerUtil.timeToMaturityFraction(market.ValuationDate, exerciseDate, trade) + timeIncrement;

            var calculator = new OneTouchCalculator(
                trade.BinaryRebateType,
                strike: option.IsMoneynessOption ? trade.Strike * trade.InitialSpotPrice : trade.Strike,
                spotPrice: spot,
                sigma: sigma,
                dividendRate: dividendRate,
                riskFreeRate: riskfreeDfAtExercise,
                cashOrNothingAmount: trade.CashOrNothingAmount,
                exerciseInYears: exerciseInYears,
                underlyingInstrumentType: trade.UnderlyingProductType,
                notional: trade.Notional);

            this._calculator = calculator;
            return(calculator);
        }
        private BarrierOptionCalculator configureCalculator(IOption option, IMarketCondition market,
                                                            double expiryDayRemainingLife = double.NaN, double timeIncrement = 0.0)
        {
            var trade        = (BarrierOption)option;
            var exerciseDate = trade.ExerciseDates.Last();
            var maturityDate = trade.UnderlyingMaturityDate;
            var spot         = market.SpotPrices.Value.Values.First();

            double exerciseInYears;

            if (!double.IsNaN(expiryDayRemainingLife))
            {
                exerciseInYears = expiryDayRemainingLife;
            }
            else
            {
                exerciseInYears = AnalyticalOptionPricerUtil.timeToMaturityFraction(market.ValuationDate, exerciseDate, trade) + timeIncrement;
            }

            //barrier adjust
            var dt = trade.DayCount.CalcDayCountFraction(trade.ObservationDates.First(), trade.ObservationDates.Last()) /
                     trade.ObservationDates.Length;

            var riskFreeRate           = market.DiscountCurve.Value.ZeroRate(market.ValuationDate, exerciseDate);
            var riskfreeRateAtMaturity = market.DiscountCurve.Value.ZeroRate(market.ValuationDate, maturityDate);

            var dividendCurveInput = market.DividendCurves.Value.Values.First().ZeroRate(market.ValuationDate, exerciseDate);
            var dividendInput      = AnalyticalOptionPricerUtil.dividendYieldOutput(dividendCurveInput, riskFreeRate,
                                                                                    option.Dividends, spot, market.ValuationDate, trade.ExerciseDates.Last(), option.DayCount);
            var dividendRate = AnalyticalOptionPricerUtil.dividenRate(trade.UnderlyingProductType, dividendInput, riskFreeRate);

            var vol = AnalyticalOptionPricerUtil.pricingVol(volSurf: market.VolSurfaces.Value.Values.First(),
                                                            exerciseDate: exerciseDate, option: option, spot: spot);

            var barrierCalculator = new BarrierOptionCalculator(
                trade.OptionType,
                trade.BarrierType,
                trade.Rebate,
                trade.IsDiscreteMonitored ? DiscreteAdjustedBarrier(trade.BarrierType, trade.Position, trade.Barrier, vol, dt, trade.BarrierShift) : trade.Barrier,
                trade.IsDiscreteMonitored ? DiscreteAdjustedBarrier(trade.BarrierType, trade.Position, trade.UpperBarrier, vol, dt, trade.BarrierShift) : trade.UpperBarrier,
                option.IsMoneynessOption ? trade.Strike * trade.InitialSpotPrice : trade.Strike,
                spot,
                exerciseInYears,
                vol,
                riskFreeRate,
                dividendRate,
                valuationDate: market.ValuationDate,
                exerciseDate: exerciseDate,
                underlyingMaturityDate: trade.UnderlyingMaturityDate,
                dayCount: trade.DayCount,
                underlyingInstrumentType: trade.UnderlyingProductType,
                notional: trade.Notional
                );

            this._calculator = barrierCalculator;
            return(barrierCalculator);
        }
Esempio n. 3
0
        private AsianOptionCalculator ConfigureCalculator(IOption option, IMarketCondition market,
                                                          double expiryDayRemainingLife = double.NaN, double timeIncrement = 0.0)
        {
            var trade = (AsianOption)option;

            var exerciseDate       = trade.ExerciseDates.Last();
            var remainingObsDates  = trade.ObservationDates.Where(x => x >= market.ValuationDate).ToArray();
            var numOfObsDates      = trade.ObservationDates.Count();
            var numOfObservedDates = numOfObsDates - remainingObsDates.Count();
            var observedAverage    = trade.Fixings.Any() ? trade.Fixings.Average(x => x.Value) : market.SpotPrices.Value.Values.First();
            //if (trade.Fixings.Count != numOfObservedDates)
            //{
            //    throw new PricingLibraryException("AsianOption: number of fixings does not match!");
            //}

            var    spot  = market.SpotPrices.Value.Values.First();
            double sigma = AnalyticalOptionPricerUtil.pricingVol(volSurf: market.VolSurfaces.Value.Values.First(),
                                                                 exerciseDate: exerciseDate, option: option, spot: spot);

            double t;

            if (!double.IsNaN(expiryDayRemainingLife))
            {
                t = expiryDayRemainingLife;
            }
            else
            {
                t = AnalyticalOptionPricerUtil.timeToMaturityFraction(market.ValuationDate, exerciseDate, trade) + timeIncrement;
            }

            var t2 = AnalyticalOptionPricerUtil.timeToMaturityFraction(trade.ObservationDates[0], remainingObsDates.Last(), trade);
            var t1 = AnalyticalOptionPricerUtil.timeToMaturityFraction(market.ValuationDate, remainingObsDates[0], trade) + timeIncrement;

            var riskFreeRate       = market.DiscountCurve.Value.ZeroRate(market.ValuationDate, exerciseDate);
            var dividendCurveInput = market.DividendCurves.Value.Values.First().ZeroRate(market.ValuationDate, exerciseDate);
            var dividendInput      = AnalyticalOptionPricerUtil.dividendYieldOutput(dividendCurveInput, riskFreeRate,
                                                                                    option.Dividends, spot, market.ValuationDate, trade.ExerciseDates.Last(), option.DayCount);
            var dividendRate = AnalyticalOptionPricerUtil.dividenRate(trade.UnderlyingProductType, dividendInput, riskFreeRate);

            var calculator = new AsianOptionCalculator(trade.OptionType, trade.AsianType, trade.UnderlyingProductType,
                                                       trade.StrikeStyle,
                                                       strike: option.IsMoneynessOption ? trade.Strike * trade.InitialSpotPrice : trade.Strike,
                                                       spotPrice: spot,
                                                       realizedAveragePrice: observedAverage,
                                                       exerciseInYears: t,
                                                       originalAveragePeriod: t2,
                                                       timetoNextAveragePoint: t1,
                                                       sigma: sigma,
                                                       riskFreeRate: riskFreeRate,
                                                       dividendRate: dividendRate,
                                                       notional: trade.Notional,
                                                       numOfObsDates: numOfObsDates,
                                                       numOfObservedDates: numOfObservedDates);

            this._calculator = calculator;
            return(calculator);
        }
Esempio n. 4
0
        private BlackScholeCalculator ConfigureCalculator(IOption option, IMarketCondition market,
                                                          double expiryDayRemainingLife = double.NaN, double timeIncrement = 0.0)
        {
            var trade = (BinaryOption)option;

            var exerciseDate = trade.ExerciseDates.Last();
            var maturityDate = trade.UnderlyingMaturityDate;

            var    riskFreeRate         = market.DiscountCurve.Value.ZeroRate(market.ValuationDate, exerciseDate);
            var    riskfreeDfAtMaturity = market.DiscountCurve.Value.ZeroRate(market.ValuationDate, maturityDate);
            var    riskfreeDfAtExercise = market.DiscountCurve.Value.ZeroRate(market.ValuationDate, exerciseDate);
            var    spot  = market.SpotPrices.Value.Values.First();
            double sigma = AnalyticalOptionPricerUtil.pricingVol(volSurf: market.VolSurfaces.Value.Values.First(),
                                                                 exerciseDate: exerciseDate, option: option, spot: spot);

            var dividendCurveInput = market.DividendCurves.Value.Values.First().ZeroRate(market.ValuationDate, exerciseDate);
            var dividendInput      = AnalyticalOptionPricerUtil.dividendYieldOutput(dividendCurveInput, riskFreeRate,
                                                                                    option.Dividends, spot, market.ValuationDate, trade.ExerciseDates.Last(), option.DayCount);

            var dividendRate = AnalyticalOptionPricerUtil.dividenRate(trade.UnderlyingProductType, dividendInput, riskfreeDfAtExercise);

            var exerciseInYears = AnalyticalOptionPricerUtil.timeToMaturityFraction(market.ValuationDate, exerciseDate, trade) + timeIncrement;

            var maturityInYears = AnalyticalOptionPricerUtil.timeToMaturityFraction(market.ValuationDate, maturityDate, trade) + timeIncrement;

            var _isDelayedPay = exerciseInYears.AlmostEqual(maturityInYears);

            var calculator = new BlackScholeCalculator(trade.OptionType,
                                                       trade.BinaryOptionPayoffType,
                                                       strike: option.IsMoneynessOption ? trade.Strike * trade.InitialSpotPrice : trade.Strike,
                                                       spotPrice: spot,
                                                       sigma: sigma,
                                                       dividendRate: dividendRate,
                                                       riskfreeRateAtExercise: riskfreeDfAtExercise,
                                                       riskfreeRateAtMaturity: riskfreeDfAtMaturity,
                                                       curveDayCount: market.DiscountCurve.Value.DayCount,
                                                       cashOrNothingAmount: trade.CashOrNothingAmount,
                                                       exerciseDate: exerciseDate,
                                                       maturityDate: maturityDate,
                                                       valuationDate: market.ValuationDate,
                                                       trade: trade,
                                                       underlyingInstrumentType: trade.UnderlyingProductType,
                                                       notional: trade.Notional,
                                                       isDelayedPay: _isDelayedPay,
                                                       expiryDayRemainingLife: expiryDayRemainingLife,
                                                       timeIncrement: timeIncrement);

            this._calculator = calculator;
            return(calculator);
        }
Esempio n. 5
0
        private LookbackOptionCalculator ConfigureCalculator(IOption option, IMarketCondition market,
                                                             double expiryDayRemainingLife = double.NaN, double timeIncrement = 0.0)
        {
            var trade = (LookbackOption)option;

            var exerciseDate = trade.ExerciseDates.Last();
            var observedMax  = trade.Fixings.Any() ? trade.Fixings.Max(x => x.Value) : market.SpotPrices.Value.Values.First();
            var observedMin  = trade.Fixings.Any() ? trade.Fixings.Min(x => x.Value) : market.SpotPrices.Value.Values.First();

            var    spot  = market.SpotPrices.Value.Values.First();
            double sigma = AnalyticalOptionPricerUtil.pricingVol(volSurf: market.VolSurfaces.Value.Values.First(),
                                                                 exerciseDate: exerciseDate, option: option, spot: spot);

            double t;

            if (!double.IsNaN(expiryDayRemainingLife))
            {
                t = expiryDayRemainingLife;
            }
            else
            {
                t = trade.DayCount.CalcDayCountFraction(market.ValuationDate, exerciseDate) + timeIncrement;
            }

            var riskFreeRate       = market.DiscountCurve.Value.ZeroRate(market.ValuationDate, exerciseDate);
            var dividendCurveInput = market.DividendCurves.Value.Values.First().ZeroRate(market.ValuationDate, exerciseDate);
            var dividendInput      = AnalyticalOptionPricerUtil.dividendYieldOutput(dividendCurveInput, riskFreeRate,
                                                                                    option.Dividends, spot, market.ValuationDate, trade.ExerciseDates.Last(), option.DayCount);
            var dividendRate = AnalyticalOptionPricerUtil.dividenRate(trade.UnderlyingProductType, dividendInput, riskFreeRate);

            var calculator = new LookbackOptionCalculator(trade.OptionType, trade.UnderlyingProductType,
                                                          trade.StrikeStyle,
                                                          strike: option.IsMoneynessOption ? trade.Strike * trade.InitialSpotPrice : trade.Strike,
                                                          spotPrice: spot,
                                                          exerciseInYears: t,
                                                          realizedMaxPrice: observedMax,
                                                          realizedMinPrice: observedMin,
                                                          sigma: sigma,
                                                          riskFreeRate: riskFreeRate,
                                                          dividendRate: dividendRate,
                                                          notional: trade.Notional);

            this._calculator = calculator;
            return(calculator);
        }
Esempio n. 6
0
        private BlackScholeCalculator ConfigureCalculator(IOption option, IMarketCondition market,
                                                          double expiryDayRemainingLife = double.NaN, double timeIncrement = 0.0)
        {
            var trade        = (VanillaOption)option;
            var exerciseDate = trade.ExerciseDates.Last();
            var maturityDate = trade.UnderlyingMaturityDate;

            var    spot  = market.SpotPrices.Value.Values.First();
            double sigma = AnalyticalOptionPricerUtil.pricingVol(volSurf: market.VolSurfaces.Value.Values.First(),
                                                                 exerciseDate: exerciseDate, option: option, spot: spot);

            var riskfreeRateAtExercise = market.DiscountCurve.Value.ZeroRate(market.ValuationDate, exerciseDate);
            var riskfreeRateAtMaturity = market.DiscountCurve.Value.ZeroRate(market.ValuationDate, maturityDate);
            var riskFreeRate           = market.DiscountCurve.Value.ZeroRate(market.ValuationDate, exerciseDate);
            var dividendCurveInput     = market.DividendCurves.Value.Values.First().ZeroRate(market.ValuationDate, exerciseDate);
            var dividendInput          = AnalyticalOptionPricerUtil.dividendYieldOutput(dividendCurveInput, riskFreeRate,
                                                                                        option.Dividends, spot, market.ValuationDate, trade.ExerciseDates.Last(), option.DayCount);

            var dividendRate = AnalyticalOptionPricerUtil.dividenRate(trade.UnderlyingProductType, dividendInput, riskFreeRate);

            var BSCalculator = new BlackScholeCalculator(trade.OptionType,
                                                         strike: option.IsMoneynessOption? trade.Strike * trade.InitialSpotPrice: trade.Strike,
                                                         spotPrice: spot,
                                                         sigma: sigma,
                                                         riskfreeRateAtExercise: riskfreeRateAtExercise,
                                                         riskfreeRateAtMaturity: riskfreeRateAtMaturity,
                                                         curveDayCount: market.DiscountCurve.Value.DayCount,
                                                         dividendRate: dividendRate,
                                                         maturityDate: trade.UnderlyingMaturityDate, //maturity of underlying, i.e. option on futures
                                                         exerciseDate: trade.ExerciseDates.Last(),
                                                         valuationDate: market.ValuationDate,
                                                         trade: trade,
                                                         underlyingInstrumentType: trade.UnderlyingProductType,
                                                         notional: trade.Notional,
                                                         expiryDayRemainingLife: expiryDayRemainingLife,
                                                         timeIncrement: timeIncrement);

            _calculator = BSCalculator;
            return(BSCalculator);
        }
        private BAWCalculator ConfigureCalculator(IOption option, IMarketCondition market,
                                                  double expiryDayRemainingLife = double.NaN, double timeIncrement = 0.0)
        {
            var trade = (VanillaOption)option;

            var exerciseDate    = trade.ExerciseDates.Last();
            var maturityDate    = trade.UnderlyingMaturityDate;
            var exerciseInYears = trade.DayCount.CalcDayCountFraction(market.ValuationDate, exerciseDate);
            var maturityInYears = trade.DayCount.CalcDayCountFraction(market.ValuationDate, maturityDate);

            var riskfreeRate         = market.DiscountCurve.Value.ZeroRate(market.ValuationDate, exerciseDate);
            var riskfreeDfAtExercise = market.DiscountCurve.Value.GetDf(market.ValuationDate, exerciseDate);
            var riskfreeDfAtMaturity = market.DiscountCurve.Value.GetDf(market.ValuationDate, maturityDate);

            var dividendCurveInput = market.DividendCurves.Value.Values.First().ZeroRate(market.ValuationDate, exerciseDate);
            var dividendInput      = AnalyticalOptionPricerUtil.dividendYieldOutput(dividendCurveInput, riskfreeRate,
                                                                                    option.Dividends, market.SpotPrices.Value.Values.First(), market.ValuationDate, trade.ExerciseDates.Last(), option.DayCount);
            var dividendRate = AnalyticalOptionPricerUtil.dividendDf(trade.UnderlyingProductType, dividendInput, riskfreeRate);

            var    spot  = market.SpotPrices.Value.Values.First();
            double sigma = AnalyticalOptionPricerUtil.pricingVol(volSurf: market.VolSurfaces.Value.Values.First(),
                                                                 exerciseDate: exerciseDate, option: option, spot: spot);

            var calculator = new BAWCalculator(trade.OptionType,
                                               option.IsMoneynessOption ? trade.Strike * trade.InitialSpotPrice : trade.Strike,
                                               spot,
                                               exerciseInYears,
                                               sigma,
                                               riskfreeRate,
                                               dividendRate,
                                               trade.Notional,
                                               trade.UnderlyingProductType,
                                               riskfreeDfAtExercise: riskfreeDfAtExercise,
                                               riskfreeDfAtMaturity: riskfreeDfAtMaturity,
                                               expiryDayRemainingLife: expiryDayRemainingLife,
                                               timeIncrement: timeIncrement);

            this._calculator = calculator;
            return(calculator);
        }