MATH2070 Computer Project: Organise Porject Fold
MATH2070 Computer Project: Organise Porject Fold
Table of Contents
Organise Porject Fold .......................................................................................................... 1
Start MATLAB ................................................................................................................... 1
Import Data ........................................................................................................................ 1
Create Returns .................................................................................................................... 2
Create Time Series Plots ...................................................................................................... 2
Get Correlation Coefficient Matrix (plots) ............................................................................... 3
The codes below are just some examples for importting data and exploratory data analysis. Hope they can help you to
write your own codes.If you don't know a function, in console window, type the function's name to get information.
Start MATLAB
%to find out your current working directory by typing pwdin console
window
% >> pwd
%>> 'D:\Usyd\2019\S2\MATH2070\Computer Project'
%path of Wen's working directory.
Import Data
Import data as table, matrix, or vectors.
%Import as Table: data object takes more memery, each column has a
name.
%Date will be imported.
%If imported data as Table, name the data as Data_Tbl, say
%Import as matrix, less memery, no names for columns
%Date will not be imported
%If imported as matrix, name the data as data_mt, say
%If imported as vectors, MATLAB will create name for each vector
1
MATH2070 Computer Project
Create Returns
data_ln=log(mydata);
ret_mt=diff(data_ln);
clear data_ln;
%Save all objects
save Project
%A MATLAB data structure named Project.mat will appear in your fold.
%To open this structure,
load Project.mat
figure
plot(ts1)
title('Price of Stock XX')
xlabel('MM/YYYY')
ylabel('US$')
%Try other stocks
%Plot returns
figure
2
MATH2070 Computer Project
plot(ts2)
title('Return of Stock XX')
xlabel('MM/YYYY')
ylabel('%')
[MM,JJ]=max(dum(:))
[J_r J_c]=ind2sub(size(dum),JJ)
[myName(J_r) myName(J_c) dum(J_r, J_c)]
%Scatter plots
figure
subplot(2,1,1)
scatter(ret_mt(:, J_r), ret_mt(:,J_c))
h=lsline;
h.Color='r';
h.LineStyle='--';
subplot(2,1,2)
scatter(ret_mt(:, I_r), ret_mt(:,I_c))
h=lsline;
h.Color='g';
3
MATH2070 Computer Project
h.LineStyle='--';