示例#1
0
 def setReverse5mIndicator(self, base_time):
     try:
         ### get 5m dataset
         target_time = base_time - timedelta(minutes=5)
 
         dataset = getBollingerWrapper(target_time, self.instrument, table_type="5m", window_size=21, connector=self.mysql_connector, sigma_valiable=2.5, length=0)
         self.upper_sigma_5m25 = dataset["upper_sigmas"][-1]
         self.lower_sigma_5m25 = dataset["lower_sigmas"][-1]
 
         dataset = getBollingerWrapper(target_time, self.instrument, table_type="5m", window_size=20, connector=self.mysql_connector, sigma_valiable=2, length=5)
         self.sma5m20 = dataset["base_lines"][-1]
         self.sma5m20_before = dataset["base_lines"][-5]
 
         dataset = getBollingerWrapper(target_time, self.instrument, table_type="5m", window_size=40, connector=self.mysql_connector, sigma_valiable=2, length=5)
         self.sma5m40 = dataset["base_lines"][-1]
         self.sma5m40_before = dataset["base_lines"][-5]
 
         dataset = getBollingerWrapper(target_time, self.instrument, table_type="5m", window_size=80, connector=self.mysql_connector, sigma_valiable=2, length=5)
         self.sma5m80 = dataset["base_lines"][-1]
         self.sma5m80_before = dataset["base_lines"][-5]
 
 #        self.sma5m20_slope = getSlope([self.sma5m20_before, self.sma5m20])
 #        self.sma5m40_slope = getSlope([self.sma5m40_before, self.sma5m40])
 #        self.sma5m80_slope = getSlope([self.sma5m80_before, self.sma5m80])
 
     except Exception as e:
         message = traceback.format_exc()
         self.debug_logger.info("# %s" % base_time)
         self.debug_logger.info("# %s" % message)
示例#2
0
    def setReverseDailyIndicator(self, base_time):
        ### get daily dataset
        target_time = base_time - timedelta(days=1)
        sql = "select max_price, min_price, start_price, end_price from %s_%s_TABLE where insert_time < \'%s\' order by insert_time desc limit 1" % (self.instrument, "day", target_time) 
        response = self.mysql_connector.select_sql(sql)
        self.max_price_1d = response[0][0]
        self.min_price_1d = response[0][1]
        self.start_price_1d = response[0][2]
        self.end_price_1d = response[0][3]

        dataset = getBollingerWrapper(target_time, self.instrument, table_type="day", window_size=21, connector=self.mysql_connector, sigma_valiable=3, length=0)
        self.upper_sigma_1d3 = dataset["upper_sigmas"][-1]
        self.lower_sigma_1d3 = dataset["lower_sigmas"][-1]


        dataset = getBollingerWrapper(target_time, self.instrument, table_type="day", window_size=21, connector=self.mysql_connector, sigma_valiable=1, length=0)
        self.upper_sigma_1d1 = dataset["upper_sigmas"][-1]
        self.lower_sigma_1d1 = dataset["lower_sigmas"][-1]

        dataset = getBollingerWrapper(target_time, self.instrument, table_type="day", window_size=20, connector=self.mysql_connector, sigma_valiable=2, length=0)
        self.sma1d20 = dataset["base_lines"][-1]

        sql = "select max_price, min_price from %s_%s_TABLE where insert_time < '%s' order by insert_time desc limit 1" % (self.instrument, "day", target_time)
        response = self.mysql_connector.select_sql(sql)
        self.max_price = response[0][0]
        self.min_price = response[0][1]

        self.rsi_value = getRsiWrapper(target_time, self.instrument, "day", self.mysql_connector, 14)
示例#3
0
    def setExpantionIndicator(self, base_time):
        upper_list, lower_list, base_list = getBollingerWrapper(
            base_time,
            self.instrument,
            ind_type="bollinger5m3",
            span=1,
            connector=self.mysql_connector)
        self.upper_sigma_5m3 = upper_list[0]
        self.lower_sigma_5m3 = lower_list[0]
        self.base_line_5m3 = base_list[0]

        upper_list, lower_list, base_list = getBollingerWrapper(
            base_time,
            self.instrument,
            ind_type="bollinger1h3",
            span=1,
            connector=self.mysql_connector)
        self.upper_sigma_1h3 = upper_list[0]
        self.lower_sigma_1h3 = lower_list[0]
        self.base_line_1h3 = base_list[0]

        upper_list, lower_list, base_list = getBollingerWrapper(
            base_time,
            self.instrument,
            ind_type="bollinger1h3",
            span=5,
            connector=self.mysql_connector)
        self.slope = getSlope(base_list)
示例#4
0
    def setReverse1hIndicator(self, base_time):
        ### get 1h dataset
        target_time = base_time - timedelta(hours=1)
        dataset = getBollingerWrapper(target_time,
                                      self.instrument,
                                      table_type="1h",
                                      window_size=28,
                                      connector=self.mysql_connector,
                                      sigma_valiable=3,
                                      length=0)
        self.upper_sigma_1h3 = dataset["upper_sigmas"][-1]
        self.lower_sigma_1h3 = dataset["lower_sigmas"][-1]

        dataset = getBollingerWrapper(target_time,
                                      self.instrument,
                                      table_type="1h",
                                      window_size=100,
                                      connector=self.mysql_connector,
                                      sigma_valiable=2,
                                      length=0)
        self.sma1h100 = dataset["base_lines"][-1]

        dataset = getBollingerWrapper(target_time,
                                      self.instrument,
                                      table_type="1h",
                                      window_size=20,
                                      connector=self.mysql_connector,
                                      sigma_valiable=2,
                                      length=1)
        self.sma1h20 = dataset["base_lines"][-1]
        self.sma1h20_before = dataset["base_lines"][-2]
        self.sma1h20_slope = getSlope([self.sma1h20_before, self.sma1h20])

        dataset = getBollingerWrapper(target_time,
                                      self.instrument,
                                      table_type="1h",
                                      window_size=40,
                                      connector=self.mysql_connector,
                                      sigma_valiable=2,
                                      length=1)
        self.sma1h40 = dataset["base_lines"][-1]
        self.sma1h40_before = dataset["base_lines"][-2]
        self.sma1h40_slope = getSlope([self.sma1h40_before, self.sma1h40])

        dataset = getBollingerWrapper(target_time,
                                      self.instrument,
                                      table_type="1h",
                                      window_size=80,
                                      connector=self.mysql_connector,
                                      sigma_valiable=2,
                                      length=1)
        self.sma1h80 = dataset["base_lines"][-1]
        self.sma1h80_before = dataset["base_lines"][-2]
        self.sma1h80_slope = getSlope([self.sma1h80_before, self.sma1h80])
示例#5
0
    def setExpantionIndicator(self, base_time):
        # set dataset 5minutes
        target_time = base_time - timedelta(minutes=5)

        # set 5m 3sigma bollinger band
        dataset = getBollingerWrapper(target_time,
                                      self.instrument,
                                      table_type="5m",
                                      window_size=28,
                                      connector=self.mysql_connector,
                                      sigma_valiable=2,
                                      length=1)
        self.upper_sigma_5m3_list = dataset["upper_sigmas"][-2:]
        self.lower_sigma_5m3_list = dataset["lower_sigmas"][-2:]
        self.base_line_5m3_list = dataset["base_lines"][-2:]

        # set 5m end price list
        sql = "select end_price from %s_%s_TABLE where insert_time < \'%s\' order by insert_time desc limit 2" % (
            self.instrument, "5m", target_time)
        response = self.mysql_connector.select_sql(sql)
        tmp = []
        for res in response:
            tmp.append(res[0])

        tmp.reverse()
        self.end_price_5m_list = tmp

        # set 5m ema value
        width = 20
        sql = "select end_price from %s_%s_TABLE where insert_time < \'%s\' order by insert_time desc limit %s" % (
            self.instrument, "5m", target_time, width)
        response = self.mysql_connector.select_sql(sql)
        tmp = []
        for res in response:
            tmp.append(res[0])
        tmp.reverse()
        self.ewma20_5mvalue = getEWMA(tmp, len(tmp))[-1]

        # set dataset 1hour
        target_time = base_time - timedelta(hours=1)

        # set 1h 3sigma bollinger band
        dataset = getBollingerWrapper(target_time,
                                      self.instrument,
                                      table_type="1h",
                                      window_size=28,
                                      connector=self.mysql_connector,
                                      sigma_valiable=3,
                                      length=0)
        self.upper_sigma_1h3 = dataset["upper_sigmas"][-1]
        self.lower_sigma_1h3 = dataset["lower_sigmas"][-1]
        self.base_line_1h3 = dataset["base_lines"][-1]
    def setReverseIndicator(self, base_time):
        target_time = base_time - timedelta(hours=1)
        #        dataset = getBollingerWrapper(target_time, self.instrument, table_type="1h", window_size=28, connector=self.mysql_connector, sigma_valiable=3, length=4)
        dataset_length = 4
        dataset = getBollingerWrapper(target_time,
                                      self.instrument,
                                      table_type="1h",
                                      window_size=28,
                                      connector=self.mysql_connector,
                                      sigma_valiable=2.5,
                                      length=dataset_length)
        self.upper_sigma_1h3_list = dataset["upper_sigmas"][(dataset_length *
                                                             -1):]
        self.lower_sigma_1h3_list = dataset["lower_sigmas"][(dataset_length *
                                                             -1):]
        self.base_line_1h3_list = dataset["base_lines"][(dataset_length) * -1:]

        self.upper_sigma_1h25 = dataset["upper_sigmas"][-1]
        self.lower_sigma_1h25 = dataset["lower_sigmas"][-1]

        dataset = getBollingerWrapper(target_time,
                                      self.instrument,
                                      table_type="1h",
                                      window_size=28,
                                      connector=self.mysql_connector,
                                      sigma_valiable=2,
                                      length=0)
        self.upper_sigma_1h2 = dataset["upper_sigmas"][-1]
        self.lower_sigma_1h2 = dataset["lower_sigmas"][-1]
        self.base_line_1h2 = dataset["base_lines"][-1]

        sql = "select start_price, end_price, max_price, min_price from %s_%s_TABLE where insert_time < '%s' order by insert_time desc limit %s" % (
            self.instrument, "1h", target_time, dataset_length)
        response = self.mysql_connector.select_sql(sql)
        self.start_price_list = []
        self.end_price_list = []
        self.max_price_list = []
        self.min_price_list = []
        for res in response:
            self.start_price_list.append(res[0])
            self.end_price_list.append(res[1])
            self.max_price_list.append(res[2])
            self.min_price_list.append(res[3])

        self.start_price_list.reverse()
        self.end_price_list.reverse()
        self.max_price_list.reverse()
        self.min_price_list.reverse()
    def setDailyIndicator(self, base_time):
        hour = base_time.hour
        minute = base_time.minute
        second = base_time.second
        if hour == 7 and minute == 0 and second <= 10:
            self.daily_slope = self.getDailySlope(
                self.instrument,
                base_time,
                span=10,
                connector=self.mysql_connector)
            base_ftime = base_time.strftime("%Y-%m-%d 07:00:00")
            self.high_price, self.low_price = getHighlowPriceWrapper(
                instrument=self.instrument,
                base_time=base_ftime,
                span=1,
                table_type="day",
                connector=self.mysql_connector)
            dataset = getBollingerWrapper(base_time,
                                          self.instrument,
                                          table_type="day",
                                          window_size=28,
                                          connector=self.mysql_connector,
                                          sigma_valiable=2,
                                          length=0)
            self.upper_sigma_1d2 = dataset["upper_sigmas"][-1]
            self.lower_sigma_1d2 = dataset["lower_sigmas"][-1]
            self.base_line_1d2 = dataset["base_lines"][-1]

        if hour == 7 and minute == 10 and second <= 10:
            self.setDailyStartPrice(base_time)
