Exemplo n.º 1
0
        /*void txtBidPriceA_TextChanged(object sender, EventArgs e)
        {
            int price = Convert.ToInt32(txtBidPriceA.Text);
            //averageLifeA = computeAverageLife();
            //txtBidSpreadA.Text = (100-price) * (360/365.25) * (100/AvgLife) + Margin;
            txtBidSpreadA.Text = "100.0";
        }*/
        // Calculate and show dates
        private void ShowCalculatedDates(TextBox txtNumber, TextBox txtBoxTradeDate, GridView grdCalculatedDates)
        {
            PublicHolidayBLL bll = new PublicHolidayBLL();
            List<tblHoliday> publicHolidays = bll.GetPublicHolidays(1);

            List<CalculatedDates> calculatedList = new List<CalculatedDates>();
            DateTime selectedDate;
            if (DateTime.TryParse(txtBoxTradeDate.Text, out selectedDate))
            {
                // I am going to display dates
                for (int i = 0; i < Convert.ToInt32(txtNumber.Text); i++)
                {
                    // Move on to next 3 month
                    selectedDate = selectedDate.AddMonths(3);

                    // Check the selected date is not in the Public holiday list and not a saturday, sunday
                    // If it exist then we need to move on to the next working day
                    int numberOfDaysPassed = 0;
                    while (IsSaturdaySundayDay(selectedDate) || IsPublicHoliday(publicHolidays, selectedDate))
                    {
                        selectedDate = selectedDate.AddDays(1);
                        numberOfDaysPassed = numberOfDaysPassed + 1;
                    }

                    CalculatedDates cal = new CalculatedDates();

                    cal.CalculatedDate = selectedDate;
                    cal.Fraction = String.Format("{0:00.00}", numberOfDaysPassed / 365.25);

                    calculatedList.Add(cal);
                }

                grdCalculatedDates.DataSource = calculatedList;
                grdCalculatedDates.DataBind();
            }
        }
