Exemplo n.º 1
0
def main(opt):
    pool = Mail_Pool()
    if opt.add_acnt:
        pool.add_account()
    elif opt.remove_acnt:
        pool.remove_account()
    elif opt.show_acnts:
        pool.show_current_accounts()
    elif opt.send:
        send_msg = SendMail()
        send_msg.fetch_acnts()
    else:
        choices = pool.mail_box()
        if choices:
            if opt.read:
                deliver(choices, 'read')
            if opt.delete:
                deliver(choices, 'delete')
            if opt.write:
                deliver(choices, 'write')
            if opt.fetch_stored:
                pool.fetch_stored(choices)
            if opt.delete_stored:
                pool.delete_stored(choices)
Exemplo n.º 2
0
    def two_eight_turn_v3(self):
        subject = "【二八轮动25天间隔测试结果】" + time.strftime("%Y-%m-%d", time.localtime())        

        code_300 = 'sh000300'
        p300_1, p300_20 = GetData().get_index_price_25(code_300)
        delta300 = p300_1 - p300_20
        percent300 = delta300/p300_20
        body_1 = "【沪深300】: %f(今天), %f(25天前), %f(差值), %f%%(差值百分比)\n" % (p300_1, p300_20, delta300, percent300*100)
        code_cyb = 'sz399006'
        pcyb_1, pcyb_20 = GetData().get_index_price_25(code_cyb)
        deltacyb = pcyb_1 - pcyb_20
        percent_cyb = deltacyb/pcyb_20
        body_2 = "【创业板】:  %f(今天), %f(25天前), %f(差值), %f%%(差值百分比)\n" % (pcyb_1, pcyb_20, deltacyb, percent_cyb*100)

        if percent_cyb > percent300 and percent_cyb > 0:
            body_3 = "【买入】创业板ETF\n"
        elif percent300 > percent_cyb and percent300 > 0:
            body_3 = "【买入】300ETF\n"
        else:
            body_3 = "【买入】纳指100\n"
        
        body = body_1 + body_2 + body_3
        print(body)
        SendMail().send_mail(subject, body)   
Exemplo n.º 3
0
    def deal_with_ma60(self):
        # 清理旧记录
        file_name = csv_path + "buy_date_record.csv"
        try:
            os.remove(file_name)
        except:
            print("csv is not exist.")

        code_list, name_list = GetData().read_index_code()
        dict = {}
        for i in range(0, len(code_list)):
            dict[code_list[i]] = name_list[i]
        #print(first_dict)
        print(time.strftime("%Y-%m-%d", time.localtime()))
        subject = "【买入时机测试结果】" + time.strftime("%Y-%m-%d", time.localtime())
        body = ""

        res_name_list = []
        #dict = {"sz000009": "中国宝安"}
        #dict = {"sz300750": "宁德时代"}
        #print(dict)
        for code in dict:
            name = dict[code]
            print("开始处理<" + name + ">")
            buy_date_list = []

            # 读取csv数据
            try:
                test_data = read_data(data_path, dict, code)
            except Exception as e:
                print("读取数据失败:<" + name + ">.csv")
                continue

            for line in test_data[-180:]:
                #print(line)
                try:
                    last_price = float(line[5])
                    ma10_price = float(line[-3])
                    ma60_price = float(line[-2])
                    line_index = test_data.index(line)

                    # 找到10日线和60日线交叉处
                    if ma10_price > ma60_price and test_data[line_index-2][-2] > test_data[line_index-2][-3] and test_data[line_index+2][-2] < test_data[line_index+2][-3]:
                        i = 0
                        count_ma10 = 0
                        count_last = 0
                        #print(test_data[line_index+20][1])
                        while i < 20:
                            # 这个交叉处后20天,10日线始终在60日线上方,每日收盘价始终在60日上方
                            i += 1
                            if test_data[line_index + 2 + i][-3] > test_data[line_index + 2 + i][-2]:
                                #print("a:" + test_data[line_index + 2 + i][-3] + "b:" + test_data[line_index + 2 + i][-2])
                                count_ma10 += 1
                            if test_data[line_index + 3 + i][5] > test_data[line_index + 3 + i][-2]:
                                #print("c:" + test_data[line_index + 2 + i][-3] + "d:" + test_data[line_index + 2 + i][-2])
                                count_last += 1
                            if count_ma10 == 20 and count_last == 20:
                                buy_date_list.append(test_data[line_index+20][1])
                                #print(test_data[line_index+20][1])
                                if get_diff_days_to_now(test_data[line_index+20][1]) < 20:
                                    res_name_list.append(name)

                except Exception as e:
                    continue
            res = "[" + name + "] 买:" + str(buy_date_list) + "\n"
            print(res)
            body = body + res
            print("【处理完成】")
            save_buy_date(csv_path, code, name, buy_date_list)

        body = ""
        res = "[10日线连续在60日线上方20天买入点5日内提示] " + "\n"
        tt = list(set(res_name_list))
        tt.sort()
        for r in tt:
            res = res + r + "\n"
        print(res)
        body = body + res
        SendMail().send_mail(subject, body)
