CS5006 Assignment 4 The Investor’s Dilemma solved

$35.00

Category: You will receive a download link of the .ZIP file upon Payment

Description

5/5 - (1 vote)

You are a bond investor with a total amount of money (t) and want to fully invest it in a portfolio that provides the greatest return on your investment. You have a number (n) of investment opportunities to choose from. For each bond, you know the number of shares (si) available, the cost per share (ci) and the yield (yi). Investment rules allow you to purchase a fraction (xi) of the available shares of any bond.

The objective is to maximize total profits:
maximize∑k=1NPkwherePk=xk⋅sk⋅ck⋅yk
subject to the cost constraint:
∑k=1NCk=twhereCk=xk⋅sk⋅ck
since you want to fully invest the total amount of money.

The assignment is to write a function invest() that takes the total amount to be invested and a collection of bonds representing the investment opportunities. The function uses a greedy algorithm to compute the optimal investment and return a portfolio of purchased bonds.

Class Bond has a string field name for the name of the bond, and float fields shares for the number of shares available, cost for the cost per share, and yield for the yield per share (e.g. 0.06 for a 6% yield). All of the fields are public to provide access. It also has public float convenience functions totalCost() for the total cost of the bond offering (shares * cost), and totalProfit() for the total profit of the bond offering (shares * cost * yield).

The greedy algorithm invests in as many shares or fractions of shares of the highest yielding Bond offerings available that, together with investments already made, do not exceed the total amount to be invested.

You may use either C++ or Java to complete this assignment. For C++, use a file named “Investment.cpp”. For Java, use a file named “Investment.java” and make Bond an inner class. As usual, you should include full CDoc or JavaDoc documentation for all fields, functions, and classes, and adequate Cunit or Junit tests.

Here are some recommended test cases:

purchasing all bonds with funds left over
purchasing only whole positions with no money left over
purchasing fractional positions with no money left over
For C++, the input is a float total and a std::list and the return value is a list. For Java, the input is a float total and a Collection and the return value is a Collection. The input collection should not be modified. If a whole position is purchased, the input Bond can be included in the returned collection. If a fractional position is purchased, a new Bond instance with the number of shares purchased should be added to the returned collection.

You will want to order the opportunities in descending yield. For C++, use a std::priority_queue with a comparator that orders Bonds by descending yield. For Java, use a PriorityQueue whose comparator orders Bonds by descending yield.