请 [注册] 或 [登录]  | 返回主站

量化交易吧 /  量化平台 帖子:3364737 新帖:1

Python入门操作

有事您说话发表于:8 月 5 日 10:47回复(1)

研究功能简介¶

感谢您使用研究功能~~

研究功能基于IPython Notebook,支持灵活的图表处理、数据处理,后续我们还会增加财务数据。

研究功能支持导入第三方库,您可以根据需要引入,查看详情。

研究功能提供分钟级数据,采用Docker技术隔离,资源独立、安全性更高、性能更好,同步支持Python2、Python3。

操作说明¶

操作说明

1 使用帮助(只读)

新手指引,常用API示例。

2 新手指引

研究功能简介,操作说明,常用API示例。

3 常用操作

  • New:

    • Text File:新建txt文件(可修改文件后缀名,修改为任意文件类型);

    • Folder:新建文件夹;

    • Python 2:新建基于Python 2的notebook;

    • Python 3:新建基于Python 3的notebook。

  • Upload:

    • 上传文件,文件上传后可以在研究和回测中使用。

Notebook常用操作¶

  • 使用 “Shift+Enter” 运行每个代码块
  • 使用“?”获取帮助
  • 使用Tab键补全代码
#使用“?”获取帮助示例,使用“Shift+Enter”运行;
get_price?
import pandas as pd
pd.DataFrame?
#使用Tab键补全函数名
get_

研究相关API¶

研究新增如下API

  • get_price()
  • get_all_securities()
  • get_index_stocks()
  • get_industry_stocks()

  • get_price - 获取历史数据

  • get_extras - 获取基金净值/期货结算价等
  • get_fundamentals - 查询财务数据
  • get_index_stocks - 获取指数成份股
  • get_industry_stocks - 获取行业成份股
  • get_concept_stocks - 获取概念成份股
  • get_all_securities - 获取所有标的信息
  • get_security_info - 获取单个标的信息
  • jqdata.get_all_trade_days - 获取所有交易日
  • jqdata.get_trade_days - 获取指定范围交易日
  • jqdata.get_money_flow - 获取资金流信息
  • 更多详见详见API
