north_data为北向资金数据
(north_data, w_list=[14, 20, 30, 60, 120])
| 236 | |
| 237 | # 北向资金可视化 |
| 238 | def plot_north_money(north_data, w_list=[14, 20, 30, 60, 120]): |
| 239 | '''north_data为北向资金数据''' |
| 240 | df = (north_data[['north_money', 'south_money']] / 100).dropna().copy() |
| 241 | for w in w_list: |
| 242 | df[str(w) + '日累计'] = df['north_money'].rolling(w).sum() |
| 243 | cols = [str(w) + '日累计' for w in w_list] |
| 244 | dd = round(df['north_money'][-1], 2) |
| 245 | date = df[cols].index[-1].strftime('%Y%m%d') |
| 246 | sig = '流入' if dd > 0 else '流出' |
| 247 | content = f'{date[:4]}年{date[4:6]}月{date[6:]}日,北向资金{sig}{abs(dd)}亿元' |
| 248 | # print(content) |
| 249 | dic = dict(df[cols].iloc[-1].round(2)) |
| 250 | |
| 251 | for k, v in dic.items(): |
| 252 | temp_sig = '流入' if v > 0 else '流出' |
| 253 | temp = f'{k}{temp_sig}{abs(v)}亿元' |
| 254 | content += ',近' + temp |
| 255 | # print(temp) |
| 256 | # 最近250日周期内可视化 |
| 257 | df[cols][-250:].plot(figsize=(15, 20), subplots=True, title='北向资金流向(亿元)'); |
| 258 | plt.xlabel(''); |
| 259 | return content |
| 260 | |
| 261 | |
| 262 | # 个股资金流向可视化 |