吾爱破解 - 52pojie.cn

 找回密码
 注册[Register]

QQ登录

只需一步,快速开始

查看: 18208|回复: 390
收起左侧

[Python 原创] 股票AI分析,兴趣分享

    [复制链接]
jiatengxian 发表于 2026-1-8 11:45
本帖最后由 jiatengxian 于 2026-1-15 13:39 编辑

注:下述仅是个人观点,仅供参考

这是一个根据自己对股票的想法用(AI)帮忙分析出来的程序,
分析想法:
1、2025今年一进二成功率最大的存在哪些共性
2、帮我生成对应的python脚本

由于自己电脑性能问题,运行脚本需要时间有些长(3-10分钟)

因:包含akshare依赖,所以.exe文件比较大(akshare = 用 Python 免费获取各类金融市场公开数据的工具库。)

由于脚本较长就不在文档中直接提现了,下方附有python脚本生成的.exe  可以直接使用,


以下源码仅供参考
[Python] 纯文本查看 复制代码
import akshare as ak
import pandas as pd
import datetime

# 新函数:动态获取热门板块(概念或行业)
def get_hot_sectors(date, top_n=10, sector_type="概念"):  # sector_type: "概念" or "行业"
    indicator = "今日"  # 可换 "5日"等
    sector_param = f"{sector_type}资金流"
    try:
        df = ak.stock_sector_fund_flow_rank(indicator=indicator, sector_type=sector_param)
        # 按主力净流入降序,取top_n名称
        hot_sectors = df.sort_values(by='主力净流入', ascending=False).head(top_n)['板块名称'].tolist()
        print(f"动态热门{sector_type} ({date}): {hot_sectors}")
        return hot_sectors
    except Exception as e:
        print(f"获取热门{sector_type}失败: {e},使用默认。")
        return ['半导体', '海南', '机器人']  # fallback

# 定义函数获取历史涨停数据并计算一进二概率(历史保持固定combo)
def analyze_historical_prob(date_start='20240101', date_end=None):
    if date_end is None:
        date_end = datetime.datetime.now().strftime('%Y%m%d')
    
    # 获取历史所有涨停池
    dates = pd.date_range(start=date_start, end=date_end).strftime('%Y%m%d')
    zt_df_list = []
    for d in dates:
        try:
            df = ak.stock_zt_pool_em(date=d)
            if not df.empty:
                df['date'] = pd.to_datetime(d)
                zt_df_list.append(df)
        except:
            pass
    if not zt_df_list:
        return None  # 无历史数据,返回None
    
    historical_zt = pd.concat(zt_df_list, ignore_index=True)
    
    # 添加circ_mv (流通市值,单位亿)
    historical_zt['circ_mv'] = historical_zt['流通市值'] / 100000000
    
    # 排序并识别首板和次日zt
    historical_zt = historical_zt.sort_values(['代码', 'date'])
    historical_zt['prev_date'] = historical_zt.groupby('代码')['date'].shift(1)
    historical_zt['is_first_board'] = historical_zt['prev_date'].isna() | (historical_zt['date'] - historical_zt['prev_date'] > pd.Timedelta(days=1))
    
    historical_zt['next_date'] = historical_zt.groupby('代码')['date'].shift(-1)
    historical_zt['next_day_zt'] = (historical_zt['next_date'] - historical_zt['date']) == pd.Timedelta(days=1)
    
    # 定义指标组合,计算概率
    # 早封板: 首次封板时间 < '1030' (格式'HHMMSS',取前4位)
    historical_zt['early_seal'] = historical_zt['首次封板时间'].astype(str).str[:4] < '1030'
    
    combos = {
        'combo1': (historical_zt['换手率'] > 20) & (historical_zt['circ_mv'] < 50) & historical_zt['early_seal'],  # 高换手+小市值+早封
        'combo2': (historical_zt['换手率'] > 15) & historical_zt['所属行业'].str.contains('半导体|海南|机器人'),  # 换手+热点(历史固定)
        # 可添加更多
    }
    max_prob = 0
    best_combo = None
    for name, cond in combos.items():
        subset = historical_zt[historical_zt['is_first_board'] & cond]
        if len(subset) > 0:
            prob = subset['next_day_zt'].mean()
            if prob > max_prob:
                max_prob = prob
                best_combo = cond
    print(f"最高概率组合: {max_prob*100:.2f}%")
    return best_combo

