示例#1
0
        public EntityResponse <List <OptionQuotation> > GetOptionQuotes(List <string> optionNumbers)
        {
            EntityResponse <List <OptionQuotation> > results = GetOptionQuotesByOptionNumbers(optionNumbers);

            if (!results.IsSuccess)
            {
                return(results);
            }

            foreach (OptionQuotation quote in results.Entity)
            {
                EntityResponse <OptionBasicInformation> basic = GetOptionInformation(quote.OptionNumber);
                if (basic.IsSuccess)
                {
                    quote.SecurityCode = basic.Entity.OptionUnderlyingCode;
                    decimal?stockPrice;
                    double  daysToMaturity = _marketWorkTimeService.GetNumberOfDaysLeftUntilExpiry(basic.Entity.ExpireDate).TotalNumberOfDaysUntilExpiry;

                    if (!MemoryCache.IsStockQuoteInfoCacheExpired(quote.SecurityCode))
                    {
                        stockPrice = MemoryCache.StockQuoteInfoCache[quote.SecurityCode].StockQuoteInfos.LastPrice;
                    }
                    else
                    {
                        var stockQuoteInfo = GetStockQuote(basic.Entity.OptionUnderlyingCode).Entity;
                        stockPrice = stockQuoteInfo.LastPrice;
                        MemoryCache.AddOrUpdateStockQuoteInfoCache(quote.SecurityCode, stockQuoteInfo);
                    }
                    //decimal? stockPrice = GetStockQuote(basic.Entity.OptionUnderlyingCode).Entity.LastPrice;
                    double spotPrice = 0;
                    if (stockPrice != null)
                    {
                        spotPrice = (double)stockPrice;
                    }
                    quote.Greeks = MarketMath.GetGreeks(daysToMaturity, (double)basic.Entity.StrikePrice,
                                                        _riskFreeRateProvider.GetRiskFreeRate(), spotPrice, quote.Ask, quote.Bid, quote.LatestTradedPrice,
                                                        basic.Entity.OptionType == OptionType.Call ? LegType.Call : LegType.Put);
                }
            }

            return(results);
        }
示例#2
0
        public void UpdateQuotation(IEnumerable <OptionQuotation> quotations)
        {
            foreach (OptionQuotation optionQuotation in quotations)
            {
                Option option = this[optionQuotation.OptionNumber];
                if (option != null)
                {
                    optionQuotation.SecurityCode = option.SecurityCode;
                    optionQuotation.OptionName   = option.OptionName;
                    optionQuotation.OptionCode   = option.OptionCode;

                    Mapper.Map(optionQuotation, option);
                    option.Name = optionQuotation.OptionName;

                    option.Greeks = MarketMath.GetGreeks(option.RootPair.Expiry.TotalNumberOfDaysUntilExpiry,
                                                         option.RootPair.StrikePrice, RiskFreeRate,
                                                         UnderlyingCurrentPrice, option.Ask, option.Bid, option.LatestTradedPrice, option.LegType);
                }
            }
        }