JDEP 183H

Fall 2006

 

Homework Assignment 4:  Help Me Find the Best Bond!

 

Assigned:  October 26, 2006

Due:  November 16, 2006

 

Note: This assignment is to be completed individually - collaboration is strictly prohibited.

Points100 points

 

Objectives

 

The objectives of this homework assignment:

  1. Familiarize with the use of arrays
    1. Manipulate a collection of data values using an array
    2. Compute statistics out of an array of values
    3. Declare and use an array of primitive/reference data types 
  2. Familiarize with the use of exception handling for data  format and range checking
  1. Familiarize with a sorting method
    1. Using the Bubble sort on an array of object elements
  1. Re-use existing classes
  1. Understand basic GUI objects
  2. Write a GUI application
    1. Identify the GUI objects that are necessary for the application
    2. Organize the positions and functions of these GUI objects for the application
    3. Design the application such that the user interface is sensible and user-friendly
  1. Familiarize with the swing and AWT packages and layout management
  2. Familiarize with code documentation, compilation, and execution
  3. Expose to Java syntax, programming styles, and Java classes

 

 Problem Description

 

By now, you have had experience in building two systems: Profit Advising System (PAS) and Transaction and Account Balance Reporting System (TABRS).  You have used GUIs, exception handling, and event-driven programming techniques.  ACB is now ready to push for something more complex and more functional—they now want to wow their potential customers with better prototypes, especially ones that could compute statistics to support decision making.  The specific application that they want to have is a GUI-based system that (1) reads from a file input on information regarding bonds, (2) computes the missing information, and (3) computes statistics on the bonds.  Once again, you have been tasked to take up this challenge, with the promise of further developing this system into something more generally encompassing in the near future.

 

What is a bond?  According to (Needles et al. 2005), a bond is a security, usually long term, representing money that a corporation or other entity borrows from the investing public.  A bond must be repaid at a specified time and requires periodic payments of interest.  Bonds must not be confused with stocks.  Because stocks are shares of ownership, stockholders are owners.  Bondholders are creditors.  Bonds are promises to repay the amount borrowed, called the principal, and interest at a specified rate on specified future dates.

Text Box: Memo To: Chief programmer
Memo From: Your boss

The company realizes that you have built two systems.  From what we have heard, you have also gotten better at OO programming. 

Now, we want something like a prototype that we could use to demo to our potential customers.  This time around, we want it to perform some decision-support functions. 

The interface should be graphical. It should be easy and intuitive to use.

Have a productive day! 8P

Now, as an OO programmer, you start to think about the objects necessary to implement this system.  The most important object class that you need is the Bond class.  What should this class have as attributes and methods?  ABC, being a company dealing with accounting, has that available for you.  A bond should have the following attributes: name or ID (ID) (which should be unique), present value (PV), annual coupon (AC), period coupon (PC), effective annual interest rate (EAR), compound periods per year (M), periods (T), face value (F), period interest rate (r), coupon discount factor (CDF), and face value discount factor (FDF).   The general formula for calculating the present value of a bond is

.

Given a per period interest rate (r), number of periods (T), and two of  present value (PV), face value (F) and period coupon (PC), it is possible to solve for the remaining value.  In addition, the per period interest rate can be solved for as a function of the number of compounding periods in a year (M) and the effective annual interest rate (EAR).  Furthermore, the period coupon is just the annual coupon (AC) divided by the number of periods per year.

 

What about the “things” you want to be able to do with a Bond object?  ABC has also considered that and here is a list of functions (or methods).

 

Method Name

Equation

CalculatePeriodInterestRate

CalculatePeriodCoupon

if AC > 0, , else .

CalculateFaceDiscountFactor

CalculateCouponDiscountFactor

CalculatePresentValue

CalculateFace

 

Having the Bond class defined in the above, what should the system or application do? Let’s call this application the BondCalculater class. As alluded to earlier, there are three primary functionalities.

 

First, the system should read from an input file, information on bonds.  The format of the file is as follows.  There are N lines.  Each line represents a bond.  Your program should read each line until the end of file.  Each line has 7 values:

 

<ID> <PV> <AC> <EAR> <M> <T> <F>

 

Folded Corner: Note:  A sample input file will be provided for you to test your program (please download this from the course website). <ID> is a string and is always non-empty.  For the remaining 10 values, each is a real number, except when it is missing, in which case, it is a ‘?’.  You may assume that there are at most 1000 lines in the input file.  You may also assume that there are bonds with more than one missing value.

 

(Your program is required to read in and process each line and then close the input file before proceeding to compute for missing values and statistics.  Why?  That way you free up the input file for other potential read/write access by other programs.)

 