示例#8
0
    def setReverse5mIndicator(self, base_time):
        ### get 5m dataset
        target_time = base_time - timedelta(minutes=5)

        dataset = getBollingerWrapper(target_time,
                                      self.instrument,
                                      table_type="5m",
                                      window_size=28,
                                      connector=self.mysql_connector,
                                      sigma_valiable=2.5,
                                      length=0)
        self.upper_sigma_5m25 = dataset["upper_sigmas"][-1]
        self.lower_sigma_5m25 = dataset["lower_sigmas"][-1]

        dataset = getBollingerWrapper(target_time,
                                      self.instrument,
                                      table_type="5m",
                                      window_size=20,
                                      connector=self.mysql_connector,
                                      sigma_valiable=2,
                                      length=5)
        self.sma5m20 = dataset["base_lines"][-1]
        self.sma5m20_before = dataset["base_lines"][-2]

        dataset = getBollingerWrapper(target_time,
                                      self.instrument,
                                      table_type="5m",
                                      window_size=40,
                                      connector=self.mysql_connector,
                                      sigma_valiable=2,
                                      length=5)
        self.sma5m40 = dataset["base_lines"][-1]
        self.sma5m40_before = dataset["base_lines"][-2]

        dataset = getBollingerWrapper(target_time,
                                      self.instrument,
                                      table_type="5m",
                                      window_size=80,
                                      connector=self.mysql_connector,
                                      sigma_valiable=2,
                                      length=5)
        self.sma5m80 = dataset["base_lines"][-1]
        self.sma5m80_before = dataset["base_lines"][-2]

        self.sma5m20_slope = getSlope([self.sma5m20_before, self.sma5m20])
        self.sma5m40_slope = getSlope([self.sma5m40_before, self.sma5m40])
        self.sma5m80_slope = getSlope([self.sma5m80_before, self.sma5m80])
示例#9
0
    def setReverse1hIndicator(self, base_time):
        ### get 1h dataset
        target_time = base_time - timedelta(hours=1)

        dataset = getBollingerWrapper(target_time, self.instrument, table_type="1h", window_size=21, connector=self.mysql_connector, sigma_valiable=1, length=0)
        self.upper_sigma_1h1 = dataset["upper_sigmas"][-1]
        self.lower_sigma_1h1 = dataset["lower_sigmas"][-1]

        dataset = getBollingerWrapper(target_time, self.instrument, table_type="1h", window_size=21, connector=self.mysql_connector, sigma_valiable=2, length=0)
        self.upper_sigma_1h2 = dataset["upper_sigmas"][-1]
        self.lower_sigma_1h2 = dataset["lower_sigmas"][-1]

        dataset = getBollingerWrapper(target_time, self.instrument, table_type="1h", window_size=21, connector=self.mysql_connector, sigma_valiable=2.5, length=0)
        self.upper_sigma_1h25 = dataset["upper_sigmas"][-1]
        self.lower_sigma_1h25 = dataset["lower_sigmas"][-1]

        dataset = getBollingerWrapper(target_time, self.instrument, table_type="1h", window_size=21, connector=self.mysql_connector, sigma_valiable=3, length=0)
        self.upper_sigma_1h3 = dataset["upper_sigmas"][-1]
        self.lower_sigma_1h3 = dataset["lower_sigmas"][-1]

        dataset = getBollingerWrapper(target_time, self.instrument, table_type="1h", window_size=100, connector=self.mysql_connector, sigma_valiable=2, length=0)
        self.sma1h100 = dataset["base_lines"][-1]

        dataset = getBollingerWrapper(target_time, self.instrument, table_type="1h", window_size=20, connector=self.mysql_connector, sigma_valiable=2, length=5)
        self.sma1h20 = dataset["base_lines"][-1]
        self.sma1h20_before = dataset["base_lines"][-5]
