A financial institution wants to develop a Java application to track its investment portfolios. Each portfolio contains 2 asset types: stocks and bonds. Each asset has specific attributes like ticker symbol, purchase price, current price, and quantity. The application needs to calculate the total value of each asset and the overall portfolio value. You are required to develop a Java application that can perform the following functions:
Define: Design Java classes for Assets, Portfolio, Stocks, and Bonds.
Create: Implement methods to create Asset objects with relevant attributes and Portfolio objects holding the references to multiple Asset types.
Update: Include methods to update the current price of an Asset and calculate its new value.
Portfolio valuation: Create methods to calculate the total value of a Portfolio considering all its assets' current price.
Please refer to the following UML diagram for reference:
Diagram 2.1 UML diagram.
Additionally, use this outline to help you solve the problem:
Classes:
Asset:
Attributes: symbol, purchasePrice, currentPrice, quantity
Methods: calculateValue(), updatePrice(newPrice), calculateReturn.
Portfolio:
Attributes: name, Asset (ArrayList of Asset Objects).
Methods: getTotalValue(), addAsset(asset), updateAssetPrice(symbol, newPrice).
Stock: (inherit from Asset)
Attributes: dividendYield
Methods: getAdditionalAttributes() (display the dividend)
Bond: (inherit from Asset)
Attributes: interestRate, maturityDate
Methods: getAdditional Attributes() (display interest rate and date).
To display the output, create a test class called main. In this class, you have the following methods:
testAddAsset(): Add asset to the portfolio using the method addAsset. The asset type can either be a stock asset or bond. After adding the asset, display the size of the asset arrayList and the content. Use the following values depending on the type of asset that is being added:
Stock: AAPL, 100.0, 150.0, 10, 0.02
Bond: US10YT, 1000.0, 1020.0, 5, 0.05
Refer to the table 2.1 below for more information:
Table 2.1: Asset type input details
able[[ able[[Asset],[Type]],Symbol, able[[Purchase],[Price]], able[[Current],[Price]],Quantity, able[[Dividend],[Yield]], able[[Interest],[rate]], able[[Maturity],[date]]],[Stock,AAPL,100,150,10,0.02,-,-],[Bond,US10YT,1000,1020,5,-,0.05, able[[Current],[date]]]]
testGetTotalValue(): after adding the asset to the portfolio, use the method calculateValue() from the asset which in turn can be checked with the portfolio method getTotalValue(). If the value returned from the calculateValue() is the same as getTotalValue(), then it passes the test.
testUpdatePrice(): After adding the asset to the portfolio, set a new price for the asset using the updatePrice() method. Then display the value of the portfolio.