private double?GetStrikePriceForLegOld(OptionChain chain, StrategyLeg leg, DateAndNumberOfDaysUntil date)
        {
            if (leg == null || leg.LegType == LegType.Security)
            {
                return(null);
            }
            IList <double> strikePrices = chain.GetStrikePrices(date);

            if (leg.BuyOrSell == BuyOrSell.Buy)
            {
                double strikePrice = leg.LegType == LegType.Call ?
                                     strikePrices.LastAndIndex(d => d < chain.UnderlyingCurrentPrice).Item2 :
                                     strikePrices.FirstAndIndex(d => d > chain.UnderlyingCurrentPrice).Item2;
                return(strikePrice);
            }
            else
            {
                List <DateAndStandardDeviation> stdDevs = _predictionAndStdDevService.GetExpiriesAndStandardDeviations(chain, chain.ExpirationDates, 1.0);
                DateAndStandardDeviation        stdDevPricesForCurrentExpiry = stdDevs.Single(d => d.DateAndNumberOfDaysUntil.FutureDate.Equals(date.FutureDate));
                double strikePrice = leg.LegType == LegType.Call
                                        ? strikePrices.GetClosest(stdDevPricesForCurrentExpiry.StdDev.UpPrice)
                                        : strikePrices.GetClosest(stdDevPricesForCurrentExpiry.StdDev.DownPrice);
                return(strikePrice);
            }
        }
示例#2
0
        public List <DateAndStandardDeviationViewModel> GetExpiriesAndStandardDeviations(string symbol, double sd, double?volatility)
        {
            OptionChain optionChain = GetOptionChainWithPredefinedVolatility(symbol, volatility);
            List <DateAndStandardDeviation> expiryAndStandardDeviation = _predictionAndStdDevService.GetExpiriesAndStandardDeviations(optionChain,
                                                                                                                                      optionChain.ExpirationDates, sd);
            List <DateAndStandardDeviationViewModel> viewModel =
                Mapper.Map <List <DateAndStandardDeviation>, List <DateAndStandardDeviationViewModel> >(expiryAndStandardDeviation);

            return(viewModel);
        }