예제 #1
0
        protected virtual HealthCheckData DoTest()
        {
            // check it even exists!
            var      count = 0;
            DateTime?oldestMessageDated = null;
            var      exists             = MessageQueue.Exists(myConfig.QueueName);
            string   info;

            if (exists)
            {
                var queue = new MessageQueue(myConfig.QueueName)
                {
                    MessageReadPropertyFilter = new MessagePropertyFilter
                    {
                        ArrivedTime = true
                    }
                };

                var me      = queue.GetMessageEnumerator2();
                var timeout = new TimeSpan(0, 0, 0);

                while (me.MoveNext(timeout))
                {
                    var msg = me.Current;

                    if (!oldestMessageDated.HasValue)
                    {
                        oldestMessageDated = msg.ArrivedTime;
                    }
                    else if (msg.ArrivedTime < oldestMessageDated)
                    {
                        oldestMessageDated = msg.ArrivedTime;
                    }

                    count++;
                }

                info = string.Format("Queue {0} has {1} messages", myConfig.QueueName, count);
            }
            else
            {
                info = string.Format("Queue {0} does not exist!", myConfig.QueueName);
            }

            var props = new ResultProperties
            {
                { "Queue", myConfig.QueueName },
                { "Count", count.ToString() }
            };

            if (oldestMessageDated.HasValue)
            {
                props.Add("Oldest", oldestMessageDated.ToString());
            }

            var result = new HealthCheckData
            {
                Identity   = Identity,
                Info       = info,
                Result     = exists,
                Properties = props
            };

            if (exists)
            {
                result.ResultCount = count;
            }

            return(result);
        }
예제 #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;
        }