Exemple #1
0
 /// <summary>
 /// Set how the underlying price ("at the money") is determined
 /// <see cref="MamdaOptionAtTheMoneyCompareType"/>
 /// </summary>
 /// <param name="atTheMoneyType"></param>
 public void setAtTheMoneyType(MamdaOptionAtTheMoneyCompareType atTheMoneyType)
 {
     if (mAtTheMoneyType != atTheMoneyType)
     {
         mAtTheMoneyType = atTheMoneyType;
         resetRange();
     }
 }
        /// <summary>
        /// Return whether the price is within a % of the money.
        /// Determine whether some price (e.g. a strike price) is within a
        /// given percentage range of the underlying (at the money) price.
        /// </summary>
        /// <param name="price">The strike price to check.</param>
        /// <param name="percentage">What % to check the strike price against.</param>
        /// <param name="compareType">What price we are checking against <see cref="MamdaOptionAtTheMoneyCompareType">(see MamdaOptionAtTheMoneyCompareType)</see></param>
        /// <returns>Whether the price is within % of the money.</returns>
        public bool getIsPriceWithinPercentOfMoney(
            double price,
            double percentage,
            MamdaOptionAtTheMoneyCompareType compareType)
        {
            double atTheMoney = getAtTheMoney(compareType);

            if (atTheMoney == 0.0)
            {
                return(false);
            }

            return(((1.0 - percentage) <= price) || (price <= (1.0 + percentage)));
        }
        /// <summary>
        /// Get the price of the option underlying.
        /// Determine the underlying price ("at the money"), based on the
        /// mode of calculation.
        /// </summary>
        /// <param name="compareType">The mode of calculation
        /// <see cref="MamdaOptionAtTheMoneyCompareType">(MamdaOptionAtTheMoneyCompareType)</see></param>
        /// <returns>The price of the underlying.</returns>
        public double getAtTheMoney(MamdaOptionAtTheMoneyCompareType compareType)
        {
            double atTheMoney = 0.0;

            switch (compareType)
            {
            case MamdaOptionAtTheMoneyCompareType.MID_QUOTE:
                if (mQuoteListener == null)
                {
                    return(0.0);
                }
                atTheMoney = (mQuoteListener.getBidPrice().getValue() + mQuoteListener.getAskPrice().getValue()) / 2.0;
                break;

            case MamdaOptionAtTheMoneyCompareType.BID:
                if (mQuoteListener == null)
                {
                    return(0.0);
                }
                atTheMoney = mQuoteListener.getBidPrice().getValue();
                break;

            case MamdaOptionAtTheMoneyCompareType.ASK:
                if (mQuoteListener == null)
                {
                    return(0.0);
                }
                atTheMoney = mQuoteListener.getAskPrice().getValue();
                break;

            case MamdaOptionAtTheMoneyCompareType.LAST_TRADE:
                if (mTradeListener == null)
                {
                    return(0.0);
                }
                atTheMoney = mTradeListener.getLastPrice().getValue();
                break;
            }
            return(atTheMoney);
        }
        /// <summary>
        /// Determine the set of strike prices that are included in a given
        /// percentage range of the underlying price.  If there are no
        /// strikes within the percentage range, then both strike prices
        /// are set to zero.
        /// <see cref="MamdaOptionAtTheMoneyCompareType"/>
        /// </summary>
        /// <param name="percentage">The percentage range of the underlying price.</param>
        /// <param name="compareType">Which underlying price to compare to.</param>
        /// <returns>Set of strike prices.</returns>
        public SortedSet getStrikesWithinPercent(
            double percentage,
            MamdaOptionAtTheMoneyCompareType compareType)
        {
            percentage /= 100.0;
            if (percentage <= 0.0)
            {
                return(null);
            }

            double atTheMoney = getAtTheMoney(compareType);

            if (atTheMoney == 0.0)
            {
                return(null);
            }

            double    lowPercent   = atTheMoney * (1.0 - percentage);
            double    highPercent  = atTheMoney * (1.0 + percentage);
            SortedSet strikeSubSet = mStrikePrices.subSet(lowPercent, highPercent);

            return(strikeSubSet);
        }
 /// <summary>
 /// Set how the underlying price ("at the money") is determined
 /// <see cref="MamdaOptionAtTheMoneyCompareType"/>
 /// </summary>
 /// <param name="atTheMoneyType"></param>
 public void setAtTheMoneyType(MamdaOptionAtTheMoneyCompareType atTheMoneyType)
 {
     if (mAtTheMoneyType != atTheMoneyType)
     {
         mAtTheMoneyType = atTheMoneyType;
         resetRange();
     }
 }
Exemple #6
0
		/// <summary>
		/// Determine the set of strike prices that are included in a given
		/// fixed size range of strikes surrounding the underlying price.
		/// If rangeLen is odd, then the strike price nearest to the
		/// underlying price is treated as a higher strike price.  If
		/// rangeLen is even and the underlying price is exactly equal to a
		/// strike price, then that strike price is treated as a higher
		/// strike price.
		/// <see cref="MamdaOptionAtTheMoneyCompareType"/>
		/// </summary>
		/// <param name="rangeLength">Number of strike prices to include in result. </param>
		/// <param name="compareType">What underlying price to use as a comparator.</param>
		/// <returns>Resulting set of strike prices.</returns>
		public SortedSet getStrikesWithinRangeSize (
			int									rangeLength,
			MamdaOptionAtTheMoneyCompareType	compareType)
		{
			if (rangeLength <= 0)
				return null;

			double atTheMoney  = getAtTheMoney(compareType);
			if (atTheMoney == 0.0)
				return null;

			int    countToMoney = 0;
			int    countFromMoney = 0;
			double halfRangeLength = rangeLength / 2.0;
			double lowerBound = Double.NaN;
			double upperBound = Double.NaN;

			// First loop determines the upper bound and count the number
			// of strikes that are less than the "money".
			Iterator strikeIter = mStrikePrices.iterator();
			while (strikeIter.hasNext())
			{
				double strikePrice = (double)strikeIter.next();
				if (strikePrice < atTheMoney)
				{
					// We're still less than the "money", so keep counting up.
					countToMoney++;
				}
				else
				{
					// Check the upper bound. Take a price that is
					// slightly higher than this strike price because we
					// want to include it (Set.subSet excludes the
					// toElement).
					countFromMoney++;
					upperBound = strikePrice + 0.00001;
					if (countFromMoney >= halfRangeLength)
					{
						// We've passed the upper end of the range
						break;
					}
				}
			}

			// Second loop determines the lower bound.
			int targetCount = countToMoney - (rangeLength - countFromMoney);
			strikeIter = mStrikePrices.iterator();
			while (strikeIter.hasNext())
			{
				double strikePrice = (double)strikeIter.next();
				if (targetCount > 0)
				{
					// We have not yet hit the lowerBound.
					targetCount--;
				}
				else
				{
					lowerBound = strikePrice;
					break;
				}
			}
			if (Double.IsNaN(lowerBound))
				lowerBound = 0.0;
			if (Double.IsNaN(upperBound))
				upperBound = Double.MaxValue;

			SortedSet result = mStrikePrices.subSet(lowerBound, upperBound);
			lowerBound = (double)result.first();
			upperBound = (double)result.last();

			return result;
		}
Exemple #7
0
		/// <summary>
		/// Determine the set of strike prices that are included in a given
		/// percentage range of the underlying price.  If there are no
		/// strikes within the percentage range, then both strike prices
		/// are set to zero.
		/// <see cref="MamdaOptionAtTheMoneyCompareType"/>
		/// </summary>
		/// <param name="percentage">The percentage range of the underlying price.</param>
		/// <param name="compareType">Which underlying price to compare to.</param>
		/// <returns>Set of strike prices.</returns>
		public SortedSet getStrikesWithinPercent(
			double	percentage,
			MamdaOptionAtTheMoneyCompareType compareType)
		{
			percentage /= 100.0;
			if (percentage <= 0.0)
				return null;

			double atTheMoney = getAtTheMoney(compareType);
			if (atTheMoney == 0.0)
				return null;

			double    lowPercent   = atTheMoney * (1.0 - percentage);
			double    highPercent  = atTheMoney * (1.0 + percentage);
			SortedSet strikeSubSet = mStrikePrices.subSet(lowPercent, highPercent);
			return strikeSubSet;
		}
Exemple #8
0
		/// <summary>
		/// Return whether the price is within a % of the money.
		/// Determine whether some price (e.g. a strike price) is within a
		/// given percentage range of the underlying (at the money) price.
		/// </summary>
		/// <param name="price">The strike price to check.</param>
		/// <param name="percentage">What % to check the strike price against.</param>
		/// <param name="compareType">What price we are checking against <see cref="MamdaOptionAtTheMoneyCompareType">(see MamdaOptionAtTheMoneyCompareType)</see></param>
		/// <returns>Whether the price is within % of the money.</returns>
		public bool getIsPriceWithinPercentOfMoney(
			double								price,
			double								percentage,
			MamdaOptionAtTheMoneyCompareType	compareType)
		{
			double atTheMoney = getAtTheMoney(compareType);
			if (atTheMoney == 0.0)
				return false;

			return (((1.0 - percentage) <= price) || (price <= (1.0 + percentage)));
		}
