📄 finchart.m
字号:
function finchart()
%FINCHART Financial Expo financial charts.
% Author(s): C.F. Garvin, 3-07-95
% Copyright (c) 1995-98 by The MathWorks, Inc.
% $Revision: 1.8 $ $Date: 1997/12/05 16:33:16 $
Fig = figure('Numbertitle','off','Name','MATLAB Financial Charts');
set(gcf,'pointer','watch')
figpos = get(gcf,'position');
Top = figpos(4);
Right = figpos(3);
Bwidth = 70;
Bheight = 20;
Bspace = 3;
FromTop = 6;
RightRow = Right - Bwidth - Bspace;
Bbottom = Top - FromTop - Bheight;
BGap = Bheight+Bspace;
TSWidth = 18;
TSHeight = 12;
load ibm.dat
set(gcf,'userdata',ibm);
[ro,co] = size(ibm);
set(gca,'position',[.1 .3 .75 .6])
highlow(ibm(ro-40:ro,2),ibm(ro-40:ro,3),ibm(ro-40:ro,4),[],'g')
xlabel(''),ylabel('Price ($)')
title('International Business Machines')
tik = timeser(datenum('28-Dec-1996'));
timeser(datenum('28-Dec-1996'));
set(gca,'xlim',[min(tik)-1 max(tik)+1])
dateaxis('x',6)
grid on
charhelp % Load in help strings
HelpBut = uicontrol('style','edit',...
'position',[.1*Right .01*Top .75*Right .235*Top],'max',50,...
'horizontalalignment','left',...
'string',highlowst,'tag','HelpBut',...
'foregroundcolor','black');
set(HelpBut,'units','normal')
CH(1) = uicontrol('position',[RightRow Bbottom-BGap Bwidth Bheight],...
'style','radio','max',400,...
'tag','chartbut',...
'string','Highlow');
CH(2) = uicontrol('position',[RightRow Bbottom-2*BGap Bwidth Bheight],...
'style','radio','max',400,...
'tag','chartbut',...
'string','Candle');
CH(3) = uicontrol('position',[RightRow Bbottom-3*BGap Bwidth Bheight],...
'style','radio','max',400,...
'tag','chartbut',...
'string','Bar');
CH(4) = uicontrol('position',[RightRow Bbottom-4*BGap Bwidth Bheight],...
'style','radio','max',400,...
'tag','chartbut',...
'string','Mov Avg');
CH(5) = uicontrol('position',[RightRow Bbottom-5*BGap Bwidth Bheight],...
'style','radio','max',400,...
'tag','chartbut',...
'string','Bollinger');
set(CH(1:5),'callback',[...
'set(gcf,''pointer'',''watch''),'...
'uis = get(gco,''userdata'');'...
'CH = findobj(gcf,''tag'',''chartbut'');'...
'set(CH(1:5),''value'',0),'...
'set(gco,''value'',400),'...
'set(gcf,''pointer'',''arrow'')']);
CH(6) = uicontrol('position',[RightRow Bbottom-6*BGap Bwidth Bheight],...
'style','text',...
'foregroundcolor','black',...
'visible','off');
CH(7) = uicontrol('position',[RightRow Bbottom-7*BGap Bwidth Bheight],...
'style','slider','value',5,...
'min',2,'max',20,...
'visible','off',...
'callback',[...
'set(gcf,''pointer'',''watch''),'...
'uis = get(gco,''userdata'');'...
'set(uis(8),''string'',[int2str(get(gco,''value'')),'' day'']),'...
'set(gcf,''pointer'',''arrow''),'...
]);
CH(8) = uicontrol('position',[RightRow Bbottom-8*BGap Bwidth Bheight],...
'style','text',...
'foregroundcolor','black',...
'visible','off',...
'string',[int2str(get(CH(7),'value')),' day']);
CH(9) = uicontrol('position',[RightRow Bbottom-9*BGap Bwidth Bheight],...
'style','text',...
'foregroundcolor','black',...
'visible','off',...
'string','Lagging');
CH(10) = uicontrol('position',[RightRow Bbottom-10*BGap Bwidth Bheight],...
'style','slider','value',25,...
'min',20,'max',150,...
'visible','off',...
'callback',[...
'set(gcf,''pointer'',''watch''),'...
'uis = get(gco,''userdata'');'...
'set(uis(11),''string'',[int2str(get(gco,''value'')),'' day'']),'...
'set(gcf,''pointer'',''arrow''),'...
]);
CH(11) = uicontrol('position',[RightRow Bbottom-11*BGap Bwidth Bheight],...
'style','text',...
'foregroundcolor','black',...
'visible','off',...
'string',[int2str(get(CH(10),'value')),' day']);
CH(12) = uicontrol('position',[RightRow Bbottom-13*BGap Bwidth Bheight],...
'style','check',...
'string','Zoom',...
'callback',[...
'ibm=get(gcf,''userdata'');'...
'[ro,co] = size(ibm);'...
'if get(gco,''value''),'...
'zoom on,'...
'set(gcf,''pointer'',''circle''),'...
'else,'...
'zoom off,'...
'set(gcf,''pointer'',''arrow''),'...
'end',...
]);
out1 = str2mat(...
' This demonstration shows some of the financial charting functions',...
' available in MATLAB and the Financial Toolbox. The charts all use',...
' the same IBM stock price and volume data.',...
'.',...
' To see a different chart, click on the desired selection under',...
' Chart Type then click the Run button.',...
'.',...
' You can magnify any portion of a chart. Click Zoom and move the',...
' cursor to the desired area. The cursor changes to a circle.',...
' To zoom in (magnify), click the primary mouse button. To zoom back');
out2 = str2mat(...
' out, click the secondary mouse button. Click Zoom again to turn off',...
' the zoom function.',...
'.',...
' Click the Main Map button to return to the Main Map.');
out = str2mat(out1,out2);
CH(13) = uicontrol('position',[RightRow Bbottom-14*BGap Bwidth Bheight],...
'string','Help',...
'callback',[...
'out = get(gco,''userdata'');'...
'helpwin(out,''Financial Charts Help'');']);
CH(14) = uicontrol('position',[RightRow Bbottom-15*BGap Bwidth Bheight],...
'string','Main Map',...
'callback','close;figure(findobj(0,''tag'',''MAINMAP''));');
CH(15) = uicontrol('style','text','string','Chart Type',...
'position',[RightRow Bbottom Bwidth Bheight],...
'foregroundcolor','black');
CH(16) = uicontrol('style','text','string','2 ',...
'position',[RightRow Bbottom-7*BGap+Bheight...
TSWidth TSHeight],...
'visible','off',...
'foregroundcolor','black');
CH(17) = uicontrol('style','text','string','20',...
'position',[RightRow+Bwidth-TSWidth Bbottom-7*BGap+Bheight...
TSWidth TSHeight],...
'visible','off',...
'foregroundcolor','black');
CH(18) = uicontrol('style','text','string','20',...
'position',[RightRow Bbottom-10*BGap+Bheight...
TSWidth TSHeight],...
'visible','off',...
'foregroundcolor','black');
CH(19) = uicontrol('style','text','string','150',...
'position',[RightRow+Bwidth-TSWidth Bbottom-10*BGap+Bheight...
TSWidth TSHeight],...
'visible','off',...
'foregroundcolor','black');
CH(20) = uicontrol('position',[RightRow Bbottom-12*BGap Bwidth Bheight],...
'string','Run',...
'callback',[...
'set(gcf,''pointer'',''watch''),'...
'legend off,'...
'set(findobj(gcf,''string'',''Zoom''),''value'',0);'...
'zoom off,'...
'delete(findobj(gcf,''type'',''axes'')),'...
'charhelp,'...
'butn = findobj(gcf,''value'',400);'...
'fct = get(butn,''string'');'...
'uis = get(butn,''userdata'');'...
'ibm=get(gcf,''userdata'');'...
'[ro,co] = size(ibm);'...
'set(gca,''position'',[.1 .3 .75 .6]),'...
'if fct(1:2) == ''Hi'','...
'set(uis([6:8,9:11,16:19]),''visible'',''off''),'...
'highlow(ibm(ro-40:ro,2),ibm(ro-40:ro,3),ibm(ro-40:ro,4),[],''g''),'...
'helpstr = highlowst;'...
'ylabel(''Price ($)''),'...
'elseif fct(1:2) == ''Ca'','...
'set(uis([6:8,9:11,16:19]),''visible'',''off''),'...
'candle(ibm(ro-40:ro,2),ibm(ro-40:ro,3),ibm(ro-40:ro,4),ibm(ro-41:ro-1,4));'...
'helpstr = candlest;'...
'ylabel(''Price ($)''),'...
'elseif fct(1:2) == ''Ba'','...
'set(uis([6:8,9:11,16:19]),''visible'',''off''),'...
'set(gcf,''tag'',''HighLow''),'...
'bx=bar(ibm(ro-40:ro,6));set(bx,''edgecolor'',''none'');'...
'helpstr = barst;'...
'ylabel(''Volume (shares, 10000s)''),'...
'set(gca,''xlim'',[0 42]),'...
'set(findobj(gcf,''tag'',''HelpBut''),''string'',helpstr),'...
'dateaxis(''x'',6,today),set(gcf,''pointer'',''arrow''),return,'...
'elseif fct(1:2) == ''Mo'','...
'set(gcf,''tag'',''''),'...
'movavg(ibm(:,4),round(get(uis(7),''value'')),round(get(uis(10),''value''))),'...
'set(uis(6),''string'',''Leading''),'...
'set(uis(16),''string'',''2''),set(uis(16),''string'',''2 ''),'...
'set(uis(17),''string'','' 20''),set(uis(17),''string'',''20 ''),'...
'set(uis([6:8,9:11,16:19]),''visible'',''on''),'...
'helpstr = movavgst;'...
'legend(''Actual'',''Lagging'',''Leading'',0),'...
'set(gcf,''tag'',''MovAver''),'...
'set(gcf,''windowbuttondownfcn'',''''),'...
'ylabel(''Price ($)''),'...
'elseif fct(1:2) == ''Bo'','...
'set(gcf,''tag'',''''),'...
'bolling(ibm(:,4),round(get(uis(7),''value'')),0),'...
'set(uis(6),''string'',''Average''),'...
'set(uis([9:11,18:19]),''visible'',''off''),'...
'set(uis(16),''string'',''2''),set(uis(16),''string'',''2 ''),'...
'set(uis(17),''string'','' 20''),set(uis(17),''string'',''20 ''),'...
'set(uis([6:8,16:17]),''visible'',''on''),'...
'set(gcf,''tag'',''Bolling''),'...
'helpstr = bollingst;'...
'legend(''Actual'',''Average'',''Bands'',0),'...
'set(gcf,''windowbuttondownfcn'',''''),'...
'ylabel(''Price ($)''),'...
'end,'...
'grid on,'...
'tik = [];'...
'tik = timeser(datenum(''28-Dec-1996''));'...
'timeser(datenum(''28-Dec-1996''));'...
'if ~isempty(tik),'...
'set(gca,''xlim'',[min(tik)-1 max(tik)+1]),'...
'end,'...
'dateaxis(''x'',6),'...
'xlabel(''''),'...
'title([''International Business Machines'']),'...
'set(findobj(gcf,''tag'',''HelpBut''),''string'',helpstr),'...
'set(gcf,''pointer'',''arrow''),'...
]);
set(CH,'units','normal','userdata',CH)
set(CH(13),'userdata',out)
set(CH(1),'value',400)
TXT = [findobj(gcf,'style','text');findobj(gcf,'style','edit')];
set(TXT,'backgroundcolor',get(gcf,'color'))
set(gcf,'pointer','arrow')
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -