机构推荐评级选股

import akshare as ak
import matplotlib.pyplot as plt

stock_institute_recommend_df = ak.stock_institute_recommend(indicator="投资评级选股")
stock_institute_recommend_df.to_excel("机构推荐评级选股.xlsx")
fig, ax = plt.subplots(1, 1)
ax.plot(stock_institute_recommend_df["股票名称"], stock_institute_recommend_df["目标价"], "r^")
ax.set_title("机构推荐评级选股")
plt.rcParams["font.sans-serif"] = ["Arial Unicode MS"]
plt.show()

新闻内容

import akshare as ak
import jieba
import wordcloud
import matplotlib.pyplot as plt 
import collections

news_cctv_df = ak.news_cctv(date="20220117")
news_cctv_df.to_excel("新闻内容.xlsx")
seg_list_words = jieba.cut(str(news_cctv_df["content"]), cut_all = False)
obj_list = []
remove_words = [line.strip() for line in open("./stopWords.txt", encoding="UTF-8").readlines()]

for word in seg_list_words:
    if word not in remove_words:
        obj_list.append(word)

word_counts = collections.Counter(obj_list)
wc = wordcloud.WordCloud(
    font_path="/System/Library/Fonts/Supplemental/Arial Unicode.ttf",
    max_words=50,
    max_font_size=100,
    mode="RGBA"
)
wc.generate_from_frequencies(word_counts)
plt.imshow(wc) 
plt.axis("off")
plt.show()

智能制造概念股

import akshare as ak
import pandas as pd
import plotly.express as px

stock_board_concept_cons_ths_df = ak.stock_board_concept_cons_ths(symbol="智能制造")
stock_board_concept_cons_ths_df.to_excel("智能制造概念股.xlsx")
df = pd.DataFrame(dict(公司名称=stock_board_concept_cons_ths_df["名称"], 
        流通股市值 = stock_board_concept_cons_ths_df["流通市值"].str.replace("亿", "0").astype("float")))
fig = px.scatter(df, x="流通股市值", y="公司名称", title="智能制造概念股流通市值(亿元)")
fig.show()

宏观杠杆

import akshare as ak
import plotly.graph_objects as go

macro_cnbs_df = ak.macro_cnbs()
macro_cnbs_df.to_excel("宏观杠杆.xlsx")
fig = go.Figure()
fig.add_trace(go.Scatter(x=macro_cnbs_df["年份"], y=macro_cnbs_df["居民部门"],
                    mode="lines+markers",
                    name="居民部门"))
fig.add_trace(go.Scatter(x=macro_cnbs_df["年份"], y=macro_cnbs_df["非金融企业部门"],
                    mode="lines+markers",
                    name="非金融企业部门"))
fig.add_trace(go.Scatter(x=macro_cnbs_df["年份"], y=macro_cnbs_df["中央政府"],
                    mode="lines+markers",
                    name="中央政府"))
fig.add_trace(go.Scatter(x=macro_cnbs_df["年份"], y=macro_cnbs_df["政府部门"],
                    mode="lines+markers",
                    name="政府部门"))
fig.add_trace(go.Scatter(x=macro_cnbs_df["年份"], y=macro_cnbs_df["地方政府"],
                    mode="lines+markers",
                    name="地方政府"))
fig.add_trace(go.Scatter(x=macro_cnbs_df["年份"], y=macro_cnbs_df["实体经济部门"],
                    mode="lines+markers",
                    name="实体经济部门"))
fig.add_trace(go.Scatter(x=macro_cnbs_df["年份"], y=macro_cnbs_df["金融部门资产方"],
                    mode="lines+markers",
                    name="金融部门资产方"))
fig.add_trace(go.Scatter(x=macro_cnbs_df["年份"], y=macro_cnbs_df["金融部门负债方"],
                    mode="lines+markers",
                    name="金融部门负债方"))
fig.show()

机构持股详情

import akshare as ak
import matplotlib.pyplot as plt

stock_institute_hold_detail_df = ak.stock_institute_hold_detail(stock="688981", quarter="20212")
stock_institute_hold_detail_df.to_excel("中芯国际机构持股详情.xlsx")
fig, ax = plt.subplots(1, 1)
ax.pie(stock_institute_hold_detail_df["持股比例"], labels=stock_institute_hold_detail_df["持股机构简称"])
ax.set_title("中芯国际机构持股详情")
plt.rcParams["font.sans-serif"] = ["Arial Unicode MS"]
plt.show()

基金净值

import akshare as ak
import plotly.express as px

fund_value_estimation_em_df = ak.fund_value_estimation_em(symbol="全部")
fund_value_estimation_em_df.to_excel("0311基金净值.xlsx")
plot = px.scatter(fund_value_estimation_em_df, 
                  x = "2022-03-11-估算数据-估算值",  
                  y = "2022-03-11-公布数据-单位净值", 
                  color="2022-03-11-公布数据-日增长率",  
                  symbol = "基金名称") 
plot.show()

截止日期季度财报

import akshare as ak
import matplotlib.pyplot as plt

stock_em_yjbb_df = ak.stock_em_yjbb(date="20210930")
stock_em_yjbb_df.to_excel("2021第三季度财报.xlsx")
plt.plot(stock_em_yjbb_df["股票代码"], stock_em_yjbb_df["净利润-净利润"], "ro")
plt.show()

股票回购数据

import akshare as ak
import plotly.express as px

stock_repurchase_em_df = ak.stock_repurchase_em()
stock_repurchase_em_df.to_excel("股票回购数据.xlsx")
groups = stock_repurchase_em_df.groupby("实施进度")
repurchasing = groups.get_group("实施中")
fig = px.bar(repurchasing, 
    x=repurchasing["股票简称"], 
    y=[repurchasing["计划回购数量区间-下限"], repurchasing["计划回购数量区间-上限"]], 
    title="计划回购-实施中")
