Technical Analysis using MATLAB
using Financial Time Series
Focus on Moving average and
Bollinger Bands
By Shivgan Joshi
Qcfinance.in
Caution
MATLAB is case sensitive
Difference formats to get data in the FTS
Object
1. From CSV
2. From file directly
3. From the .dat file
. Using ascii2fints carefully by specifying the right
parameters
Input CSV Method 1
filename = 'csvlist.dat'; M = csvread(filename)
Make sure it is numeric format
Then create fts object from matrices
http://in.mathworks.com/help/matlab/ref/csvr
ead.html
Inputting Data
.dat are tab delimited data which can be saved using
excel txt save
myinc = ascii2fts('input.dat');
An alternative is the load command to bring all
variables from a file into the current variables
ASCII2FTS is an important conversion function
http://in.mathworks.com/help/finance/ascii2fts.ht
ml
http://in.mathworks.com/help/finance/technical-an
Code Part 1
Use GUI to import the FTS
Things work with the close price so all other
prices dont matter
macd_input = macd(input);
Code for Moving average of the data
subplot(2, 1, 1);
plot(macd_input);
title('MACD of Input Close Stock Prices,
10/01/95-12/31/95');
datetick('x', 'mm/dd/yy');
subplot(2, 1, 2);
highlow(part_input);
title('IBM Stock Prices, 10/01/95-12/31/95');
datetick('x', 'mm/dd/yy')
Bollinger Band on the Data
[input_Mid,input_Uppr,input_Lowr]=
bollinger(myinc);
input_CloseBolling = [input_Mid.CLOSE,
input_Uppr.CLOSE,...
input_Lowr.CLOSE];
plot(input_CloseBolling)
title('Bollinger Bands for inputney Closing
Prices')
Cleaning and Exporting Data
Count rows and columns of matrix
[rows columns] = size(input)
for a = 1:rows
Input(a,2)
end
if input(2,a)>100
disp('Value within specified range.')
end
csvwrite('csvlist.dat',input)
http://in.mathworks.com/help/matlab/ref/if.html
Saving output
http://in.mathworks.com/help/matlab/ref/csvw
rite.html
Playing with matrix
Logic including count, for and if to extract the
data
[input_Mid,input_Uppr,input_Lowr]=
bollinger(candle);
tsmat = fts2mat(tsobj)
Tasks
candle excel sheet
Bollinger code
3d plotting
Candle Sticks
Body nature
DOJI
HAMMER
HANGING MAN
Inverted Hammer
Shooting star
http://in.mathworks.com/help/finance/candle.
html;jsessionid=12076760ee3791f11ef00890ed8e
Matrix of Strings in MATLAB
http://stackoverflow.com/questions/15643119/
how-can-i-fill-a-matrix-dynamically-withstrings-in-matlab
3D Charts
Heatmaps and 3D charts
Charting fundamentals
Matrix format
http://in.mathworks.com/help/bioinfo/ref/hea
tmap.html
http://in.mathworks.com/help/bioinfo/ref/data
matrix.html
Revising Financial Toolbox
PV FV
Portfolio Toolboxx
Regression
Fixed income standards
Mesh