本文是量化交易零基础入门教程中的一篇,点击蓝字链接可查看该系列详情。
文章内容请看附的研究(notebook)。研究内的链接建议右键-选择在新标签页打开。
查看下一篇
本文是量化交易零基础入门教程中的一篇,点击蓝字连接可查看该系列详情。
编辑模式是编辑单元格里内容的模式,识别方法是单元格边框为绿色,左侧粗边为绿色,可以看到编辑光标,如下图(截图截不到光标)。按esc转为命令模式。
在导航栏-帮助中可以查看快捷键,建议都至少看一遍。重点提几个:
# APIget_fundamentals_continuously()
scu=['000651.XSHE', '000333.XSHE']
date='2018-07-01'
n=400
q=query(
valuation.market_cap
).filter(
valuation.code.in_(scu)
)
df=get_fundamentals_continuously(q, end_date=date,count=n)
# [panel类型数据怎么处理](https://joinquant.com/post/9375)
df=df['market_cap',:,:]
# 显示结果
# notebook中单独的变量视为命令:显示该变量
df
code | 000333.XSHE | 000651.XSHE |
---|---|---|
day | ||
2016-11-10 | 1778.9700 | 1347.5200 |
2016-11-11 | 1769.9500 | 1347.5200 |
2016-11-14 | 1748.7000 | 1347.5200 |
2016-11-15 | 1742.2700 | 1347.5200 |
2016-11-16 | 1738.4301 | 1347.5200 |
2016-11-17 | 1742.3400 | 1373.9900 |
2016-11-18 | 1750.7500 | 1354.7400 |
2016-11-21 | 1779.8000 | 1371.5900 |
2016-11-22 | 1770.8101 | 1397.4500 |
2016-11-23 | 1810.2100 | 1537.0200 |
2016-11-24 | 1870.2600 | 1586.9500 |
2016-11-25 | 1871.6200 | 1638.0800 |
2016-11-28 | 1943.9900 | 1712.6801 |
2016-11-29 | 2031.1801 | 1712.6801 |
2016-11-30 | 1954.5000 | 1712.6801 |
2016-12-01 | 1991.5000 | 1840.2100 |
2016-12-02 | 1928.3400 | 1730.1200 |
2016-12-05 | 1847.7600 | 1556.8700 |
2016-12-06 | 1863.9600 | 1583.9399 |
2016-12-07 | 1865.3199 | 1575.5200 |
2016-12-08 | 1879.5800 | 1578.5300 |
2016-12-09 | 1948.7400 | 1623.6500 |
2016-12-12 | 1891.3000 | 1524.3900 |
2016-12-13 | 1859.7100 | 1536.4200 |
2016-12-14 | 1833.9200 | 1521.9800 |
2016-12-15 | 1797.1600 | 1488.8900 |
2016-12-16 | 1885.6500 | 1503.3300 |
2016-12-19 | 1863.0699 | 1453.4000 |
2016-12-20 | 1823.0500 | 1443.7800 |
2016-12-21 | 1832.7400 | 1455.8101 |
... | ... | ... |
2018-05-18 | 3550.1040 | 2903.7932 |
2018-05-21 | 3554.0566 | 2883.9414 |
2018-05-22 | 3467.4939 | 2815.3621 |
2018-05-23 | 3412.9788 | 2780.4707 |
2018-05-24 | 3353.8423 | 2743.7749 |
2018-05-25 | 3333.4963 | 2751.5952 |
2018-05-28 | 3422.5503 | 2805.1353 |
2018-05-29 | 3393.0447 | 2771.4473 |
2018-05-30 | 3341.6448 | 2726.9309 |
2018-05-31 | 3486.6187 | 2857.4722 |
2018-06-01 | 3436.7046 | 2802.1274 |
2018-06-04 | 3558.7542 | 2876.1208 |
2018-06-05 | 3623.9751 | 2920.6372 |
2018-06-06 | 3609.2573 | 2912.2153 |
2018-06-07 | 3580.6230 | 2886.3477 |
2018-06-08 | 3604.7749 | 2896.5745 |
2018-06-11 | 3714.4561 | 2943.4971 |
2018-06-12 | 3772.0862 | 3031.9285 |
2018-06-13 | 3759.3374 | 3000.6465 |
2018-06-14 | 3680.0955 | 2944.0986 |
2018-06-15 | 3714.0586 | 2948.3098 |
2018-06-19 | 3604.9099 | 2847.2454 |
2018-06-20 | 3637.3328 | 2880.3318 |
2018-06-21 | 3586.5007 | 2879.1289 |
2018-06-22 | 3553.5083 | 2891.1604 |
2018-06-25 | 3504.1943 | 2873.1130 |
2018-06-26 | 3467.0208 | 2845.4407 |
2018-06-27 | 3344.4526 | 2735.3528 |
2018-06-28 | 3319.2766 | 2717.9072 |
2018-06-29 | 3459.7329 | 2836.4170 |
400 rows × 2 columns
# 画折线图
df.plot(figsize=(18,8))
<matplotlib.axes._subplots.AxesSubplot at 0x7fb20da6b5d0>
# 计算格力电器市值比上美的集团市值
df['mc_ratio']=df['000651.XSHE']/df['000333.XSHE']
# 取出比值作为新的变量df2,并维持其类型为dataframe
df2=df[['mc_ratio']]
# 作图
df2.plot(figsize=(18,8))
<matplotlib.axes._subplots.AxesSubplot at 0x7fb20d904e10>
以下应用案例选自聚宽社区
本社区仅针对特定人员开放
查看需注册登录并通过风险意识测评
5秒后跳转登录页面...
移动端课程