Пример #1
0
        public IRZeroCurve GenerateCurve(BusinessDay currentDate)
        {
            if (_curve_dictionary.ContainsKey(currentDate.DateTime))
            {
                return(_curve_dictionary[currentDate.DateTime]);
            }

            IRZeroCurve curve = new IRZeroCurve(currentDate);

            foreach (InterestRate rate in _interest_rate_lst)
            {
                try
                {
                    double value = rate[currentDate.DateTime, TimeSeriesType.Last, DataProvider.DefaultProvider, TimeSeriesRollType.Exact] / 100.0;

                    if (double.IsNaN(value))
                    {
                        value = rate[Calendar.Close(currentDate.DateTime), TimeSeriesType.Last, DataProvider.DefaultProvider, TimeSeriesRollType.Last] / 100.0;
                    }

                    if (!double.IsNaN(value))
                    {
                        // Console.WriteLine("Generate Curve: " + this._currency + " " + currentDate.DateTime + " " + rate + " " + value);

                        if (rate.InstrumentType == InstrumentType.Deposit)
                        {
                            Deposit deposit = (rate as Deposit);
                            curve.AddCashFlow(value, deposit.MaturityType, deposit.Maturity, deposit.MaturityType, deposit.Maturity, deposit.DayCountConvention);

                            // Console.WriteLine("     Add deposit:" + rate + " " + deposit.MaturityType + " " + deposit.Maturity + " " + deposit.MaturityType + " " + deposit.Maturity + " " + deposit.DayCountConvention);
                        }
                        else if (rate.InstrumentType == InstrumentType.InterestRateSwap)
                        {
                            InterestRateSwap swap = (rate as InterestRateSwap);
                            curve.AddCashFlow(value, swap.FixedFrequencyType, swap.FixedFrequency, swap.MaturityType, swap.Maturity, swap.FixedDayCountConvention);
                            // Console.WriteLine("     Add Swap:" + rate + " " + swap.FixedFrequency + " " + swap.MaturityType + " " + swap.Maturity + " " + swap.FixedDayCountConvention);
                        }
                    }
                }
                catch { }
            }

            curve.BootStrap();
            if (_curve_dictionary.ContainsKey(currentDate.DateTime))
            {
                _curve_dictionary[currentDate.DateTime] = curve;
            }
            else
            {
                _curve_dictionary.TryAdd(currentDate.DateTime, curve);
            }

            return(curve);
        }
Пример #2
0
        public double NPV(BusinessDay businessDay)
        {
            IRZeroCurve curve = _curveCollection == null ? null : _curveCollection.GenerateCurve(businessDay);

            return(Amount * (curve.PresentValue(this.Calendar.GetClosestBusinessDay(Date, TimeSeries.DateSearchType.Previous))));
        }