Exemplo n.º 4
0
    def deal_with_ma240_down(self):
        # 清理旧记录
        file_name = csv_path + "buy_date_record.csv"
        try:
            os.remove(file_name)
        except:
            print("csv is not exist.")

        code_list, name_list = GetData().read_index_code()
        dict = {}
        for i in range(0, len(code_list)):
            dict[code_list[i]] = name_list[i]
        #print(first_dict)
        print(time.strftime("%Y-%m-%d", time.localtime()))
        subject = "【买入时机测试结果】" + time.strftime("%Y-%m-%d", time.localtime())
        body = ""

        res_name_list = []
        #dict = {"sz000009": "中国宝安"}
        #dict = {"sz300750": "宁德时代"}
        #print(dict)
        for code in dict:
            name = dict[code]
            print("开始处理<" + name + ">")
            buy_date_list = []

            # 读取csv数据
            try:
                test_data = read_data(data_path, dict, code)
            except Exception as e:
                print("读取数据失败:<" + name + ">.csv")
                continue

            for line in test_data[-600:]:
                #print(line)
                try:
                    last_price = float(line[-5])
                    ma120_price = float(line[-3])
                    ma180_price = float(line[-2])
                    ma240_price = float(line[-1])
                    line_index = test_data.index(line)

                    # 找到每日和240日线交叉处
                    #if ((last_price > ma240_price) and (test_data[line_index-2][-1] > test_data[line_index-2][5])) and (test_data[line_index+2][-1] < test_data[line_index+2][5]):

                    #print(type(test_data[line_index - 2][-1]), type(test_data[line_index - 2][-5]))
                    if (float(test_data[line_index - 2][-1]) < float(test_data[line_index - 2][-5])) and (last_price < ma240_price):
                        i = 0
                        count_ma240 = 0
                        count_last = 0
                        print(line_index, line[1], last_price, ma240_price, test_data[line_index - 2][1], test_data[line_index - 2][-1],
                         test_data[line_index - 2][-5])
                        while i < 30:
                            # 这个交叉处后30天,日线始终在240日线上方,每日收盘价始终在240日上方
                            i += 1
                            if test_data[line_index + 1 + i][-5] < test_data[line_index + 1 + i][-1]:
                                #print("a:" + test_data[line_index + 2 + i][-3] + "b:" + test_data[line_index + 2 + i][-2])
                                count_ma240 += 1
                            if count_ma240 == 30:
                                buy_date_list.append(test_data[line_index+30][1])
                                #print(test_data[line_index+20][1])
                                # 距离现在30天内的日期列入
                                if get_diff_days_to_now(test_data[line_index+30][1]) < 30:
                                    res_name_list.append(name)

                except Exception as e:
                    continue
            res = "[" + name + "] 买:" + str(buy_date_list) + "\n"
            print(res)
            body = body + res
            print("【处理完成】")
            save_buy_date(csv_path, code, name, buy_date_list)

        body = "Total:" + str(len(res_name_list)) + "\n"
        res = "[日线连续在240日线下方30天买入点30日内提示] " + "\n"
        print("Total:" + str(len(res_name_list)))
        tt = list(set(res_name_list))
        tt.sort()
        for r in tt:
            res = res + r + "\n"
        print(res)
        body = body + res
        SendMail().send_mail(subject, body)