Exemplo n.º 1
0
		/// <summary>
		/// To get the underlying asset by the derivative.
		/// </summary>
		/// <param name="derivative">The derivative.</param>
		/// <param name="provider">The provider of information about instruments.</param>
		/// <returns>Underlying asset.</returns>
		public static Security GetUnderlyingAsset(this Security derivative, ISecurityProvider provider)
		{
			if (derivative == null)
				throw new ArgumentNullException("derivative");

			if (provider == null)
				throw new ArgumentNullException("provider");

			if (derivative.Type == SecurityTypes.Option)
			{
				derivative.CheckOption();

				return _underlyingSecurities.SafeAdd(derivative, key =>
				{
					var underlyingSecurity = provider.LookupById(key.UnderlyingSecurityId);

					if (underlyingSecurity == null)
						throw new InvalidOperationException(LocalizedStrings.Str704Params.Put(key.UnderlyingSecurityId));

					return underlyingSecurity;
				});
			}
			else
			{
				return provider.LookupById(derivative.UnderlyingSecurityId);
			}
		}
Exemplo n.º 2
0
		/// <summary>
		/// To get the internal option value.
		/// </summary>
		/// <param name="option">Options contract.</param>
		/// <param name="securityProvider">The provider of information about instruments.</param>
		/// <param name="dataProvider">The market data provider.</param>
		/// <returns>The internal value. If it is impossible to get the current market price of the asset then the <see langword="null" /> will be returned.</returns>
		public static decimal? GetIntrinsicValue(this Security option, ISecurityProvider securityProvider, IMarketDataProvider dataProvider)
		{
			if (securityProvider == null)
				throw new ArgumentNullException("securityProvider");
			
			option.CheckOption();

			var assetPrice = option.GetUnderlyingAsset(securityProvider).GetCurrentPrice(dataProvider);

			if (assetPrice == null)
				return null;

			return ((decimal)((option.OptionType == OptionTypes.Call) ? assetPrice - option.Strike : option.Strike - assetPrice)).Max(0);
		}
Exemplo n.º 3
0
		/// <summary>
		/// To get the timed option value.
		/// </summary>
		/// <param name="option">Options contract.</param>
		/// <param name="securityProvider">The provider of information about instruments.</param>
		/// <param name="dataProvider">The market data provider.</param>
		/// <returns>The timed value. If it is impossible to get the current market price of the asset then the <see langword="null" /> will be returned.</returns>
		public static decimal? GetTimeValue(this Security option, ISecurityProvider securityProvider, IMarketDataProvider dataProvider)
		{
			if (securityProvider == null)
				throw new ArgumentNullException("securityProvider");

			option.CheckOption();

			var price = option.GetCurrentPrice(dataProvider);
			var intrinsic = option.GetIntrinsicValue(securityProvider, dataProvider);

			if (price == null || intrinsic == null)
				return null;

			return (decimal)(price - intrinsic);
		}
Exemplo n.º 4
0
		/// <summary>
		/// To get opposite option (for Call to get Put, for Put to get Call).
		/// </summary>
		/// <param name="option">Options contract.</param>
		/// <param name="provider">The provider of information about instruments.</param>
		/// <returns>The opposite option.</returns>
		public static Security GetOppositeOption(this Security option, ISecurityProvider provider)
		{
			if (provider == null)
				throw new ArgumentNullException("provider");

			option.CheckOption();

			var oppositeOption = provider
				.Lookup(new Security
				{
					OptionType = option.OptionType == OptionTypes.Call ? OptionTypes.Put : OptionTypes.Call,
					Strike = option.Strike,
					ExpiryDate = option.ExpiryDate,
					UnderlyingSecurityId = option.UnderlyingSecurityId,
				})
				.FirstOrDefault();

			if (oppositeOption == null)
				throw new ArgumentException(LocalizedStrings.Str706Params.Put(option.Id), "option");

			return oppositeOption;
		}