#        self.sma1h20_slope = getSlope([self.sma1h20_before, self.sma1h20])


        dataset = getBollingerWrapper(target_time, self.instrument, table_type="1h", window_size=40, connector=self.mysql_connector, sigma_valiable=2, length=5)
        self.sma1h40 = dataset["base_lines"][-1]
        self.sma1h40_before = dataset["base_lines"][-5]
#        self.sma1h40_slope = getSlope([self.sma1h40_before, self.sma1h40])


        dataset = getBollingerWrapper(target_time, self.instrument, table_type="1h", window_size=80, connector=self.mysql_connector, sigma_valiable=2, length=5)
        self.sma1h80 = dataset["base_lines"][-1]
        self.sma1h80_before = dataset["base_lines"][-5]
#        self.sma1h80_slope = getSlope([self.sma1h80_before, self.sma1h80])


        start_time = self.getStartTime(base_time)
        sql = "select max_price, min_price from %s_%s_TABLE where insert_time > \'%s\' and insert_time < \'%s\'" % (self.instrument, "1h", start_time, base_time)
        response = self.mysql_connector.select_sql(sql)
        tmp_max = []
        tmp_min = []
        for res in response:
            tmp_max.append(res[0])
            tmp_min.append(res[1])
        
        self.thisday_max = max(tmp_max)
        self.thisday_min = min(tmp_min)
示例#10
0
    def setExpantionIndicator(self, base_time):
        dataset = getBollingerWrapper(base_time,
                                      self.instrument,
                                      table_type="5m",
                                      window_size=28,
                                      connector=self.mysql_connector,
                                      sigma_valiable=3,
                                      length=0)
        self.upper_sigma_5m3 = dataset["upper_sigmas"][-1]
        self.lower_sigma_5m3 = dataset["lower_sigmas"][-1]
        self.base_line_5m3 = dataset["base_lines"][-1]

        dataset = getBollingerWrapper(base_time,
                                      self.instrument,
                                      table_type="1h",
                                      window_size=28,
                                      connector=self.mysql_connector,
                                      sigma_valiable=3,
                                      length=0)
        self.upper_sigma_1h3 = dataset["upper_sigmas"][-1]
        self.lower_sigma_1h3 = dataset["lower_sigmas"][-1]
        self.base_line_1h3 = dataset["base_lines"][-1]
示例#11
0
def getDailyIndicator(base_time, con, span):
    ### get daily dataset
    instrument = "GBP_JPY"
    target_time = base_time - timedelta(days=1)
    sql = "select max_price, min_price, start_price, end_price from %s_%s_TABLE where insert_time < \'%s\' order by insert_time desc limit %s" % (
        instrument, "day", target_time, span)
    response = con.select_sql(sql)

    max_price_list = []
    min_price_list = []
    start_price_list = []
    end_price_list = []
    for res in response:
        max_price_list.append(res[0])
        min_price_list.append(res[1])
        start_price_list.append(res[2])
        end_price_list.append(res[3])

    max_price_list.reverse()
    min_price_list.reverse()
    start_price_list.reverse()
    end_price_list.reverse()

    sma1d20_list = []
    time_list = []

    for i in range(0, span):
        tmp_time = target_time - timedelta(days=i)
        dataset = getBollingerWrapper(tmp_time,
                                      instrument,
                                      table_type="day",
                                      window_size=20,
                                      connector=con,
                                      sigma_valiable=2,
                                      length=0)
        sma1d20_list.append(dataset["base_lines"][-1])
        time_list.append(tmp_time)

    sma1d20_list.reverse()
    time_list.reverse()

    df = pd.DataFrame([])

    df["end"] = end_price_list
    df["time"] = time_list
    df["max"] = max_price_list
    df["min"] = min_price_list
    df["start"] = start_price_list
    df["sma1d20"] = sma1d20_list

    return df
    def setReverseIndicator(self, base_time):

        ### get 5m dataset
        target_time = base_time - timedelta(minutes=5)

        dataset = getBollingerWrapper(target_time,
                                      self.instrument,
                                      table_type="5m",
                                      window_size=28,
                                      connector=self.mysql_connector,
                                      sigma_valiable=2.5,
                                      length=0)
        self.upper_sigma_5m25 = dataset["upper_sigmas"][-1]
        self.lower_sigma_5m25 = dataset["lower_sigmas"][-1]

        dataset = getBollingerWrapper(target_time,
                                      self.instrument,
                                      table_type="5m",
                                      window_size=20,
                                      connector=self.mysql_connector,
                                      sigma_valiable=2,
                                      length=5)
        self.sma5m20 = dataset["base_lines"][-1]
        self.sma5m20_before = dataset["base_lines"][-2]

        dataset = getBollingerWrapper(target_time,
                                      self.instrument,
                                      table_type="5m",
                                      window_size=40,
                                      connector=self.mysql_connector,
                                      sigma_valiable=2,
                                      length=5)
        self.sma5m40 = dataset["base_lines"][-1]
        self.sma5m40_before = dataset["base_lines"][-2]

        dataset = getBollingerWrapper(target_time,
                                      self.instrument,
                                      table_type="5m",
                                      window_size=80,
                                      connector=self.mysql_connector,
                                      sigma_valiable=2,
                                      length=5)
        self.sma5m80 = dataset["base_lines"][-1]
        self.sma5m80_before = dataset["base_lines"][-2]

        self.sma5m20_slope = getSlope([self.sma5m20_before, self.sma5m20])
        self.sma5m40_slope = getSlope([self.sma5m40_before, self.sma5m40])
        self.sma5m80_slope = getSlope([self.sma5m80_before, self.sma5m80])

        ### get 1h dataset
        target_time = base_time - timedelta(hours=1)
        dataset = getBollingerWrapper(target_time,
                                      self.instrument,
                                      table_type="1h",
                                      window_size=100,
                                      connector=self.mysql_connector,
                                      sigma_valiable=2,
                                      length=0)
        self.sma1h100 = dataset["base_lines"][-1]
        self.upper_sigma_1h2 = dataset["upper_sigmas"][-1]
        self.lower_sigma_1h2 = dataset["lower_sigmas"][-1]

        dataset = getBollingerWrapper(target_time,
                                      self.instrument,
                                      table_type="1h",
                                      window_size=20,
                                      connector=self.mysql_connector,
                                      sigma_valiable=2,
                                      length=1)
        self.sma1h20 = dataset["base_lines"][-1]
        self.sma1h20_before = dataset["base_lines"][-2]
        self.sma1h20_slope = getSlope([self.sma1h20_before, self.sma1h20])

        dataset = getBollingerWrapper(target_time,
                                      self.instrument,
                                      table_type="1h",
                                      window_size=40,
                                      connector=self.mysql_connector,
                                      sigma_valiable=2,
                                      length=1)
        self.sma1h40 = dataset["base_lines"][-1]
        self.sma1h40_before = dataset["base_lines"][-2]
        self.sma1h40_slope = getSlope([self.sma1h40_before, self.sma1h40])

        dataset = getBollingerWrapper(target_time,
                                      self.instrument,
                                      table_type="1h",
                                      window_size=80,
                                      connector=self.mysql_connector,
                                      sigma_valiable=2,
                                      length=1)
        self.sma1h80 = dataset["base_lines"][-1]
        self.sma1h80_before = dataset["base_lines"][-2]
        self.sma1h80_slope = getSlope([self.sma1h80_before, self.sma1h80])

        ### get daily dataset
        target_time = base_time - timedelta(days=1)
        sql = "select max_price, min_price, start_price, end_price from %s_%s_TABLE where insert_time < \'%s\' order by insert_time desc limit 1" % (
            self.instrument, "day", target_time)
        response = self.mysql_connector.select_sql(sql)
        self.max_price_1d = response[0][0]
        self.min_price_1d = response[0][1]
        self.start_price_1d = response[0][2]
        self.end_price_1d = response[0][3]

        dataset = getBollingerWrapper(target_time,
                                      self.instrument,
                                      table_type="day",
                                      window_size=28,
                                      connector=self.mysql_connector,
                                      sigma_valiable=2,
                                      length=0)
        self.upper_sigma_1d2 = dataset["upper_sigmas"][-1]
        self.lower_sigma_1d2 = dataset["lower_sigmas"][-1]

        dataset = getBollingerWrapper(target_time,
                                      self.instrument,
                                      table_type="day",
                                      window_size=20,
                                      connector=self.mysql_connector,
                                      sigma_valiable=2,
                                      length=0)

        self.sma20_1d = dataset["base_lines"][-1]
示例#13
0
    def setExpantionIndicator(self, base_time):
        # set dataset 5minutes
        target_time = base_time - timedelta(minutes=5)

        # set 5m 2sigma bollinger band
        dataset = getBollingerWrapper(target_time,
                                      self.instrument,
                                      table_type="5m",
                                      window_size=28,
                                      connector=self.mysql_connector,
                                      sigma_valiable=2,
                                      length=5)
        self.upper_sigma_5m2_list = dataset["upper_sigmas"][-5:]
        self.lower_sigma_5m2_list = dataset["lower_sigmas"][-5:]
        self.base_line_5m2_list = dataset["base_lines"][-5:]

        # set 5m 3sigma bollinger band
        dataset = getBollingerWrapper(target_time,
                                      self.instrument,
                                      table_type="5m",
                                      window_size=28,
                                      connector=self.mysql_connector,
                                      sigma_valiable=3,
                                      length=5)
        self.upper_sigma_5m3_list = dataset["upper_sigmas"][-5:]
        self.lower_sigma_5m3_list = dataset["lower_sigmas"][-5:]
        self.base_line_5m3_list = dataset["base_lines"][-5:]

        # set 5m end price list
        sql = "select end_price from %s_%s_TABLE where insert_time < \'%s\' order by insert_time desc limit 6" % (
            self.instrument, "5m", target_time)
        response = self.mysql_connector.select_sql(sql)
        tmp = []
        for res in response:
            tmp.append(res[0])

        tmp.reverse()
        self.end_price_5m_list = tmp

        # set dataset 1hour
        target_time = base_time - timedelta(hours=1)

        # set 1h end price list
        sql = "select end_price from %s_%s_TABLE where insert_time < \'%s\' order by insert_time desc limit 80" % (
            self.instrument, "1h", target_time)
        response = self.mysql_connector.select_sql(sql)
        tmp = []
        for res in response:
            tmp.append(res[0])

        tmp.reverse()
        self.end_price_1h_list = tmp

        self.sma20_1h = sum(self.end_price_1h_list[-20:]) / len(
            self.end_price_1h_list[-20:])
        self.sma40_1h = sum(self.end_price_1h_list[-40:]) / len(
            self.end_price_1h_list[-40:])
        self.sma80_1h = sum(self.end_price_1h_list[-80:]) / len(
            self.end_price_1h_list[-80:])

        # set 1h 2sigma bollinger band
        dataset = getBollingerWrapper(target_time,
                                      self.instrument,
                                      table_type="1h",
                                      window_size=28,
                                      connector=self.mysql_connector,
                                      sigma_valiable=2,
                                      length=0)
        self.upper_sigma_1h2 = dataset["upper_sigmas"][-1]
        self.lower_sigma_1h2 = dataset["lower_sigmas"][-1]
        self.base_line_1h2 = dataset["base_lines"][-1]

        sql = "select max_price, min_price from %s_%s_TABLE where insert_time < \'%s\' order by insert_time desc limit 1" % (
            self.instrument, "1h", target_time)
        response = self.mysql_connector.select_sql(sql)
        self.max_price_1h = response[0][0]
        self.min_price_1h = response[0][1]