#导入需要的库
import pandas as pd
import seaborn as sns
#获取股票510300.XSHG2015年1月的日级交易数据
df = get_price('510300.XSHG', start_date='2017-08-04', end_date='2019-08-04', frequency='daily', fields=['open','close']) 
df.head()
open close
2017-08-04 3.672 3.649
2017-08-07 3.643 3.672
2017-08-08 3.674 3.673
2017-08-09 3.670 3.670
2017-08-10 3.663 3.662
#获取平台支持的所有股票, ETF基金信息
get_all_securities()
display_name name start_date end_date type
000001.XSHE 平安银行 PAYH 1991-04-03 2200-01-01 stock
000002.XSHE 万科A WKA 1991-01-29 2200-01-01 stock
000004.XSHE 国农科技 GNKJ 1990-12-01 2200-01-01 stock
000005.XSHE 世纪星源 SJXY 1990-12-10 2200-01-01 stock
000006.XSHE 深振业A SZYA 1992-04-27 2200-01-01 stock
000007.XSHE 全新好 QXH 1992-04-13 2200-01-01 stock
000008.XSHE 神州高铁 SZGT 1992-05-07 2200-01-01 stock
000009.XSHE 中国宝安 ZGBA 1991-06-25 2200-01-01 stock
000010.XSHE *ST美丽 *STML 1995-10-27 2200-01-01 stock
000011.XSHE 深物业A SWYA 1992-03-30 2200-01-01 stock
000012.XSHE 南玻A NBA 1992-02-28 2200-01-01 stock
000014.XSHE 沙河股份 SHGF 1992-06-02 2200-01-01 stock
000016.XSHE 深康佳A SKJA 1992-03-27 2200-01-01 stock
000017.XSHE 深中华A SZHA 1992-03-31 2200-01-01 stock
000018.XSHE *ST神城 *STSC 1992-06-16 2200-01-01 stock
000019.XSHE 深粮控股 SLKG 1992-10-12 2200-01-01 stock
000020.XSHE 深华发A SHFA 1992-04-28 2200-01-01 stock
000021.XSHE 深科技 SKJ 1994-02-02 2200-01-01 stock
000022.XSHE 深赤湾A SCWA 1993-05-05 2018-12-25 stock
000023.XSHE 深天地A STDA 1993-04-29 2200-01-01 stock
000024.XSHE 招商地产 ZSDC 1993-06-07 2015-12-29 stock
000025.XSHE 特力A TLA 1993-06-21 2200-01-01 stock
000026.XSHE 飞亚达A FYDA 1993-06-03 2200-01-01 stock
000027.XSHE 深圳能源 SZNY 1993-09-03 2200-01-01 stock
000028.XSHE 国药一致 GYYZ 1993-08-09 2200-01-01 stock
000029.XSHE 深深房A SSFA 1993-09-15 2200-01-01 stock
000030.XSHE 富奥股份 FAGF 1993-09-29 2200-01-01 stock
000031.XSHE 大悦城 DYC 1993-10-08 2200-01-01 stock
000032.XSHE 深桑达A SSDA 1993-10-28 2200-01-01 stock
000033.XSHE 新都退 STXD 1994-01-03 2017-07-06 stock
... ... ... ... ... ...
603993.XSHG 洛阳钼业 LYMY 2012-10-09 2200-01-01 stock
603996.XSHG ST中新 STZX 2015-12-22 2200-01-01 stock
603997.XSHG 继峰股份 JFGF 2015-03-02 2200-01-01 stock
603998.XSHG 方盛制药 FSZY 2014-12-05 2200-01-01 stock
603999.XSHG 读者传媒 DZCM 2015-12-10 2200-01-01 stock
688001.XSHG 华兴源创 HXYC 2019-07-22 2200-01-01 stock
688002.XSHG 睿创微纳 RCWN 2019-07-22 2200-01-01 stock
688003.XSHG 天准科技 TZKJ 2019-07-22 2200-01-01 stock
688005.XSHG 容百科技 RBKJ 2019-07-22 2200-01-01 stock
688006.XSHG 杭可科技 HKKJ 2019-07-22 2200-01-01 stock
688007.XSHG 光峰科技 GFKJ 2019-07-22 2200-01-01 stock
688008.XSHG 澜起科技 LQKJ 2019-07-22 2200-01-01 stock
688009.XSHG 中国通号 ZGTH 2019-07-22 2200-01-01 stock
688010.XSHG 福光股份 FGGF 2019-07-22 2200-01-01 stock
688011.XSHG 新光光电 XGGD 2019-07-22 2200-01-01 stock
688012.XSHG 中微公司 ZWGS 2019-07-22 2200-01-01 stock
688015.XSHG 交控科技 JKKJ 2019-07-22 2200-01-01 stock
688016.XSHG 心脉医疗 XMYL 2019-07-22 2200-01-01 stock
688018.XSHG 乐鑫科技 LXKJ 2019-07-22 2200-01-01 stock
688019.XSHG 安集科技 AJKJ 2019-07-22 2200-01-01 stock
688020.XSHG 方邦股份 FBGF 2019-07-22 2200-01-01 stock
688022.XSHG 瀚川智能 HCZN 2019-07-22 2200-01-01 stock
688028.XSHG 沃尔德 WED 2019-07-22 2200-01-01 stock
688029.XSHG 南微医学 NWYX 2019-07-22 2200-01-01 stock
688033.XSHG 天宜上佳 TYSJ 2019-07-22 2200-01-01 stock
688066.XSHG 航天宏图 HTHT 2019-07-22 2200-01-01 stock
688088.XSHG 虹软科技 HRKJ 2019-07-22 2200-01-01 stock
688122.XSHG 西部超导 XBCD 2019-07-22 2200-01-01 stock
688333.XSHG 铂力特 BLT 2019-07-22 2200-01-01 stock
688388.XSHG 嘉元科技 JYKJ 2019-07-22 2200-01-01 stock

3749 rows × 5 columns

