Matlab读取yahoo股票数据

网友投稿 403 2022-11-28

Matlab读取yahoo股票数据

Matlab在读取雅虎数据时经常出现不稳定的现象,因此,为了能够将更多精力集中到数据处理上不再每次花费漫长时间在等待连接上,可以将读取数据的代码单独放置在一个m中,比如:

clear;c=yahoo;D=fetch(c,'600177.ss','05/18/09','06/18/09'); %雅戈尔format long g %不以默认的科学计数法显示数据D %输出数据save testD D %保存数据

上述程序处理后,编号为“600177.ss”深市的股票“雅戈尔”的相关数据被保存在当前目录下“testD”中D变量内,以后在需要的时候可以随时读取。

fetch函数的含义为:

fetch Request data from Yahoo!. D = fetch(C,S) returns data for all fields from the Yahoo's web site for given securities, S, given the connection handle, C. D = fetch(C,S,F) returns the data for the specified fields, F. D = fetch(C,S,D1) returns all data fields for the given security for the date D1. If D1 is today's date, the data from yesterday will be returned. D = fetch(C,S,F,D1) returns the data for the specified fields, F, for the date D1. D = fetch(C,S,D1,D2) returns the data for the given security for the date range D1 to D2. D = fetch(C,S,F,D1,D2) returns the data for the specified fields, F, for the date range D1 to D2. D = fetch(C,S,D1,D2,P) returns the data for the given security for the date range D1 to D2 with a period of P. P can be entered as: 'd' for daily values. 'w' for weekly values. 'm' for monthly values. 'v' for dividends.

可以看到,fetch支持多种参数设置形式,可以根据自己的需要进行设置。

下面看看如何读取数据D,

clc;load testD.mat %导入format long g %显示形式datestr(D(:,1)) %日期显示格式为可识别方式。

上述程序能够输出数据D的第一列,结果为:

ans =18-Jun-200917-Jun-200916-Jun-200915-Jun-200912-Jun-200911-Jun-200910-Jun-200909-Jun-200908-Jun-200905-Jun-200904-Jun-200903-Jun-200902-Jun-200901-Jun-200929-May-200928-May-200927-May-200926-May-200925-May-200922-May-200921-May-200920-May-200919-May-200918-May-2009

其中,

datestr(D(:,1)) %日期显示格式为可识别方式。

语句用来将第一列的数据进行格式转换后输出,否则输出结果为:

ans = 733942 733941 733940 733939 733936 733935 733934 733933 733932 733929 733928 733927 733926 733925 733922 733921 733920 733919 733918 733915 733914 733913 733912 733911

当然,需要更多的开盘数据、收盘价、交易量等,可以通过

D(:,N)

来实现,N可以是不同的数字,分别为2~7.

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:Java ArrayList集合详解(Java动态数组)
下一篇:TIA Porta中的可视化---创建HMI画面
相关文章

 发表评论

暂时没有评论,来抢沙发吧~