010:连续跌3天,同时这三天收盘价都在20日均线下,第四天上涨的概率--以京泉华为例

对于《连续跌三天,压第四天上涨的盈利计算》,我们可以继续优化这个策略,增加条件:同时三天都收盘在20日均线下。

因为我们上一篇《获取20日均线数据到excel表中》获得了20日均线数据,我们可以利用均线数据来编写新的脚本。这里我们用京泉华(SZ002885)为例子。

步骤:

1,用《根据股票代码和起始日期获取K线数据到excel表》的脚本获取京泉华最近大约三年的K线数据,得到文件《002885.csv》

2,用《获取20日均线数据到excel表中》的脚本获取到文件《avg_20_002885.csv》

3,最后用以下脚本(名为:three_day_green_20_low.py)来获取最终的结果:

python 复制代码
import tkinter as tk
from tkinter import filedialog
import pandas as pd

path=''
benjin = 10000.00

def open_file():
    global path
    path = filedialog.askopenfilename(initialdir="./", title="Select file", filetypes=(("Text files", "*"), ("All files", "*.*")))
    print("Selected file:", path)
    root.quit()  # 选择完文件后退出主循环

root = tk.Tk()
root.title("File Selector")

button = tk.Button(root, text="Open File", command=open_file)
button.pack()

root.mainloop()

# 读取表格数据
data = pd.read_csv(path, delimiter=',')

# 初始化计数器
total_count = 0
old_count = 0
up_count = 0
sum = 0

# 遍历数据
for i in range(len(data)-3):
    if(i<20):
        continue
    # 判断是否连续三天下跌
    if data['涨跌幅'][i] < 0 and data['涨跌幅'][i+1] < 0 and data['涨跌幅'][i+2] < 0:
        old_count += 1
        if data['收盘'][i] <  data["20日均线"][i] and data['收盘'][i+1] <  data["20日均线"][i+1] and data['收盘'][i+2] <  data["20日均线"][i+2] :
            total_count += 1
            if(i+4<len(data)):
                sum = data['涨跌幅'][i+4]/100*benjin + sum
            # 判断第四天是否上涨
            if data['涨跌幅'][i+3] > 0:
                up_count += 1

# 计算概率
probability = up_count / total_count
print("K线总数:",len(data))
print("连续三天下跌的次数为:", old_count)
print("连续三天下跌,而且三天收盘价都小于20日均线的次数:", total_count)

print("连续三天下跌后,而且三天收盘价都小于20日均线,下一天上涨次数为:", up_count)
print("连续三天下跌后,而且三天收盘价都小于20日均线,下一天上涨的概率为:", probability)
print("出现连续三天下跌,而且三天收盘价都小于20日均线,平均需要多少条K线:" , len(data)/total_count)
print("假如每次买",benjin,"最后会赚的钱为:",sum)

执行后,选择文《avg_20_002885.csv》:

打开,然后看结果:

可以多统计不同的个股,找到一些相对合适的标的。

相关推荐
天天进步20151 分钟前
Python全栈项目--基于机器学习的异常检测系统
开发语言·python·机器学习
xxie1237947 小时前
return与print
开发语言·python
秋97 小时前
从 Python 后端工程师转型 AI Engineer(AI 工程化)的完整补课清单(2026实战版)
开发语言·人工智能·python
慕木沐8 小时前
Google ADK Java 1.0版本 核心机制与实战 Demo
java·开发语言·python
Tbisnic8 小时前
AI大模型学习第十一天:技术选型、安全防护与金融实战
python·学习·ai·大模型·提示词工程
hboot9 小时前
AI工程师第一课 - Python
前端·后端·python
许彰午10 小时前
30_Java Stream流操作全解
java·windows·python
秋910 小时前
3年经验Python后端转AI Engineer:3个月实战转型计划(2026版)
开发语言·人工智能·python
2601_9563198810 小时前
期货夜盘无人值守监控什么:断线、无成交与拒单信号
python·区块链
CTA终结者10 小时前
期货量化目标仓和净持仓对不齐:天勤 TargetPosTask 与 pos 偏差排查
python·区块链