Question
1) A printed copy of source code to be turned in at the beginning of class 2) A printout of the console output of the
1) A printed copy of source code to be turned in at the beginning of class
2) A printout of the console output of the correlationMatrix contents
3) Email through Canvas a copy of the entire Netbeans project ZIPPED
Objective To master working with File handlers and ArrayLists Overview You are to read and parse the contents of the Stock_Data.txt. The Stock_Data.txt comma delimited file contains historical data on five stocks:
Date,X,GE,APPL,GOOG,F, 8/9/17,23.93,24.69,158.59,922.90,10.36, 8/10/17,23.69,24.29,153.54,907.24,10.22, 8/11/17,23.01,24.20,155.68,914.39,10.22, 8/14/17,23.18,24.35,158.02,922.67,10.35, 8/15/17,23.56,24.14,159.75,922.22,10.28, 8/16/17,24.48,24.10,159.11,926.96,10.25, 8/17/17,23.60,23.76,156.05,910.98,10.09, 8/18/17,23.55,23.57,155.70,910.67,10.02, 8/21/17,23.17,23.51,155.41,906.66,10.03, 8/22/17,24.10,23.62,157.95,924.69,10.10, 8/23/17,24.73,23.42,158.15,927.00,10.16, 8/24/17,24.65,23.33,157.45,921.28,10.16, 8/25/17,24.78,23.51,158.03,915.89,10.27, 8/28/17,25.14,23.49,159.62,913.81,10.24, 8/29/17,25.80,23.47,161.05,921.29,10.28, 8/30/17,26.68,23.31,161.48,929.57,10.38, 8/31/17,26.44,23.57,162.12,939.33,10.46, 9/1/17,26.82,24.14,162.17,937.34,10.77, 9/5/17,27.06,23.76,160.23,928.45,10.78, 9/6/17,27.34,23.93,160.06,927.81,10.91, 9/7/17,27.51,23.06,159.42,935.95,10.82, 9/8/17,26.79,22.87,156.82,926.50,10.78, 9/11/17,26.69,22.77,159.65,929.08,10.83, 9/12/17,26.49,22.96,159.02,932.07,11.00, 9/13/17,26.49,23.15,157.82,935.09,11.02, 9/14/17,25.45,23.29,156.47,925.11,10.97, 9/15/17,24.93,23.21,158.05,920.29,11.02, 9/18/17,25.37,23.72,156.85,915.00,11.03, 9/19/17,25.49,23.47,156.91,921.81,11.12, 9/20/17,25.63,23.58,154.28,931.58,11.11, 9/21/17,24.51,24.00,151.64,932.45,11.12, 9/22/17,23.68,24.12,150.15,928.53,11.23, 9/25/17,23.90,24.35,148.83,920.97,11.33, 9/26/17,24.21,24.18,151.39,924.86,11.32, 9/27/17,25.03,23.63,152.47,944.49,11.34, 9/28/17,25.28,23.51,151.53,949.50,11.35, 9/29/17,25.50,23.45,152.36,959.11,11.36, 10/2/17,25.97,23.83,152.05,953.27,11.47, 10/3/17,26.15,24.05,152.71,957.79,11.71, 10/4/17,26.29,23.74,151.72,951.68,11.67, 10/5/17,26.37,23.80,153.61,969.96,11.62, 10/6/17,25.89,23.65,153.52,978.89,11.68, 10/9/17,24.86,22.72,154.06,977.00,11.71, 10/10/17,24.82,22.65,154.12,972.60,11.76, 10/11/17,25.04,22.37,154.76,989.25,11.75, 10/12/17,25.40,22.35,154.22,987.83,11.50, 10/13/17,27.19,22.28,155.19,989.68,11.43, 10/16/17,26.50,22.65,158.05,992.00,11.50, 10/17/17,26.46,22.49,158.63,992.18,11.64, 10/18/17,27.08,22.42,157.93,992.81,11.57, 10/19/17,27.51,22.87,154.20,984.45,11.60, 10/20/17,28.25,23.11,154.46,988.20,11.62, 10/23/17,27.81,21.64,154.38,968.45,11.57, 10/24/17,28.51,21.23,155.30,970.54,11.71, 10/25/17,27.93,20.85,154.62,973.33,11.57, 10/26/17,27.52,20.67,155.61,972.56,11.79, 10/27/17,26.91,20.16,161.18,1019.27,11.58, 10/30/17,26.29,19.79,164.81,1017.11,11.62, 10/31/17,25.16,19.55,167.11,1016.64,11.79, 11/1/17,27.13,19.41,164.98,1025.50,11.86, 11/2/17,27.42,19.34,166.19,1025.58,11.93, 11/3/17,26.87,19.53,170.53,1032.48,11.87, 11/6/17,27.34,19.52,172.26,1025.90,11.84, 11/7/17,26.78,19.60,172.81,1033.33,11.68, 11/8/17,27.10,19.51,174.22,1039.85,11.58, 11/9/17,26.98,19.38,173.87,1031.26,11.57, 11/10/17,27.34,19.87,173.29,1028.07,11.54, 11/13/17,27.50,18.44,172.60,1025.75,11.68, 11/14/17,26.55,17.36,169.99,1026.00,11.55, 11/15/17,26.99,17.71,167.75,1020.91,11.53, 11/16/17,27.01,17.70,169.75,1032.50,11.57, 11/17/17,27.16,17.66,168.81,1019.09,11.54, 11/20/17,27.73,17.44,168.64,1018.38,11.65, 11/21/17,28.03,17.29,171.77,1034.49,11.64, 11/22/17,28.38,17.60,173.58,1035.96,11.59, 11/24/17,29.08,17.64,173.59,1040.61,11.62, 11/27/17,28.67,17.57,172.72,1054.21,11.63, 11/28/17,28.48,17.85,171.71,1047.41,11.73, 11/29/17,28.50,17.92,168.14,1021.66,12.06, 11/30/17,28.79,17.74,170.49,1021.41,12.03, 12/1/17,29.17,17.34,169.70,1010.17,12.08, 12/4/17,29.71,17.41,168.46,998.68,12.13, 12/5/17,29.70,17.22,168.30,1005.15,11.94, 12/6/17,30.97,17.24,167.68,1018.38,11.89, 12/7/17,31.71,17.29,167.98,1030.93,12.04, 12/8/17,33.08,17.29,168.03,1037.05,12.11, 12/11/17,33.27,17.23,171.31,1041.10,12.08, 12/12/17,32.85,17.49,170.35,1040.48,12.10, 12/13/17,32.69,17.34,170.91,1040.61,12.13, 12/14/17,31.59,17.22,170.86,1049.15,11.97, 12/15/17,31.71,17.40,172.60,1064.19,12.08, 12/18/17,33.28,17.34,175.03,1077.14,12.16, 12/19/17,33.69,17.17,173.16,1070.68,12.19, 12/20/17,34.22,17.04,172.98,1064.95,12.22, 12/21/17,35.51,17.06,173.63,1063.63,12.13, 12/22/17,34.95,17.09,173.63,1060.12,12.08, 12/26/17,35.19,17.13,169.22,1056.74,12.10, 12/27/17,34.86,17.09,169.25,1049.37,12.01, 12/28/17,35.58,17.07,169.73,1048.14,12.08, 12/29/17,35.03,17.15,167.90,1046.40,12.00, 1/2/18,37.25,17.68,170.90,1065.00,12.16, 1/3/18,37.32,17.84,170.87,1082.48,12.26, 1/4/18,37.70,18.22,171.67,1086.40,12.47, 1/5/18,38.32,18.23,173.62,1102.23,12.68, 1/8/18,39.24,17.97,172.98,1106.94,12.63, 1/9/18,38.24,18.25,172.96,1106.26,12.56, 1/10/18,39.03,18.61,172.92,1102.61,12.52, 1/11/18,39.34,18.70,173.90,1105.52,12.64, 1/12/18,38.97,18.44,175.69,1122.26,12.71, 1/16/18,38.50,17.90,174.80,1121.76,12.58, 1/17/18,39.13,17.06,177.69,1131.98,11.70, 1/18/18,38.86,16.49,177.85,1129.79,11.59, 1/19/18,38.60,15.98,177.05,1137.51,11.53, 1/22/18,39.13,15.90,175.60,1155.81,11.55, 1/23/18,39.88,16.60,175.64,1169.97,11.49, 1/24/18,39.81,16.16,172.85,1164.24,11.57, 1/25/18,40.09,15.91,169.76,1170.37,11.11, 1/26/18,40.77,15.86,170.16,1175.84,11.19, 1/29/18,40.97,16.00,166.64,1175.58,10.82, 1/30/18,38.44,15.68,165.65,1163.69,10.76, 1/31/18,37.24,15.90,166.11,1169.94,10.67, 2/1/18,36.45,15.75,166.46,1167.70,10.63, 2/2/18,34.43,15.38,159.23,1111.90,10.42, 2/5/18,33.87,14.66,155.26,1055.80,9.96, 2/6/18,35.15,15.01,161.74,1080.60,10.47, 2/7/18,35.17,14.99,158.28,1048.58,10.47, 2/8/18,33.85,14.21,153.93,1001.52,10.15, 2/9/18,34.14,14.69,155.81,1037.78,10.25, 2/12/18,36.11,14.57,162.08,1051.94,10.41, 2/13/18,36.69,14.42,163.71,1052.10,10.30, 2/14/18,38.57,14.65,166.73,1069.70,10.45, 2/15/18,38.87,14.60,172.33,1089.52,10.47, 2/16/18,44.61,14.80,171.77,1094.80,10.32, 2/20/18,44.69,14.49,171.19,1102.46,10.34, 2/21/18,42.73,14.24,170.41,1111.34,10.31, 2/22/18,42.85,14.37,171.84,1106.63,10.34, 2/23/18,43.39,14.36,174.83,1126.79,10.41, 2/26/18,44.23,14.52,178.28,1143.75,10.60, 2/27/18,43.87,14.37,177.70,1118.29,10.32, 2/28/18,43.38,13.99,177.44,1104.73,10.32, 3/1/18,45.87,13.90,174.33,1069.52,10.01, 3/2/18,45.25,14.00,175.53,1078.92,10.12, 3/5/18,44.61,14.29,176.14,1090.93,10.30, 3/6/18,44.39,14.51,175.99,1095.06,10.34, 3/7/18,45.55,14.38,174.36,1109.64,10.34, 3/8/18,44.22,14.39,176.26,1126.00,10.32, 3/9/18,43.56,14.81,179.29,1160.04,10.44, 3/12/18,43.44,14.97,181.02,1164.50,10.52, 3/13/18,40.12,14.30,179.28,1138.17,10.49, 3/14/18,38.26,14.14,177.75,1149.49,10.72, 3/15/18,38.31,14.23,177.96,1149.58,10.77, 3/16/18,39.84,14.18,177.34,1135.73,10.85, 3/19/18,38.94,13.95,174.63,1099.82,10.71, 3/20/18,38.40,13.52,174.57,1097.71,10.69, 3/21/18,38.64,13.76,170.61,1090.88,10.80, 3/22/18,34.39,13.23,168.20,1049.08,10.46, 3/23/18,33.84,12.96,164.31,1021.57,10.28, 3/26/18,35.29,12.78,172.11,1053.21,10.54, 3/27/18,33.57,13.32,167.69,1005.10,10.54, 3/28/18,33.44,13.56,165.84,1004.56,10.57, 3/29/18,35.08,13.36,167.14,1031.79,10.78, 4/2/18,34.12,13.00,166.04,1006.47,10.57, 4/3/18,34.89,13.01,167.74,1013.41,10.85, 4/4/18,34.88,13.16,170.95,1025.14,11.03, 4/5/18,36.50,13.31,172.14,1027.81,11.04, 4/6/18,34.39,12.95,167.73,1007.04,10.88, 4/9/18,34.68,12.72,169.40,1015.45,10.95, 4/10/18,35.77,12.94,172.58,1031.64,11.14, 4/11/18,34.63,12.86,171.78,1019.97,11.12, 4/12/18,35.77,13.06,173.47,1032.51,11.01, 4/13/18,35.40,13.37,174.06,1029.27,10.98, 4/16/18,35.64,13.21,175.14,1037.98,11.07, 4/17/18,36.25,13.67,177.56,1074.16,11.07, 4/18/18,37.39,13.54,177.16,1072.08,11.03, 4/19/18,37.23,13.87,172.14,1087.70,10.81, 4/20/18,36.54,14.41,165.08,1072.96,10.67, 4/23/18,36.42,14.39,164.61,1067.45,10.89, 4/24/18,36.36,14.55,162.31,1019.98,10.81, 4/25/18,36.94,13.93,163.02,1021.18,10.96, 4/26/18,37.59,14.25,163.59,1040.04,11.27, 4/27/18,32.27,14.25,161.70,1030.05,11.33, 4/30/18,33.73,13.95,164.63,1017.33,11.08, 5/1/18,32.09,13.93,168.45,1037.31,11.10, 5/2/18,32.15,14.06,175.89,1024.38,11.05, 5/3/18,32.81,13.81,176.21,1023.72,11.04, 5/4/18,34.41,13.98,183.12,1048.21,11.20, 5/7/18,34.40,13.95,184.45,1054.79,11.18, 5/8/18,34.49,14.14,185.34,1053.91,11.11, 5/9/18,34.90,14.49,186.64,1082.76,10.91, 5/10/18,35.84,14.56,189.31,1097.57,11.05, 5/11/18,35.70,14.47,188.59,1098.26,11.03, 5/14/18,36.24,14.58,188.15,1100.20,11.03, 5/15/18,35.80,14.58,186.44,1079.23,11.06, 5/16/18,37.45,14.90,188.18,1081.77,11.24, 5/17/18,37.48,14.90,186.99,1078.59,11.30, 5/18/18,36.40,14.84,186.31,1066.36,11.17, 5/21/18,35.00,15.13,187.63,1079.58,11.35, 5/22/18,35.75,15.16,187.16,1069.73,11.36, 5/23/18,35.38,14.06,188.36,1079.69,11.28, 5/24/18,35.71,14.47,188.15,1079.24,11.46, 5/25/18,35.33,14.50,188.58,1075.66,11.35, 5/29/18,35.16,14.06,187.90,1060.32,11.28, 5/30/18,36.19,14.05,187.50,1067.80,11.39, 5/31/18,36.81,13.96,186.87,1084.99,11.39, 6/1/18,37.63,13.98,190.24,1119.50,11.55, 6/4/18,37.21,13.59,191.83,1139.29,11.58, 6/5/18,36.80,13.68,193.31,1139.66,11.67, 6/6/18,37.49,13.52,193.98,1136.88,11.80, 6/7/18,36.76,13.66,193.46,1123.86,11.86, 6/8/18,37.10,13.81,191.70,1120.87,11.93, 6/11/18,37.02,13.86,191.23,1129.99,11.86, 6/12/18,37.52,13.86,192.28,1139.32,11.94, 6/13/18,37.32,13.77,190.70,1134.79,11.85, 6/14/18,37.56,13.52,190.80,1152.12,11.73, 6/15/18,35.99,13.30,188.84,1152.26,11.72, 6/18/18,36.06,13.20,188.74,1173.46,11.82, 6/19/18,35.09,12.95,185.69,1168.06,11.73, 6/20/18,35.67,12.88,186.50,1169.84,11.71, 6/21/18,35.34,12.76,185.46,1157.66,11.55, 6/22/18,36.85,13.05,184.92,1155.48,11.49, 6/25/18,34.46,12.75,182.17,1124.81,11.34, 6/26/18,35.27,13.74,184.43,1118.46,11.36, 6/27/18,34.41,13.96,184.16,1103.98,11.26, 6/28/18,34.59,13.83,185.50,1114.22,11.12, 6/29/18,34.69,13.61,185.11,1115.65,10.92, 7/2/18,35.07,13.37,187.18,1127.46,10.95, 7/3/18,33.88,13.37,183.92,1102.89,10.84, 7/5/18,34.92,13.43,185.40,1124.27,10.90, 7/6/18,35.28,13.85,187.97,1140.17,10.91, 7/9/18,35.47,13.95,190.58,1154.05,11.04, 7/10/18,36.47,14.17,190.35,1152.84,11.09, 7/11/18,36.22,13.99,187.88,1153.90,10.92, 7/12/18,35.88,13.99,191.03,1183.48,10.90, 7/13/18,36.15,13.89,191.33,1188.82,10.83, 7/16/18,35.87,13.90,190.91,1183.86,10.70, 7/17/18,36.35,13.69,191.45,1198.80,10.71, 7/18/18,37.71,13.75,190.40,1195.88,10.72, 7/19/18,36.87,13.73,191.88,1186.96,10.67, 7/20/18,37.07,13.12,191.44,1184.91,10.56, 7/23/18,37.38,12.99,191.61,1205.50,10.47, 7/24/18,37.81,13.12,193.00,1248.08,10.57, 7/25/18,38.20,13.11,194.82,1263.70,10.52, 7/26/18,37.18,13.15,194.21,1268.33,9.89, 7/27/18,36.94,13.06,190.98,1238.50,9.93, 7/30/18,36.75,13.16,189.91,1219.74,10.07, 7/31/18,36.37,13.63,190.29,1217.26,10.04, 8/1/18,35.75,13.24,201.50,1220.01,9.90, 8/2/18,32.08,13.17,207.39,1226.15,9.92, 8/3/18,32.25,13.14,207.99,1223.71,10.04, 8/6/18,31.44,13.10,209.07,1224.77,10.03, 8/7/18,31.18,13.16,207.11,1242.22,10.08, 8/8/18,30.77,13.05,207.25,1245.61,10.05,
You are to store the data for each stock into an ArrayList for example ArrayList x_stockPrices = new ArrayList(); Then you need to calculate the correlation matrix and display it in the console. Note the correlation matrix is a 2D ArrayList i.e ArrayList> correlationMatrix = new ArrayList>(); Here are some useful formulas you need to complete the project. If you have any questions, please ask me I am here to help you.
What you need to do
1) You need to read store the stock price contents Stock_Data.txt for each stock into an ArrayList. Heads up remembered that the stock data file has a header that you need to deal with. Note, you will find the Stock_Data.txt file in the data folder of the Netbeans skeleton project provided to you. Example: ArrayList x_stockPrices = new ArrayList();
2) Implement the following methods: public static double findAverage(ArrayList prices) public static double findStandardDeviation(ArrayList prices) public static double findCorrelation(ArrayList firstPrices, ArrayList secondPrices )
3) Create ArrayList that store each stock correlation values against the other stocks. Example: ArrayList xCorrelations = new ArrayList();
4) Create a 2D ArrayList called correlationMatrix at stores all the stock correlations Example: ArrayList> correlationMatrix = new ArrayList>();
5) Output the contents of the correlationMatrix to the console and print out the values: Examples:
package project1;
//--------------------------------------------------
// Imports
//--------------------------------------------------
import java.io.*;
import java.util.*;
public class Project1 {
public static void main(String[] args) {
// The name of the file to open.
// notice that the StockPrice_X_Data.txt is in the data package
String fileName = "src/data/Stock_Data.txt";
// This will reference one line at a time
String line = null;
try {
// FileReader reads text files in the default encoding.
FileReader fileReader = new FileReader(fileName);
// Always wrap FileReader in BufferedReader.
BufferedReader bufferedReader = new BufferedReader(fileReader);
//PUT CODE HERE
// Always close files.
bufferedReader.close();
//------------------------------------------------------------------
// Doing some calculations
//------------------------------------------------------------------
//PUT CODE HERE
// handle errors if they arise
} catch(FileNotFoundException ex) {
System.out.println(
"Unable to open file '" +
fileName + "'");
} catch(IOException ex) {
System.out.println(
"Error reading file '"
+ fileName + "'");
}//end try
}// end main()
//------------------------------------------------------------------------------
// helper functions/
//------------------------------------------------------------------------------
public static double findAverage(ArrayList
double average = 0.0;
//PUT CODE HERE
return average;
}//end findAverage()
//--------------------------------------------------------------------------
public static double findStandardDeviation(ArrayList
double stdDev = 0.0;
//PUT CODE HERE
return stdDev;
}
//--------------------------------------------------------------------------
public static double findCorrelation(ArrayList
double correlation = 0.0 ;
//PUT CODE HERE
return correlation;
}//end findCorrelation()
}
Output Projectl (run) run: 1 0.1%-0.11 [1:0, -0.19, [-0.79, 1., -0.75, -0.78, 0.151 0.57, -0.75, 1.0, 0.84,-0.051 [0.75, -0.78, 0.84, 1.0, -0.07] [-0.1, 0.15, -0.05, -0.07, 1.0 BUILD SUCCESSFUL (total time: 0 seconds) 0.57, Output Projectl (run) run: 1 0.1%-0.11 [1:0, -0.19, [-0.79, 1., -0.75, -0.78, 0.151 0.57, -0.75, 1.0, 0.84,-0.051 [0.75, -0.78, 0.84, 1.0, -0.07] [-0.1, 0.15, -0.05, -0.07, 1.0 BUILD SUCCESSFUL (total time: 0 seconds) 0.57Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started