Ejemplo n.º 1
0
def main():
    act = input(
        "1.执行今日操作\n2.进行数据模拟\n 3.拉取全部基金列表\n4.拉取指定基金数据\n5.进行当前数据排名\n6.修复拉取忽略列表\n"
    )
    if act == "1":
        for code in code_list:
            market = simulation_market()
            market.code = code
            market.handel_today()
    elif act == "2":
        market = simulation_market()
        code = input("fund code = ")
        start_day = input("start date = ")
        end_day = input("end date = ")
        start_money = int(input("start money = "))
        market.auto_running(code, start_day, end_day, start_money)
    elif act == "3":
        fund_data_manager.get_ins().check_out_all_fund_code()
    elif act == "4":
        fund_data_manager.get_ins().check_out_fund_base_data()
    elif act == "5":
        fund_filter.rank_fund_base_data()
    elif act == "6":
        db = db_loader.get_ins().load_db("fund_base_data")
        code_list_cur = db.get_all_keys()
        ignore_db = db_loader.get_ins().load_db("ignore_base_data_pull_list")
        ignore_db.set_info("ignore_list", code_list_cur)
    db_loader.get_ins().close()
Ejemplo n.º 2
0
def update(code):
    cur_time = time.localtime() 
    year = cur_time[0]
    mon = cur_time[1]
    day = cur_time[2]
    today_str = "{0}-{1}-{2}".format(str(year).zfill(2), str(mon).zfill(2),str(day).zfill(2))
    today_struct = time.strptime(today_str,'%Y-%m-%d')
    today_stamp = time.mktime(today_struct)
    target_day = None
    while True:
        time_struct = time.localtime(today_stamp) 
        year = time_struct[0]
        mon = time_struct[1]
        day = time_struct[2]
        day_str = "{0}-{1}-{2}".format(str(year).zfill(2), str(mon).zfill(2),str(day).zfill(2))
        if fund_data_manager.get_ins().get_day_data(code,day_str) != "sub":
            target_day = day_str
            break
        else:
            today_stamp -= 24 * 3600
    if target_day:
        if target_day == today_str:
            print("data is already up to date")
        else:
            print(code,"update from ",target_day," to ",today_str)
            fund_data_manager.get_ins().pull_cur_to_target_day(code,target_day)
            print("update finish !")
Ejemplo n.º 3
0
def check_out(code):
    date = input("input date = ")
    print(code,date,"START CHECK OUT ?(y/n)")
    go = input()
    if go == "y":
        fund_data_manager.get_ins().pull_cur_to_target_day(str(code),date)
        print("check out finish !")
    else: 
        print("cancel CHECK OUT")
Ejemplo n.º 4
0
    def handel_today(self):
        if self.code == None:
            self.code = input("input code = ")
        else:
            print("====================> handel ", self.code)
        is_exist = fund_data_manager.get_ins().check_fund_data_exist(self.code)
        if not is_exist:
            print("缺少基础数据库,需要先checkout当前基金数据")
            fund_data_puller.main()
        tactics = None

        if fund_data_manager.get_ins().check_fund_data_exist("running_data_" +
                                                             self.code):
            print("加载交易进程")
            tactics = every_day_tactics(0, "", self.code)
            tactics.load_today()
        else:
            print("不存在该进程")
            if input("初始化交易进程?(Y/N) ") == "y":
                start_date = input("start date (year-mon-day) ")
                if start_date == "":
                    today_struct = time.localtime()
                    start_date = "{0}-{1}-{2}".format(
                        str(today_struct[0]).zfill(2),
                        str(today_struct[1]).zfill(2),
                        str(today_struct[2]).zfill(2))
                start_money = input("start money ")
                tactics = every_day_tactics(int(start_money), start_date,
                                            self.code)
                db_loader.get_ins().load_db("running_data_" + self.code)
            else:
                return
        self.tactics.append(tactics)
        if fund_data_manager.get_ins().check_today_need_pull(self.code):
            tactics.update_db_data()
        today_struct = time.localtime()
        today = "{0}-{1}-{2}".format(
            str(today_struct[0]).zfill(2),
            str(today_struct[1]).zfill(2),
            str(today_struct[2]).zfill(2))
        print("今日交易日期", today, "操作代码", self.code)
        is_go = True
        self.today = today
        tactics.on_end_today(self.today)
        self.simulation()
        tactics.save_today()
        if input("显示折线图?(Y/N) ") == "y":
            ret = self.filter_tactic_record()
            self.draw_plt(ret)
Ejemplo n.º 5
0
    def cal_next_day(self):

        target_day = time.strptime(self.today, '%Y-%m-%d')
        target_stamp = time.mktime(target_day)
        target_stamp += 3600 * 24
        next_day = time.localtime(target_stamp)
        self.today = "{0}-{1}-{2}".format(
            str(next_day[0]).zfill(2),
            str(next_day[1]).zfill(2),
            str(next_day[2]).zfill(2))
        if fund_data_manager.get_ins().get_day_data(self.code,
                                                    self.today) == "sub":
            return False
        else:
            return True
