public double CalculateCurApproxPnL(double futPrice)
        {
            double result = 0.0;
            double exitPrice;

            foreach (Option opt in Options)
            {
                exitPrice = GreeksCalculator.CalculateOptionPrice_BS(opt.OptionType, futPrice, opt.Strike,
                                                                     opt.RemainingDays, GreeksCalculator.DAYS_IN_YEAR, opt.ImplVol);
                result += opt.Position.CalcCurrentPnL(exitPrice);
            }

            result += Futures == null ? 0.0 : Futures.Position.CalcCurrentPnL(futPrice);
            result += FixedPnL;

            return(result);
        }
        public double CalculateExpirationPnL(double futPrice)
        {
            double tempPnL = 0.0;

            TradeBlotter tempBlotter = new TradeBlotter();

            tempBlotter.AskPrice = futPrice;
            tempBlotter.BidPrice = futPrice;

            tempPnL += Futures == null ? 0.0 : Futures.Position.CalcCurrentPnL(tempBlotter);
            tempPnL += FixedPnL;

            foreach (Option opt in Options)
            {
                tempPnL += GreeksCalculator.CalculateOptionPnLOnExpiration(opt, futPrice);
            }

            return(tempPnL);
        }
        private double CalculatePositionsAbsDelta_GO(List <Option> options, Futures fut, double worstPrice, double worstVola)
        {
            double result = 0.0;
            double tempDelta;

            foreach (Option opt in options)
            {
                tempDelta = GreeksCalculator.CalculateDelta(
                    opt.OptionType,
                    worstPrice,
                    opt.Strike, opt.RemainingDays,
                    GreeksCalculator.DAYS_IN_YEAR,
                    worstVola) * opt.Position.Quantity;

                result += tempDelta;
            }

            if (fut != null)
            {
                result += fut.Position.Quantity;
            }

            return(-Math.Abs(result));
        }
        public void UpdateAllGreeksTogether()
        {
            LOGGER.Debug("All greeks update requested.");
            double optionTime = this.RemainingDays / GreeksCalculator.DAYS_IN_YEAR;
            double spotPrice  = this.Futures.GetTradeBlotter().AskPrice;

            BuyVol = GreeksCalculator.GetFilteredVolatilityValue(
                GreeksCalculator.CalculateImpliedVolatility(
                    this.OptionType,
                    spotPrice,
                    this.Strike,
                    this.RemainingDays,
                    GreeksCalculator.DAYS_IN_YEAR,
                    this.GetTradeBlotter().AskPrice,
                    0.5));
            SellVol = GreeksCalculator.GetFilteredVolatilityValue(
                GreeksCalculator.CalculateImpliedVolatility(
                    this.OptionType,
                    spotPrice,
                    this.Strike,
                    this.RemainingDays,
                    GreeksCalculator.DAYS_IN_YEAR,
                    this.GetTradeBlotter().BidPrice,
                    0.5));

            //double vola = GreeksCalculator.GetFilteredVolatilityValue(GreeksCalculator.CalculateImpliedVolatility(this.OptionType, spotPrice, this.Strike, this.RemainingDays, GreeksCalculator.DAYS_IN_YEAR,
            //    this.GetTradeBlotter().AskPrice, 0.5));

            double vola;

            if (this.Position == null)
            {
                vola = BuyVol;
            }
            else
            {
                if (this.Position.Quantity == 0)
                {
                    vola = BuyVol;
                }
                else
                {
                    vola = this.Position.Quantity > 0 ? SellVol : BuyVol;
                }
            }


            if (Math.Abs(vola) < 0.0001) // vola==0
            {
                Delta = 0;
                Gamma = 0;
                Vega  = 0;
                Theta = 0;
            }
            else
            {
                double deltaDistr_d1 = GreeksCalculator.CalculateDistributionOfStNrmDstr(GreeksCalculator.Calculate_d1(spotPrice, this.Strike, this.RemainingDays, GreeksCalculator.DAYS_IN_YEAR, vola));
                double distr_d1      = GreeksCalculator.GreeksDistribution(GreeksCalculator.Calculate_d1(spotPrice, this.Strike, this.RemainingDays, GreeksCalculator.DAYS_IN_YEAR, vola));

                Delta = GreeksCalculator.CalculateDelta(this.OptionType, deltaDistr_d1);
                Gamma = GreeksCalculator.CalculateGamma(spotPrice, distr_d1, optionTime, vola);
                Vega  = GreeksCalculator.CalculateVega(spotPrice, distr_d1, optionTime);
                Theta = GreeksCalculator.CalculateTheta(spotPrice, distr_d1, GreeksCalculator.DAYS_IN_YEAR, optionTime, vola, true);
            }


            ImplVol = vola;


            LOGGER.Debug("Greeks update complete, result: Delta: {0}, Gamma: {1}, Vega: {2}, Theta: {3}, ImplVol: {4}, BuyVol: {5}, SellVol: {6}",
                         Delta, Gamma, Vega, Theta, ImplVol, BuyVol, SellVol)
            ;
        }