python汇总个股资金量分布情况

      个股资金是判断个股趋势的一个有参考价值的指标之一,通过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个月的统计数据。

  • 22
    点赞
  • 15
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

tanrenzong1986

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值