参看:https://stock.hexun.com/2024-10-31/215251914.html
涨幅计算公式:(当前价格 - 上一个交易日收盘价)÷ 上一个交易日收盘价 × 100% 。
跌幅计算公式:(上一个交易日收盘价 - 当前价格)÷ 上一个交易日收盘价 × 100% 。
1、A股
涨幅
比如 5% 到 8%之间
import akshare as ak
import pandas as pd
# 获取当天所有 A 股数据
stock_data = ak.stock_zh_a_spot_em()
# 计算涨幅
stock_data['涨幅'] = (stock_data['最新价'] - stock_data['昨收']) / stock_data['昨收'] * 100
# 筛选涨幅在 5% 到 8% 之间的数据
filtered_data = stock_data[(stock_data['涨幅'] >= 5) & (stock_data['涨幅'] <= 8)]
# 显示结果
filtered_data[['代码', '名称', '涨幅']]
跌幅范围
比如 5% 到 8%之间
import akshare as ak
import pandas as pd
# 获取当天所有 A 股数据
stock_data = ak.stock_zh_a_spot_em()
# 计算跌幅
stock_data['跌幅'] = (stock_data['昨收'] - stock_data['最新价']) / stock_data['昨收'] * 100
# 筛选跌幅在 5% 到 8% 之间的数据
filtered_data = stock_data[(stock_data['跌幅'] >= 5) & (stock_data['跌幅'] <= 8)]
# 显示结果
filtered_data[['代码', '名称', '跌幅']]
2、港股
import akshare as ak
stock_hk_spot_em_df = ak.stock_hk_spot_em()
# 计算跌幅
stock_hk_spot_em_df['跌幅'] = (stock_hk_spot_em_df['昨收'] - stock_hk_spot_em_df['最新价']) / stock_hk_spot_em_df['昨收'] * 100
# 筛选跌幅在 5% 到 8% 之间的数据
filtered_data = stock_hk_spot_em_df[(stock_hk_spot_em_df['跌幅'] >= 5) & (stock_hk_spot_em_df['跌幅'] <= 8)]
# 显示结果
filtered_data[['代码', '名称', '跌幅']]
# 计算涨幅
stock_hk_spot_em_df['涨幅'] = (stock_hk_spot_em_df['最新价'] - stock_hk_spot_em_df['昨收']) / stock_hk_spot_em_df['昨收'] * 100
# 筛选涨幅在 5% 到 8% 之间的数据
filtered_data = stock_hk_spot_em_df[(stock_hk_spot_em_df['涨幅'] >= 5) & (stock_hk_spot_em_df['涨幅'] <= 8)]
# 显示结果
filtered_data[['代码', '名称', '涨幅']]
3、美股
import akshare as ak
stock_us_spot_em_df = ak.stock_us_spot_em()
# 计算涨幅
stock_us_spot_em_df['涨幅'] = (stock_us_spot_em_df['最新价'] - stock_us_spot_em_df['昨收价']) / stock_us_spot_em_df['昨收价'] * 100
# 筛选涨幅在 5% 到 8% 之间的数据
filtered_data = stock_us_spot_em_df[(stock_us_spot_em_df['涨幅'] >= 5) & (stock_us_spot_em_df['涨幅'] <= 8)]
# 显示结果
filtered_data[['代码', '名称', '涨幅']]
# 计算跌幅
stock_us_spot_em_df['跌幅'] = (stock_us_spot_em_df['昨收价'] - stock_us_spot_em_df['最新价']) / stock_us_spot_em_df['昨收价'] * 100
# 筛选跌幅在 5% 到 8% 之间的数据
filtered_data = stock_us_spot_em_df[(stock_us_spot_em_df['跌幅'] >= 5) & (stock_us_spot_em_df['跌幅'] <= 8)]
# 显示结果
print(filtered_data[['代码', '名称', '跌幅']])