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 #
Load the data file, "Stocks.dat" into the data matrix, 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:
zscore;
This command shifts and scales the column vectors to be zeromean and unitvariance. Also
plot the columns of the 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 D histogram. Use the following code to compute the D
histogram first and then to approximate the joint pdf say, between the and stocks eg
A and Turn this into a MATLAB function so that you can use it to approximate all
other joint pdfs This code uses Matlab's hist command to compute the D
histogram in an iterative way. The for loop segregates the stocks of by the value bins.
Then for each subset of stocks, it creates a D histogram of the corresponding stocks
and puts them into the appropriate bins in the D histogram. It requires you to set bi ns which
is the number of bins on each axis. You can use for instance: bins
Next, as for the marginal pdf approximation, we need to normalize the histogram so that the
joint pdf sums up to one:
;
Finally, plot the pdf using one of the following options, so that the pdf is clearly visible.
Image Plot: imagesc; colorbar;
Surface Plot: surf; view ;
Mesh Plot: mesh; view;
Contour Plot: contour; 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 CovarianceCorrelation 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 wellknown formula:
covyinSf
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 for other stock pairs dots, Which pair of stocks is
giving you the highest and least correlation? Put all the crosscorrelation results into a
Cxy matrix where the ijth and th elements will both take the correlation value between
the and stock. The diagonal elements should be all 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 pdfs 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 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
pdfs that are estimated, b directly from the sample covariance matrix
OUTPUTS: the estimated correlation from the joint pdfs and estimated correlation
matrix from pdfs 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.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