# 辅助函数:回溯找到非空涨停数据日期(max_back_days=7)
def get_valid_zt_date(target_date, max_back_days=7):
    date_obj = datetime.datetime.strptime(target_date, '%Y%m%d')
    for i in range(max_back_days + 1):
        check_date = (date_obj - datetime.timedelta(days=i)).strftime('%Y%m%d')
        try:
            df = ak.stock_zt_pool_em(date=check_date)
            if not df.empty:
                print(f"使用回溯日期: {check_date} (原: {target_date})")
                return check_date, df
        except:
            pass
    print("无可用涨停数据。")
    return None, pd.DataFrame()

# 主函数(推荐时使用动态热点)
def recommend_stocks():
    now = datetime.datetime.now()
    today = now.strftime('%Y%m%d')
    if now.hour >= 15:
        # 分析今日首板,推荐明天买
        analysis_date = today
        buy_day = '明天'
    else:
        # 分析昨天首板,推荐今天买
        yesterday = (now - datetime.timedelta(days=1)).strftime('%Y%m%d')
        analysis_date = yesterday
        buy_day = '今天'
    
    # 获取分析日涨停池(回溯如果空)
    analysis_date, zt_df = get_valid_zt_date(analysis_date)
    if zt_df.empty:
        print("无涨停数据,无法推荐。")
        return
    
    # 获取前日涨停池(回溯如果空)
    prev_date = (datetime.datetime.strptime(analysis_date, '%Y%m%d') - datetime.timedelta(days=1)).strftime('%Y%m%d')
    prev_date, prev_zt = get_valid_zt_date(prev_date)
    # 处理空prev_zt
    try:
        prev_codes = prev_zt['代码']
    except KeyError:
        prev_codes = pd.Series()
    
    # 过滤首板
    first_board = zt_df[~zt_df['代码'].isin(prev_codes)]
    
    if first_board.empty:
        print("无首板股票,无法推荐。")
        return
    
    # 添加circ_mv
    first_board['circ_mv'] = first_board['流通市值'] / 100000000
    
    # 添加early_seal
    first_board['early_seal'] = first_board['首次封板时间'].astype(str).str[:4] < '1030'
    
    # 获取最佳组合(从历史)
    best_combo = analyze_historical_prob()
    
    # 为推荐动态更新热点(假设best_combo含热点;否则默认combo1)
    hot_sectors = get_hot_sectors(analysis_date, top_n=10, sector_type="概念")  # 或 "行业"
    dynamic_contains = '|'.join(hot_sectors)
    dynamic_combo = (first_board['换手率'] > 15) & first_board['所属行业'].str.contains(dynamic_contains)
    
    if best_combo is None:
        best_combo = (first_board['换手率'] > 20) & (first_board['circ_mv'] < 50) & first_board['early_seal']
    else:
        # 合并动态热点到best_combo
        best_combo = dynamic_combo | best_combo  # 或根据实际
    
    # 应用最佳组合,推荐5只(按换手率降序)
    recommended = first_board[best_combo].sort_values(by='换手率', ascending=False).head(5)
    
    # 如果少于5,补充top换手率首板股
    if len(recommended) < 5:
        print(f"最高组合只找到{len(recommended)}只,补充top换手率首板股到5只。")
        additional = first_board[~first_board['代码'].isin(recommended['代码'])].sort_values(by='换手率', ascending=False).head(5 - len(recommended))
        recommended = pd.concat([recommended, additional])
    
    print(f"基于{analysis_date}首板,推荐{buy_day}买的5只股票(最高概率组合,动态热点):")
    print(recommended[['代码', '名称', '换手率', 'circ_mv', '首次封板时间', '所属行业']])

if __name__ == '__main__':
    new_var = recommend_stocks()





(由于只是测试版,后续还要根据市场完善,使用test临时命名)

通过网盘分享的文件:test_new.exe
链接: https://pan.baidu.com/s/1z2x0Qjg4i1Nwau98m2UFeQ?pwd=erv2 提取码: erv2
评论区好多告警的,或者是运行直接闪退的,问题优化
运行时长:10分钟
下载至桌面直接双击运行。运行中屏蔽告警,运行完毕后自动关闭并在桌面生成test.txt文件,可直接在txt文档中查看结果