fig.show()

大笔买入

import akshare as ak
import plotly.express as px

stock_changes_em_df = ak.stock_changes_em(symbol="大笔买入")
stock_changes_em_df.to_excel(".xlsx")
fig = px.scatter(stock_changes_em_df, x=stock_changes_em_df["代码"], y=stock_changes_em_df["相关信息"].astype(int),
	        hover_name=stock_changes_em_df["名称"], log_x=True)
fig.show()

人均持股数量增幅

import akshare as ak
import pandas as pd
import plotly.express as px

stock_hold_num_cninfo_df = ak.stock_hold_num_cninfo(date="20210930")
stock_hold_num_cninfo_df.to_excel("持股人数变化.xlsx")
df = pd.DataFrame(dict(name=stock_hold_num_cninfo_df["证券简称"], 
        number = stock_hold_num_cninfo_df["人均持股数量增幅"]))
fig = px.scatter(df, x="number", y="name", title="人均持股数量增幅")
fig.show()

新股

import akshare as ak
import matplotlib.pyplot as plt

stock_zh_a_new_em_df = ak.stock_zh_a_new_em()
stock_zh_a_new_em_df.to_excel("新股.xlsx")
fig, ax = plt.subplots(1, 1)
line1, = ax.plot(stock_zh_a_new_em_df["名称"], stock_zh_a_new_em_df["市净率"], "r<")
ax.set_title("新股")
ax.grid(True) 
plt.rcParams["font.sans-serif"] = ["Arial Unicode MS"]
plt.show()

个股主要股东

import akshare as ak
import matplotlib.pyplot as plt

stock_main_stock_holder_df = ak.stock_main_stock_holder(stock="600000")
stock_main_stock_holder_df.to_excel("浦发银行主要股东.xlsx")
stock_main_stock_holder_df = stock_main_stock_holder_df.replace("1.7↓",1.7)
recent_data = stock_main_stock_holder_df.loc[stock_main_stock_holder_df["公告日期"] == "2021-10-30"]
fig, ax = plt.subplots(1, 1)
ax.pie(recent_data["持股比例(%)"], labels=recent_data["股东名称"])
ax.set_title("浦发银行主要股东")
plt.rcParams["font.sans-serif"] = ["Arial Unicode MS"]
plt.show()

大笔卖出

import akshare as ak
import plotly.express as px

stock_changes_em_df = ak.stock_changes_em(symbol="大笔卖出")
stock_changes_em_df.to_excel("大笔卖出.xlsx")
fig = px.scatter(stock_changes_em_df, x=stock_changes_em_df["代码"], 
            y=stock_changes_em_df["相关信息"].astype(int),
	        hover_name=stock_changes_em_df["名称"], log_x=True)
fig.show()

股权质押情况

import akshare as ak

stock_em_gpzy_pledge_ratio_df = ak.stock_em_gpzy_pledge_ratio(trade_date="2021-12-10")
stock_em_gpzy_pledge_ratio_df.to_excel("股权质押情况.xlsx")

机构调研

import akshare as ak
import matplotlib.pyplot as plt

stock_em_jgdy_tj_df = ak.stock_em_jgdy_tj(start_date="20211201")
stock_em_jgdy_tj_df.to_excel("机构调研.xlsx")
fig, ax = plt.subplots(1, 1)
line1, = ax.plot(stock_em_jgdy_tj_df["名称"], stock_em_jgdy_tj_df["接待机构数量"], "ro")
ax.set_title("机构调研情况")
ax.grid(True) 
plt.rcParams["font.sans-serif"] = ["Arial Unicode MS"]
plt.show()

基金公司历年管理规模

import akshare as ak
import matplotlib.pyplot as plt

fund_em_aum_hist_2021_df = ak.fund_em_aum_hist(year="2021")
fund_em_aum_hist_2021_df.to_excel("基金公司历年管理规模2021.xlsx")
fund_em_aum_hist_2020_df = ak.fund_em_aum_hist(year="2020")
fund_em_aum_hist_2020_df.to_excel("基金公司历年管理规模2020.xlsx")
fig, ax = plt.subplots(1, 2)
ax[0].set_title("基金公司历年管理规模2020")
ax[0].plot(fund_em_aum_hist_2020_df["基金公司"], fund_em_aum_hist_2020_df["总规模"], "r^")
ax[0].set_xticklabels(fund_em_aum_hist_2020_df["基金公司"], rotation=90, fontsize=3)
ax[1].set_title("基金公司历年管理规模2021")
ax[1].plot(fund_em_aum_hist_2021_df["基金公司"], fund_em_aum_hist_2021_df["总规模"], "ro")
ax[1].set_xticklabels(fund_em_aum_hist_2021_df["基金公司"], rotation=90, fontsize=3)
plt.rcParams["font.sans-serif"] = ["Arial Unicode MS"]
plt.show()

中概股

import akshare as ak
import plotly.graph_objects as go

stock_baba = ak.stock_us_daily(symbol="BABA", adjust="")
stock_baba.reset_index(inplace=True)
stock_weibo = ak.stock_us_daily(symbol="WB", adjust="")
stock_weibo.reset_index(inplace=True)
stock_wangyi = ak.stock_us_daily(symbol="NTES", adjust="")
stock_wangyi.reset_index(inplace=True)
stock_soho = ak.stock_us_daily(symbol="SOHU", adjust="")
stock_soho.reset_index(inplace=True)
stock_baidu = ak.stock_us_daily(symbol="BIDU", adjust="")
stock_baidu.reset_index(inplace=True)
stock_jd = ak.stock_us_daily(symbol="JD", adjust="")
stock_jd.reset_index(inplace=True)
stock_pdd = ak.stock_us_daily(symbol="PDD", adjust="")
stock_pdd.reset_index(inplace=True)
stock_tengxunmusic = ak.stock_us_daily(symbol="TME", adjust="")
stock_tengxunmusic.reset_index(inplace=True)

