Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations cowski on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

Boxsplot chart in matlab for analysis of the financial market

Status
Not open for further replies.

ilson

Industrial
Dec 13, 2011
1
Hi.
I can generate boxsplot chart in matlab for analysis of the financial market. Example: I have a table of quotations containing the Open, High, Low, Close financial value. For ease of explanation left a graphic done in excel Any suggestions to make this graph?

Translation with google translator

Date Open High Low Close Volume
2008.09.01 3,16 3,22 3,12 3,15 367
2008.09.02 3,14 3,22 3,11 3,2 976
2008.09.03 3,22 3,23 3,16 3,19 1448
2008.09.04 3,17 3,29 3,13 3,13 3058
2008.09.05 3,11 3,19 3,11 3,17 1123
2008.09.08 3,22 3,28 3,15 3,19 1425
2008.09.09 3,15 3,26 3,15 3,23 1829
2008.09.10 3,21 3,34 3,21 3,34 2029
2008.09.11 3,35 3,46 3,32 3,39 2638
2008.09.12 3,39 3,39 3,3 3,31 2384
2008.09.15 3,19 3,34 3,17 3,21 1452
2008.09.16 3,17 3,17 3,06 3,11 2375
2008.09.17 3,1 3,12 2,97 3,02 2108
2008.09.18 3,03 3,13 2,94 3,13 2034
2008.09.19 3,25 3,35 3,22 3,35 1849
2008.09.22 3,33 3,38 3,25 3,32 1176
2008.09.23 3,32 3,32 3,16 3,16 1222
2008.09.24 3,19 3,25 3,18 3,25 647
2008.09.25 3,29 3,35 3,26 3,35 1100
2008.09.26 3,32 3,35 3,25 3,25 1123
2008.09.29 3,22 3,22 3 3,12 1327
2008.09.30 3,4 3,4 3,12 3,37 1167
2008.10.01 3,37 3,45 3,32 3,38 1173
2008.10.02 3,36 3,43 3,24 3,32 1618
2008.10.03 3,3 3,38 3,22 3,29 1629
2008.10.06 3,16 3,27 2,97 3,19 1420
2008.10.07 3,19 3,3 3,07 3,08 2264
2008.10.08 3,04 3,05 2,82 2,94 3827
2008.10.09 2,96 3,06 2,72 2,76 2012
2008.10.10 2,47 2,87 2,44 2,85 2558

Graf.gif

 
Replies continue below

Recommended for you

Have you read the help files?

TTFN
faq731-376
7ofakss

Need help writing a question or understanding a reply? forum1529

Of course I can. I can do anything. I can do absolutely anything. I'm an expert!
 
These aren't actually called boxplots (which are a statistical tool). What you're really asking for are candlestick plots. As it turns out, Matlab has a function to generate them for you. If the data that you're trying to plot is put into a text file called [tt]stkdata.dat[/tt], something like this should do what you want:

Code:
function mkCandle

clc;close all;
fid = fopen('stkdata.dat','r');
header = fgets(fid);
disp(header)
year=[]; month=[]; day=[]; opn=[]; hgh=[]; low=[]; clos=[]; vol=[];
while ~feof(fid)
    line = fgets(fid);
    for n = 1:length(line)
        if line(n)=='.'
            line(n)='-';
        elseif line(n)==','
            line(n)='.';
        end
    end
    stkData = sscanf(line,'%04f-%02f-%f %f %f %f %f %i');
    year(length(year)+1,:)   = stkData(1);
    month(length(month)+1,:) = stkData(2);
    day(length(day)+1,:)     = stkData(3);
    opn(length(opn)+1,:)     = stkData(4);
    hgh(length(hgh)+1,:)     = stkData(5);
    low(length(low)+1,:)     = stkData(6);
    clos(length(clos)+1,:)   = stkData(7);
    vol(length(vol)+1,:)     = stkData(8);
end
fclose(fid);

% Making the plot
h = figure(1);
Date = datenum(year, month, day,0,0,0);
candle(hgh, low, clos, opn, [.231,.443,0.642], Date);
set(gca,'YGrid','on');
yh = ylabel('Stock Price, US Dollars');
nicePrint(h,6,3,11); % Make a nice plot
set(yh,'FontSize',12, 'FontWeight','bold'); % Bold the label
print(h,'-deps', 'Candle.eps'); % Make an EPS file
print(h,'-dpdf', 'Candle.pdf'); % Make an PDF file
print(h,'-dmeta','Candle.emf'); % Make an EMF file (Windows only)

% A function for making nice plots
function nicePrint(H,WIDTH,HEIGHT,FONTSIZE)
set(H,'PaperUnits','inches');
set(H,'PaperOrientation','portrait');
set(H,'PaperSize',[WIDTH,HEIGHT]);
set(H,'PaperPosition',[0,0,WIDTH,HEIGHT])
FN = findall(H,'-property','FontName');
set(FN,'FontName','Avant Garde');
FS = findall(H,'-property','FontSize');
set(FS,'FontSize',FONTSIZE);

-Chris
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor