AMain_demo_Tushare_Index
by LiYang_faruto
Email:farutoliyang@foxmail.com
2019/01/01
通过Tushare Pro获取数据样例(使用 Tushare_MATLAB_FSDK)
Tushare_MATLAB_FSDK see
Contents
A Little Clean Work
tic; % clear; % clc; % close all; format compact;
全局参数
gPara.len_demo = 8;
tushare api connect
输入您自己的Token,查看位置 https://tushare.pro/user/token
YourTushareToken_char = TushareToken; token = YourTushareToken_char; api = pro_api(token);
指数基本信息
tic; tData = api.query('index_basic','market','SW'); tData(1:gPara.len_demo,:) toc;
ans = 8×8 table ts_code name market publisher category base_date base_point list_date ___________ ____________ ______ _________ ____________ __________ __________ __________ '801001.SI' '申万50' 'SW' '申万研究' '其他' '19991230' [1000] [] '801002.SI' '申万中小板' 'SW' '申万研究' '其他' '20040705' [1000] [] '801003.SI' '申万A股' 'SW' '申万研究' '其他' '19991230' [1000] [] '801004.SI' '申万股改指数' 'SW' '申万研究' '其他' '20050815' [1000] [] '801005.SI' '申万创业板' 'SW' '申万研究' '其他' '20091105' [1000] '20091106' '801010.SI' '农林牧渔' 'SW' '申万研究' '一级行业指数' '19991230' [1000] '20031015' '801011.SI' '林业Ⅱ' 'SW' '申万研究' '二级行业指数' '19991230' [1000] [] '801012.SI' '农产品加工' 'SW' '申万研究' '二级行业指数' '19991230' [1000] [] 时间已过 0.241025 秒。
指数日线行情
tic; tData = api.query('index_daily','ts_code','399300.SZ','start_date','20180201','end_date','20181010'); tData(1:gPara.len_demo,:) toc;
ans = 8×11 table ts_code trade_date close open high low pre_close change pct_chg vol amount ___________ __________ ______ ______ ______ ______ _________ _______ _______ __________ __________ '399300.SZ' '20180201' 4245.9 4276.3 4287.4 4214.3 4275.9 -30.001 -0.7016 1.9e+08 2.3923e+08 '399300.SZ' '20180202' 4271.2 4213.9 4271.8 4181.8 4245.9 25.335 0.5967 1.4607e+08 1.9117e+08 '399300.SZ' '20180205' 4274.1 4204.5 4274.1 4200.1 4271.2 2.9138 0.0682 1.6135e+08 2.1736e+08 '399300.SZ' '20180206' 4148.9 4182.3 4211.5 4131.6 4274.1 -125.26 -2.9307 2.1491e+08 2.7942e+08 '399300.SZ' '20180207' 4050.5 4205.7 4212.6 4048.4 4148.9 -98.388 -2.3714 2.0313e+08 2.6151e+08 '399300.SZ' '20180208' 4012 4022.9 4071.7 3974.7 4050.5 -38.45 -0.9493 1.5927e+08 1.9906e+08 '399300.SZ' '20180209' 3840.7 3896.2 3911.3 3759.1 4012 -171.39 -4.272 2.0635e+08 2.4677e+08 '399300.SZ' '20180212' 3890.1 3846.3 3907.8 3828.1 3840.7 49.452 1.2876 1.1618e+08 1.4986e+08 时间已过 0.134953 秒。
指数成分和权重
tic; tData = api.query('index_weight','index_code','399300.SZ','start_date','20180901','end_date','20181010'); tData(1:gPara.len_demo,:) toc;
ans = 8×4 table index_code con_code trade_date weight ___________ ___________ __________ ______ '399300.SZ' '001965.SZ' '20180903' 0.0453 '399300.SZ' '002925.SZ' '20180903' 0.0395 '399300.SZ' '600025.SH' '20180903' 0.0497 '399300.SZ' '603260.SH' '20180903' 0.0434 '399300.SZ' '001979.SZ' '20180903' 0.4153 '399300.SZ' '601155.SH' '20180903' 0.2341 '399300.SZ' '601108.SH' '20180903' 0.0385 '399300.SZ' '601228.SH' '20180903' 0.0914 时间已过 0.686683 秒。
大盘指数每日指标
tic; tData = api.query('index_dailybasic','trade_date','20181018','fields','ts_code,trade_date,turnover_rate,pe'); tData(1:gPara.len_demo,:) toc;
ans = 8×12 table ts_code trade_date total_mv float_mv total_share float_share free_share turnover_rate turnover_rate_f pe pe_ttm pb ___________ __________ __________ __________ ___________ ___________ __________ _____________ _______________ _____ ______ ____ '000001.SH' '20181018' 3.1699e+13 2.2966e+13 4.4428e+12 3.2899e+12 1.244e+12 0.38 1.01 11.92 11.13 1.28 '000300.SH' '20181018' 2.9449e+13 2.1843e+13 3.692e+12 2.7031e+12 9.2888e+11 0.27 0.79 11.17 10.47 1.3 '000905.SH' '20181018' 5.6874e+12 4.4656e+12 8.8114e+11 7.2493e+11 4.1554e+11 0.82 1.44 18.03 16.65 1.51 '399001.SZ' '20181018' 1.0179e+13 7.7054e+12 1.0887e+12 8.4577e+11 5.0947e+11 0.88 1.46 17.48 16.16 1.93 '399005.SZ' '20181018' 3.085e+12 2.2289e+12 2.4421e+11 1.798e+11 1.1033e+11 0.85 1.39 21.43 19.55 2.73 '399006.SZ' '20181018' 1.6939e+12 1.0838e+12 1.288e+11 9.3588e+10 6.9878e+10 1.5 2.01 29.56 27.04 3.2 '399016.SZ' '20181018' 2.1854e+12 1.7031e+12 1.7449e+11 1.4094e+11 9.5872e+10 1.06 1.56 18.86 17.93 2.72 '399300.SZ' '20181018' 2.9449e+13 2.1843e+13 3.692e+12 2.7031e+12 9.2888e+11 0.27 0.79 11.17 10.47 1.3 时间已过 0.050366 秒。
ETC
over = 1;
Record Time
toc; displayEndOfDemoMessage(mfilename);
时间已过 0.062308 秒。