fig = go.Figure()
fig.add_trace(go.Candlestick(x=stock_baba["date"],
                open=stock_baba["open"],
                high=stock_baba["high"],
                low=stock_baba["low"],
                close=stock_baba["close"],
                increasing_line_color="red", decreasing_line_color="green",
                name="阿里"
            ))
fig.add_trace(go.Candlestick(x=stock_weibo["date"],
                open=stock_weibo["open"],
                high=stock_weibo["high"],
                low=stock_weibo["low"],
                close=stock_weibo["close"],
                increasing_line_color="red", decreasing_line_color="green",
                name="微博"
            ))
fig.add_trace(go.Candlestick(x=stock_wangyi["date"],
                open=stock_wangyi["open"],
                high=stock_wangyi["high"],
                low=stock_wangyi["low"],
                close=stock_wangyi["close"],
                increasing_line_color="red", decreasing_line_color="green",
                name="网易"
            ))
fig.add_trace(go.Candlestick(x=stock_soho["date"],
                open=stock_soho["open"],
                high=stock_soho["high"],
                low=stock_soho["low"],
                close=stock_soho["close"],
                increasing_line_color="red", decreasing_line_color="green",
                name="搜狐"
            ))
fig.add_trace(go.Candlestick(x=stock_baidu["date"],
                open=stock_baidu["open"],
                high=stock_baidu["high"],
                low=stock_baidu["low"],
                close=stock_baidu["close"],
                increasing_line_color="red", decreasing_line_color="green",
                name="百度"
            ))
fig.add_trace(go.Candlestick(x=stock_jd["date"],
                open=stock_jd["open"],
                high=stock_jd["high"],
                low=stock_jd["low"],
                close=stock_jd["close"],
                increasing_line_color="red", decreasing_line_color="green",
                name="京东"
            ))
fig.add_trace(go.Candlestick(x=stock_pdd["date"],
                open=stock_pdd["open"],
                high=stock_pdd["high"],
                low=stock_pdd["low"],
                close=stock_pdd["close"],
                increasing_line_color="red", decreasing_line_color="green",
                name="拼多多"
            ))
fig.add_trace(go.Candlestick(x=stock_tengxunmusic["date"],
                open=stock_tengxunmusic["open"],
                high=stock_tengxunmusic["high"],
                low=stock_tengxunmusic["low"],
                close=stock_tengxunmusic["close"],
                increasing_line_color="red", decreasing_line_color="green",
                name="腾讯音乐"
            ))
fig.show()

概念股

import akshare as ak
import pandas as pd
import plotly.express as px

stock_board_concept_name_ths_df = ak.stock_board_concept_name_ths()
stock_board_concept_name_ths_df.to_excel("概念时间表.xlsx")
df = pd.DataFrame(dict(name=stock_board_concept_name_ths_df["概念名称"], 
        number = stock_board_concept_name_ths_df["成分股数量"]))
fig = px.scatter(df, x="number", y="name", title="概念股及数量")
fig.show()

封涨停板

import akshare as ak
import plotly.express as px

stock_changes_em_df = ak.stock_changes_em(symbol="封涨停板")
stock_changes_em_df.to_excel("~/Desktop/封涨停板.xlsx")
fig = px.scatter(stock_changes_em_df, x=stock_changes_em_df["代码"], 
            y=stock_changes_em_df["相关信息"],
            hover_name=stock_changes_em_df["名称"], log_x=True)
fig.show()

个股年走势

import akshare as ak
import mplfinance as mpf

stock_us_daily_df = ak.stock_us_daily(symbol="AAPL", adjust="qfq")
stock_us_daily_df.to_excel("苹果过去一年走势.xlsx")
stock_us_daily_df = stock_us_daily_df[["open", "high", "low", "close", "volume"]]
stock_us_daily_df.columns = ["Open", "High", "Low", "Close", "Volume"]
stock_us_daily_df.index.name = "Date"
stock_us_daily_df = stock_us_daily_df["2021-01-01": "2022-01-25"]
mpf.plot(stock_us_daily_df, type="candle", mav=(3, 6, 9), volume=True, show_nontrading=False)

月份龙虎榜

import efinance as ef

start_date = "2021-11-01" 
end_date = "2021-11-30" 
df = ef.stock.get_daily_billboard(start_date = start_date,end_date = end_date)
df.to_excel("11月龙虎榜.xlsx")

春节后走势

from os import name
import akshare as ak
from plotly.subplots import make_subplots
import plotly.graph_objects as go

def history(satrt_date, end_date):
    stock_zh_a_hist_df = ak.stock_zh_a_hist(symbol="000001", period="daily", start_date=satrt_date, end_date=end_date, adjust="qfq")
    return stock_zh_a_hist_df

num_2010 = history("20100214", "20100228")
num_2011 = history("20110203", "20110217")
num_2012 = history("20120123", "20120205")
num_2013 = history("20130210", "20130224")
num_2014 = history("20140131", "20140213")
num_2015 = history("20150219", "20150304")
num_2016 = history("20160208", "20160222")
num_2017 = history("20170128", "20170210")
num_2018 = history("20180216", "20180301")
num_2019 = history("20190205", "20190219")
num_2020 = history("20200125", "20200207")
num_2021 = history("20210212", "20210226")


fig = make_subplots(rows=3, cols=4) 
fig.append_trace(go.Candlestick(x=num_2010["日期"],
                open=num_2010["开盘"],
                high=num_2010["最高"],
                low=num_2010["最低"],
                close=num_2010["收盘"],
                increasing_line_color="red", decreasing_line_color="green",
                name="2010"
            ), row=1, col=1)
fig.append_trace(go.Candlestick(x=num_2011["日期"],
                open=num_2011["开盘"],
                high=num_2011["最高"],
                low=num_2011["最低"],
                close=num_2011["收盘"],
                increasing_line_color="red", decreasing_line_color="green",
                name="2011"
            ), row=1, col=2)