#获取沪深300指数的所有股票
get_index_stocks('000300.XSHG')
[u'000001.XSHE',
 u'000002.XSHE',
 u'000063.XSHE',
 u'000069.XSHE',
 u'000100.XSHE',
 u'000157.XSHE',
 u'000166.XSHE',
 u'000333.XSHE',
 u'000338.XSHE',
 u'000402.XSHE',
 u'000408.XSHE',
 u'000413.XSHE',
 u'000415.XSHE',
 u'000423.XSHE',
 u'000425.XSHE',
 u'000538.XSHE',
 u'000553.XSHE',
 u'000568.XSHE',
 u'000596.XSHE',
 u'000625.XSHE',
 u'000627.XSHE',
 u'000629.XSHE',
 u'000630.XSHE',
 u'000651.XSHE',
 u'000656.XSHE',
 u'000661.XSHE',
 u'000671.XSHE',
 u'000703.XSHE',
 u'000709.XSHE',
 u'000725.XSHE',
 u'000728.XSHE',
 u'000768.XSHE',
 u'000776.XSHE',
 u'000783.XSHE',
 u'000786.XSHE',
 u'000858.XSHE',
 u'000876.XSHE',
 u'000895.XSHE',
 u'000898.XSHE',
 u'000938.XSHE',
 u'000961.XSHE',
 u'000963.XSHE',
 u'001979.XSHE',
 u'002001.XSHE',
 u'002007.XSHE',
 u'002008.XSHE',
 u'002010.XSHE',
 u'002024.XSHE',
 u'002027.XSHE',
 u'002032.XSHE',
 u'002044.XSHE',
 u'002050.XSHE',
 u'002065.XSHE',
 u'002081.XSHE',
 u'002120.XSHE',
 u'002142.XSHE',
 u'002146.XSHE',
 u'002153.XSHE',
 u'002179.XSHE',
 u'002202.XSHE',
 u'002230.XSHE',
 u'002236.XSHE',
 u'002241.XSHE',
 u'002252.XSHE',
 u'002271.XSHE',
 u'002294.XSHE',
 u'002304.XSHE',
 u'002310.XSHE',
 u'002311.XSHE',
 u'002352.XSHE',
 u'002410.XSHE',
 u'002411.XSHE',
 u'002415.XSHE',
 u'002422.XSHE',
 u'002456.XSHE',
 u'002460.XSHE',
 u'002466.XSHE',
 u'002468.XSHE',
 u'002475.XSHE',
 u'002493.XSHE',
 u'002508.XSHE',
 u'002555.XSHE',
 u'002558.XSHE',
 u'002594.XSHE',
 u'002601.XSHE',
 u'002602.XSHE',
 u'002624.XSHE',
 u'002625.XSHE',
 u'002673.XSHE',
 u'002714.XSHE',
 u'002736.XSHE',
 u'002739.XSHE',
 u'002773.XSHE',
 u'002925.XSHE',
 u'002938.XSHE',
 u'002939.XSHE',
 u'002945.XSHE',
 u'300003.XSHE',
 u'300015.XSHE',
 u'300017.XSHE',
 u'300024.XSHE',
 u'300033.XSHE',
 u'300059.XSHE',
 u'300070.XSHE',
 u'300072.XSHE',
 u'300122.XSHE',
 u'300124.XSHE',
 u'300136.XSHE',
 u'300142.XSHE',
 u'300144.XSHE',
 u'300251.XSHE',
 u'300296.XSHE',
 u'300408.XSHE',
 u'300413.XSHE',
 u'300433.XSHE',
 u'300498.XSHE',
 u'600000.XSHG',
 u'600004.XSHG',
 u'600009.XSHG',
 u'600010.XSHG',
 u'600011.XSHG',
 u'600015.XSHG',
 u'600016.XSHG',
 u'600018.XSHG',
 u'600019.XSHG',
 u'600023.XSHG',
 u'600025.XSHG',
 u'600027.XSHG',
 u'600028.XSHG',
 u'600029.XSHG',
 u'600030.XSHG',
 u'600031.XSHG',
 u'600036.XSHG',
 u'600038.XSHG',
 u'600048.XSHG',
 u'600050.XSHG',
 u'600061.XSHG',
 u'600066.XSHG',
 u'600068.XSHG',
 u'600085.XSHG',
 u'600089.XSHG',
 u'600100.XSHG',
 u'600104.XSHG',
 u'600109.XSHG',
 u'600111.XSHG',
 u'600115.XSHG',
 u'600118.XSHG',
 u'600153.XSHG',
 u'600170.XSHG',
 u'600176.XSHG',
 u'600177.XSHG',
 u'600188.XSHG',
 u'600196.XSHG',
 u'600208.XSHG',
 u'600219.XSHG',
 u'600221.XSHG',
 u'600233.XSHG',
 u'600271.XSHG',
 u'600276.XSHG',
 u'600297.XSHG',
 u'600299.XSHG',
 u'600309.XSHG',
 u'600332.XSHG',
 u'600339.XSHG',
 u'600340.XSHG',
 u'600346.XSHG',
 u'600352.XSHG',
 u'600362.XSHG',
 u'600369.XSHG',
 u'600372.XSHG',
 u'600383.XSHG',
 u'600390.XSHG',
 u'600398.XSHG',
 u'600406.XSHG',
 u'600415.XSHG',
 u'600436.XSHG',
 u'600438.XSHG',
 u'600482.XSHG',
 u'600487.XSHG',
 u'600489.XSHG',
 u'600498.XSHG',
 u'600516.XSHG',
 u'600519.XSHG',
 u'600522.XSHG',
 u'600535.XSHG',
 u'600547.XSHG',
 u'600566.XSHG',
 u'600570.XSHG',
 u'600583.XSHG',
 u'600585.XSHG',
 u'600588.XSHG',
 u'600606.XSHG',
 u'600637.XSHG',
 u'600660.XSHG',
 u'600663.XSHG',
 u'600674.XSHG',
 u'600688.XSHG',
 u'600690.XSHG',
 u'600703.XSHG',
 u'600704.XSHG',
 u'600705.XSHG',
 u'600733.XSHG',
 u'600741.XSHG',
 u'600760.XSHG',
 u'600795.XSHG',
 u'600809.XSHG',
 u'600816.XSHG',
 u'600837.XSHG',
 u'600867.XSHG',
 u'600886.XSHG',
 u'600887.XSHG',
 u'600893.XSHG',
 u'600900.XSHG',
 u'600919.XSHG',
 u'600926.XSHG',
 u'600958.XSHG',
 u'600977.XSHG',
 u'600998.XSHG',
 u'600999.XSHG',
 u'601006.XSHG',
 u'601009.XSHG',
 u'601012.XSHG',
 u'601018.XSHG',
 u'601021.XSHG',
 u'601066.XSHG',
 u'601088.XSHG',
 u'601108.XSHG',
 u'601111.XSHG',
 u'601117.XSHG',
 u'601138.XSHG',
 u'601155.XSHG',
 u'601162.XSHG',
 u'601166.XSHG',
 u'601169.XSHG',
 u'601186.XSHG',
 u'601198.XSHG',
 u'601211.XSHG',
 u'601212.XSHG',
 u'601216.XSHG',
 u'601225.XSHG',
 u'601228.XSHG',
 u'601229.XSHG',
 u'601238.XSHG',
 u'601288.XSHG',
 u'601298.XSHG',
 u'601318.XSHG',
 u'601319.XSHG',
 u'601328.XSHG',
 u'601336.XSHG',
 u'601360.XSHG',
 u'601377.XSHG',
 u'601390.XSHG',
 u'601398.XSHG',
 u'601555.XSHG',
 u'601577.XSHG',
 u'601600.XSHG',
 u'601601.XSHG',
 u'601607.XSHG',
 u'601618.XSHG',
 u'601628.XSHG',
 u'601633.XSHG',
 u'601668.XSHG',
 u'601669.XSHG',
 u'601688.XSHG',
 u'601727.XSHG',
 u'601766.XSHG',
 u'601788.XSHG',
 u'601800.XSHG',
 u'601808.XSHG',
 u'601818.XSHG',
 u'601828.XSHG',
 u'601838.XSHG',
 u'601857.XSHG',
 u'601877.XSHG',
 u'601878.XSHG',
 u'601881.XSHG',
 u'601888.XSHG',
 u'601898.XSHG',
 u'601899.XSHG',
 u'601901.XSHG',
 u'601919.XSHG',
 u'601933.XSHG',
 u'601939.XSHG',
 u'601985.XSHG',
 u'601988.XSHG',
 u'601989.XSHG',
 u'601992.XSHG',
 u'601997.XSHG',
 u'601998.XSHG',
 u'603019.XSHG',
 u'603156.XSHG',
 u'603160.XSHG',
 u'603259.XSHG',
 u'603260.XSHG',
 u'603288.XSHG',
 u'603799.XSHG',
 u'603833.XSHG',
 u'603858.XSHG',
 u'603986.XSHG',
 u'603993.XSHG']
