Calculation of Bond coupon and honour date

Source: Internet
Author: User

1. (1) Business scenario

The coupon frequency is the month/time unit can get the field start date due date need to calculate the middle all interest payment plan date

(2) Main issues:

1> if the starting date is 31st in a month, you will need to take number 30th for the month without number 31st.

2> if the starting date is 30th or 29th, common year February needs to take number 28th.

(3) Algorithm analysis:

Get each coupon month in accordance with the coupon frequency you can use the Calendar class to bring the addition operation of the month method add (int field, int amount) (this method takes the date if the start date is one month 30th if the next interest month is February will give you automatically take the last day 28th then Counting down in the for loop will be taken to the 28th number of interest month

Calendar class comes with a way to get to the last day of one months then if number 31st is taken to the last day of the month

If number 30th or 29th is calculated by the Add method, all interest dates are placed in the list and then the list is not replaced by the date of February with 30th or 29th.

(4) Code

[Java]View PlainCopy
Private list<string> awardintedate (long d1, long D2,long frequency) throws ParseException, Java.text.Pa          rseexception {String str = d1.tostring ();          list<string> list = new arraylist<string> (); Getmonthspace () Gets the number of months between two dates for (int i = 0; i < Infordintecalculatelogic.getmonthspace (d1.tostring), d2.to String ())/frequency;              i++) {SimpleDateFormat SDF = new SimpleDateFormat ("YyyyMMdd");              Date date = Sdf.parse (str);              Calendar ins = Calendar.getinstance ();              Ins.settime (date);              Ins.add (Calendar.month,frequency.intvalue ());              The date of the YYYYMMDD format is taken to the day String s = d1.tostring (). substring (Str.length ()-2, Str.length ()); if ("+". Equals (s)) {//If it is 31st, take the last day of each month Ins.set (calendar.date, Ins.getactualmaximum (Cal Endar.                  DATE));                  str = Sdf.format (Ins.gettime ()). ToString (); LisT.add (str);                  } else {str = Sdf.format (Ins.gettime ()). ToString ();              List.add (str);          }} String SS = d1.tostring (). substring (Str.length ()-2, Str.length ());                   If it's number 30th, change the date of all months except February to number 30th if ("+". Equals (ss)) {for (int i = 0; i < list.size (); i++) {                  String str1 = List.get (i); if (! "                      ". Equals (Str1.substring (4, 6))) {StringBuilder builder = new StringBuilder (STR1);                      Builder.replace (6, 8, "30");                      STR1 = Builder.tostring ();                  List.set (i, str1);                  }}} if ("". Equals (ss)) {for (int i = 0; i < list.size (); i++) {                  String str1 = List.get (i); if (! " ". Equals (Str1.substring (4, 6))) {StringBuilder builder = new StringBuilder (STR1);                      Builder.replace (6, 8, "29");                      STR1 = Builder.tostring ();                  List.set (i, str1);  }}} return list;

[Java]View PlainCopy
    //calculate the number of months between two dates method         Public Static intGetmonthspace (String date1, String date2)throwsParseException, java.text.ParseException {intresult = 0; SimpleDateFormat SDF=NewSimpleDateFormat ("YyyyMMdd"); Calendar C1=calendar.getinstance (); Calendar C2=calendar.getinstance ();              C1.settime (Sdf.parse (date1));                    C2.settime (Sdf.parse (date2)); Result= (C2.get (calendar.year)-C1.get (calendar.year)) * + (C2.get (calendar.month)-C1.get (calendar.month)); returnresult = = 0? 1: Math.Abs (Result); }  



—— —— —— —— —— —— —— —— —— —— —— —— —— —— —— —— —— ——

2. (1) Business scenario

1> non-leap year interest-bearing annual determination

The year of interest is determined by the life cycle of the product itself. In the case of an interest-bearing debt financing scheme, the 5-year period, which pays interest every three months, the starting date is April 20, 2016, then July 20, 2016 is the first coupon date, October 20, 2016 is the second coupon date, then April 20, 2016- April 20, 2017 (the interest calculation head is not counted, the same as below) for the first full year of interest for the product, the product has a total of 5 interest year.

2> years of interest in leap year determination

The leap year is determined as a standard for whether it crosses February 29 of a leap year in a full interest period. As an example of the products mentioned in the previous paragraph, the Year of interest is the year of interest in leap years, since February 2020 is the year of interest in the product from April 20, 2019 to April 20, 2020. As a result, 2019 is not a leap year in the natural years, but the fourth interest period (January 20, 2020 – April 20, 2020) is due to fall into the year of interest for the product April 20, 2019-April 20, 2020, which should be processed in leap years. While 2020 is a leap year in the natural year, its fifth year of interest (April 20, 2020-April 20, 2021) is not a leap years and is still treated as non-leap-years.

(2) Algorithm analysis:

Get 2 of all leap years in time if the date of interest is a period after February 29, then the first year of splicing and the Year 2 for the interest year are put into the array

If it's a date before February 29, then splice the current year and the next year for the 2 year span of the year, put these two years into the array

If the coupon plan time is within two time spans of any one array in the array list, then the flag+1 is marked as a leap year in the leap year period of interest

(3) Code

[Java]View PlainCopy
    //to determine whether the year method is for leap years    Private intJudgeleapyearstyle (String date,string begin,string end) {inti; List<Integer> list=NewArraylist<integer>(); List<string []> arrlist=NewArraylist<string []>();  for(I=integer.parseint (begin.substring (0, 4)); I<=integer.parseint (end.substring (0, 4)); i++){            if((i%4==0&&i%100!=0) | | (i%400==0) {list.add (i); }          }          //get 2 of all leap years in time if the date of interest is a period after February 29, then the first year of splicing and the Year 2 for the interest year are put into the array//if it's a date before February 29, then splice the current year and the next year for the 2 year span of the year, put these two years into the array//if the coupon plan time is within two time spans of any one array in the array list, then the flag+1 is marked as a leap year in the leap year period of interestString MonthDay; if("0". Equals (Begin.substring (4, 5)) {MonthDay=begin.substring (5, 8); if(Integer.parseint (MonthDay) >=229){                   for(Integer integer:list) {String D1=string.valueof (integer-1) + "0" +MonthDay; String D2=string.valueof (integer) + "0" +MonthDay; String[] Arr=NewString []{d1,d2};                  Arrlist.add (arr); }                         }Else{                   for(Integer integer:list) {String D1=string.valueof (integer) + "0" +MonthDay; String D2=string.valueof (integer+1) + "0" +MonthDay; String[] Arr=NewString []{d1,d2};                  Arrlist.add (arr); }              }          }Else{MonthDay=begin.substring (4, 8); if(Integer.parseint (MonthDay) >=229){                   for(Integer integer:list) {String D1=string.valueof (integer-1) +MonthDay; String D2=string.valueof (integer) +MonthDay; String[] Arr=NewString []{d1,d2};                  Arrlist.add (arr); }                         }Else{                   for(Integer integer:list) {String D1=string.valueof (integer) + "0" +MonthDay; String D2=string.valueof (integer+1) + "0" +MonthDay; String[] Arr=NewString []{d1,d2};                  Arrlist.add (arr); }              }          }          intFlag = 0;  for(string[] strings:arrlist) {if(Integer.parseint (date) >=integer.parseint (Strings[0]) && integer.parseint (date) <=integer.parseint ( Strings[1]) {flag+=1; }          }          returnFlag; }  


The algorithm of floating-rate debt is more complicated than this.

Calculation of Bond coupon and honour date

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.