Giter VIP home page Giter VIP logo

tushare_matlab's Introduction

Tushare Matlab接口说明

Lianrui Fu 2018.10.31

1 概要说明

Matlab版本需要2016b及以上。接口使用说明可以用help pro_api和help pro_bar查看。调用示例见tushare_pro_test.m所示。

2 接口说明

当前Matlab版本主要提供query接口(可获取股票列表、日线行情等数据),以及通用行情接口(pro_bar)。 输出数据为matalb table数据类型,和pandas的DataFrame非常接近。调用失败时返回[]并显示相应原因,常见原因:

(1)token无效

(2)网络不正常

(3)Matlab版本过低,需2016b及以上

(4)参数输入有问题

2.1 query说明

%调用方式:

% results = api.query(api,api_name,param_name1,param_1,param_name2, param_2, ...); %具体参数与python接口参数一致。

(1) stock_basic

调用示例:

token = 'c75b7d8389a****************'; % replace your token here api = pro_api(token); df_basic = api.query('stock_basic'); disp(df_basic(1:10,:));

  ts_code       symbol      name     area    industry    market    list_date 
___________    ________    ______    ____    ________    ______    __________

'000001.SZ'    '000001'    '平安银行'    '深圳'    '银行'        '主板'      '19910403'
'000002.SZ'    '000002'    '万科A'     '深圳'    '全国地产'      '主板'      '19910129'
'000004.SZ'    '000004'    '国农科技'    '深圳'    '生物制药'      '主板'      '19910114'
'000005.SZ'    '000005'    '世纪星源'    '深圳'    '房产服务'      '主板'      '19901210'
'000006.SZ'    '000006'    '深振业A'    '深圳'    '区域地产'      '主板'      '19920427'
'000007.SZ'    '000007'    '全新好'     '深圳'    '酒店餐饮'      '主板'      '19920413'
'000008.SZ'    '000008'    '神州高铁'    '北京'    '运输设备'      '主板'      '19920507'
'000009.SZ'    '000009'    '**宝安'    '深圳'    '综合类'       '主板'      '19910625'
'000010.SZ'    '000010'    '美丽生态'    '深圳'    '建筑施工'      '主板'      '19951027'
'000011.SZ'    '000011'    '深物业A'    '深圳'    '区域地产'      '主板'      '19920330' 

(2) daily

% 参数如下: % ts_code:证券代码,支持股票,ETF/LOF,期货/期权,港股,数字货币,如'000001.SZ','000905.SH' % start_date:开始日期 YYYYMMDD, 如'20181001' % end_date:结束日期 YYYYMMDD,''表示当前日期

调用示例:

token = 'c75b7d8389a****************'; % replace your token here api = pro_api(token); df_daily = api.query('daily', 'ts_code', '000001.SZ', 'start_date', '19990101', 'end_date', ''); disp(df_daily(1:10,:));

  ts_code      trade_date    open     high      low     close    pre_close    change    pct_change       vol          amount  
___________    __________    _____    _____    _____    _____    _________    ______    __________    __________    __________

'000001.SZ'    '20181030'    10.78    11.08    10.73     10.9    10.75         0.15      1.3953       1.5018e+06    1.6414e+06
'000001.SZ'    '20181029'     11.2    11.24    10.62    10.75    11.18        -0.43     -3.8462       1.5916e+06    1.7259e+06
'000001.SZ'    '20181026'    11.29    11.31    10.96    11.18    11.29        -0.11     -0.9743          1.3e+06    1.4488e+06
'000001.SZ'    '20181025'     10.8    11.29    10.71    11.29    11.04         0.25      2.2645        1.685e+06    1.8558e+06
'000001.SZ'    '20181024'     10.9    11.33     10.8    11.04    10.84          0.2       1.845       1.8294e+06    2.0262e+06
'000001.SZ'    '20181023'     11.2    11.22    10.73    10.84    11.15        -0.31     -2.7803       1.6025e+06    1.7593e+06
'000001.SZ'    '20181022'    10.81    11.46    10.78    11.15    10.76         0.39      3.6245       2.6455e+06    2.9327e+06
'000001.SZ'    '20181019'     9.95    10.78     9.92    10.76    10.09         0.67      6.6402       2.0837e+06    2.1736e+06
'000001.SZ'    '20181018'    10.29    10.29    10.06    10.09    10.33        -0.24     -2.3233       1.0012e+06    1.0157e+06
'000001.SZ'    '20181017'     10.5    10.55    10.14    10.33    10.37        -0.04     -0.3857       1.3509e+06    1.4003e+06  

2.2 pro_bar说明

data = pro_bar(ts_code, pro_api, start_date, end_date, freq, asset, market, adj, ma, factors, retry_count);

