Beispiel #1
0
        private void PlusCount(ExpirationDate expD)
        {
            int idx = ExpirationDates.IndexOf(expD);

            expD.Count++;
            ExpirationDates[idx] = expD;
        }
Beispiel #2
0
 private void MinusCount(ExpirationDate expD)
 {
     if (expD.Count > 0)
     {
         int idx = ExpirationDates.IndexOf(expD);
         expD.Count--;
         ExpirationDates[idx] = expD;
     }
 }
        /// <summary>
        /// Get expire dates with days to expire closest to daysInFuture
        /// </summary>
        public void GetClosestExpiryDatesToDaysInFeature(double daysInFuture, out DateAndNumberOfDaysUntil low, out DateAndNumberOfDaysUntil highOrEqual)
        {
            Tuple <int, DateAndNumberOfDaysUntil> lastSmaler  = ExpirationDates.LastAndIndex(e => e.TotalNumberOfDaysUntilExpiry < daysInFuture);
            Tuple <int, DateAndNumberOfDaysUntil> firstBigger = ExpirationDates.FirstAndIndex(e => e.TotalNumberOfDaysUntilExpiry >= daysInFuture);

            low = lastSmaler.Item1 == -1
                                ? ExpirationDates[0]
                                : lastSmaler.Item2;
            highOrEqual = firstBigger.Item1 == -1
                                ? ExpirationDates[ExpirationDates.Count - 1]
                                : firstBigger.Item2;
        }
        private double GetVolatilityForPrediction(IReadOnlyList <OptionPair> optionPairs, double daysInFuture)
        {
            double volatility;
            // if there are dates with NumOfDaysUntilExpired == daysInFuture
            // the volatility is calculated as average impliedVolatility from options with this date
            DateAndNumberOfDaysUntil futureExpiry = ExpirationDates.FirstOrDefault(date => date.TotalNumberOfDaysUntilExpiry.AlmostEqual(daysInFuture));

            if (futureExpiry != null)
            {
                List <OptionPair> chainsWithExpiry = optionPairs.Where(chain => chain.Expiry == futureExpiry).ToList();
                volatility = GetAverageVolatilityFromAtTheMoneyOption(chainsWithExpiry);
                return(volatility);
            }

            DateAndNumberOfDaysUntil sigma1Date, sigma2Date;

            GetClosestExpiryDatesToDaysInFeature(daysInFuture, out sigma1Date, out sigma2Date);
            if (sigma1Date.FutureDate == sigma2Date.FutureDate)
            {
                List <OptionPair> chainsWithExpiry = optionPairs.Where(chain => chain.Expiry == sigma1Date).ToList();
                volatility = GetAverageVolatilityFromAtTheMoneyOption(chainsWithExpiry);
                return(volatility);
            }

            List <OptionPair> optionChainsSigma1 = optionPairs.Where(chain => chain.Expiry == sigma1Date).ToList();
            List <OptionPair> optionChainsSigma2 = optionPairs.Where(chain => chain.Expiry == sigma2Date).ToList();

            double sigma1 = GetAverageVolatilityFromAtTheMoneyOption(optionChainsSigma1);
            double sigma2 = GetAverageVolatilityFromAtTheMoneyOption(optionChainsSigma2);

            double n1 = sigma1Date.TotalNumberOfDaysUntilExpiry;
            double n2 = sigma2Date.TotalNumberOfDaysUntilExpiry;

            volatility = Math.Sqrt(365.0 / daysInFuture *
                                   ((n1 / 365.0 * sigma1 * sigma1) * (n2 - daysInFuture) / (n2 - n1) +
                                    n2 / 365.0 * sigma2 * sigma2 * (daysInFuture - n1) / (n2 - n1)));
            return(volatility);
        }
Beispiel #5
0
 public string Validate()
 {
     // check sum of the items which have an expiration date and compare it with the item count
     return(NumItems == ExpirationDates.Sum(x => x.NumItems) ? null :
            "Son kullanma tarihi listesindeki ürünlerin sayısı stoktaki toplam ürün sayısından farklı.\nLütfen düzeltip tekrar deneyin.");
 }