最近在利用资金流向分析股票,图例有(东富龙、坚朗五金、紫光国微等)。
1、注册Tushare。
2、利用python从Tushare获取A股的数据。
3、绘制特定股票的 大单、特大单资金流向图。
4、绘制特定股票 融资融券余额与股价。
5、绘制 股东人数与股价。
6、查询 个股公告。
下面是程序基本设置
# This allows multiple outputs from a single jupyter notebook cell:
# 配置单个cell多重输出
from IPython.core.interactiveshell import InteractiveShell
InteractiveShell.ast_node_interactivity = "all"
import tushare as ts
ts.set_token('your token')
pro = ts.pro_api()A股清单
data = pro.query('stock_basic', list_status='L', fields='ts_code,name') #获取A股数据
code_list = dict(zip(data.name,data.ts_code)) # 做成字典最近交易日
# 获取最近20个交易日
from datetime import *
start_date = (datetime.today() + timedelta(-40)).strftime(format="%Y%m%d")
end_date = (datetime.today() + timedelta(-1)).strftime(format="%Y%m%d")
df = pro.trade_cal(exchange='', start_date=start_date, end_date=end_date)
df = df[df.is_open == 1].cal_date
start = df.iloc[-20]
end = df.iloc[-1]资金流向绘图
# 资金流绘图函数
def money_flow(name, start, end):
df = pro.moneyflow(ts_code=code_list[name], start_date=start, end_date=end)
df.sort_values(by='trade_date', inplace=True)
df.set_index('trade_date', inplace=True)
fig, (ax1, ax2) = plt.subplots(2, 1, sharex=True, figsize=(16, 10), dpi=400)
data1 = df[df.net_mf_amount >= 0].net_mf_amount
data2 = df[df.net_mf_amount < 0].net_mf_amount
ax1.bar(x=df.index,
height=df.net_mf_amount,
color=['g' if i <= 0 else 'r'