输入参数: 不能少于4个

 ts_code:证券代码,支持股票,ETF/LOF,期货/期权,港股,数字货币,如'000001.SZ','000905.SH'
 start_date:开始日期  YYYYMMDD, 如'20181001'
 end_date:结束日期 YYYYMMDD,''表示当前日期
 freq:支持1/5/15/30/60分钟,周/月/季/年, 如'D'
 asset:证券类型 E:股票和交易所基金,I:沪深指数,C:数字货币,F:期货/期权/港股/中概美国/中证指数/国际指数,如'E'
 market:市场代码,默认''
 adj:复权类型,''不复权,'qfq':前复权,'hfq':后复权
 ma:均线,支持自定义均线频度,如:ma5/ma10/ma20/ma60/maN,如[],5,[5,10],[5,10,20],有n个MA值,输出就会相应追加列,不足N天的均线值用NaN填充
 factors因子数据,目前支持以下两种:
     vr:量比,默认不返回,返回需指定:factor=['vr']
     tor:换手率,默认不返回,返回需指定:factor=['tor']
                 以上两种都需要:factor=['vr', 'tor']
 retry_count:网络重试次数,默认3

输出: data为matalb table数据类型,和pandas的DataFrame非常接近

调用示例

token = 'c75b7d8389a****************'; % replace your token here api = pro_api(token); dd1 = pro_bar('000001.SZ', api, '19990101', '20181031'); dd2 = pro_bar('000001.SZ', api, '19990101', ''); dd_ma1 = pro_bar('000001.SZ', api, '19990101', '', 'D', 'E', '', 'qfq', [5]); dd_ma3 = pro_bar('000001.SZ', api, '19990101', '', 'D', 'E', '', 'qfq', [5, 10, 20]); dd_index = pro_bar('000905.SH', api, '19990101', '', 'D', 'I'); disp(dd_ma3(1:10,:));

  ts_code      trade_date    open     high      low     close    pre_close    change    pct_change       vol          amount       ma5     ma10     ma20 
___________    __________    _____    _____    _____    _____    _________    ______    __________    __________    __________    _____    _____    _____

'000001.SZ'    '20181030'    10.78    11.08    10.73     10.9    10.75         0.15      1.3953       1.5018e+06    1.6414e+06    11.03    10.83    10.65
'000001.SZ'    '20181029'     11.2    11.24    10.62    10.75    11.18        -0.43     -3.8462       1.5916e+06    1.7259e+06    11.02    10.78    10.63
'000001.SZ'    '20181026'    11.29    11.31    10.96    11.18    11.29        -0.11     -0.9743          1.3e+06    1.4488e+06     11.1    10.72    10.63
'000001.SZ'    '20181025'     10.8    11.29    10.71    11.29    11.04         0.25      2.2645        1.685e+06    1.8558e+06    11.02    10.63    10.58
'000001.SZ'    '20181024'     10.9    11.33     10.8    11.04    10.84          0.2       1.845       1.8294e+06    2.0262e+06    10.78    10.49    10.53
'000001.SZ'    '20181023'     11.2    11.22    10.73    10.84    11.15        -0.31     -2.7803       1.6025e+06    1.7593e+06    10.63    10.43    10.48
'000001.SZ'    '20181022'    10.81    11.46    10.78    11.15    10.76         0.39      3.6245       2.6455e+06    2.9327e+06    10.54     10.4    10.42
'000001.SZ'    '20181019'     9.95    10.78     9.92    10.76    10.09         0.67      6.6402       2.0837e+06    2.1736e+06    10.33    10.33    10.35
'000001.SZ'    '20181018'    10.29    10.29    10.06    10.09    10.33        -0.24     -2.3233       1.0012e+06    1.0157e+06    10.24    10.36    10.31
'000001.SZ'    '20181017'     10.5    10.55    10.14    10.33    10.37        -0.04     -0.3857       1.3509e+06    1.4003e+06    10.19    10.42     10.3 

3 常见问题(FAQs)

(1) Matlab版本必须得2016b及以上吗?

是的。

(2) 如何引用tushare的matlab接口?

如果是在matlab_sdk目录下,可以直接调用。如果在其它目录下调用,可以添加matlab_sdk目录到Matlab的系统环境变量中。 addpath(‘D:/xxx/xxx/ matlab_sdk’);%相对路径和绝对路径均可

(3) Pro_bar所列参数都支持吗?

有的参数是预留的,后面会继续完善。具体见示例程序所示。

(4) 问题和建议反馈。

可以发邮件 fulrbuaa#163{dot}com, 邮件标题请注明 “Tushare Matlab ***问题”。

4 账号与TOKEN的获取,请访问Tushare Pro官方网站 https://tushare.pro

tushare_matlab's People

Contributors

jimmysoa avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.