matlab如何读取股票数据,Matlab通过sina web接口获取个数即时股票数据函数实现代码...

代码如下:

function stockinfo = queryprice(stocktype, stockid)

%stocktype 股票类型:sh和sz

%stockid 股票编码:

url = sprintf('http://hq.sinajs.cn/list=%s%d', stocktype, stockid);

[sourcefile, status] = urlread(url);

if (~status)

disp('无法获取数据');

else

%取出字符串

str = javaObject('java.lang.String', sourcefile);

str = str.replaceAll('var ', '');

strs = str.split('=');

str = strs(2);

str = str.replaceFirst('"', '{''');

str = str.replaceFirst('"', '''};');

str = str.replaceAll(',', ''', ''');

str = strcat('stock=', char(str));

eval(str);

stockinfo = {};

stockinfo.name = stock(1);

stockinfo.today_start_price = str2double(stock(2));

stockinfo.yestoday_end_price = str2double(stock(3));

stockinfo.current_price = str2double(stock(4));

stockinfo.today_highest_price = str2double(stock(5));

stockinfo.today_lowest_price = str2double(stock(6));

stockinfo.today_first_buy_price = str2double(stock(7));

stockinfo.today_first_sale_price = str2double(stock(8));

stockinfo.today_success_stock_mount = str2double(stock(9))/100; %单位:手

stockinfo.today_success_money = str2double(stock(10)); %单位:万

stockinfo.today_first_buy_price = str2double(stock(11));

stockinfo.today_first_sale_price = str2double(stock(12));

stockinfo.buy_stock_mount1 = str2double(stock(13)) / 100; %单位:手

stockinfo.buy_stock_price1 = str2double(stock(14)); %单位:万

stockinfo.buy_stock_mount2 = str2double(stock(15));

stockinfo.buy_stock_price2 = str2double(stock(16));

stockinfo.buy_stock_mount3 = str2double(stock(17));

stockinfo.buy_stock_price3 = str2double(stock(18));

stockinfo.buy_stock_mount4 = str2double(stock(19));

stockinfo.buy_stock_price4 = str2double(stock(20));

stockinfo.buy_stock_mount5 = str2double(stock(21));

stockinfo.buy_stock_price5 = str2double(stock(22));

stockinfo.sale_stock_mount1 = str2double(stock(23));

stockinfo.sale_stock_price1 = str2double(stock(24));

stockinfo.sale_stock_mount2 = str2double(stock(25));

stockinfo.sale_stock_price2 = str2double(stock(26));

stockinfo.sale_stock_mount3 = str2double(stock(27));

stockinfo.sale_stock_price3 = str2double(stock(28));

stockinfo.sale_stock_mount4 = str2double(stock(29));

stockinfo.sale_stock_price4 = str2double(stock(30));

stockinfo.date = stock(31);

stockinfo.time = stock(32);

end

end

示例使用:

info = queryprice(‘sh‘, 601006)  %大秦铁路

结果为:

info =

name: {‘大秦铁路‘}

today_start_price: 10.5800

yestoday_end_price: 10.6300

current_price: 10.8500

today_highest_price: 10.9500

today_lowest_price: 10.5000

today_first_buy_price: 272852

today_first_sale_price: 10.8500

today_success_stock_mount: 1.1826e+06

today_success_money: 1.2708e+09

buy_stock_mount1: 410

buy_stock_price1: 10.8400

buy_stock_mount2: 43000

buy_stock_price2: 10.8300

buy_stock_mount3: 61300

buy_stock_price3: 10.8200

buy_stock_mount4: 67700

buy_stock_price4: 10.8100

buy_stock_mount5: 109038

buy_stock_price5: 10.8600

sale_stock_mount1: 86015

sale_stock_price1: 10.8700

sale_stock_mount2: 273900

sale_stock_price2: 10.8800

sale_stock_mount3: 180878

sale_stock_price3: 10.8900

sale_stock_mount4: 313838

sale_stock_price4: 10.9000

date: {‘2014-12-26‘}

time: {‘15:03:06‘}

原文:http://blog.csdn.net/miscclp/article/details/42201249

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值