資源簡介
MATLAB 通常從雅虎獲得數據,但雅虎數據有時間滯后,有些歷史數據缺失,如創業板指數。
所以從新浪取得股票交易數據是很好的來源。
本資料包含方法和源代碼

代碼片段和文件信息
function?stock_data=get_stock_hist(stock_codebegin_dateend_date)
%作者:langslike,E-mail:langslike@126.com
%參數含義:
%stock_code:字符陣列型,表示證券代碼,如sh600000
%begin_date:字符陣列型,表示希望獲取股票數據所在時段的開始日期,如19900215
%end_date:字符陣列型,表示希望獲取股票數據所在時段的結束日期
tic
url=[‘http://biz.finance.sina.com.cn/stock/flash_hq/kline_data.php?symbol=‘?stock_code?‘&end_date=‘?end_date?‘&begin_date=‘?begin_date];
xml_data=urlread(url);
fid=fopen(‘kline_data_htm.xml‘‘w‘);
fwrite(fidxml_data);
temp=parsexml(‘kline_data_htm.xml‘);
temp=temp.Children;
%這個結構體構成的數組中,只有下標為偶數的含有有效數據
num=numel(temp);
if?num==1
????disp([‘無法取得代碼為:‘?stock_code?‘的股票數據!‘]);
????%返回一個空結構體
????stock_data=struct;
return;
end;
temp=temp(2:2:num);
num=numel(temp);
if?num==0
????stock_data=struct;
else
%為變量預分配空間,加快程序運行速度
????stock_data(num)=struct(‘close‘[]‘date‘[]‘high‘[]‘low‘[]‘open‘[]‘volume‘[]);
????for?k=1:num
????????stock_data(k).close=str2double(temp(1k).Attributes(12).Value);
????????stock_data(k).date=temp(1k).Attributes(13).Value;
????????stock_data(k).high=str2double(temp(1k).Attributes(14).Value);
????????stock_data(k).low=str2double(temp(1k).Attributes(15).Value);
????????stock_data(k).open=str2double(temp(1k).Attributes(16).Value);
????????stock_data(k).volume=str2double(temp(1k).Attributes(17).Value);
????end;
end;
toc
end
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件?????570161??2013-04-05?14:50??【干貨】怎樣從新浪財經獲取股票交易數據?-?MATLAB?計算金融?-?MATLAB中文論壇?-?Powered?by?Discuz!.pdf
?????文件???????1483??2013-04-06?15:42??get_stock_hist.m
?????文件???????2101??2013-04-06?15:42??parsexm
?????文件?????363513??2013-04-10?21:49??MATLAB在金融時間序列分析及建模中的應用.pdf
-----------?---------??----------?-----??----
???????????????937258????????????????????4
- 上一篇:基音周期的matlab程序
- 下一篇:基于Simuli
nk 的解耦系統設計與仿真
評論
共有 條評論