尽管有连续三天跌,第四天上涨的概率>0.5,但是也不意味着一定会盈利。因为还要看涨跌大幅度。所以,我们应该来假设,于连续跌三天的最后时刻买入,而后第四天临近收盘卖出,看这样的最终盈利是多少。假设我们每次买的都是1w的本金。我们来计算。
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
up_count = 0
sum = 0
# 遍历数据
for i in range(len(data)-3):
# 判断是否连续三天下跌
if data['涨跌幅'][i] < 0 and data['涨跌幅'][i+1] < 0 and data['涨跌幅'][i+2] < 0:
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("连续三天下跌的次数为:", total_count)
print("连续三天下跌后,下一天上涨次数为:", up_count)
print("连续三天下跌后,下一天上涨的概率为:", probability)
print("出现连续三天下跌平均需要多少条K线:" , len(data)/total_count)
print("假如每次买",benjin,"最后会赚的钱为:",sum)
看结果:
可见,胜率高不代表赚得就多,胜率低,不代表赚的就少。