酒股近年来发展地比较好,所以想到了中短线策略,通过阶梯式的做多做空策略,最大化收益率的情况下尽可能减小波动率。
# 使用?快速获取帮助
# 获取财务数据接口帮助
get_fundamentals?
# 注释掉下面的行来查询各个API的介绍
# query?
# # 各个表的介绍
# valuation?
# income?
# balance?
# cash_flow?
# # 各个表的字段的介绍示例
# valuation.pe_ratio?
# income.total_operating_revenue?
### 获取单只股票在某一日期的市值数据
df = get_fundamentals(query(
valuation
).filter(
valuation.code == '000001.XSHE'
), date='2015-10-15')
df
id | code | pe_ratio | turnover_ratio | pb_ratio | ps_ratio | pcf_ratio | capitalization | market_cap | circulating_cap | circulating_market_cap | day | |
---|---|---|---|---|---|---|---|---|---|---|---|---|
0 | 5024884 | 000001.XSHE | 7.5 | 0.41 | 1.06 | 1.87 | 1.02 | 1430868 | 1598.28 | 1180405 | 1318.51 | 2015-10-15 |
# 取出总市值
df['market_cap'][0]
1598.28
### 获取多只股票在某一日期的市值, 利润
df = get_fundamentals(query(
valuation, income
).filter(
# 这里不能使用 in 操作, 要使用in_()函数
valuation.code.in_(['000001.XSHE', '600000.XSHG'])
), date='2015-10-15')
df
id | code | pe_ratio | turnover_ratio | pb_ratio | ps_ratio | pcf_ratio | capitalization | market_cap | circulating_cap | ... | income_tax_expense | net_profit | np_parent_company_owners | minority_profit | basic_eps | diluted_eps | other_composite_income | total_composite_income | ci_parent_company_owners | ci_minority_owners | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
0 | 5024884 | 000001.XSHE | 7.50 | 0.41 | 1.06 | 1.87 | 1.02 | 1430868 | 1598.2800 | 1180405 | ... | 1866000000 | 5955999744 | 5955999744 | 0 | 0.430 | 0.430 | 268000000 | 6224000000 | 0 | 0 |
1 | 5031852 | 600000.XSHG | 6.14 | 0.00 | 1.04 | 2.20 | 8.15 | 1865347 | 2965.8999 | 1865347 | ... | 3915000064 | 12817000448 | 12709000192 | 108000000 | 0.681 | 0.681 | 1614000000 | 14430999552 | 14323000320 | 108000000 |
2 rows × 53 columns
# 只选择表里的某些字段
### 获取多只股票在某一日期的市值, 利润, 现金流和负债数据
df = get_fundamentals(query(
valuation.code, valuation.market_cap, valuation.pe_ratio, income.total_operating_revenue
).filter(
# 这里不能使用 in 操作, 要使用in_()函数
valuation.code.in_(['000001.XSHE', '600000.XSHG'])
), date='2015-10-15')
df
code | market_cap | pe_ratio | total_operating_revenue | |
---|---|---|---|---|
0 | 000001.XSHE | 1598.2800 | 7.50 | 25904001024 |
1 | 600000.XSHG | 2965.8999 | 6.14 | 37710000128 |
# 选出所有的总市值大于1000亿元, 市盈率小于10, 营业总收入大于200亿元的股票
df = get_fundamentals(query(
valuation.code, valuation.market_cap, valuation.pe_ratio, income.total_operating_revenue
).filter(
valuation.market_cap > 1000,
valuation.pe_ratio < 10,
income.total_operating_revenue > 2e10
), date='2015-10-15')
df
code | market_cap | pe_ratio | total_operating_revenue | |
---|---|---|---|---|
0 | 000001.XSHE | 1598.2800 | 7.50 | 2.590400e+10 |
1 | 000002.XSHE | 1493.9100 | 9.47 | 4.137246e+10 |
2 | 000333.XSHE | 1173.9200 | 9.61 | 4.030065e+10 |
3 | 000651.XSHE | 1049.7500 | 7.41 | 2.651671e+10 |
4 | 600000.XSHG | 2965.8999 | 6.14 | 3.771000e+10 |
5 | 600016.XSHG | 3137.7400 | 6.86 | 4.087200e+10 |
6 | 600030.XSHG | 1904.7800 | 9.65 | 2.117836e+10 |
7 | 600036.XSHG | 4625.3198 | 7.92 | 5.338800e+10 |
8 | 600104.XSHG | 1959.2400 | 6.86 | 1.537495e+11 |
9 | 600606.XSHG | 1844.6899 | -243.86 | 8.609665e+10 |
10 | 601166.XSHG | 2894.0500 | 5.86 | 3.805100e+10 |
11 | 601288.XSHG | 10166.0596 | 5.66 | 1.347040e+11 |
12 | 601328.XSHG | 4678.5498 | 7.05 | 4.731700e+10 |
13 | 601398.XSHG | 16002.6396 | 5.78 | 1.750780e+11 |
14 | 601668.XSHG | 1869.0000 | 7.63 | 2.199666e+11 |
15 | 601818.XSHG | 1890.5000 | 6.46 | 2.327500e+10 |
16 | 601939.XSHG | 13575.5996 | 5.93 | 1.486750e+11 |
17 | 601988.XSHG | 11451.6904 | 6.71 | 1.181210e+11 |
18 | 601998.XSHG | 2942.9199 | 7.14 | 3.704600e+10 |
# 在回测环境中可用: 选取上面的结果作为universe
# set_universe(list(df['code']))
本社区仅针对特定人员开放
查看需注册登录并通过风险意识测评
5秒后跳转登录页面...
移动端课程