示例#1
0
        private void ProcessCalculatedResult(optionPriceResult pricings, IOptionDetail optionToPrice)
        {
            try
            {
                if (pricings != null)
                {
                    if (optionToPrice != null)
                    {
                        if (log.IsDebugEnabled)
                        {
                            log.Debug("delta: " + pricings.delta + ", gamma: " + pricings.gamma + ", theta: " + pricings.theta
                                      + ", vega: " + pricings.vega + ", price: " + pricings.price + ", Quantity: " + optionToPrice.Quantity
                                      + ", Type: " + (optionToPrice.IsCall ? "Call" : "Put"));
                        }
                        optionToPrice.PremiumAmount = pricings.price * optionToPrice.Quantity * (optionToPrice.Side == SideEnum.BUY ? -1 : 1);
                        optionToPrice.Delta         = pricings.delta * optionToPrice.Quantity * (optionToPrice.Side == SideEnum.BUY ? 1 : -1);
                        optionToPrice.Gamma         = optionToPrice.Quantity * pricings.gamma * (optionToPrice.Side == SideEnum.BUY ? 1 : -1); // long options => long gamma
                        optionToPrice.Theta         = optionToPrice.Quantity * pricings.theta * (optionToPrice.Side == SideEnum.BUY ? 1 : -1); // long options => short theta
                        optionToPrice.Vega          = optionToPrice.Quantity * pricings.vega * (optionToPrice.Side == SideEnum.BUY ? 1 : -1);  // long options => long vega
                        optionToPrice.Rho           = optionToPrice.Quantity * pricings.rho;

                        optionToPrice.ParentRequest.Delta         += optionToPrice.Delta;
                        optionToPrice.ParentRequest.Gamma         += optionToPrice.Gamma;
                        optionToPrice.ParentRequest.Vega          += optionToPrice.Vega;
                        optionToPrice.ParentRequest.Theta         += optionToPrice.Theta;
                        optionToPrice.ParentRequest.Rho           += optionToPrice.Rho;
                        optionToPrice.ParentRequest.PremiumAmount += optionToPrice.PremiumAmount;
                    }
                }
            }
            catch (Exception asyncException)
            {
                log.Error(asyncException.Message, asyncException);
            }
        }
示例#2
0
        public bool CalculatePricing(IOptionDetail optionToPrice)
        {
            if (optionToPrice == null)
            {
                throw new ArgumentNullException("optionToPrice");
            }

            try
            {
                if (CanCalculatePricing(optionToPrice.Strike, optionToPrice.Volatility, optionToPrice.UnderlyingPrice, optionToPrice.InterestRate, optionToPrice.DaysToExpiry, optionToPrice.DayCountConvention))
                {
                    if (log.IsDebugEnabled)
                    {
                        log.Debug("strike: " + optionToPrice.Strike + ", volatility: " + optionToPrice.Volatility + ", underlying price: " + optionToPrice.UnderlyingPrice
                                  + ", interest rate: " + optionToPrice.InterestRate + ", days to expiry: " + optionToPrice.DaysToExpiry + ", DayCountConvention: "
                                  + optionToPrice.DayCountConvention + ", Type: " + (optionToPrice.IsEuropean ? "European " : "American ") + (optionToPrice.IsCall ? "Call" : "Put"));
                    }
                    ProcessCalculatedResult(pricerProxy.calculate(optionToPrice.Strike, optionToPrice.Volatility, optionToPrice.UnderlyingPrice, optionToPrice.DaysToExpiry,
                                                                  optionToPrice.InterestRate, optionToPrice.IsCall, optionToPrice.IsEuropean, optionToPrice.DayCountConvention), optionToPrice);
                }

                return(true);
            }
            catch (Exception asyncException)
            {
                log.Error(asyncException.Message, asyncException);
                return(false);
            }
        }
示例#3
0
        /// <summary>
        /// Converts GUI formatted option leg of the RFQ into the web service format.
        /// </summary>
        /// <param name="requestForQuoteOptionLeg"> the GUI formatted RFQ's option leg to be converted.</param>
        /// <returns> the web service formatted RFQ's option leg.</returns>
        /// <exception cref="ArgumentNullException"> thrown if the GUI formatted RFQ's option leg is null.</exception>
        private optionDetailImpl CreateServiceOptionLegFromRequestForQuoteLeg(IOptionDetail requestForQuoteOptionLeg)
        {
            if (requestForQuoteOptionLeg == null)
            {
                throw new ArgumentNullException("requestForQuoteOptionLeg");
            }

            if (Math.Abs(requestForQuoteOptionLeg.DayCountConvention - 0) < RequestForQuoteConstants.EPSILON)
            {
                throw new ArgumentException("DayCountConvention CANNOT BE ZERO");
            }

            return(new optionDetailImpl()
            {
                isCall = requestForQuoteOptionLeg.IsCall,
                isEuropean = requestForQuoteOptionLeg.IsEuropean,
                legId = requestForQuoteOptionLeg.LegId,
                quantity = requestForQuoteOptionLeg.Quantity,
                description = requestForQuoteOptionLeg.Description,
                strikePercentage = requestForQuoteOptionLeg.StrikePercentage,
                maturityDate = requestForQuoteOptionLeg.MaturityDate.ToShortDateString(),
                tradeDate = requestForQuoteOptionLeg.TradeDate.ToShortDateString(),
                yearsToExpiry = requestForQuoteOptionLeg.DaysToExpiry / requestForQuoteOptionLeg.DayCountConvention,
                premiumPercentage = requestForQuoteOptionLeg.PremiumPercentage,
                delta = requestForQuoteOptionLeg.Delta,
                gamma = requestForQuoteOptionLeg.Gamma,
                vega = requestForQuoteOptionLeg.Vega,
                theta = requestForQuoteOptionLeg.Theta,
                rho = requestForQuoteOptionLeg.Rho,
                interestRate = requestForQuoteOptionLeg.InterestRate,
                volatility = requestForQuoteOptionLeg.Volatility,
                underlyingPrice = requestForQuoteOptionLeg.UnderlyingPrice,
                dayCountConvention = requestForQuoteOptionLeg.DayCountConvention,
                daysToExpiry = requestForQuoteOptionLeg.DaysToExpiry,
                premium = requestForQuoteOptionLeg.PremiumAmount,
                underlyingRIC = requestForQuoteOptionLeg.RIC,
                strike = requestForQuoteOptionLeg.Strike,
                side = requestForQuoteOptionLeg.Side.ToString(),
            });
        }