fig.append_trace(go.Candlestick(x=num_2012["日期"],
                open=num_2012["开盘"],
                high=num_2012["最高"],
                low=num_2012["最低"],
                close=num_2012["收盘"],
                increasing_line_color="red", decreasing_line_color="green",
                name="2012"
            ), row=1, col=3) 
fig.append_trace(go.Candlestick(x=num_2013["日期"],
                open=num_2013["开盘"],
                high=num_2013["最高"],
                low=num_2013["最低"],
                close=num_2013["收盘"],
                increasing_line_color="red", decreasing_line_color="green",
                name="2013"
            ), row=1, col=4)            
fig.append_trace(go.Candlestick(x=num_2018["日期"],
                open=num_2018["开盘"],
                high=num_2018["最高"],
                low=num_2018["最低"],
                close=num_2018["收盘"],
                increasing_line_color="red", decreasing_line_color="green",
                name="2018"
            ), row=3, col=1)
fig.append_trace(go.Candlestick(x=num_2019["日期"],
                open=num_2019["开盘"],
                high=num_2019["最高"],
                low=num_2019["最低"],
                close=num_2019["收盘"],
                increasing_line_color="red", decreasing_line_color="green",
                name="2019"
            ), row=3, col=2)
fig.append_trace(go.Candlestick(x=num_2020["日期"],
                open=num_2020["开盘"],
                high=num_2020["最高"],
                low=num_2020["最低"],
                close=num_2020["收盘"],
                increasing_line_color="red", decreasing_line_color="green",
                name="2020"
            ), row=3, col=3) 
fig.append_trace(go.Candlestick(x=num_2021["日期"],
                open=num_2021["开盘"],
                high=num_2021["最高"],
                low=num_2021["最低"],
                close=num_2021["收盘"],
                increasing_line_color="red", decreasing_line_color="green",
                name="2021"
            ), row=3, col=4)  
fig.append_trace(go.Candlestick(x=num_2014["日期"],
                open=num_2014["开盘"],
                high=num_2014["最高"],
                low=num_2014["最低"],
                close=num_2014["收盘"],
                increasing_line_color="red", decreasing_line_color="green",
                name="2014"
            ), row=2, col=1)
fig.append_trace(go.Candlestick(x=num_2015["日期"],
                open=num_2015["开盘"],
                high=num_2015["最高"],
                low=num_2015["最低"],
                close=num_2015["收盘"],
                increasing_line_color="red", decreasing_line_color="green",
                name="2015"
            ), row=2, col=2)
fig.append_trace(go.Candlestick(x=num_2016["日期"],
                open=num_2016["开盘"],
                high=num_2016["最高"],
                low=num_2016["最低"],
                close=num_2016["收盘"],
                increasing_line_color="red", decreasing_line_color="green",
                name="2016"
            ), row=2, col=3) 
fig.append_trace(go.Candlestick(x=num_2017["日期"],
                open=num_2017["开盘"],
                high=num_2017["最高"],
                low=num_2017["最低"],
                close=num_2017["收盘"],
                increasing_line_color="red", decreasing_line_color="green",
                name="2017"
            ), row=2, col=4)  
fig.update_layout(height=900, width=1200, title_text="春节后走势")
fig.show()

存款准备金率

import akshare as ak
import matplotlib.pyplot as plt

macro_china_reserve_requirement_ratio_df = ak.macro_china_reserve_requirement_ratio()
macro_china_reserve_requirement_ratio_df.to_excel("存款准备金率.xlsx")
plt.plot(macro_china_reserve_requirement_ratio_df["月份"], macro_china_reserve_requirement_ratio_df["大型金融机构-调整后"])
plt.plot(macro_china_reserve_requirement_ratio_df["月份"], macro_china_reserve_requirement_ratio_df["中小金融机构-调整后"])
plt.show()

个股解禁统计

import akshare as ak
import plotly.graph_objects as go

stock_restricted_shares_df = ak.stock_restricted_shares(stock="300750")
stock_restricted_shares_df.to_excel("~/Desktop/解禁.xlsx")
fig = go.Figure()
fig.add_trace(go.Scatter(x=stock_restricted_shares_df["解禁日期"], 
                         y=stock_restricted_shares_df["解禁数量(万股)"],
                         mode="lines+markers",
                         name="解禁数量(万股)"))
fig.show()

汇率走势

import akshare as ak
import matplotlib.pyplot as plt
import matplotlib.ticker as ticker

currency_boc_sina_df = ak.currency_boc_sina(symbol="澳大利亚元", date="20211215")
currency_boc_sina_df.to_excel("澳元汇率走势.xlsx")
tick_spacing = 600
fig, ax = plt.subplots(1, 1)
ax.plot(currency_boc_sina_df["日期"][::-1], currency_boc_sina_df["中行汇买价"][::-1],label="汇买价")
ax.plot(currency_boc_sina_df["日期"][::-1],currency_boc_sina_df["中行钞卖价/汇卖价"][::-1],label="汇卖价")
ax.grid(True) 
ax.xaxis.set_major_locator(ticker.MultipleLocator(tick_spacing))
plt.show()

北向月排行

import akshare as ak
import plotly.express as px

stock_em_hsgt_hold_stock_df = ak.stock_hsgt_hold_stock_em(market="北向", indicator="月排行")
stock_em_hsgt_hold_stock_df.to_excel("北向月排行.xlsx")
fig = px.scatter(stock_em_hsgt_hold_stock_df, x=stock_em_hsgt_hold_stock_df["今日收盘价"], 
            y=stock_em_hsgt_hold_stock_df["月增持估计-股数"].astype(int),
	        hover_name=stock_em_hsgt_hold_stock_df["名称"], log_x=True)
fig.show()

基金持仓信息

