CPT206 Computer Programming for Financial Mathematics:
Coursework 3 Task Specification
This is the specification task sheet for the Coursework 3 assessment component of your CPT206 module. The task covers all Learning Outcomes, and has a weighting of 70% towards the final grade for this module. This assignment has two parts: a coding part described in Section 1, and a report described in Section 2.
1 Program description (70 marks)
The aim of this coursework is to build a system which manages investments in companies’ shares. All the work should be coded into a single Java NetBeans project, with the class structure and different functionalities of the program described below. All classes should be properly encapsulated, as seen in the Lectures and Labs throughout the semester. Your project should also contain a Controller class for testing. You may leave some or all of your test code in the Controller class if you wish when submitting, but no marks are allocated for this class’s contents in your submission. Instead you will be asked to describe your testing in the report (see Section 2.3), and marked on that.
1.1 Market class (7 marks)
The Market class represents the current companies that are on the market, that is whose shares can be traded (bought or sold). It therefore stores a collection of Company objects (see Section 1.2). Any company can only appear on the market at most once. The class should also have methods add() and remove() to add or remove a given company from the market, and contains() to check if a given company is on the market or not. There will only be one market in the program, so all members of the class should be static.
1.2 Company class (25 marks)
A Company object should store its (legal) name, a stability coefficient (a percentage between 0 and 100) indicating how stable its share prices are, and the history of its share prices. When a Company object is created, its initial share price is specified (as well as the name and stability coefficient). The history then consists of this initial share price. The Company class should have a method getCurrentSharePrice() which returns the current share price of the company (this will be the last share price in its history) and a method getInitialSharePrice() which returns the initial share price of the company (this will be the first share price in its history). There should be methods to add or remove the company from the market, and to check if it is currently on the market. There should be a method updateSharePrice() to update the valuation of a company’s share price, according to the following formula:
Sharenew = Sharelast (1 + (1 - stab) * U) ,
where:
• Sharenew is the new current share price of the property (after update);
• Sharelast is its old current share price (before update);
• stab is the company’s stability coefficient;
• U is a uniform random variable on the interval [-1, 1].
The new share price should then be added to the company’s history (as its last element).
Finally, there should be a method getTrend(int movementNumber, int significance) to determine the trend of a company’s share value based on a number of recent movements. Given two share prices in a company’s history s1 and s2 , the movement is simply the difference s2 - s1 . A movement is consecutive if it is between two consecutive share prices in the company’s history. A movement is considered significant if the ratio s1/|s2−s1| is greater than or equal to the significance
threshold. Otherwise it is insignificant. The trend of the company is then calculated by looking at the last movementNumber consecutive movements as follows.
• If strictly more than half of these are significant increases, and the share price has overall increased significantly over the whole period, then the trend is increasing.
• If strictly more than half of these are significant decreases, and the share price has overall decreased significantly over the whole period, then the trend is decreasing.
• If strictly more than half of these are insignificant, and the share price movement over the whole period is also insignificant, then the trend is stable.
• Otherwise, the trend is uncertain. This includes the case where there is insufficient data in the history.
For example, suppose movementNumber = 3, and the last four values in a company’s share history are [100, 105, 97, 103], so that the last three consecutive movements are +5, -8, +6. The overall movement over this period is 103 - 100 = 3.
• If the significance threshold is equal to 3 (or less), then the trend is increasing: the consecutive movements +5 and +6 both meet the significance threshold (this is a strict majority of them), as does the overall movement.
• If the significance threshold is equal to 7 (or more), then the trend is stable: the consecutive movements +5 and +6 are both within the stability threshold, as is the overall movement.
• If the significance threshold is equal to 5, then the trend is uncertain: while there are two significant increases in the consecutive movements, the overall movement is too small to be significant.
• If the significance threshold is equal to 6, then the trend is also uncertain: the consecutive movement +5 is insignificant, -8 is a significant decrease, and +6 is a significant increase, so there is no majority of consecutive movement type.
1.3 (Basic)Strategy class (12 marks)
The investor will need to devise strategies determining when they should invest in a given company, and how many shares they should buy when doing so. The building block for this will be a Strategy interface, with a method invest(company) that takes as parameter a Company object, and returns the number of shares to invest in based on the company’s current performance in the market. The number returned is a signed integer, with a negative value indicating that the investor should sell shares in that company.
The strategy should then be implemented through a BasicStrategy class. This class should store a maxTransaction variable, indicating how much they are willing to invest or divest in shares in a given transaction. It should also store variables movementNumber and significance. The implementation of the invest(company) method should first calculate the company’s trend based on these two variables, and then decide how much to invest/divest as follows.
• If the company’s trend is stable or uncertain, there is no investment to be made (the method should return 0).
• If the company’s trend is increasing, the investor should buy shares. The number they buy is equal to the maximal value such that they spend no more than maxTransaction on the transaction.
• If the company’s trend is decreasing, the investor should sell shares. As above, the number they sell is equal to the maximal value such that they receive no more than maxTransaction from the transaction.
1.4 Investor class (16 marks)
Finally, your project should have an Investor class, responsible for managing investment in the market (this could be an individual investor, or a company’s own investments in the market, for example). Each investor should have a collection of companies (on the market) they are interested in investing in. The investor should then associate to each of these a Strategy dictating how they will invest, and the number of shares in the company they currently own. By default, Investor objects are created with no companies of interest. They can also be created with a specified collection of such companies together with their corresponding strategies, but no shares in any of the companies. The various functionalities of the class are as follows.