Exemple #9
0
		/// <summary>
		/// Get the price of the option underlying.
		/// Determine the underlying price ("at the money"), based on the
		/// mode of calculation.
		/// </summary>
		/// <param name="compareType">The mode of calculation
		/// <see cref="MamdaOptionAtTheMoneyCompareType">(MamdaOptionAtTheMoneyCompareType)</see></param>
		/// <returns>The price of the underlying.</returns>
		public double getAtTheMoney(MamdaOptionAtTheMoneyCompareType compareType)
		{
			double atTheMoney = 0.0;
			switch (compareType)
			{
				case MamdaOptionAtTheMoneyCompareType.MID_QUOTE:
					if (mQuoteListener == null) return 0.0;
					atTheMoney = (mQuoteListener.getBidPrice().getValue() + mQuoteListener.getAskPrice().getValue()) / 2.0;
					break;
				case MamdaOptionAtTheMoneyCompareType.BID:
					if (mQuoteListener == null) return 0.0;
					atTheMoney = mQuoteListener.getBidPrice().getValue();
					break;
				case MamdaOptionAtTheMoneyCompareType.ASK:
					if (mQuoteListener == null) return 0.0;
					atTheMoney = mQuoteListener.getAskPrice().getValue();
					break;
				case MamdaOptionAtTheMoneyCompareType.LAST_TRADE:
					if (mTradeListener == null) return 0.0;
					atTheMoney = mTradeListener.getLastPrice().getValue();
					break;
			}
			return atTheMoney;
		}
        /// <summary>
        /// Determine the set of strike prices that are included in a given
        /// fixed size range of strikes surrounding the underlying price.
        /// If rangeLen is odd, then the strike price nearest to the
        /// underlying price is treated as a higher strike price.  If
        /// rangeLen is even and the underlying price is exactly equal to a
        /// strike price, then that strike price is treated as a higher
        /// strike price.
        /// <see cref="MamdaOptionAtTheMoneyCompareType"/>
        /// </summary>
        /// <param name="rangeLength">Number of strike prices to include in result. </param>
        /// <param name="compareType">What underlying price to use as a comparator.</param>
        /// <returns>Resulting set of strike prices.</returns>
        public SortedSet getStrikesWithinRangeSize(
            int rangeLength,
            MamdaOptionAtTheMoneyCompareType compareType)
        {
            if (rangeLength <= 0)
            {
                return(null);
            }

            double atTheMoney = getAtTheMoney(compareType);

            if (atTheMoney == 0.0)
            {
                return(null);
            }

            int    countToMoney    = 0;
            int    countFromMoney  = 0;
            double halfRangeLength = rangeLength / 2.0;
            double lowerBound      = Double.NaN;
            double upperBound      = Double.NaN;

            // First loop determines the upper bound and count the number
            // of strikes that are less than the "money".
            Iterator strikeIter = mStrikePrices.iterator();

            while (strikeIter.hasNext())
            {
                double strikePrice = (double)strikeIter.next();
                if (strikePrice < atTheMoney)
                {
                    // We're still less than the "money", so keep counting up.
                    countToMoney++;
                }
                else
                {
                    // Check the upper bound. Take a price that is
                    // slightly higher than this strike price because we
                    // want to include it (Set.subSet excludes the
                    // toElement).
                    countFromMoney++;
                    upperBound = strikePrice + 0.00001;
                    if (countFromMoney >= halfRangeLength)
                    {
                        // We've passed the upper end of the range
                        break;
                    }
                }
            }

            // Second loop determines the lower bound.
            int targetCount = countToMoney - (rangeLength - countFromMoney);

            strikeIter = mStrikePrices.iterator();
            while (strikeIter.hasNext())
            {
                double strikePrice = (double)strikeIter.next();
                if (targetCount > 0)
                {
                    // We have not yet hit the lowerBound.
                    targetCount--;
                }
                else
                {
                    lowerBound = strikePrice;
                    break;
                }
            }
            if (Double.IsNaN(lowerBound))
            {
                lowerBound = 0.0;
            }
            if (Double.IsNaN(upperBound))
            {
                upperBound = Double.MaxValue;
            }

            SortedSet result = mStrikePrices.subSet(lowerBound, upperBound);

            lowerBound = (double)result.first();
            upperBound = (double)result.last();

            return(result);
        }