个股资金是判断个股趋势的一个有参考价值的指标之一,通过akshare的接口我们可以轻易地获取资金量并通过numpy的统计接口实现按我们自己的想法实现基础的统计分析。
# 资金流向指标
def fund_flow_index(code, market):
individual_flow = []
individual_flow = ak.stock_individual_fund_flow(code, market=market)
# 根据日期进行倒序排序,保证最新的数据靠前
flow_desc = individual_flow.sort_values('日期', ascending=False)
result = []
if len(flow_desc) > 30:
#资金量字段
fund_flow = flow_desc[[
'主力净流入-净额', '超大单净流入-净额', '大单净流入-净额', '中单净流入-净额', '小单净流入-净额']]
#占比字段
fund_flow_rate = flow_desc[[
'主力净流入-净占比', '超大单净流入-净占比', '大单净流入-净占比', '中单净流入-净占比', '小单净流入-净占比']]
# numpy.sum函数实现资金的汇总
last_day_flow = np.sum(fund_flow[0:1].astype(float), axis=0)
# sum函数实现资金合计
one_total = sum(last_day_flow)
print("当日资金量:", one_total)
result.append(str(one_total))
three_day_flow = np.sum(fund_flow[0:3].astype(float), axis=0)
print("3天资金量:", sum(three_day_flow))
three_total = sum(three_day_flow)
result.append(str(three_total))
five_day_flow = np.sum(fund_flow[0:5].astype(float), axis=0)
print("5天资金量:", sum(five_day_flow))
five_total = sum(five_day_flow)
result.append(str(five_total))
ten_day_flow = np.sum(fund_flow[0:10].astype(float), axis=0)
print("10天资金量:", sum(ten_day_flow))
ten_total = sum(ten_day_flow)
result.append(str(ten_total))
# 资金指标
flow_index = "满足" if ten_total > five_total > three_total > one_total > 0 else "不满足"
result.append(str(flow_index))
print(fund_flow_rate[0:1])
# 当日交易的资金分布情况
fst_day_flow_rate = fund_flow_rate[0:1].values[0]
for i in range(len(fst_day_flow_rate)):
result.append(str(fst_day_flow_rate[i]))
return result
if __name__ == '__main__':
fund_flow_index('002130', 'sz')
执行结果:

通过以上方法可以一目了然地看到资金汇总情况,资金分布情况。用户也可以根据自己的想法进行不同时间段的资金统计分析,stock_individual_fund_flow接口支持最多4个月的统计数据。










