Exemplo n.º 1
0
        /// <summary>
        /// Calculate price of the bond
        /// </summary>
        /// <returns></returns>
        public double GetCurrentPrice()
        {
            Lists    lists        = new Lists();
            CashFlow getCashFlow  = new CashFlow();
            ZeroRate z            = new ZeroRate();
            var      asof         = (DateTime)AsOfDate.SelectedDate;
            var      principal    = Double.Parse(Principal.Text);
            var      interestRate = Double.Parse(InterestRate.Text);
            var      startDate    = (DateTime)StartPick.SelectedDate;
            var      endDate      = (DateTime)EndPick.SelectedDate;

            _interestList = lists.GetInterestList(NameInterest.Text, Ccy.Text, asof); // get list from interestTable
            _scheduleList = lists.GetScheduleList(Name.Text);                         // get list from schedule table

            Double FinalSum = 0;
            Double sum      = getCashFlow.GetDiscoutendCashFlow(startDate, _scheduleList[0].Item2, principal, interestRate);

            if (_scheduleList.Count > 0)
            {
                for (Int32 i = 0; i < _scheduleList.Count; i++)
                {
                    var zeroRate = (Double)z.LinearInterpolation(asof, _scheduleList[i].Item2, _interestList); // get interest rate at payday
                    if (i == 0)
                    {
                        FinalSum = FinalSum + getCashFlow.GetCurrentCashFlow(asof, _scheduleList[0].Item2, sum, 1.6);
                    }

                    if (_scheduleList.Count > 1 && _scheduleList[i] != _scheduleList[_scheduleList.Count - 1])
                    // if there is only one item in schedule
                    // and we are not at the last pair
                    {
                        sum      = getCashFlow.GetDiscoutendCashFlow(_scheduleList[i].Item2, _scheduleList[i + 1].Item2, principal, interestRate);
                        FinalSum = FinalSum + getCashFlow.GetCurrentCashFlow(asof, _scheduleList[i].Item2, sum, zeroRate);
                    }


                    if (_scheduleList[i] == _scheduleList[_scheduleList.Count - 1] || _scheduleList.Count == 1) // if we are at the last pair
                    {
                        var zeroRateFinal = (Double)z.LinearInterpolation(asof, endDate, _interestList);
                        // if(zeroRateFinal == 0)
                        // {
                        //     MessageBox.Show("Not enough data in interestList");
                        // }
                        sum      = principal;
                        FinalSum = FinalSum + getCashFlow.GetCurrentCashFlow(asof, endDate, sum, 1.8);
                    }
                }
            }

            return((FinalSum / principal) * 100);
        }