/// <summary> /// Создать <see cref="InnerModel"/>. /// </summary> /// <param name="model">Модель расчета значений "греков" по формуле Блэка-Шоулза.</param> /// <param name="positionManager">Менеджер позиции.</param> public InnerModel(BlackScholes model, IPositionManager positionManager) { if (model == null) { throw new ArgumentNullException("model"); } if (positionManager == null) { throw new ArgumentNullException("positionManager"); } Model = model; PositionManager = positionManager; }
private void Calculate_Click(object sender, RoutedEventArgs e) { var option = SelectedOption; var volatility = Volatility.Text.To<decimal>() / 100; var bs = new BlackScholes(option); Delta.Text = bs.Delta(volatility).ToString("0.000"); Gamma.Text = bs.Gamma(volatility).ToString("0.000000"); Vega.Text = bs.Vega(volatility).ToString("0.00"); Theta.Text = bs.Theta(volatility).ToString("0.00"); Rho.Text = bs.Rho(volatility).ToString("0.00"); if (option.LastTrade != null) IV.Text = bs.IV(option.LastTrade.Price).ToString("0.00"); }
/// <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)); }
/// <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)); }
internal void ApplyModel() { Model = _desk.UseBlackModel ? new Black(Option, _desk.SecurityProvider, _desk.MarketDataProvider) : new BlackScholes(Option, _desk.SecurityProvider, _desk.MarketDataProvider); }
/// <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); }