上述如报错“”C:\\Users\\XXXXX\\AppData\\Local\\Temp\\_MEI25011\\akshare\\file_fold\\calendar.json'“”
可以试下,下方连接
链接:https://pan.baidu.com/s/1bvPbabQ46u7xQ4Rs4lC-Xg?pwd=3udt 提取码:3udt 复制这段内容后打开百度网盘手机App,操作更方便哦
有告警,需要根据运行图一图二使用命令行运行,运行时间10分钟


注:兴趣分享,仅供参考,不作为任何建议





补充运行方式:文件下载后直接放到桌面,win+R后按照图一,图二运行后就可以静等结果,不同配置电脑运行时间不同




运行方式图2

运行方式图2

运行方式图1

运行方式图1

上述.exe文件运行结果

上述.exe文件运行结果

免费评分

参与人数 82吾爱币 +83 热心值 +75 收起 理由
liao123 + 1 谢谢@Thanks!
woeine + 1 + 1 我很赞同!
a247464 + 1 + 1 热心回复!
yaoshuai930 + 1 我很赞同!
chen152 + 1 + 1 我很赞同!
xicole + 1 + 1 谢谢@Thanks!
Gentia + 1 + 1 我很赞同!
caciko + 1 + 1 谢谢@Thanks!
af8889 + 1 + 1 谢谢@Thanks!
小志在90 + 1 我很赞同!
lejingsky + 1 + 1 我很赞同!
苏紫方璇 + 7 + 1 欢迎分析讨论交流,吾爱破解论坛有你更精彩!
lgg51 + 1 + 1 感谢发布原创作品,吾爱破解论坛因你更精彩!
lyasima + 1 + 1 谢谢@Thanks!
sunnymed + 1 + 1 有钱大家赚
18630082047 + 1 + 1 用心讨论,共获提升!
myqyx819 + 1 + 1 谢谢@Thanks!
rebirthboy + 1 我很赞同!
zbxzbxzbx + 1 + 1 谢谢@Thanks!
hello95271 + 1 + 1 我很赞同!
zzmjxxy + 1 + 1 我很赞同!
ivy + 1 + 1 我很赞同!
ningyuana + 1 + 1 谢谢@Thanks!
lijiaxian + 1 + 1 谢谢@Thanks!
hhhh1230 + 1 + 1 热心回复!
wzqlove11 + 1 + 1 谢谢@Thanks!
凡凡之呗 + 2 + 1 热心回复!
dingwuai + 1 + 1 谢谢@Thanks!
wuyuedian + 1 + 1 用心讨论,共获提升!
nizhengaiqiu + 1 + 1 感谢发布原创作品,吾爱破解论坛因你更精彩!
yzqgeorge + 1 + 1 谢谢@Thanks!
鬼话 + 1 + 1 2026能不能发大财就靠它了
种花家的流芒兔 + 1 + 1 用心讨论,共获提升!
xiaodaoke + 1 谢谢@Thanks!
策士 + 1 + 1 鼓励转贴优秀软件安全工具和文档!
Guaf + 1 + 1 谢谢@Thanks!
艾弗幽C剋 + 1 + 1 我很赞同!
imumu1239 + 1 + 1 谢谢@Thanks!
lin5789 + 1 热心回复!
gaomi666 + 1 + 1 热心回复!
xfsan + 1 + 1 热心回复!
Pablo + 1 + 1 热心回复!
szddsxj + 1 + 1 谢谢@Thanks!
心脏 + 1 + 1 我很赞同!
chzhy1986 + 1 用心讨论,共获提升!
Alldate + 1 谢谢@Thanks!
PCWL1969 + 1 + 1 谢谢@Thanks!
snakenba580 + 1 + 1 谢谢@Thanks!
alpomg0 + 1 + 1 我很赞同!
shudao3001 + 1 + 1 谢谢@Thanks!
jikic + 1 + 1 热心回复!
一个快乐的富豪 + 1 我很赞同!
zj_tj + 1 + 1 热心回复!
九九 + 1 + 1 我很赞同!
Xfx188 + 1 我很赞同!
douhao1423 + 1 谢谢@Thanks!
xiaogao66 + 1 谢谢@Thanks!
hyyqxx + 1 + 1 谢谢@Thanks!
szyuhong + 1 + 1 热心回复!
arctan1 + 1 + 1 热心回复!
xiaoyubuyu + 1 + 1 我很赞同!
不会上树的鱼 + 1 + 1 谢谢@Thanks!
wzywxi + 1 + 1 谢谢@Thanks!
shaunkelly + 1 + 1 我很赞同!
Kellyfor123 + 1 + 1 我很赞同!
lzl12061103 + 1 + 1 谢谢@Thanks!
skykingfox + 1 + 1 谢谢@Thanks!
yangfan1 + 1 + 1 谢谢@Thanks!
lixiaoqiang + 1 + 1 热心回复!
安道尔的鱼 + 1 + 1 热心回复!
liu844363462 + 1 + 1 我很赞同!
zephyrcn + 1 + 1 感谢发布原创作品,吾爱破解论坛因你更精彩!
fengkuang658 + 1 + 1 谢谢@Thanks!
Ttpower + 1 + 1 谢谢@Thanks!
kira007 + 1 + 1 谢谢@Thanks!
zt185 + 2 + 1 我很赞同!
xie303 + 1 + 1 用心讨论,共获提升!
kanekiyan + 1 + 1 谢谢@Thanks!
嘚瑟挨顿揍 + 1 + 1 谢谢@Thanks!
980 + 1 谢谢@Thanks!
liyu0828 + 1 我很赞同!
nywthy + 1 + 1 我很赞同!