示例#14
0
def getDataset(base_time, con, window_size, learning_span, output_train_index,
               table_layout):
    ### get daily dataset

    length = learning_span + output_train_index

    instrument = "GBP_JPY"
    if table_layout == "day":
        target_time = base_time - timedelta(days=1)
    elif table_layout == "1h":
        target_time = base_time - timedelta(hours=1)
    elif table_layout == "5m":
        target_time = base_time - timedelta(minuites=5)
    elif table_layout == "1m":
        target_time = base_time - timedelta(minuites=1)

    sql = "select max_price, min_price, start_price, end_price, insert_time from %s_%s_TABLE where insert_time < \'%s\' order by insert_time desc limit %s" % (
        instrument, table_layout, target_time, length)
    response = con.select_sql(sql)
    #print(sql)

    max_price_list = []
    min_price_list = []
    start_price_list = []
    end_price_list = []
    time_list = []
    for res in response:
        max_price_list.append(res[0])
        min_price_list.append(res[1])
        start_price_list.append(res[2])
        end_price_list.append(res[3])
        time_list.append(res[4])

    max_price_list.reverse()
    min_price_list.reverse()
    start_price_list.reverse()
    end_price_list.reverse()
    time_list.reverse()

    sma1d20_list = []
    i = 0
    while len(end_price_list) != len(sma1d20_list):
        if table_layout == "day":
            tmp_time = target_time - timedelta(days=i)
        elif table_layout == "1h":
            tmp_time = target_time - timedelta(hours=i)
        elif table_layout == "5m":
            tmp_time = target_time - timedelta(minuites=(i * 5))
        elif table_layout == "1m":
            tmp_time = target_time - timedelta(minuites=i)

        dataset = getBollingerWrapper(tmp_time,
                                      instrument,
                                      table_type=table_layout,
                                      window_size=20,
                                      connector=con,
                                      sigma_valiable=2,
                                      length=0)
        try:
            sma1d20_list.append(dataset["base_lines"][-1])
        except Exception as e:
            pass

        i = i + 1

    sma1d20_list.reverse()

    original_dataset = {
        "end": end_price_list,
        "start": start_price_list,
        "max": max_price_list,
        "min": min_price_list,
        "sma1d20": sma1d20_list,
        "time": time_list
    }

    value_dataset = {
        "end": end_price_list,
        "start": start_price_list,
        "max": max_price_list,
        "min": min_price_list,
        "sma1d20": sma1d20_list
    }

    return original_dataset, value_dataset