(IMPORTANT:  You are required to use an array to store the information as you read the lines from the input file.  Think about what each line means to your program from the viewpoint of objects.  And think about how you can make use of the array.  And think about how your BondCalculator can make use of the array and how your BondCalculator can make use of the Bond class.)

 

Second, for each bond that has a missing value, your program is required to calculate that value.  Potential attributes with missing values are: period interest rate (r), period coupon (PC), face discount factor (FDF), coupon discount factor (CDF), present value (PV), and face value (F).

 

Third, your BondCalculator application should have the following functions for the user to compute:

(1) The number of bonds in the file,

(2) The number of bonds with no missing values to begin with, the number of bonds with all missing values calculated for, and the number of bonds with missing values that cannot be calculated for,

(3) The minimum and maximum values of an attribute (including all values originally supplied by the file and the computed missing values), and

(4)  The average, median, and standard deviation values of an attribute (including all values originally supplied by the file and the computed missing values),

Please see the appendix for some formulas on how to compute for the statistical parameters above.

 

Further, your BondCalculator application should allow the user to sort (in an ascending order) the list of bonds and output the sorted list to an output file.  (Note that your program is not allowed to sort using any readily available Java sort libraries/functions. You must implement your own Bubble sort method.)  The application should give the user the choice of selecting one of the 11 attributes as the sorting key.  For example, if the user chooses to sort all bonds by their name or ID, then your program should do so accordingly.  If the user chooses to sort all bonds by their PV, then your program should do so accordingly as well.

 

Your program must handle exceptions and be robust.  For example, if an attribute value in the input file is a string instead of a real number, your program should not crash.  Your program should treat these entry errors as “missing values”.

 

Finally, you are required to build a GUI-based application.  ABC does not have any specific requirements on how the GUI should look like.  However, they expect to see (1) a welcome panel, (2) an input panel that prompts the user for the input filename or to browse the directory for the input file, and (3) a calculation panel that performs the three primary functions discussed above.  For calculations that involve outputting the results to an output file, there should also be an output panel that prompts the user for the output filename or to browse the directory for the output file and then writes the output.  Once all calculations are completed, the GUI should return to the welcome panel such that the user.  The welcome panel should have at least choices of actions: (1) quit, or (2) proceed. 

 

Challenge - Extra Credit (10 points)

 

For extra credit, your BondCalculator application is required to provide the following trend analysis for each bond: 

 

(1)   Show that for a given set of F, AC and EAR, for an N-year bond, PV is increasing in M.

(2)   Show that for a given set of F, AC, and M, for an N-year bond, PV is decreasing in EAR.

(3)   Show that for a given set of F, M and EAR, for an N-year bond, PC is increasing in PV.

 

For the first analysis, for example, suppose that there are K bonds from the input file.  Identify all subsets of these bonds such that members of a subset have the same set of F, AC and EAR values, sort these members by their PV values ascendingly, and then determine whether M is increasing.  Your application should output the results to an output file.

 

Your application should have an additional GUI panel for the above. 

 

Submission Procedure

 

This assignment is due on November 16th, 2006 at the start of class (12:30 PM).  Assignments five minutes late will NOT be accepted.  It is highly recommended that you read the grading policy and grading guidelines on the course website for a complete explanation of how the assignments will be graded. Remember, your program should follow a good programming style, include plenty of comments – both inline documentation and Javadoc documentation, and perform all of the functionality outlined above. Also, in the welcome message of your program, state whether you are implementing the extra credit functionality. 

 

There are two submission steps:

 

(1)    You must “handin” the following files on-line:

1.      Source files: Bond.java BondCalculator.java

2.   Compiled files: Bond.class BondCalculator.class

3.   Readme file:  README

4.   Testing file:  TEST, SampleInput, SampleOutput, TestInput, TestOutput, and all screen snapshots if applicable

 

(2)    You must submit a stapled paper copy of a coversheet, your source files, the README file, and all the testing files. 

 

Both of these steps must be done by the start of the class on the day the assignment is due.  Please download this coversheet from the instructor’s course website, under the Homework Assignments link.   This coversheet allows the grader to give comments and categorize the points for your homework.

 

Appendix 

1.      Bubble Sort (a Java implementation can be found in your textbook, Chapter 11).

 2. Average of n values is defined as

 3.     Median: In a sorted data set, the median is the value of the data positioned at  (the lower median) or  (the upper median).  You can just use the lower median for your homework.

4.   Standard deviation: σ , where xi is the value of a particular instance, n is the number of instances.

References

 

Needles, B. E., Jr., M. Powers, and S. V. Crosson (2005).  Principles of Accounting, Boston: Houghton Mifflin.