Example #1
0
        public Option Price(OptionType optionType, string underlyingName, DateTime maturity, double strike, double spot, double volatility, double interestRate)
        {
            Option option = new Option();
            option.OptionType = optionType;
            option.UnderlyingName = underlyingName;
            option.Spot = spot;
            option.Maturity = maturity;
            option.Strike = strike;

            if (optionType == PricerTuto.OptionType.Call)
            {
                option.PayOff = Math.Max(spot - strike, 0);
            }
            else //if (optionType == PricerTuto.OptionType.Put)
            {
                option.PayOff = Math.Max(strike - spot, 0);
            }

            option.Volatility = volatility;
            option.InterestRate = interestRate;
            var timeToExpirationYears = maturity.Subtract(this.DateService.Now).TotalDays / 260.0;
            option.Price = BlackSholes.Price(
                optionType,
                option.Spot,
                option.Strike,
                timeToExpirationYears,
                option.InterestRate,
                option.Volatility);
            option.Delta = BlackSholes.Delta(
                optionType,
                option.Spot,
                option.Strike,
                timeToExpirationYears,
                option.InterestRate,
                option.Volatility);
            option.Gamma = BlackSholes.Gamma(
                optionType,
                option.Spot,
                option.Strike,
                timeToExpirationYears,
                option.InterestRate,
                option.Volatility);

            return option;
        }
 public void WhenIComputeThePrice()
 {
     this.result = pricer.Price(this.input.OptionType, this.input.Underlying, this.input.Maturity, this.input.Strike, this.input.Spot, this.input.Volatility, this.input.Rate);
 }
        public void WhenIComputeThePriceWithMarketData(Table table)
        {
            var optionType = (OptionType)Enum.Parse(typeof(OptionType), table.Rows[0]["type"]);
            var maturityString = table.Rows[0]["maturity"];
            var strike = Double.Parse(table.Rows[0]["strike"], CultureInfo.InvariantCulture);
            var underlyingName = table.Rows[0]["underlying"];

            var maturity = this.ParseMaturity(maturityString);

            this.result = pricer.PriceWithMarketData(optionType, underlyingName, maturity, strike);
        }