FDataInterface接口介绍
- 金融数据Matlab接口(Finance Data Matlab Interface)基于Yahoo与Sina的金融数据接口为Matlab提供金融数据,数据主要包括股票、指数、交易型基金的历史行情与实时行情数据
- 由于程序中应用了Matlab新型数据类型Table,该程序适用于Matlab2014A以上版本
- 程序下载 FDataInterface接口,调用函数前请运行InterfaceSetup
- 支持网站 ArisZheng金融数据,更多信息参看网站
- This MatlabInterface code by Ariszheng & Faruto
获取历史数据HistoryData函数语法
HDataTable=HistoryData(StockCode,StartDate, EndDate, Freq) 输入参数:
- StockCode:证券代码,上海交易所'sh+代码',深圳交易所'sz+代码',例如中信证券为'sh600030';
- StartDate:起始时间,格式为‘2013-10-1’即可;
- EndDate :结束时间,格式为‘2014-10-1’即可;
- Freq :频率,每交易日为'd'、每周为'w'、每月为'm'
输出参数:
- HistoryData:输出为表格式
其中Date_datestr为日期,OpenPrice为开盘价格,HighPrice为最高价格;
LowPrice为最低价格,ClosePrice为收盘价格,djClosePrice为向前复权价格;
调用OpenPrice方式为A=HDataTable.OpenPrice
HistoryData函数示例调取中信证券2013-1-1~2014-9-30的价格数据
StockCode = 'sh600030'; %代码StartDate = '2013-1-1'; %开始日期EndDate = '2014-9-30'; %结束日期Freq = 'd'; %每日价格%调用HistoryData函数HDataTable=HistoryData(StockCode,StartDate, EndDate, Freq);% 展示HDataTable的数据格式,显示前10组数据HDataTable(1:10,:)% K线展示scrsz = get(0,'ScreenSize');figure('Position',[scrsz(3)*1/4 scrsz(4)*1/6 scrsz(3)*4/5 scrsz(4)]*3/4);OpenPrice = HDataTable.OpenPrice;HighPrice = HDataTable.HighPrice;LowPrice = HDataTable.LowPrice;ClosePrice = HDataTable.ClosePrice;Date_datenum=datenum(HDataTable.Date_datestr);MT_candle(OpenPrice,HighPrice,LowPrice ,ClosePrice,[],Date_datenum);xlim( [0 length(OpenPrice)+1] );title(StockCode);ans = Date_datestr OpenPrice HighPrice LowPrice ClosePrice ____________ _________ _________ ________ __________ '2013-01-01' 13.36 13.36 13.36 13.36 '2013-01-02' 13.36 13.36 13.36 13.36 '2013-01-03' 13.36 13.36 13.36 13.36 '2013-01-04' 13.6 13.72 13.09 13.26 '2013-01-07' 13.19 13.57 13.04 13.26 '2013-01-08' 13.27 13.33 12.85 13.05 '2013-01-09' 12.95 13.24 12.82 13.03 '2013-01-10' 13.05 13.54 13.01 13.22 '2013-01-11' 13.2 13.29 12.58 12.71 '2013-01-14' 12.63 13.66 12.6 13.59 Volume AdjClosePrice __________ _____________ 0 12.9 0 12.9 0 12.9 1.2657e+08 12.81 8.979e+07 12.81 1.1139e+08 12.6 8.5897e+07 12.58 1.0582e+08 12.77 1.1767e+08 12.27 1.6431e+08 13.12 获取实时数据RealTimeData函数语法RDataTable=RealTimeData(StockCode) 输入参数:
- StockCode:证券代码,上海交易所'sh+代码',深圳交易所'sz+代码',例如中信证券为'sh600030';
输出参数:
- RDataTable:输出为表格式
RDataTable包含:StockName,StockDate,StockTime,OpenPrice,YClosePrice,RtimePrice,HighPrice,LowPrice,... BuyPrice,SellPrice,Volume,Money,Buy1Volume,Buy1Price,Buy2Volume,Buy2Price,Buy3Volume,Buy3Price,... Buy4Volume,Buy4Price,Buy5Volume,Buy5Price,Sell1Volume,Sell1Price,Sell2Volume,Sell2Price,Sell3Volume,... Sell3Price,Sell4Volume,Sell4Price,Sell5Volume,Sell5Price
RDataTable包含:股票名称、日期、时间、开盘价、收盘价、昨日收盘价、实时价格、最高价、最低价、买入价格、卖出价格 成交易量、成交金额、买一量、买一价格……卖一量、卖一价格……
RealTimeData函数示例调取中信证券实时数据
StockCode = 'sh600030'; %代码%调用RDataTableRDataTable=RealTimeData(StockCode)RDataTable = StockName StockDate StockTime OpenPrice YClosePrice _________ ____________ __________ _________ ___________ '中信证券' '2014-10-10' '15:03:03' 13.31 13.39 RtimePrice HighPrice LowPrice BuyPrice SellPrice Volume __________ _________ ________ ________ _________ __________ 13.24 13.44 13.2 13.24 13.25 1.2775e+08 Money Buy1Volume Buy1Price Buy2Volume Buy2Price __________ __________ _________ __________ _________ 1.6975e+09 7700 13.24 90400 13.23 Buy3Volume Buy3Price Buy4Volume Buy4Price Buy5Volume __________ _________ __________ _________ __________ 7.666e+05 13.22 9.934e+05 13.21 9.1776e+05 Buy5Price Sell1Volume Sell1Price Sell2Volume Sell2Price _________ ___________ __________ ___________ __________ 13.2 2.5331e+05 3.3186e+05 3.3186e+05 13.26 Sell3Volume Sell3Price Sell4Volume Sell4Price Sell5Volume ___________ __________ ___________ __________ ___________ 3.6545e+05 13.27 1.511e+05 13.28 2.0335e+05 Sell5Price __________ 13.29 综合示例提取2013-1-1~2014-9-30中信证券、平安银行数据对比。
%代码StockCode = ['sh600030'; 'sz000001'];StartDate = '2013-1-1'; %开始日期EndDate = '2014-9-30'; %结束日期Freq = 'd'; %每日价格for i=1:size(StockCode,1) HDataTable=HistoryData(StockCode(i,:),StartDate, EndDate, Freq); PriceMatrix(:,i)=HDataTable.ClosePrice;endDate_datenum=datenum(HDataTable.Date_datestr);for i=1:size(PriceMatrix,2) PriceMatrix(:,i)=PriceMatrix(:,i)/PriceMatrix(1,i);endfigure;hold on;colorv=['r','b'];for i=1:size(StockCode,1) plot(Date_datenum, PriceMatrix(:,i),colorv(i));endxlim([Date_datenum(1),Date_datenum(end)]);dateaxis('x',2);legend('中信证券','平安银行');xlabel('日期');ylabel('价格');支持网站 ArisZheng金融数据,更多信息参看网站
disp(StatScript);站长统计| 今日IP[61] | 今日PV[162] | 昨日IP[112] | 昨日PV[313] |当前在线[5][size=0.8em]
Published with MATLAB® R2014a