public async Task <IActionResult> UpdateOptions([Bind("Expiry,UnderlyingPrice")] UpdateOptionsModel updateOptionsModel) { if (ModelState.IsValid) { TradingAccount tradingAccount = _context.TradingAccounts.First(); Decimal spread; foreach (Option option in await _context.Options.ToListAsync()) { option.Expiry = updateOptionsModel.Expiry; option.UnderlyingPrice = updateOptionsModel.UnderlyingPrice; option.BlackScholesPrice = option.CalculateBlackScholesPrice(tradingAccount, updateOptionsModel.UnderlyingPrice); spread = option.Spread; option.Bid = option.BlackScholesPrice - (spread / 2m); option.Ask = option.BlackScholesPrice + (spread / 2m); option.FillCalculatedFields(tradingAccount); } _context.SaveChanges(); return(RedirectToAction("Index", "Home")); } return(View(updateOptionsModel)); }
public IActionResult UpdateOptions() { Option firstOption = _context.Options.First(); UpdateOptionsModel updateOptionsModel = new UpdateOptionsModel { Expiry = firstOption.Expiry, UnderlyingPrice = firstOption.UnderlyingPrice }; return(View(updateOptionsModel)); }