import efinance as ef
import openpyxl
from openpyxl.chart import (ProjectedPieChart,Reference)

def createProjectedPieChart(fileName):
    wb = openpyxl.load_workbook(fileName)
    ws = wb["Sheet1"]
    projected_pie = ProjectedPieChart()
    projected_pie.type = "pie"
    projected_pie.splitType = "val"
    labels = Reference(ws, min_col=4, min_row=2, max_row=20)
    data = Reference(ws, min_col=5, min_row=1, max_row=20)
    projected_pie.add_data(data, titles_from_data=True)
    projected_pie.set_categories(labels)
    projected_pie.title = "易方达持仓信息"
    ws.add_chart(projected_pie, "G1")
    wb.save(fileName)

df = ef.fund.get_inverst_position("110011")
df.to_excel("易方达持仓信息.xlsx")
createProjectedPieChart("易方达持仓信息.xlsx")

开放式基金排行

import akshare as ak
import matplotlib.pyplot as plt

fund_em_lcx_rank_df = ak.fund_em_open_fund_rank(symbol="全部")
fund_em_lcx_rank_df.to_excel("开放式基金排行.xlsx")
fig, ax = plt.subplots(1, 1)
ax.set_title("开放式基金排行")
ax.set_xticklabels(fund_em_lcx_rank_df["基金简称"][::300], rotation=90,fontsize="5")
ylabels= list(map(float,fund_em_lcx_rank_df["成立来"][::300]))
ylabels.sort()
ax.set_yticklabels(ylabels)
ax.grid(True)
ax.plot(fund_em_lcx_rank_df["基金简称"][::300],list(map(float,fund_em_lcx_rank_df["成立来"][::300])), "r^")
plt.rcParams["font.sans-serif"] = ["Arial Unicode MS"]
plt.show()

每股分红

import akshare as ak
import plotly.express as px

stock_fhps_em_df = ak.stock_fhps_em(date="20211231")
stock_fhps_em_df.to_excel("2021分红.xlsx")
fig = px.scatter(stock_fhps_em_df, x="每股收益", y="现金分红-现金分红比例",
	            size="总股本", color="每股净资产",
                hover_name="名称", log_x=True, size_max=200)
fig.show()

黄金趋势

import akshare as ak
from plotly.subplots import make_subplots
import plotly.graph_objects as go

spot_hist_sge_df = ak.spot_hist_sge(symbol="Au99.99")
spot_hist_sge_df.to_excel("黄金.xlsx")
fig = make_subplots(rows=1, cols=1) 
fig.append_trace(go.Candlestick(x=spot_hist_sge_df["date"],
                open=spot_hist_sge_df["open"],
                high=spot_hist_sge_df["high"],
                low=spot_hist_sge_df["low"],
                close=spot_hist_sge_df["close"],
                increasing_line_color="red", decreasing_line_color="green",
                name="黄金趋势"
            ), row=1, col=1)
fig.update_layout(height=900, width=1200, title_text="黄金趋势")
fig.show()

每日数据流入

import efinance as ef

df = ef.stock.get_history_bill("300750")
df.to_excel("宁王每日数据流入.xlsx")

债券现券市场概览

import akshare as ak
import plotly as py
import plotly.graph_objs as go

bond_cash_summary_sse_df = ak.bond_cash_summary_sse(date="20220119")
bond_cash_summary_sse_df.to_excel("债券现券市场概览.xls")
pyplt = py.offline.plot
labels = bond_cash_summary_sse_df["债券现货"][:-1]
values = bond_cash_summary_sse_df["托管面值"][:-1]
trace = [go.Pie(labels=labels, values=values)]
layout = go.Layout(
    title = "债券现券市场概览",
)
fig = go.Figure(data = trace, layout = layout)
pyplt(fig, filename="1.html")

基金构成

import efinance as ef
funds = ef.fund.get_quote_history("110011")
funds.to_excel("易方达中小盘.xlsx")

股票账户统计

import akshare as ak
import plotly.graph_objects as go

stock_account_statistics_em_df = ak.stock_account_statistics_em()
stock_account_statistics_em_df.to_excel("股票账户统计.xlsx")
fig = go.Figure()
fig.add_trace(go.Scatter(x=stock_account_statistics_em_df["数据日期"], y=stock_account_statistics_em_df["新增投资者-数量"],
                    mode="lines+markers",
                    name="新增投资者-数量"))
fig.add_trace(go.Scatter(x=stock_account_statistics_em_df["数据日期"], y=stock_account_statistics_em_df["上证指数-收盘"],
                    mode="lines+markers",
                    name="上证指数-收盘"))
fig.show()

IPO获益股投资额

import akshare as ak
import matplotlib.pyplot as plt

stock_ipo_benefit_ths_df = ak.stock_ipo_benefit_ths()
stock_ipo_benefit_ths_df.to_excel("IPO获益股.xlsx")
fig, ax = plt.subplots(1, 1)
line1, =ax.plot(stock_ipo_benefit_ths_df["股票简称"][::-1], stock_ipo_benefit_ths_df["投资总额"][::-1],"ro", label="IPO投资额")
ax.set_xticklabels(stock_ipo_benefit_ths_df["股票简称"][::-1],rotation=90, fontsize="small")
ax.set_title("IPO获益股投资额")
ax.grid(True) 
plt.rcParams["font.sans-serif"] = ["Arial Unicode MS"]
plt.show()

风险板块

import akshare as ak
import matplotlib.pyplot as plt

stock_zh_a_st_em_df = ak.stock_zh_a_st_em()
stock_zh_a_st_em_df.to_excel("风险板块.xlsx")
fig, ax = plt.subplots(1, 1)
line1, = ax.plot(stock_zh_a_st_em_df["名称"], stock_zh_a_st_em_df["涨跌幅"], "r^")
ax.set_title("风险板块")
ax.grid(True) 
plt.rcParams["font.sans-serif"] = ["Arial Unicode MS"]
plt.show()