#获取互联网和相关行业的所有股票
get_industry_stocks('I64') #互联网相关行业代码为I64
[u'000503.XSHE',
 u'002095.XSHE',
 u'002113.XSHE',
 u'002131.XSHE',
 u'002174.XSHE',
 u'002175.XSHE',
 u'002315.XSHE',
 u'002354.XSHE',
 u'002439.XSHE',
 u'002464.XSHE',
 u'002467.XSHE',
 u'002517.XSHE',
 u'002555.XSHE',
 u'002558.XSHE',
 u'002624.XSHE',
 u'300031.XSHE',
 u'300052.XSHE',
 u'300059.XSHE',
 u'300104.XSHE',
 u'300113.XSHE',
 u'300226.XSHE',
 u'300295.XSHE',
 u'300315.XSHE',
 u'300343.XSHE',
 u'300392.XSHE',
 u'300418.XSHE',
 u'300431.XSHE',
 u'300467.XSHE',
 u'300494.XSHE',
 u'300571.XSHE',
 u'600634.XSHG',
 u'600652.XSHG',
 u'600804.XSHG',
 u'600986.XSHG',
 u'603000.XSHG',
 u'603258.XSHG',
 u'603444.XSHG',
 u'603881.XSHG',
 u'603888.XSHG']

pandas和seaborn库的使用说明见Tutorials and Documentation(使用帮助)文件夹¶

彩蛋¶

为了增加研究功能的体验,我们新增了如下两个彩蛋

回测和研究打通¶

为了打通回测和研究功能,我们新增了两个回测API,回测过程中需要保存的文件,您可以保存到研究模块,也可以直接调用研究模块的文件。

详见API

回测和研究打通

分享到社区¶

为了便于交流,研究模块支持分享,您可以把notebook分享到社区,与大家交流。

分享到社区

|

全部回复

0/140

量化课程

    移动端课程