Ejemplo n.º 6
0
 def load_today(self):
     db = db_loader.get_ins().get_db("running_data_" + self.code)
     self.start_money = db.get_info("start_money")
     self.last_money = db.get_info("last_money")
     self.cur_money = db.get_info("cur_money")
     self.trading_list = db.get_info("trading_list")
     self.hold_stock = db.get_info("hold_stock")
     self.start_day = db.get_info("start_day")
     self.today = db.get_info("today")
     self.record_list = db.get_info("record_list")
     self.today_trading_money = db.get_info("today_trading_money")
     self.today_sell_vol = db.get_info("today_sell_vol")
     self.temp_data = db.get_info("temp_data")
     self.buy_list = db.get_info("buy_list")
     self.risk_per = db.get_info("risk_per")
     self.price_list = db.get_info("price_list")
     self.sell_per = db.get_info("sell_per")
     date = self.find_next_trad_day(self.start_day)
     self.start_price = fund_data_manager.get_ins().get_day_data(
         self.code, date)
     self.wave = db.get_info("wave") or []
     self.wave_dir = db.get_info("wave_dir") or 0
     self.last_dir = db.get_info("last_dir") or 0
     self.limit_price = db.get_info("limit_price") or 0
Ejemplo n.º 7
0
    def today_decision(self):
        cur_time = time.localtime()
        if cur_time[3] > 14:
            print("今日买卖时间已经结束,不能再进行交易")
            return
        basis_day = self.find_next_trad_day(self.today, end_date=-1, dir=-1)
        basis_data = fund_data_manager.get_ins().get_day_data(
            self.code, basis_day)
        if basis_data == "sub":
            return
        cur_price = basis_data[1]  #当前价格
        hold_price = self.cal_hold_avg_price()  #持有成本价格
        last_price = self.find_last_limit_price(20)
        avg10 = self.cal_last_average(10)
        min_20 = last_price[0]
        max_20 = last_price[1]

        if self.hold_stock == 0:
            if cur_price >= max_20:
                print(basis_day, "BUY", "突破二十日最大值,当前价格", cur_price, "20日最高价",
                      max_20, "买入", round(self.last_money * 0.25, 2), "(Y/N)?")
                if input() == "y":
                    self.buy(self.last_money * 0.25, "突破二十日最大值")
                return
        else:
            last_buy_day = self.trading_list[-1][2]
            cur_time_stamp = time.mktime(time.strptime(basis_day, '%Y-%m-%d'))
            last_time_stamp = time.mktime(
                time.strptime(last_buy_day, '%Y-%m-%d'))
            if (avg10 - cur_price) / avg10 > 0.05 and (
                    cur_time_stamp - last_time_stamp) / (24 * 3600) > 5:
                self.sell_per -= 10
                self.sell_per = max(self.sell_per, 100)
                print(basis_day, "BUY", "补仓,当前价格", cur_price, "10日均价", avg10,
                      "买入", round(self.cur_money * 0.25, 2), "(Y/N)?")
                if input() == "y":
                    self.buy(self.cur_money * 0.1, "补仓")
                return

            if (cur_price -
                    hold_price) / hold_price * 100 > self.sell_per + 10 and (
                        cur_time_stamp - last_time_stamp) / (24 * 3600) > 5:
                self.sell_per += 10
                print(basis_day, "SELL", "触发卖出点", cur_price, "持仓价", hold_price,
                      "卖出", round(self.hold_stock * 0.2, 2), "(Y/N)?")
                if input() == "y":
                    self.sell(self.hold_stock * 0.2, "卖出20%")
                return
            if (cur_price - hold_price) / hold_price * 100 > 20:
                self.sell_per = 100
                print(basis_day, "SELL", "触发止盈点", cur_price, "持仓价", hold_price,
                      "卖出", round(self.hold_stock, 2), "(Y/N)?")
                if input() == "y":
                    self.sell(self.hold_stock, "止盈")
                return

        today_avg = self.cal_last_average_start_date(5, basis_day)
        last_avg = self.cal_last_average_start_date(5, basis_day, 1)
        today_dir = self.wave_dir
        if last_avg > today_avg:
            today_dir = -1
        elif last_avg < today_avg:
            today_dir = 1
        if len(self.wave) == 0:
            self.wave.append((basis_day, today_avg))
            self.wave_dir = today_dir
            self.last_dir = today_dir
            self.limit_price = today_avg
            return
        else:
            cur_dir = self.wave_dir
            #当前不是平台期
            if cur_dir != 0:
                #出现方向变化,转入平台期
                if cur_dir != today_dir:
                    self.last_dir = self.wave_dir
                    self.wave_dir = 0
                    self.wave.append((basis_day, today_avg))
                self.limit_price = today_avg
            else:
                #当前是平台期
                #平台期均价和当前均价相差3%就视为移出平台期
                if abs(self.limit_price -
                       today_avg) / self.limit_price * 100 > 3:
                    self.wave_dir = today_dir
                    self.wave.append((basis_day, today_avg))
                    if today_dir == 1 and self.hold_stock > 0:
                        print(basis_day, "SELL", "触发平台期结束", cur_price,
                              "持仓价", hold_price, "卖出",
                              round(self.hold_stock / 2, 2), "(Y/N)?")
                        if input() == "y":
                            self.sell(self.hold_stock / 2, "触发平台期结束")
                    if today_dir == -1:
                        if hold_price > cur_price:
                            print(basis_day, "BUY", "触发平台期结束,方向向下", cur_price,
                                  "持仓价", hold_price, "加仓",
                                  round(self.cur_money / 4, 2), "(Y/N)?")
                            if input() == "y":
                                self.buy(self.cur_money / 4, "继续加仓")
                        elif self.hold_stock > 0:
                            print(basis_day, "SELL", "触发平台期结束,方向向下", cur_price,
                                  "持仓价", hold_price, "清仓",
                                  round(self.hold_stock, 2), "(Y/N)?")
                            if input() == "y":
                                self.sell(self.hold_stock, "清仓")

        print(self.today, "没有任何操作")