public void Update(MarketDetailsResponse marketDetails) { Bid = Convert.ToDouble(marketDetails.snapshot.bid); Ask = Convert.ToDouble(marketDetails.snapshot.offer); Prime = (Bid + Ask) / 2; Spread = Ask - Bid; InterestRate = EuriborHelper.GetInterestRate(Expiry.Subtract(DateTime.Now)); CurrentPrice = Convert.ToDouble(marketDetails.snapshot.netChange); var isCall = Directions == OptionDirections.Call; var time = Expiry.Subtract(DateTime.Now).TotalDays / 365; var correctedPrime = Math.Min(Bid + Spread * (Bid / 20), Prime); Volatility = BlackScholesHelper.ImpliedVolatility(isCall, CurrentPrice, Strike, time, 0, correctedPrime); InterestRate = Math.Round(InterestRate * 100, 2); Volatility = Math.Round(Volatility * 100, 2); }
public OptionItem(MarketDetailsResponse marketDetails) { Epic = marketDetails.instrument.epic; Quantity = 1; Name = $"{marketDetails.instrument.name} ({marketDetails.instrument.expiry})"; var infos = marketDetails.instrument.name.Split(' '); var dir = infos[infos.Length - 1]; var strike = infos[infos.Length - 2]; Directions = dir.ToUpper() == "CALL" ? OptionDirections.Call : OptionDirections.Put; Strike = Convert.ToDouble(strike); Expiry = Convert.ToDateTime(marketDetails.instrument.expiryDetails.lastDealingDate, CultureInfo.GetCultureInfo("fr-FR")); Bid = Convert.ToDouble(marketDetails.snapshot.bid); Ask = Convert.ToDouble(marketDetails.snapshot.offer); Prime = (Bid + Ask) / 2; CurrentPrime = Prime; Spread = Ask - Bid; PrimeString = $"({Ask}/{Bid})"; InterestRate = EuriborHelper.GetInterestRate(Expiry.Subtract(DateTime.Now)); CurrentPrice = Convert.ToDouble(marketDetails.snapshot.netChange); var isCall = Directions == OptionDirections.Call; var time = Expiry.Subtract(DateTime.Now).TotalDays / 365; var correctedPrime = Math.Min(Bid + Spread * (Bid / 20), Prime); Volatility = BlackScholesHelper.ImpliedVolatility(isCall, CurrentPrice, Strike, time, 0, correctedPrime); InterestRate = Math.Round(InterestRate * 100, 2); Volatility = Math.Round(Volatility * 100, 2); }