Exemplo n.º 2
0
        private void ComputeCouponDatesAndFractionsOld(RadDatePicker txtBoxTradeDate, RadComboBox txtBoxLoanName, RadDatePicker txtBoxSettlementDate,
            RadDatePicker txtBoxMaturityDate, RadTextBox txtBoxCouponFrequency, RadTextBox txtNonDiscountedAverageLife, RadGrid grdCalculatedDates, int type, RadTextBox txtNotional, RadTextBox txtMargin, RadTextBox txtCurrency)
        {
            try
            {

                int countryID = getCountryForLoan(txtBoxLoanName);
                PublicHolidayBLL bll = new PublicHolidayBLL();
                List<tblHoliday> publicHolidays = bll.GetPublicHolidays(countryID);
                List<CalculatedDates> calculatedList = new List<CalculatedDates>();

                DateTime cpnDT;
                cpnDT = AddBusinessDays(DateTime.Now, 10);
                LoanScheduleBL loanScheduleBL = new LoanScheduleBL();
                DataTable dtSchedule = loanScheduleBL.GenerateTable(15, 10, cpnDT, txtBoxCouponFrequency.Text, txtNotional.Text, txtBoxMaturityDate.SelectedDate.Value, cpnDT, Convert.ToDecimal(txtMargin.Text), Convert.ToString(txtCurrency.Text), Convert.ToDateTime(txtBoxTradeDate.SelectedDate.Value), txtBoxSettlementDate.SelectedDate.Value);

                DateTime currentCouponDate;
                DateTime previousCouponDate;
                DateTime maturityDate;
                DateTime tradeDate;

                DateTime tradeDate1 = DateTime.Now.Date;
                if (txtBoxTradeDate.SelectedDate != null)
                {
                    tradeDate1 = txtBoxTradeDate.SelectedDate.Value;
                }

                //DateTime settlementDate = DateTime.Now.Date;
                //if (txtBoxSettlementDate.SelectedDate != null)
                //{
                //    settlementDate = AddBusinessDays(txtBoxSettlementDate.SelectedDate.Value, 10);
                //}
                DateTime boxMaturityDate = DateTime.Now.Date;

                DateTime.TryParse(txtBoxSettlementDate.SelectedDate.Value.ToShortDateString(), out currentCouponDate);
                DateTime.TryParse(txtBoxSettlementDate.SelectedDate.Value.ToShortDateString(), out previousCouponDate);
                if (txtBoxMaturityDate.SelectedDate != null)
                {
                    boxMaturityDate = txtBoxMaturityDate.SelectedDate.Value;
                }
                DateTime.TryParse(boxMaturityDate.ToShortDateString(), out maturityDate);
                DateTime.TryParse(tradeDate1.ToShortDateString(), out tradeDate);

                if (DateTime.TryParse(txtBoxSettlementDate.SelectedDate.Value.ToShortDateString(), out currentCouponDate))
                {
                    int cF = 0;
                    System.Numeric.Frequency f = new System.Numeric.Frequency();
                    while (CurrentCouponDateLessThanMaturityDate(currentCouponDate, maturityDate))
                    {
                        if (txtBoxCouponFrequency.Text == "Annual")
                        {
                            cF = 1;
                            f = System.Numeric.Frequency.Annual;
                        }
                        if (txtBoxCouponFrequency.Text == "Semi-Annual")
                        {
                            cF = 2;
                            f = System.Numeric.Frequency.SemiAnnual;
                        }
                        if (txtBoxCouponFrequency.Text == "Quarterly")
                        {
                            cF = 4;
                            f = System.Numeric.Frequency.Quarterly;
                        }
                        if (txtBoxCouponFrequency.Text == "Monthly")
                        {
                            cF = 12;
                        }

                        int numberOfDaysPassed = 0;
                        // if a weekend date or holiday move forward
                        //while (IsSaturdaySundayDay(currentCouponDate) || IsPublicHoliday(publicHolidays, currentCouponDate))
                        //{
                        //    currentCouponDate = currentCouponDate.AddDays(1);
                        //    numberOfDaysPassed = numberOfDaysPassed + 1;
                        //}

                        // Compute next coupon date using CoupNCD and correct for weekends
                        CalculatedDates cal = new CalculatedDates();
                        System.Numeric.DayCountBasis d = System.Numeric.DayCountBasis.Actual365;
                        previousCouponDate = currentCouponDate;
                        currentCouponDate = System.Numeric.Financial.CoupNCD(currentCouponDate, maturityDate, f, d);
                        DateTime previousBusinessDay = PreviousBusinessDay(currentCouponDate);
                        cal.CalculatedDate = previousBusinessDay;

                        //numberOfDaysPassed = currentCouponDate.Subtract(tradeDate).Days;  // removed 31-03- 2014 asked by avr
                        numberOfDaysPassed = currentCouponDate.Subtract(txtBoxSettlementDate.SelectedDate.Value).Days;

                        //cal.Fraction = String.Format("{0:00.000}", numberOfDaysPassed / 365.25);
                        cal.Fraction = String.Format("{0:00.00}", numberOfDaysPassed / 365.25);
                        cal.ActualFraction = numberOfDaysPassed / 365.25;
                        calculatedList.Add(cal);

                    }
                    if (calculatedList != null && calculatedList.Count > 0)
                    {
                        // When the cashflow is computed take the average of the fractions and set that to the non discounted average life text box.
                        //  txtNonDiscountedAverageLife.Text =Convert.ToDecimal( calculatedList.Last().ActualFraction).ToString("0.00");
                    }
                    grdCalculatedDates.Visible = true;
                    grdCalculatedDates.DataSource = calculatedList;
                    grdCalculatedDates.DataBind();
                    switch (type)
                    {
                        case 1:
                            tempCalculatedList1 = calculatedList;
                            break;
                        case 2:
                            tempCalculatedList2 = calculatedList;
                            break;
                        case 3:
                            tempCalculatedList3 = calculatedList;
                            break;
                        default:
                            break;
                    }

                }
                // tempLegend = txtBoxLoanName;
            }
            catch (Exception)
            {

            }
        }