全部可转债

import efinance as ef

df = ef.bond.get_all_base_info()
df.to_excel("全部可转债.xlsx")

历史走势

import efinance as ef
import matplotlib.pyplot as plt

def minuteStock(stock_code):    
    freq = 1
    df = ef.stock.get_quote_history(stock_code, klt=freq)
    df.to_csv(f"{stock_code}.csv", encoding="utf-8-sig", index=None)
    plt.plot(df["收盘"], "g")
    plt.show()

minuteStock("600519")

历史分红

import akshare as ak
import pandas as pd
import plotly.express as px

stock_history_dividend_df = ak.stock_history_dividend()
stock_history_dividend_df.to_excel("历史分红.xlsx")
df = pd.DataFrame(dict(name=stock_history_dividend_df["名称"], 
        number = stock_history_dividend_df["年均股息(%)"]))
fig = px.scatter(df, x="number", y="name", title="年均股息(%)")
fig.show()

机构调研信息

import akshare as ak
import matplotlib.pyplot as plt

stock_em_jgdy_detail_df = ak.stock_em_jgdy_detail(start_date="20211201")
stock_em_jgdy_detail_df.to_excel("机构调研-详细.xlsx")
groups = stock_em_jgdy_detail_df.groupby("名称")
fig, ax = plt.subplots(1, 1)
ax.pie(groups.size().values,labels=groups.size().index)
ax.set_title("")
ax.legend(loc=1, fontsize="xx-small")
plt.rcParams["font.sans-serif"] = ["Arial Unicode MS"]
plt.show()

日K线

import akshare as ak
import matplotlib.pyplot as plt
import plotly as py
import plotly.graph_objs as go

stock_hk_hist_df = ak.stock_hk_hist(symbol="00001", start_date="20210123", end_date="20220122", adjust="")
stock_hk_hist_df.to_excel("长和.xlsx")
pyplt = py.offline.plot
layout = go.Layout(
    title = "长和日K线",
)
fig = go.Figure(data=[go.Candlestick(x=stock_hk_hist_df["日期"],
                open=stock_hk_hist_df["开盘"],
                high=stock_hk_hist_df["最高"],
                low=stock_hk_hist_df["最低"],
                close=stock_hk_hist_df["收盘"],
                increasing_line_color="red", decreasing_line_color="green", name="日K线")])
pyplt(fig, filename="1.html")

个股可转债

import efinance as ef
import matplotlib.pyplot as plt

bond_code = "113627"
df = ef.bond.get_quote_history(bond_code)
df.to_excel("太平鸟可转债.xlsx")
plt.plot(df["收盘"], "g")
plt.show()

连续上涨

import akshare as ak
import plotly.express as px

stock_rank_lxsz_ths_df = ak.stock_rank_lxsz_ths()
stock_rank_lxsz_ths_df.to_excel("~/Desktop/连续上涨.xlsx")
fig = px.scatter(stock_rank_lxsz_ths_df, y="连续涨跌幅", x="股票简称",  color="连涨天数")
fig.update_traces(marker_size=10)
fig.show()

油价

import akshare as ak
import plotly.graph_objects as go

energy_oil_hist_df = ak.energy_oil_hist()
energy_oil_hist_df.to_excel("~/Desktop/油价.xlsx")
fig = go.Figure()
fig.add_trace(go.Scatter(x=energy_oil_hist_df["日期"], 
                         y=energy_oil_hist_df["汽油价格"],
                    mode="lines+markers",
                    name="汽油价格"))
fig.add_trace(go.Scatter(x=energy_oil_hist_df["日期"], 
                         y=energy_oil_hist_df["柴油价格"],
                    mode="lines+markers",
                    name="柴油价格"))

fig.show()

最新10000条财经信息

import akshare as ak
import jieba
import wordcloud
import matplotlib.pyplot as plt 
import collections

stock_zh_a_alerts_cls_df = ak.stock_zh_a_alerts_cls()
stock_zh_a_alerts_cls_df.to_excel("最新10000条财经信息.xlsx")
seg_list_words = jieba.cut(str(stock_zh_a_alerts_cls_df["快讯信息"]), cut_all = False)
obj_list = []
remove_words = [line.strip() for line in open("/Users/universe/Documents/python/Excel基础操作/词云/stopWords.txt", encoding="UTF-8").readlines()]

for word in seg_list_words:
    if word not in remove_words:
        obj_list.append(word)

word_counts = collections.Counter(obj_list)
wc = wordcloud.WordCloud(
    font_path="/System/Library/Fonts/Supplemental/Arial Unicode.ttf",
    max_words=50,
    max_font_size=100,
    mode="RGBA"
)
wc.generate_from_frequencies(word_counts)
plt.imshow(wc) 
plt.axis("off")
plt.show()

个股热度

import akshare as ak
import plotly.express as px

stock_hot_rank_wc_df = ak.stock_hot_rank_wc(date="20220301")
stock_hot_rank_wc_df.to_excel("热度.xlsx")
fig = px.scatter(stock_hot_rank_wc_df, x="现价", y="涨跌幅",
                 size="个股热度", color="个股热度排名",
                 hover_name="股票简称", log_x=True)
fig.show()

跌停股池

import akshare as ak
import plotly.express as px

stock_zt_pool_dtgc_em_df = ak.stock_zt_pool_dtgc_em(date="20220301")
stock_zt_pool_dtgc_em_df.to_excel("~/Desktop/跌停股池.xlsx")
fig = px.scatter(stock_zt_pool_dtgc_em_df, y="最新价", x="名称",  symbol="动态市盈率")
fig.update_traces(marker_size=10)
fig.show()

股东统计

import akshare as ak
import plotly.graph_objects as go