示例#15
0
    def setReverseIndicator(self, base_time):
        target_time = base_time - timedelta(minutes=1)

        ### get 1m dataset
        dataset = getBollingerWrapper(target_time, self.instrument, table_type="1m", window_size=28, connector=self.mysql_connector, sigma_valiable=2, length=0)
        self.upper_sigma_1m2 = dataset["upper_sigmas"][-1]
        self.lower_sigma_1m2 = dataset["lower_sigmas"][-1]
        self.base_line_1m2 = dataset["base_lines"][-1]


        sql = "select start_price, end_price, max_price, min_price from %s_%s_TABLE where insert_time < \'%s\' order by insert_time desc limit 2" % (self.instrument, "1m", target_time)
        response = self.mysql_connector.select_sql(sql)
        self.start_price_1m = response[0][0]
        self.end_price_1m = response[0][1]
        self.max_price_1m = response[0][2]
        self.min_price_1m = response[0][3]


        dataset = getBollingerWrapper(target_time, self.instrument, table_type="1m", window_size=28, connector=self.mysql_connector, sigma_valiable=2, length=9)
        base_line_1m2_list = dataset["base_lines"][-10:]
        self.slope_1m = getSlope(base_line_1m2_list)

        target_time = base_time

        width = 60*30
        sql = "select ask_price, bid_price from %s_TABLE where insert_time < \'%s\' order by insert_time desc limit %s" % (self.instrument, target_time, width)
        response = self.mysql_connector.select_sql(sql)
        tmp = []
        for res in response:
            tmp.append((res[0]+res[1])/2)
        tmp.reverse()

        ewma30_rawdata = tmp[-1*width:]
        self.ewma30_1mvalue = getEWMA(ewma30_rawdata, len(ewma30_rawdata))[-1]

        width = 60*50
        sql = "select ask_price, bid_price from %s_TABLE where insert_time < \'%s\' order by insert_time desc limit %s" % (self.instrument, target_time, width)
        response = self.mysql_connector.select_sql(sql)
        tmp = []
        for res in response:
            tmp.append((res[0]+res[1])/2)
        tmp.reverse()

        ewma50_rawdata = tmp[-1*width:]
        self.ewma50_1mvalue = getEWMA(ewma50_rawdata, len(ewma50_rawdata))[-1]


        ### get 5m dataset
        target_time = base_time - timedelta(minutes=5)

        sql = "select start_price, end_price, max_price, min_price from %s_%s_TABLE where insert_time < \'%s\' order by insert_time desc limit 2" % (self.instrument, "5m", target_time)
        response = self.mysql_connector.select_sql(sql)
        self.start_price_5m_list = [response[1][0], response[0][0]]
        self.end_price_5m_list   = [response[1][1], response[0][1]]
        self.max_price_5m_list   = [response[1][2], response[0][2]]
        self.min_price_5m_list   = [response[1][3], response[0][3]]


        width = 20
        sql = "select end_price from %s_%s_TABLE where insert_time < \'%s\' order by insert_time desc limit %s" % (self.instrument, "5m", target_time, width)
        response = self.mysql_connector.select_sql(sql)
        tmp = []
        for res in response:
            tmp.append(res[0])
        tmp.reverse()
        self.ewma20_5mvalue = getEWMA(tmp, len(tmp))[-1]

        dataset = getBollingerWrapper(target_time, self.instrument, table_type="5m", window_size=28, connector=self.mysql_connector, sigma_valiable=2, length=0)
        self.base_line_5m2 = dataset["base_lines"][-1]
        self.upper_sigma_5m2 = dataset["upper_sigmas"][-1]
        self.lower_sigma_5m2 = dataset["lower_sigmas"][-1]
    def setReverseIndicator(self, base_time):
        target_time = base_time - timedelta(minutes=1)

        ### get 1m dataset
        #        dataset = getBollingerWrapper(target_time, self.instrument, table_type="1m", window_size=28, connector=self.mysql_connector, sigma_valiable=2, length=0)
        #        self.upper_sigma_1m2 = dataset["upper_sigmas"][-1]
        #        self.lower_sigma_1m2 = dataset["lower_sigmas"][-1]
        #        self.base_line_1m2 = dataset["base_lines"][-1]

        dataset = getBollingerWrapper(target_time,
                                      self.instrument,
                                      table_type="1m",
                                      window_size=28,
                                      connector=self.mysql_connector,
                                      sigma_valiable=2.5,
                                      length=0)
        self.upper_sigma_1m25 = dataset["upper_sigmas"][-1]
        self.lower_sigma_1m25 = dataset["lower_sigmas"][-1]
        self.base_line_1m25 = dataset["base_lines"][-1]

        #        sql = "select start_price, end_price, max_price, min_price from %s_%s_TABLE where insert_time < \'%s\' order by insert_time desc limit 1" % (self.instrument, "1m", target_time)
        #        response = self.mysql_connector.select_sql(sql)
        #        self.start_price_1m = response[0][0]
        #        self.end_price_1m = response[0][1]
        #        self.max_price_1m = response[0][2]
        #        self.min_price_1m = response[0][3]

        #        dataset = getBollingerWrapper(target_time, self.instrument, table_type="1m", window_size=28, connector=self.mysql_connector, sigma_valiable=2, length=9)
        #        base_line_1m2_list = dataset["base_lines"][-10:]
        #        self.slope_1m = getSlope(base_line_1m2_list)

        target_time = base_time
        width = 60 * 40
        sql = "select ask_price, bid_price from %s_TABLE where insert_time < \'%s\' order by insert_time desc limit %s" % (
            self.instrument, target_time, width)
        response = self.mysql_connector.select_sql(sql)
        tmp = []
        for res in response:
            tmp.append((res[0] + res[1]) / 2)
        tmp.reverse()

        ewma40_rawdata = tmp[-1 * 60 * 40:]
        self.ewma40_1mvalue = getEWMA(ewma40_rawdata, len(ewma40_rawdata))[-1]

        ### get 5m dataset
        target_time = base_time - timedelta(minutes=5)

        #        width = 20
        #        sql = "select end_price from %s_%s_TABLE where insert_time < \'%s\' order by insert_time desc limit %s" % (self.instrument, "5m", target_time, width)
        #        response = self.mysql_connector.select_sql(sql)
        #        tmp = []
        #        for res in response:
        #            tmp.append(res[0])
        #        tmp.reverse()
        #        self.ewma20_5mvalue = getEWMA(tmp, len(tmp))[-1]
        #
        #        dataset = getBollingerWrapper(target_time, self.instrument, table_type="5m", window_size=28, connector=self.mysql_connector, sigma_valiable=2, length=0)
        #        self.base_line_5m2 = dataset["base_lines"][-1]
        #        self.upper_sigma_5m2 = dataset["upper_sigmas"][-1]
        #        self.lower_sigma_5m2 = dataset["lower_sigmas"][-1]

        dataset = getBollingerWrapper(target_time,
                                      self.instrument,
                                      table_type="5m",
                                      window_size=20,
                                      connector=self.mysql_connector,
                                      sigma_valiable=2,
                                      length=5)
        self.sma5m20 = dataset["base_lines"][-1]
        self.sma5m20_before = dataset["base_lines"][-5]

        dataset = getBollingerWrapper(target_time,
                                      self.instrument,
                                      table_type="5m",
                                      window_size=40,
                                      connector=self.mysql_connector,
                                      sigma_valiable=2,
                                      length=5)
        self.sma5m40 = dataset["base_lines"][-1]
        self.sma5m40_before = dataset["base_lines"][-5]

        dataset = getBollingerWrapper(target_time,
                                      self.instrument,
                                      table_type="5m",
                                      window_size=80,
                                      connector=self.mysql_connector,
                                      sigma_valiable=2,
                                      length=5)
        self.sma5m80 = dataset["base_lines"][-1]
        self.sma5m80_before = dataset["base_lines"][-5]

        self.sma5m20_slope = getSlope([self.sma5m20_before, self.sma5m20])
        self.sma5m40_slope = getSlope([self.sma5m40_before, self.sma5m40])
        self.sma5m80_slope = getSlope([self.sma5m80_before, self.sma5m80])

        target_time = base_time - timedelta(hours=1)
        dataset = getBollingerWrapper(target_time,
                                      self.instrument,
                                      table_type="1h",
                                      window_size=80,
                                      connector=self.mysql_connector,
                                      sigma_valiable=2,
                                      length=0)
        self.sma1h80 = dataset["base_lines"][-1]