查看全部评分

本帖被以下淘专辑推荐:

发帖前要善用论坛搜索功能,那里可能会有你要找的答案或者已经有人发布过相同内容了,请勿重复发帖。

炫迈 发表于 2026-1-8 14:20
akshare这个库确实好用,但体积大是硬伤,我建议老哥可以把exe拆分成两部分,一部分是数据获取,一部分是分析逻辑,这样更新起来方便,用户也不用每次下载大文件

注意到你用了回溯机制找涨停数据,这个很实用,因为A股节假日多,经常遇到空数据,我之前写程序就栽在这上面,老哥这个处理很老道

不过提醒老哥,股票推荐这个事风险很大,特别是用历史数据回测,2024年的成功率不代表2025年还有效,去年半导体板块火,今年可能就换AI了,动态热点虽然好,但概念轮动太快,建议加个风险控制模块

免费评分

参与人数 4吾爱币 +2 热心值 +4 收起 理由
策士 + 1 + 1 鼓励转贴优秀软件安全工具和文档!
happy曲月 + 1 + 1 我很赞同!
Do_zh + 1 我很赞同!
980 + 1 热心回复!

查看全部评分

ppp111 发表于 2026-1-9 21:25
使用回溯日期: 20260109 (原: 20260109)
使用回溯日期: 20260108 (原: 20260108)
pandas\core\generic.py:4497: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead

See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
pandas\core\generic.py:4497: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead

See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
piwei 发表于 2026-1-12 10:07
使用回溯日期: 20260109 (原: 20260111)
使用回溯日期: 20260108 (原: 20260108)
pandas\core\generic.py:4497: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead

See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
pandas\core\generic.py:4497: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead

See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy

一样提示这个
水清有鱼 发表于 2026-1-11 19:33
支持一下,老哥6666
gfy82 发表于 2026-1-8 16:00
了解一下这个软件
wzgztx 发表于 2026-1-8 15:07
支持下老哥
nywthy 发表于 2026-1-8 14:17
这个必须支持一下子!
nywthy 发表于 2026-1-8 14:18
期待完善更新。
agdzc 发表于 2026-1-8 14:22
下载看看效果
lsll 发表于 2026-1-8 14:25
支持原创,虽然不用,但精神可嘉
mzwlj05 发表于 2026-1-8 14:33
期待完善,继续更新
YiRenYiCheng 发表于 2026-1-8 14:36
试一下也好
DUNJIAO 发表于 2026-1-8 14:43
厉害啊,一直都有这样的想法
lasx 发表于 2026-1-8 14:46
支持
但我不上。
您需要登录后才可以回帖 登录 | 注册[Register]

本版积分规则

返回列表

RSS订阅|小黑屋|处罚记录|联系我们|吾爱破解 - 52pojie.cn ( 京ICP备16042023号 | 京公网安备 11010502030087号 )

GMT+8, 2026-9-11 06:26

Powered by Discuz!

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表