/// <summary>
        /// To create the volatility order book from usual order book.
        /// </summary>
        /// <param name="depth">The order book quotes of which will be changed to volatility quotes.</param>
        /// <param name="model">The model for calculating Greeks values by the Black-Scholes formula.</param>
        /// <param name="currentTime">The current time.</param>
        /// <returns>The order book volatility.</returns>
        public static MarketDepth ImpliedVolatility(this MarketDepth depth, BlackScholes model, DateTimeOffset currentTime)
        {
            if (depth == null)
            {
                throw new ArgumentNullException(nameof(depth));
            }

            if (model == null)
            {
                throw new ArgumentNullException(nameof(model));
            }

            QuoteChange Convert(QuoteChange quote)
            {
                quote.Price = model.ImpliedVolatility(currentTime, quote.Price) ?? 0;
                return(quote);
            }

            return(new MarketDepth(depth.Security).Update(depth.Bids2.Select(Convert).ToArray(), depth.Asks2.Select(Convert).ToArray(), depth.LastChangeTime));
        }
Example #2
0
        /// <summary>
        /// To create the volatility order book from usual order book.
        /// </summary>
        /// <param name="depth">The order book quotes of which will be changed to volatility quotes.</param>
        /// <param name="model">The model for calculating Greeks values by the Black-Scholes formula.</param>
        /// <param name="currentTime">The current time.</param>
        /// <returns>The order book volatility.</returns>
        public static MarketDepth ImpliedVolatility(this MarketDepth depth, BlackScholes model, DateTimeOffset currentTime)
        {
            if (depth == null)
            {
                throw new ArgumentNullException(nameof(depth));
            }

            if (model == null)
            {
                throw new ArgumentNullException(nameof(model));
            }

            Func <Quote, Quote> convert = quote =>
            {
                quote       = quote.Clone();
                quote.Price = model.ImpliedVolatility(currentTime, quote.Price) ?? 0;
                return(quote);
            };

            return(new MarketDepth(depth.Security).Update(depth.Bids.Select(convert), depth.Asks.Select(convert), true, depth.LastChangeTime));
        }
Example #3
0
		/// <summary>
		/// To create the volatility order book from usual order book.
		/// </summary>
		/// <param name="depth">The order book quotes of which will be changed to volatility quotes.</param>
		/// <param name="model">The model for calculating Greeks values by the Black-Scholes formula.</param>
		/// <param name="currentTime">The current time.</param>
		/// <returns>The order book volatility.</returns>
		public static MarketDepth ImpliedVolatility(this MarketDepth depth, BlackScholes model, DateTimeOffset currentTime)
		{
			if (depth == null)
				throw new ArgumentNullException("depth");

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

			Func<Quote, Quote> convert = quote =>
			{
				quote = quote.Clone();
				quote.Price = model.ImpliedVolatility(currentTime, quote.Price) ?? 0;
				return quote;
			};

			return new MarketDepth(depth.Security).Update(depth.Bids.Select(convert), depth.Asks.Select(convert), true, depth.LastChangeTime);
		}