Пример #1
0
 public void CalculateOption(OptionType optionType, BinomialStrategyType binomialStrategyType, int numberSteps, double interestRate, double volatility, double strike, double expiry, double currentPrice, double costOfCarry, bool isCall, ref double price, ref double delta, ref double vega)
 {
     wrapper.setOption((int)optionType, interestRate, volatility, strike, expiry, currentPrice, costOfCarry, isCall);
     wrapper.calculateOptionBinomial((int)binomialStrategyType, numberSteps);
     price = wrapper._price;
     delta = wrapper._delta;
     vega  = wrapper._vega;
     wrapper.calculateOptionBlackScholes(1, numberSteps, numberSteps);
     double[,] test = wrapper._price_data;
     for (int i = 0; i < test.GetLength(0); i++)
     {
         List <double> tmp = new List <double>();
         for (int j = 0; j < test.GetLength(1); j++)
         {
             tmp.Add(test[i, j]);
         }
         PriceData.Add(tmp);
     }
 }
Пример #2
0
        void CalculateOptionPrice()
        {
            //FIXME: This entire function

            OptionType           optionType = OptionType.AmericanOptionType;
            BinomialStrategyType binomialStrategyType = BinomialStrategyType.CRRBinomialStrategyType; int numberSteps = 200; double interestRate = 0.1;
            double volatility = 0.1; double strike = 200; double expiry = 1.0; double currentPrice = 200; double costOfCarry = 0.1; bool isCall = true;

            foreach (Property property in InputProperties)
            {
                if (property.Key is string)
                {
                    string key = property.Key as string;
                    if (key == InputKeyConstants.OptionType)
                    {
                        optionType = ((property.Value as Selection).SelectedItem == "American Option") ? OptionType.AmericanOptionType : OptionType.EuropeanOptionType;
                    }
                    else if (key == InputKeyConstants.BinomialType)
                    {
                        binomialStrategyType = BinomialStrategyType.CRRBinomialStrategyType;
                    }
                    else if (key == InputKeyConstants.NumberOfSteps)
                    {
                        numberSteps = int.Parse(property.Value.ToString());
                    }
                    else if (key == InputKeyConstants.InterestRate)
                    {
                        interestRate = double.Parse(property.Value.ToString());
                    }
                    else if (key == InputKeyConstants.Volatility)
                    {
                        volatility = double.Parse(property.Value.ToString());
                    }
                    else if (key == InputKeyConstants.Strike)
                    {
                        strike = double.Parse(property.Value.ToString());
                    }
                    else if (key == InputKeyConstants.Expiry)
                    {
                        expiry = double.Parse(property.Value.ToString());
                    }
                    else if (key == InputKeyConstants.CurrentPrice)
                    {
                        currentPrice = double.Parse(property.Value.ToString());
                    }
                    else if (key == InputKeyConstants.IsCall)
                    {
                        isCall = true;//FIXME
                    }
                }
            }
            VegaCLR clr = new VegaCLR();
            double  price = 0.0;
            double  delta = 0.0;
            double  vega = 0.0;

            clr.CalculateOption(optionType, binomialStrategyType, numberSteps, interestRate, volatility, strike, expiry, currentPrice, costOfCarry, isCall, ref price, ref delta, ref vega);
            foreach (Property property in ResultProperties)
            {
                if (property.Key == ResultKeyConstants.Price)
                {
                    property.Value = price;
                }
                else if (property.Key == ResultKeyConstants.Delta)
                {
                    property.Value = delta;
                }
                else if (property.Key == ResultKeyConstants.Vega)
                {
                    property.Value = vega;
                }
            }
            ResultProperties.Add(new Property("", ""));
            ResultProperties.Remove(ResultProperties.Last()); //FIXME

            _plotViewModel.GraphData = clr.PriceData;
        }