MATLAB Quesion The ’YahooStocks.txt’ and ’AmazonStocks.txt’ file contains stock
ID: 3681583 • Letter: M
Question
MATLAB Quesion
The ’YahooStocks.txt’ and ’AmazonStocks.txt’ file contains stock price data from Yahoo, Inc. and Amazon, Inc. shares from January, 2000 till March, 2016. For each day, the field ’Open’ shows the opening price, the field ’Close’ shows the closing price, the field ’High’ shows the highest price during the day and the field ’Low’ shows the lowest price during the day. Further, ’Volume’ is the total number of stocks exchanged (sold and bought) during a day. For this data file, please implement a MATLAB file that answers the following questions: 1 a. Read the data from the Yahoo input file and create following vector variables: date, open, close, high, low, volume. Please be careful with the type (String, double etc.) of each column in the input file. Hint: The date is not a single numerical value, and therefore cannot be read into a vector using ’fscanf’. To address this, read the date as 3 separate numbers for day, month and year using the ’fscanf’ function or read the file second time using the ’textscan’ function to extract the date. b. Assuming on day 1 (January, 3rd 2000), a customer bought $10000 worth of shares and holds this stock, without conducting any additional transactions. What is the value of this stock on March 14th 2016? Your program should work with both data files by only modifying the filename in one line in the program. Use the following format to print out the result for both files and complete the missing parts: Initial money Final money Profit (Percentage) 10000 ..... ... c. Given the same assumptions as in subquestion b, what is the best and worst day in year 2000 that the investor could have chosen in order to maximize profit (instead of Jan 3rd, 2000) for both stocks? d. What is the expected profit if the investor chooses a random day in 2000 (each day being equally likely) for both stocks? Hint: calculate the profit for every day in 2000 and then take the mean.
Explanation / Answer
x = [1 2 3 4 5 6 7 8 9 10];
y1 = [.16 .08 .04 .02 .013 .007 .004 .002 .001 .0008 ];
y2 = [.16 .07 .03 .01 .008 .003 .0008 .0003 .00007 .00002 ];
semilogy(x,y1,'-bo;y1;',x,y2,'-kx;y2;');
title('Plot title');
xlabel('X Axis');
ylabel('Y Axis');
print -dpdf graph.pdf
filename='yahoostocks.txt';
t=readfile(filename);
[nrows, ncols] = size(filename,'yahoostocks');
avgs = zeros(1,ncols);
for idx = 1:ncols
avgs(idx) = mean(filename.yahoostocks(:,idx));
end
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.