示例#17
0
def getDataset(base_time, con, window_size, learning_span, output_train_index,
               table_layout):
    ### get daily dataset

    length = learning_span + output_train_index

    instrument = "GBP_JPY"
    if table_layout == "day":
        target_time = base_time - timedelta(days=1)
    elif table_layout == "1h":
        target_time = base_time - timedelta(hours=1)
    elif table_layout == "5m":
        target_time = base_time - timedelta(minuites=5)
    elif table_layout == "1m":
        target_time = base_time - timedelta(minuites=1)

    sql = "select max_price, min_price, start_price, end_price, insert_time from %s_%s_TABLE where insert_time < \'%s\' order by insert_time desc limit %s" % (
        instrument, table_layout, target_time, length)
    response = con.select_sql(sql)

    max_price_list = []
    min_price_list = []
    start_price_list = []
    end_price_list = []
    time_list = []
    for res in response:
        max_price_list.append(res[0])
        min_price_list.append(res[1])
        start_price_list.append(res[2])
        end_price_list.append(res[3])
        time_list.append(res[4])

    max_price_list.reverse()
    min_price_list.reverse()
    start_price_list.reverse()
    end_price_list.reverse()
    time_list.reverse()

    dataset_sma20 = getBollingerWrapper(target_time,
                                        instrument,
                                        table_type=table_layout,
                                        window_size=20,
                                        connector=con,
                                        sigma_valiable=2,
                                        length=(length - 1))
    dataset_sma40 = getBollingerWrapper(target_time,
                                        instrument,
                                        table_type=table_layout,
                                        window_size=40,
                                        connector=con,
                                        sigma_valiable=2,
                                        length=(length - 1))
    dataset_sma80 = getBollingerWrapper(target_time,
                                        instrument,
                                        table_type=table_layout,
                                        window_size=80,
                                        connector=con,
                                        sigma_valiable=2,
                                        length=(length - 1))
    dataset_bollinger25 = getBollingerWrapper(target_time,
                                              instrument,
                                              table_type=table_layout,
                                              window_size=21,
                                              connector=con,
                                              sigma_valiable=2.5,
                                              length=(length - 1))

    sma20_list = dataset_sma20["base_lines"][-1 * length:]
    sma40_list = dataset_sma40["base_lines"][-1 * length:]
    sma80_list = dataset_sma80["base_lines"][-1 * length:]
    upper25_list = dataset_bollinger25["upper_sigmas"][-1 * length:]
    lower25_list = dataset_bollinger25["lower_sigmas"][-1 * length:]

    print(len(max_price_list))
    print(len(min_price_list))
    print(len(start_price_list))
    print(len(end_price_list))
    print(len(time_list))

    print(len(sma20_list))
    print(len(sma40_list))
    print(len(sma80_list))
    print(len(upper25_list))
    print(len(lower25_list))

    original_dataset = {
        "end": end_price_list,
        "start": start_price_list,
        "max": max_price_list,
        "min": min_price_list,
        "sma20": sma20_list,
        "sma40": sma40_list,
        "sma80": sma80_list,
        "upper25": upper25_list,
        "lower25": lower25_list,
        "time": time_list
    }

    value_dataset = {
        "end": end_price_list,
        "start": start_price_list,
        "max": max_price_list,
        "min": min_price_list,
        "sma20": sma20_list,
        "sma40": sma40_list,
        "sma80": sma80_list,
        "upper25": upper25_list,
        "lower25": lower25_list
    }

    return original_dataset, value_dataset