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

due October 16th

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 hyphens removed, and the commas should be 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)

Date,Open,High,Low,Close,Adj Close,Volume
2015-08-31,49.759998,49.759998,49.759998,49.759998,47.914398,0
2015-09-01,48.320000,48.320000,48.320000,48.320000,46.527809,0
2015-09-02,49.180000,49.180000,49.180000,49.180000,47.355907,0
2015-09-03,49.250000,49.250000,49.250000,49.250000,47.423309,0
2015-09-04,48.549999,48.549999,48.549999,48.549999,46.749268,0
2015-09-08,49.750000,49.750000,49.750000,49.750000,47.904774,0
2015-09-09,49.090000,49.090000,49.090000,49.090000,47.269253,0
2015-09-10,49.320000,49.320000,49.320000,49.320000,47.490723,0
2015-09-11,49.560001,49.560001,49.560001,49.560001,47.721821,0

...

Modified Input File (VTSMXmodified.csv)

20150831 49.759998 49.759998 49.759998 49.759998 47.914398 0
20150901 48.320000 48.320000 48.320000 48.320000 46.527809 0
20150902 49.180000 49.180000 49.180000 49.180000 47.355907 0
20150903 49.250000 49.250000 49.250000 49.250000 47.423309 0
20150904 48.549999 48.549999 48.549999 48.549999 46.749268 0
20150908 49.750000 49.750000 49.750000 49.750000 47.904774 0
20150909 49.090000 49.090000 49.090000 49.090000 47.269253 0
20150910 49.320000 49.320000 49.320000 49.320000 47.490723 0
20150911 49.560001 49.560001 49.560001 49.560001 47.721821 0

...

Array Data

20150831   4976
20150901   4832
20150902   4918
20150903   4925
20150904   4855
20150908   4975
20150909   4909
20150910   4932
20150911   4956
20150914   4936
...

Program Output

Current Date: 08/23/17
Current Close: $60.94

The latest five closes are:
08/23/17   $60.94
08/22/17   $61.12
08/21/17   $60.51
08/18/17   $60.45
08/17/17   $60.56

The oldest five closes are:
08/31/15   $49.76
09/01/15   $48.32
09/02/15   $49.18
09/03/15   $49.25
09/04/15   $48.55

The five highest closes are:
07/25/17   $61.96
07/26/17   $61.93
08/07/17   $61.87
07/27/17   $61.83
07/19/17   $61.83

Percent gain YTD: 8.70%

50 Day Moving Average: $61.26
200 Day Moving Average: $58.89
Percent gain over 200 Day Moving Average: 3.48%
Recommendation: Hold


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 (2016).  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