stock_zh_a_gdhs_detail_em_df = ak.stock_zh_a_gdhs_detail_em(symbol="000002")
fig = go.Figure()
fig.add_trace(go.Scatter(x=stock_zh_a_gdhs_detail_em_df["股东户数统计截止日"], 
                         y=stock_zh_a_gdhs_detail_em_df["股东户数-本次"],
                         mode="lines+markers",
                         name="股东户数-本次"))
fig.add_trace(go.Scatter(x=stock_zh_a_gdhs_detail_em_df["股东户数统计截止日"],
                         y=stock_zh_a_gdhs_detail_em_df["户均持股市值"],
                         mode="lines+markers",
                         name="户均持股市值"))
fig.add_trace(go.Scatter(x=stock_zh_a_gdhs_detail_em_df["股东户数统计截止日"], 
                         y=stock_zh_a_gdhs_detail_em_df["户均持股数量"],
                         mode="lines+markers", 
                         name="户均持股数量"))

fig.show()

机构行业关注度

import akshare as ak
import matplotlib.pyplot as plt

stock_institute_recommend_df = ak.stock_institute_recommend(indicator="行业关注度")
stock_institute_recommend_df.to_excel("机构行业关注度.xlsx")
fig, ax = plt.subplots(1, 1)
ax.plot(stock_institute_recommend_df["行业名称"], stock_institute_recommend_df["买入评级数"], "r^")
ax.set_title("机构行业关注度")
plt.rcParams["font.sans-serif"] = ["Arial Unicode MS"]
plt.show()

连续上涨行业计数

from typing import Counter
import akshare as ak
import matplotlib.pyplot as plt

stock_rank_lxsz_ths_df = ak.stock_rank_lxsz_ths()
stock_rank_lxsz_ths_df.to_excel("连续上涨.xlsx")
fig, ax = plt.subplots(1, 1)
groups = stock_rank_lxsz_ths_df.groupby("所属行业")
ax.plot(groups["股票简称"].count(), "r^")
ax.set_title("连续上涨行业计数")
plt.rcParams["font.sans-serif"] = ["Arial Unicode MS"]
plt.show()

现金流量表

import akshare as ak
import matplotlib.pyplot as plt

stock_financial_report_sina_df = ak.stock_financial_report_sina(stock="600009", symbol="现金流量表")
stock_financial_report_sina_df.to_excel("上海机场现金流量表.xlsx")
fig, ax = plt.subplots(1, 1)
ax.set_title("上海机场现金流量表")
ax.plot(stock_financial_report_sina_df["经营活动现金流出小计"].astype(float), "ro")
ax.plot(stock_financial_report_sina_df["经营活动现金流入小计"].astype(float), "b-.")
ax.set_xticklabels(stock_financial_report_sina_df["报表日期"])
ax.grid(True)
plt.rcParams["font.sans-serif"] = ["Arial Unicode MS"]
plt.show()

资产负债表

import akshare as ak
import matplotlib.pyplot as plt

stock_financial_report_sina_df = ak.stock_financial_report_sina(stock="600009", symbol="资产负债表")
stock_financial_report_sina_df.to_excel("上海机场资产负债表.xlsx")
fig, ax = plt.subplots(1, 1)
ax.set_title("上海机场资产负债表")
ax.plot(stock_financial_report_sina_df["资产总计"].astype(float), "r-.", label="资产总计")
ax.plot(stock_financial_report_sina_df["负债合计"].astype(float), "b-", label="负债合计")
ax.set_xticklabels(stock_financial_report_sina_df["报表日期"])
ax.grid(True)
ax.legend()
plt.rcParams["font.sans-serif"] = ["Arial Unicode MS"]
plt.show()

个股打新

import akshare as ak
import plotly.express as px

stock_dxsyl_em_df = ak.stock_dxsyl_em()
stock_dxsyl_em_df.to_excel("打新.xlsx")
fig = px.scatter(stock_dxsyl_em_df.dropna(), y="首日涨幅", x="股票简称", color="打新收益")
fig.update_traces(marker_size=10)
fig.show()

本周新增热门

import akshare as ak
import plotly.express as px

stock_hot_follow_xq_df = ak.stock_hot_follow_xq(symbol="本周新增")
stock_hot_follow_xq_df.to_excel("本周新增热门.xlsx")
fig = px.scatter(stock_hot_follow_xq_df, x="关注", y="最新价",
	            size="最新价", color="关注",
                hover_name="股票简称", log_x=True, size_max=150)
fig.show()

市值统计

import akshare as ak
import plotly.express as px

stock_em_zt_pool_df = ak.stock_em_zt_pool(date="20220214")
fig = px.scatter(stock_em_zt_pool_df, x="最新价", y="总市值",
	         size="流通市值", color="continent",
             hover_name="名称", log_x=True, size_max=100)
fig.show()

个股周期走势

from pandas_datareader import data
import matplotlib.pyplot as plt

stock_info = data.get_data_yahoo("600519.ss", "2010-01-01","2021-12-02")
stock_info.to_excel("茅台.xlsx")
plt.plot(stock_info["Close"], "g")
plt.show()

股市整体分析

import akshare as ak
import plotly.express as px

stock_market_activity_legu_df = ak.stock_market_activity_legu()
stock_market_activity_legu_df.to_excel("整体分析.xlsx")
fig = px.pie(stock_market_activity_legu_df, 
    values = stock_market_activity_legu_df["value"], 
    names=stock_market_activity_legu_df["item"],
    title="整体概况")
fig.show()

上调评级股票

import akshare as ak
import matplotlib.pyplot as plt

stock_institute_recommend_df = ak.stock_institute_recommend(indicator="上调评级股票")
stock_institute_recommend_df.to_excel("上调评级股票.xlsx")
fig, ax = plt.subplots(1, 1)
stock_institute_recommend_df = stock_institute_recommend_df.dropna()
ax.plot(stock_institute_recommend_df["股票名称"], stock_institute_recommend_df["目标价"], "r^")
ax.set_title("机构行业关注度")
ax.set_xticklabels(stock_institute_recommend_df["股票名称"], rotation=45, fontsize="x-small")
ax.grid(True)
plt.rcParams["font.sans-serif"] = ["Arial Unicode MS"]
plt.show()

