您当前的位置:首页 > 计算机 > 编程开发 > Python

前50%股票成交量占比计算

时间:01-16来源:作者:点击数:

一个成熟市场,前50%市值的股票成交量占比总的成交量是4%。

2016年是45%,A股目前(2020.12)是19%,预测这个数字会越来越低,用python计算了当日成交占比。

import pandas as pd
import tushare as ts
import time
import datetime
import os
import csv
import numpy as np


def cmp(elem):
    return elem[1]


todate = datetime.date.today()
path = r'D:\stock\data\all_stock\\' + str(todate.strftime('%Y-%m-%d')) + '.csv'
if os.path.exists(path):
    stock_all = pd.read_csv(path)
    # print(stock_all.shape)
else:
    stock_all = ts.get_today_all()
    stock_all.to_csv(path)

# get stocks code
all_stock_code = stock_all.iloc[:, 1].tolist()

# get stocks mktcap 总市值
all_stock_mktcap = stock_all.iloc[:, -2].tolist()

# get stocks nmc 流通市值
all_stock_nmc = stock_all.iloc[:, -1].tolist()

# get stocks amount
all_stock_amount = stock_all.iloc[:, -5].tolist()

# dict_stock_mktcap = dict(zip(all_stock_code, all_stock_mktcap))
list_stock_nmc_amount = list(zip(all_stock_code, all_stock_nmc, all_stock_amount))

# print(list_stock_mktcap_amount)

list_stock_nmc_amount.sort(key=cmp, reverse=True)
# print(list_stock_nmc_amount)

list_stock_mktcap_amount_np = np.array(list_stock_nmc_amount)
# print(list_stock_mktcap_amount_np)
# print(list_stock_mktcap_amount_np.shape[0])
sum_50 = np.sum(list_stock_mktcap_amount_np[0:int(list_stock_mktcap_amount_np.shape[0] / 2)], axis=0)[2]
sum_all = np.sum(list_stock_mktcap_amount_np, axis=0)[2]

print("日期:{}".format(str(todate.strftime('%Y-%m-%d'))))
print("流通市值前50%的股票成交总量为{}亿元\n总成交量为{}亿元".format(round(sum_50 / 100000000, 2), round(sum_all / 100000000, 2)))
print("流通市值前50%的股票成交总量占比为{}%".format(100 * round(sum_50 / sum_all, 3)))
print("流通市值后50%的股票成交总量占比为{}%".format(100 * (1 - round(sum_50 / sum_all, 3))))

在这里插入图片描述

目前才12.4%,a股还会继续成熟,漂亮300,漂亮50,加油!

方便获取更多学习、工作、生活信息请关注本站微信公众号城东书院 微信服务号城东书院 微信订阅号
推荐内容
相关内容
栏目更新
栏目热门