MATH2070 Computer Project 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 dont know a function, in console window, type the functions name to get information.
Organise Porject Fold
Create a folder named MATH2070 or MATH2090, if you have not done so
yet.
In MATH2070, create another folder named as Computer Project
Save data csv file and OFM project 2019 pdf file into the
folder.
Start MATLAB
to find out your current working directory by typing pwdin console
window
pwd
D:Usyd2019S2MATH2070Computer Project
path of Wens working directory.
If your working directory is not the one data is saved,
in console window typing
cd project fold path
Check if the directory has been changed:
pwd
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 DataTbl, say
Import as matrix, less memery, no names for columns
Date will not be imported
If imported as matrix, name the data as datamt, say
If imported as vectors, MATLAB will create name for each vector
1
MATH2070 Computer Project
sizeDataTbl1698 rows, 33 columns
Get varaible names
VarNamesDataTbl.Properties.VariableNames;
VarNames
delete columns 1 and 10 from matrix,
mydatadatamt;
mydata:, 1 10;
delete column from a table:
myTblDataTbl;
myTblremovevarsmyTbl, DowInc;
Create Returns
datalnlogmydata;
retmtdiffdataln;
clear dataln;
Save all objects
save Project
A MATLAB data structure named Project.mat will appear in your fold.
To open this structure,
load Project.mat
Create Time Series Plots
ts1timeseriesmydata:, 1,1:1698; convert a column of a matrix
into a time series
ts1.TimeInfo.StartDate01Jan2013;Set starting date
ts1.Timets1.Timets1.Time1;
start date.
ts1.NameStock xx;
ts1.TimeInfo.Unitsdays;
ts1.TimeInfo.Formatmmmyyyy;
figure
plotts1
titlePrice of Stock XX
xlabelMMYYYY
ylabelUS
Try other stocks
Plot returns
Express time relative to the
convert a column of a matrix into a time series
ts.2TimeInfo.StartDate01Jan2013;Set starting date
ts2.Timets2.Timets2.Time1;
start date.
ts2.NameStock xx;
ts2.TimeInfo.Unitsdays;
ts2.TimeInfo.Formatmmmyyyy;
figure
Express time relative to the
2
MATH2070 Computer Project
plotts2
titleReturn of Stock XX
xlabelMMYYYY
ylabel
Get minimum returns and dates
retmin, minindminretmt;
myNameVarNames;
myName1 10;
retminmyName, retmin, Datesminind;
Get Correlation Coefficient Matrix plots
retcorrcorrretmt;
or
rrcorrplotretmt;
Convert matrix to table:
retcorrTblarray2tableretcorr, VariableNames,myName, RowName,
myName;
Export data
writetableretcorrTbl , COrrelationMatrix.xlsx,Sheet,1,Range,A1, WriteR
Get minimum corr
corrmin1, minind1minretcorr;
corrmin, corrminindminminretmt;
corr1, ind1findretcorrcorrmin
corrmin1corrminind
xretcorr;
mm,iiminx:
Ir Icind2subsizex,ii
myNameIr myNameIc xIr, Ic
Get max corrretcorr
dumretcorr;
for i1:sizeretcorr, 1
dumi,i0
end;
MM,JJmaxdum:
Jr Jcind2subsizedum,JJ
myNameJr myNameJc dumJr, Jc
Scatter plots
figure
subplot2,1,1
scatterretmt:, Jr, retmt:,Jc
hlsline;
h.Colorr;
h.LineStyle;
subplot2,1,2
scatterretmt:, Ir, retmt:,Ic
hlsline;
h.Colorg;
3
h.LineStyle;
Published with MATLAB R2018a
MATH2070 Computer Project
4
Reviews
There are no reviews yet.