盈利预测

import akshare as ak
import matplotlib.pyplot as plt

stock_profit_forecast_df = ak.stock_profit_forecast()
stock_profit_forecast_df.to_excel("盈利预测.xlsx")
fig, ax = plt.subplots(1, 1)
line1, =ax.plot(stock_profit_forecast_df["名称"], stock_profit_forecast_df["2022预测每股收益"],"ro")
line2, =ax.plot(stock_profit_forecast_df["名称"], stock_profit_forecast_df["2023预测每股收益"],"bo")
ax.set_xticklabels(stock_profit_forecast_df["名称"],rotation=90, fontsize="xx-small")
ax.set_title("盈利预测")
ax.legend([line1,line2], labels=["2022收益", "2023收益"])
plt.rcParams["font.sans-serif"] = ["Arial Unicode MS"]
plt.show()

个股相关资讯

import akshare as ak
import jieba
import wordcloud
import matplotlib.pyplot as plt 
import collections

stock_news_em_df = ak.stock_news_em(stock="600509")
stock_news_em_df.to_excel("茅台相关资讯.xlsx")
seg_list_words = jieba.cut(str(stock_news_em_df["content"]), cut_all = False)
obj_list = []
remove_words = [line.strip() for line in open("/Users/universe/Documents/python/Excel基础操作/词云/stopWords.txt", encoding="UTF-8").readlines()]

for word in seg_list_words:
    if word not in remove_words:
        obj_list.append(word)

word_counts = collections.Counter(obj_list)
wc = wordcloud.WordCloud(
    font_path="/System/Library/Fonts/Supplemental/Arial Unicode.ttf",
    max_words=50,
    max_font_size=100,
    mode="RGBA"
)
wc.generate_from_frequencies(word_counts)
plt.imshow(wc) 
plt.axis("off")
plt.show()

最新季度财报

import efinance as ef

df = ef.stock.get_all_company_performance()
df.to_excel("最新季度财报.xlsx")

B股

import akshare as ak
import matplotlib.pyplot as plt

stock_zh_b_spot_df = ak.stock_zh_b_spot()
stock_zh_b_spot_df.to_excel("B股.xlsx")
fig, ax = plt.subplots(1, 1)
line1, =ax.plot(stock_zh_b_spot_df["名称"], stock_zh_b_spot_df["成交额"],"ro", label="B股成交额")
ax.set_xticklabels(stock_zh_b_spot_df["名称"],rotation=90, fontsize="small")
ax.set_title("B股成交额")
ax.grid(True) 
plt.rcParams["font.sans-serif"] = ["Arial Unicode MS"]
plt.show()

次新股

import akshare as ak
import matplotlib.pyplot as plt

stock_zh_a_new_df = ak.stock_zh_a_new()
stock_zh_a_new_df.to_excel("次新股.xlsx")
fig, ax = plt.subplots(1, 1)
line1, =ax.plot(stock_zh_a_new_df["name"], stock_zh_a_new_df["mktcap"][::-1],"ro", label="IPO投资额")
ax.set_xticklabels(stock_zh_a_new_df["name"],rotation=90, fontsize="small")
ax.set_title("次新股市值")
ax.grid(True) 
plt.rcParams["font.sans-serif"] = ["Arial Unicode MS"]
plt.show()

REITs行情

import akshare as ak
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.ticker as ticker

reits_realtime_em_df = ak.reits_realtime_em()
reits_realtime_em_df.to_excel("REITs行情.xlsx")
fig, ax = plt.subplots(1, 1)
line1, =ax.plot(reits_realtime_em_df["名称"], reits_realtime_em_df["最新价"].replace("-",0.0),"ro")
line2, = ax.plot(reits_realtime_em_df["名称"], reits_realtime_em_df["涨跌幅"].replace("-",0.0),"gv")
ax.set_xticklabels(reits_realtime_em_df["名称"],rotation=30, fontsize="small")
ax.set_title("Reits最高价及最近涨跌幅信息")
ax.legend((line1, line2), ["最近最新价", "最近涨跌幅"])
ax.grid(True) 
plt.rcParams["font.sans-serif"] = ["Arial Unicode MS"]
plt.show()

分析师指数排行

import akshare as ak
import matplotlib.pyplot as plt

stock_em_analyst_rank_df = ak.stock_em_analyst_rank()
stock_em_analyst_rank_df.to_excel("分析师指数排行.xlsx")
fig, ax = plt.subplots(1, 1)
ax.set_title("分析师指数排行")
ax.set_xticklabels(stock_em_analyst_rank_df["2021最新个股评级"], rotation=90, fontsize=5)
ax.plot(stock_em_analyst_rank_df["2021最新个股评级"], stock_em_analyst_rank_df["2021年收益率"], "ro")
plt.rcParams["font.sans-serif"] = ["Arial Unicode MS"]
plt.show()

利润表

import akshare as ak
import matplotlib.pyplot as plt

stock_financial_report_sina_df = ak.stock_financial_report_sina(stock="600009", symbol="利润表")
stock_financial_report_sina_df.to_excel("上海机场利润表.xlsx")
fig, ax = plt.subplots(1, 1)
ax.set_title("上海机场利润表")
ax.plot(stock_financial_report_sina_df["一、营业总收入"].astype(float), "r-.")
ax.plot(stock_financial_report_sina_df["二、营业总成本"].astype(float), "b-")
ax.set_xticklabels(stock_financial_report_sina_df["报表日期"])
ax.grid(True)
plt.rcParams["font.sans-serif"] = ["Arial Unicode MS"]
plt.show()