context: namespace StockSharp.Xaml
  {
  	using System;
  	using System.ComponentModel;
  
  	using Ecng.Common;
  	using Ecng.ComponentModel;
  
  	using StockSharp.Algo.Derivatives;
  	using StockSharp.BusinessEntities;
  	using StockSharp.Messages;
  
  	using Xceed.Wpf.Toolkit.PropertyGrid.Attributes;
  
  	using StockSharp.Localization;
  
  	/// <summary>
  	/// The board row.
  	/// </summary>
  	[DisplayNameLoc(LocalizedStrings.Str1525Key)]
  	class OptionDeskRow : NotifiableObject
  	{
  		/// <summary>
  		/// Information <see cref="OptionTypes.Call"/> or <see cref="OptionTypes.Put"/> of board row.
  		/// </summary>
  		[ExpandableObject]
  		public sealed class OptionDeskRowSide
  		{
  			private readonly OptionDesk _desk;
  
  			internal OptionDeskRowSide(OptionDesk desk, Security option)
  			{
  				if (desk == null)
  					throw new ArgumentNullException("desk");
  
  				if (option == null)
  					throw new ArgumentNullException("option");
  
  				_desk = desk;
  				Option = option;
  				
  				ApplyModel();
  			}
  
  			/// <summary>
  			/// The best buy price.
  			/// </summary>
  			public decimal? BestBidPrice { get; set; }
  
  			/// <summary>
  			/// The best buy price.
  			/// </summary>
  			public decimal? BestAskPrice { get; set; }
  
  			/// <summary>
  			/// Volume per session.
  			/// </summary>
  			public decimal? Volume { get; set; }
  
  			/// <summary>
  			/// Theoretical price.
  			/// </summary>
  			public decimal? TheorPrice { get; set; }
  
  			/// <summary>
  			/// Reserved.
  			/// </summary>
  			[Browsable(false)]
  			public decimal MaxOpenInterest { get; set; }
  
  			/// <summary>
  			/// Information about the option.
  			/// </summary>
  			[ReadOnly(true)]
  			[DisplayNameLoc(LocalizedStrings.OptionsContractKey)]
  			[DescriptionLoc(LocalizedStrings.Str1526Key)]
  			public Security Option { get; private set; }
  
  			/// <summary>
  			/// Option delta.
  			/// </summary>
  			[DisplayNameLoc(LocalizedStrings.DeltaKey)]
  			[DescriptionLoc(LocalizedStrings.OptionDeltaKey)]
  			public decimal? Delta { get; set; }
  
  			/// <summary>
  			/// Option gamma.
  			/// </summary>
  			[DisplayNameLoc(LocalizedStrings.GammaKey)]
  			[DescriptionLoc(LocalizedStrings.OptionGammaKey)]
  			public decimal? Gamma { get; set; }
  
  			/// <summary>
  			/// Option theta.
  			/// </summary>
  			[DisplayNameLoc(LocalizedStrings.ThetaKey)]
  			[DescriptionLoc(LocalizedStrings.OptionThetaKey)]
  			public decimal? Theta { get; set; }
  
  			/// <summary>
  			/// Option vega.
  			/// </summary>
  			[DisplayNameLoc(LocalizedStrings.VegaKey)]
  			[DescriptionLoc(LocalizedStrings.OptionVegaKey)]
  			public decimal? Vega { get; set; }
  
  			/// <summary>
  			/// Option rho.
  			/// </summary>
  			[DisplayNameLoc(LocalizedStrings.RhoKey)]
  			[DescriptionLoc(LocalizedStrings.OptionRhoKey)]
  			public decimal? Rho { get; set; }
  
  			/// <summary>
  			/// Open interest.
  			/// </summary>
  			[DisplayNameLoc(LocalizedStrings.OIKey)]
  			[DescriptionLoc(LocalizedStrings.OpenInterestKey)]
  			public decimal? OpenInterest { get; set; }
  
  			/// <summary>
  			/// Profitability of an option contract.
  			/// </summary>
  			[DisplayNameLoc(LocalizedStrings.Str1527Key)]
  			[DescriptionLoc(LocalizedStrings.Str1528Key)]
  			[CategoryLoc(LocalizedStrings.Str1529Key)]
  			public decimal? PnL { get; set; }
  
  			/// <summary>
  			/// Reserved.
  			/// </summary>
  			[Browsable(false)]
  			public decimal MaxVolume { get; set; }
  
  			/// <summary>
  			/// Returns a string that represents the current object.
  			/// </summary>
  			/// <returns>A string that represents the current object.</returns>
  			public override string ToString()
  			{
  				return string.Empty;
  			}
  
  			public BlackScholes Model { get; private set; }
  
  			internal void ApplyModel()
  			{
  				Model = _desk.UseBlackModel ? new Black(Option, _desk.SecurityProvider, _desk.MarketDataProvider) : new BlackScholes(Option, _desk.SecurityProvider, _desk.MarketDataProvider);
  			}
  		}
  
  		private readonly OptionDesk _desk;
  
  		internal OptionDeskRow(OptionDesk desk, Security call, Security put)
  		{
  			if (desk == null)
  				throw new ArgumentNullException("desk");
  
  			if (call == null && put == null)
  				throw new ArgumentException(LocalizedStrings.Str1530);
  
  			if (call != null)
  				Call = new OptionDeskRowSide(desk, call);
  
  			if (put != null)
  				Put = new OptionDeskRowSide(desk, put);
  
  			_desk = desk;
  			Strike = (call ?? put).Strike;
  			UnderlyingAsset = (call ?? put).GetUnderlyingAsset(desk.SecurityProvider);
  		}
  
  		/// <summary>
  		/// Option strike price.
  		/// </summary>
  		[DisplayNameLoc(LocalizedStrings.StrikeKey)]
  		[DescriptionLoc(LocalizedStrings.OptionStrikePriceKey)]
  		[CategoryLoc(LocalizedStrings.Str1529Key)]
  		public decimal? Strike { get; private set; }
  
  		/// <summary>
  		/// Option volatility (implied).
  		/// </summary>
  		[DisplayNameLoc(LocalizedStrings.Str293Key)]
  		[DescriptionLoc(LocalizedStrings.Str1531Key)]
  		[CategoryLoc(LocalizedStrings.Str1529Key)]
  		public decimal? ImpliedVolatility
  		{
  			get
  			{
  				var provider = _desk.MarketDataProvider;
  
  				if (provider == null)
  					return null;
  
  				return (decimal?)provider.GetSecurityValue((Call ?? Put).Option, Level1Fields.ImpliedVolatility);
  			}
  		}
  
  		/// <summary>
  		/// Option volatility (historic).
  		/// </summary>
  		[DisplayNameLoc(LocalizedStrings.Str299Key)]
  		[DescriptionLoc(LocalizedStrings.Str1532Key)]
  		[CategoryLoc(LocalizedStrings.Str1529Key)]
  		public decimal? HistoricalVolatility
  		{
  			get
  			{
  				var provider = _desk.MarketDataProvider;
  
  				if (provider == null)
  					return null;
  
  				return (decimal?)provider.GetSecurityValue((Call ?? Put).Option, Level1Fields.HistoricalVolatility);
  			}
  		}
  
  		/// <summary>
  		/// Profitability of an option contract.
  		/// </summary>
  		[DisplayNameLoc(LocalizedStrings.Str1527Key)]
  		[DescriptionLoc(LocalizedStrings.Str1528Key)]
  		[CategoryLoc(LocalizedStrings.Str1529Key)]
  		public decimal? PnL
  		{
  			get
  			{
  				decimal? pnl = null;
  
  				if (Call != null)
  					pnl = Call.PnL * (Call.OpenInterest ?? 0).Max(Call.Option.VolumeStep ?? 1);
  
  
gt: 				if (Put != null)