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-10-16,50.860001,50.860001,50.860001,50.860001,49.009617,0
2015-10-19,50.880001,50.880001,50.880001,50.880001,49.028889,0
2015-10-20,50.810001,50.810001,50.810001,50.810001,48.961437,0
2015-10-21,50.439999,50.439999,50.439999,50.439999,48.604893,0
2015-10-22,51.200001,51.200001,51.200001,51.200001,49.337242,0
2015-10-23,51.720001,51.720001,51.720001,51.720001,49.838326,0
2015-10-26,51.610001,51.610001,51.610001,51.610001,49.732330,0
2015-10-27,51.419998,51.419998,51.419998,51.419998,49.549244,0
2015-10-28,52.130001,52.130001,52.130001,52.130001,50.233410,0
2015-10-29,52.049999,52.049999,52.049999,52.049999,50.156319,0
...

Modified Input File (VTSMXmodified.csv)

20151016 50.860001 50.860001 50.860001 50.860001 49.009617 0
20151019 50.880001 50.880001 50.880001 50.880001 49.028889 0
20151020 50.810001 50.810001 50.810001 50.810001 48.961437 0
20151021 50.439999 50.439999 50.439999 50.439999 48.604893 0
20151022 51.200001 51.200001 51.200001 51.200001 49.337242 0
20151023 51.720001 51.720001 51.720001 51.720001 49.838326 0
20151026 51.610001 51.610001 51.610001 51.610001 49.732330 0
20151027 51.419998 51.419998 51.419998 51.419998 49.549244 0
20151028 52.130001 52.130001 52.130001 52.130001 50.233410 0
20151029 52.049999 52.049999 52.049999 52.049999 50.156319 0
...

Array Data

20151016   5086
20151019   5088
20151020   5081
20151021   5044
20151022   5120
20151023   5172
20151026   5161
20151027   5142
20151028   5213
20151029   5205
...

Program Output

Current Date: 10/10/17
Current Close: $63.84

The latest five closes are:
10/10/17   $63.84
10/09/17   $63.69
10/06/17   $63.83
10/05/17   $63.89
10/04/17   $63.55

The oldest five closes are:
10/16/15   $50.86
10/19/15   $50.88
10/20/15   $50.81
10/21/15   $50.44
10/22/15   $51.20

The five highest closes are:
10/05/17   $63.89
10/10/17   $63.84
10/06/17   $63.83
10/09/17   $63.69
10/04/17   $63.55

Percent gain YTD: 13.88%

50 Day Moving Average: $62.02
200 Day Moving Average: $60.00
Percent gain over 200 Day Moving Average: 6.41%
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 (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