Ejemplo n.º 1
0
        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 void GetUpdateOptions(DateTime newExpiry, Decimal newUnderlyingPrice)
        {
            TradingAccount tradingAccount = _context.TradingAccounts.First();
            Decimal        spread;

            foreach (Option option in _context.Options.ToList())
            {
                option.Expiry            = newExpiry;
                option.UnderlyingPrice   = newUnderlyingPrice;
                option.BlackScholesPrice = option.CalculateBlackScholesPrice(tradingAccount, newUnderlyingPrice);

                spread     = option.Spread;
                option.Bid = option.BlackScholesPrice - (spread / 2m);
                option.Ask = option.BlackScholesPrice + (spread / 2m);
                option.FillCalculatedFields(tradingAccount);
            }

            _context.SaveChanges();
        }