Assignment 3 - Processing Mutual Fund Data with a 2-Dimensional Array

due October 15th

The purpose of this assignment is the use of 2-dimensional arrays, reading and writing text files, writing functions, performing calculations, and program planning and development.

You will read an original input file and write it back out in a modified forrmat.  You will then read the modifed file storing some of the data in a 2-dimensional array.  The array will need to be sorted in different orders and processed. 

Step-by-step Instructions

  1. Read in the original file, VTSMX.csv, partially shown below. Write that data out into a second file, VTSMXmodified.csv, partially displayed below.  The second file should have the headings removed and the commas replaced by spaces.  The original file contains 501 records and the modified file should contain 500 records.
  2. Read in the modified file into a 2-dimensional int array with 500 rows and two columns.  You should store the first column of data (the Date) and the fifth column of data (the Close) into the two columns of your array.  Note, the floating point Close value should be converted to a rounded int value.  Sample array values are shown below.  Note, the original data is sorted in ascending order by date.
  3. Write a sort function that will allow you to sort the array data by either column in ascending or descending order.
  4. Produce the report shown below, matching exactly the formats shown.  You will need to sort the array a few times to produce the desired results.

Input File (VTSMX.csv)  [file updated 10/8/18]

Date,Open,High,Low,Close,Adj Close,Volume
2016-10-10,54.070000,54.070000,54.070000,54.070000,52.190102,0
2016-10-11,53.360001,53.360001,53.360001,53.360001,51.504784,0
2016-10-12,53.419998,53.419998,53.419998,53.419998,51.562695,0
2016-10-13,53.230000,53.230000,53.230000,53.230000,51.379307,0
2016-10-14,53.209999,53.209999,53.209999,53.209999,51.360001,0
2016-10-17,53.070000,53.070000,53.070000,53.070000,51.224869,0
2016-10-18,53.389999,53.389999,53.389999,53.389999,51.533741,0
2016-10-19,53.529999,53.529999,53.529999,53.529999,51.668877,0
2016-10-20,53.450001,53.450001,53.450001,53.450001,51.591660,0
...

Modified Input File (VTSMXmodified.csv)

2016-10-10 54.070000 54.070000 54.070000 54.070000 52.190102 0
2016-10-11 53.360001 53.360001 53.360001 53.360001 51.504784 0
2016-10-12 53.419998 53.419998 53.419998 53.419998 51.562695 0
2016-10-13 53.230000 53.230000 53.230000 53.230000 51.379307 0
2016-10-14 53.209999 53.209999 53.209999 53.209999 51.360001 0
2016-10-17 53.070000 53.070000 53.070000 53.070000 51.224869 0
2016-10-18 53.389999 53.389999 53.389999 53.389999 51.533741 0
2016-10-19 53.529999 53.529999 53.529999 53.529999 51.668877 0
2016-10-20 53.450001 53.450001 53.450001 53.450001 51.591660 0
...

Array Data

20161010   5407
20161011   5336
20161012   5342
20161013   5323
20161014   5321
20161017   5307
20161018   5339
20161019   5353
20161020   5345
20161021   5344
...

Program Output

Current Date: 10/03/18
Current Close: $72.93

The latest five closes are:
10/03/18   $72.93
10/02/18   $72.81
10/01/18   $72.93
09/28/18   $72.82
09/27/18   $72.79

The oldest five closes are:
10/10/16   $54.07
10/11/16   $53.36
10/12/16   $53.42
10/13/16   $53.23
10/14/16   $53.21

The five highest closes are:
09/20/18   $73.61
09/21/18   $73.55
09/24/18   $73.28
08/29/18   $73.27
09/25/18   $73.23

Percent gain YTD: 9.34%

50 Day Moving Average: $72.18
200 Day Moving Average: $69.18
Percent gain over 200 Day Moving Average: 5.42%
Recommendation: Sell



Program requirements

  1. You must use a 2-dimensional array for all of the data.
  2. Your output must match the sample output exactly.
  3. Do not "hard-code" any of the output values.  All dates and numbers must be retrieved from the array or calculated.  Your program will be tested using a file with newer input data.
  4. Your solution must include at least 5 functions.  And ...
  5. All files must be checked for a successful open.

Formulas and Calculations

  1. The current date and current close represents the newest data that is stored.
  2. The percent gain YTD (year to date) represents the gain since the last date of the previous year (2017).  The gain (YTD) is calculated by subtracting the last close of the last year from the current close.  The percent gain (YTD) is then calculated by dividing the gain (YTD) by the last close of the last year and expressing that result as a percent.  Note, for this calculation, you will have to determine the the last close of the last year.
  3. The 50 day moving average is calculated by taking the average of the last 50 close values.
  4. The 200 day moving average is calculated by taking the average of the last 200 close values.
  5. The Percent gain over the 200 day moving average is determined by first determining the gain over the 200 day moving average.  That is the difference between the latest close and the 200 day moving average,  To calculate the percent gain, divide the gain by the 200 day moving average and express that result as a percent.
  6. The recommendation (Buy/Sell/Hold) is:  
if the percent gain over the 200 day moving average is greater than 5%, you should sell
if the percent gain over the 200 day moving average is less than -5%, you should buy
otherwise, you should hold