Question: CBA # 2 Load the data file, Stocks.dat into the data matrix, x , where the columns are the stock vectors. C D E ]

CBA #2
Load the data file, "Stocks.dat" into the data matrix, x, where the columns are the stock
vectors. C D E]. Plot each column separetely in a single plot (different color) and
observe. Which stocks would you think that has the highest correlation?
Perform statistical normalization: zero mean + unit variance
First perform the MATLAB comment:
Z=zscore(x);
This command shifts and scales the column vectors to be zero-mean and unit-variance. Also
plot the columns of the Z matrix and discuss what you see. Is each column really zero mean
and unit variance? Verify.
Compute and plot the joint pdf
Recall that we can use histograms to "approximate" the true pdf. However, there is no standard
Matlab command to generate a 2D histogram. Use the following code to compute the 2D
histogram first and then to approximate the joint pdf, say, between the 1st and 2nd stocks (e.g.,
x1=A and x2=B). Turn this into a MATLAB function so that you can use it to approximate all
other joint pdf.s (1-3,.,4-5). This code uses Matlab's hist command to compute the 1-D
histogram in an iterative way. The for loop segregates the stocks of x1 by the x1-value bins.
Then for each subset of x1 stocks, it creates a 1-D histogram of the corresponding x2 stocks
and puts them into the appropriate bins in the 2-D histogram. It requires you to set bi ns, which
is the number of bins on each axis. You can use for instance: bins=16.
Next, as for the marginal pdf approximation, we need to normalize the histogram so that the
joint pdf sums up to one:
pdf=n2d.??(??(n2d));
Finally, plot the pdf using one of the following options, so that the pdf is clearly visible.
Image Plot: h=imagesc(x1,x2,pdf); colorbar;
Surface Plot: h=surf(x1,x2,pdf); view (20,30);
Mesh Plot: h=mesh(x1,x2,pdf); view(20,30);
Contour Plot: h=contour(x1,x2,pdf); colorbar;
Do not forget to grid and label your plots. Insert and discuss two different joint pdf plots in
your report. Pick whichever two you think best show the features of your pdf. Estimate the Covariance/Correlation from the joint pdf
As you have the approximated joint pdf, now you can now compute the Covariance for any
pair of stocks using the well-known formula:
cov(x,Y)=xY=(x)?,yinSf(x,y)(x-x)(y-Y)
You can use the following code to implement this summation:
As you statistically normalize the data at the beginning, what do you say about Covariance
and Correlation? Repeat steps 2-3 for other stock pairs (1,3),dots,(4,5). Which pair of stocks is
giving you the highest and least correlation? Put all the cross-correlation results into a 55
Cxy matrix where the (i,j)th and (j,i) th elements will both take the correlation value between
the ith and jth stock. The diagonal elements should be all 1(no need for calcuWHO WANTS TO BE A MILLIONAIRE?
Joint Distribution and Correlation
The weekly rates of return for five stocks listed on the New York Stock Exchange are given in
the file Stocks.dat. Call these stock column vectors: A, B, C, D and E. Let the data matrix be
C In this assignment, first you will approximate the joint distribution of the pair
of stocks. Then you will find the covariance and correlation between each pair of stocks using
the approximated pdf's and directly over the data (sample covariance) too. The idea is to find
out which two stocks have the highest correlation and how to use this information for
investment.
Here are the main steps:
Load Stocks.DAT into MATLAB
Visualize (plot) each of the 5 stocks. OUTPUT: Stock plots.
Perform statistical normalization (zero mean, unit variance) of each stock data vector
OUTPUT: Plots of all normalized stocks
Approximate the joint pdf for your data. OUTPUT: Two different plots of your joint pdf.
Compute the covariance matrix and the correlation coefficient by a) from the joint
pdf.s that are estimated, b) directly from the sample covariance matrix
OUTPUTS: the estimated correlation from the joint pdf.s and estimated correlation
matrix from pdf.s and the sample correlation matrix.
You should create ONLY one technical report (in pdf) containing: comments, discussions,
MATLAB script and all outputs (plots, etc.) of your assignment.
CBA # 2 Load the data file, "Stocks.dat" into the

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!