示例#1
0
    def algorithm(self, ticker):
        """
        计算部分
        :param ticker: 订阅的数据
        :return:
        """
        df = self.df.iloc[-9 * 60:]
        kdj_dvalue = kdj(self.df, n=9 * 24 * 60, m=3 * 24 * 60)
        kdj_hvalue = kdj(df, n=9 * 60, m=3 * 60)
        d_k, d_d, d_j = kdj_dvalue['kdj_k'], kdj_dvalue['kdj_d'], kdj_dvalue[
            'kdj_j']
        h_k, h_d, h_j = kdj_hvalue['kdj_k'], kdj_hvalue['kdj_d'], kdj_hvalue[
            'kdj_j']
        if (d_k > d_d) and (self.position == -1):
            self.position = 1
        elif (d_k < d_d) and (self.position == 1):
            self.position = -1
        elif h_k > h_d:
            if self.position == 0:
                self.position = 1
                self.uid = Userchoose().choose(self.pid)
            elif self.position == -1:
                self.position = 0
                Userchoose().reset(self.uid, self.pid)
        elif h_k < h_d:
            if self.position == 0:
                self.position = -1
                self.uid = Userchoose().choose(self.pid)
            elif self.position == 1:
                self.position = 0
                Userchoose().reset(self.uid, self.pid)

        self.df = updatedata(self.df, ticker)
示例#2
0
    def algorithm(self, ticker):
        df = self.df.iloc[-26 * 60:]
        macd_dval = macd(self.df,
                         short=12 * 24 * 60,
                         long=26 * 24 * 60,
                         mid=9 * 24 * 60)
        macd_hval = macd(df, short=12 * 60, long=26 * 60, mid=9 * 60)
        d_diff = macd_dval['diff']
        d_dea = macd_dval['dea']
        h_diff = macd_hval['diff']
        h_dea = macd_hval['dea']
        if (d_diff > d_dea) and (self.position == -1):
            self.position = 1
        elif (d_diff < d_dea) and (self.position == 1):
            self.position = -1
        elif h_diff > h_dea:
            if self.position == 0:
                self.position = 1
                self.uid = Userchoose().choose(self.pid)
            elif self.position == -1:
                self.position = 0
                self.uid = Userchoose().choose(self.pid)
        elif h_diff < h_dea:
            if self.position == 0:
                self.position = -1
                Userchoose().reset(self.uid, self.pid)
            elif self.position == 1:
                self.position = 0
                Userchoose().reset(self.uid, self.pid)

        self.df = updatedata(self.df, ticker)
示例#3
0
    def algorithm(self, ticker):
        """

        :param ticker: 订阅的数据
        :return:
        """
        price = np.float64(ticker['close'])
        rsi_val = rsi(self.df, n=7 * 60)
        high10 = self.df.iloc[-10 * 60:]['high'].max()
        low10 = self.df.iloc[-10 * 60:]['low'].min()
        high20 = self.df.iloc[-20 * 60:]['high'].max()
        low20 = self.df.iloc[-20 * 60:]['low'].min()
        if rsi_val < 20:
            self.status = -1
            if self.position == 1:
                self.position = 0
                Userchoose().reset(self.uid, self.pid)

        elif rsi_val > 80:
            self.status = 1
            if self.position == -1:
                self.position = 0
                Userchoose().reset(self.uid, self.pid)
        if self.position == 0:
            if (self.status == -1) and (price > high10):
                self.position = 1
                self.uid = Userchoose().choose(self.pid)
                self.stoploss = low20
            elif (self.status == 1) and (price < low10):
                self.position = -1
                self.uid = Userchoose().choose(self.pid)
                self.stoploss = high20
            else:
                pass
        elif (self.position == 1) and (price < self.stoploss):
            self.position = 0
            self.stoploss = 0
            self.status = 0
            Userchoose().reset(self.uid, self.pid)
        elif (self.position == -1) and (price > self.stoploss):
            self.position = 0
            self.stoploss = 0
            self.status = 0
            Userchoose().reset(self.uid, self.pid)
        else:
            pass
        # 更新分钟k线数据
        self.df = updatedata(self.df, ticker)
示例#4
0
    def algorithm(self, ticker):
        """
        :param ticker: 订阅的数据
        :return:
        """
        price = np.float64(ticker['close'])
        high30 = self.df['high'].max()
        low30 = self.df['low'].min()
        df = self.df.iloc[-20 * 4 * 60]
        high20 = df['high'].max()
        low20 = df['low'].low()

        if price > high30:
            if self.position == 0:
                self.uid = Userchoose().choose(self.pid)
                self.position = 1
                self.price = price
            elif self.position == -1:
                self.position = 1
                self.price = price
        elif price < low30:
            if self.position == 0:
                self.uid = Userchoose().choose(self.pid)
                self.position = -1
                self.price = price
            elif self.position == 1:
                self.position = -1
                self.price = price

        elif price > high20:
            if self.position == -1:
                Userchoose().reset(self.uid, self.pid)
                self.position = 0
                self.price = price

        elif price < low20:
            if self.position == 1:
                Userchoose().reset(self.uid, self.pid)
                self.position = 0
                self.price = price

        else:
            pass

        self.df = updatedata(self.df, ticker)
示例#5
0
    def algorithm(self, ticker):
        price = np.float64(ticker['price'])
        high30 = self.df['high'].max()
        low30 = self.df['low'].min()
        df = self.df.iloc[-20 * 2 * 60:]
        high20 = df['high'].max()
        low20 = df['low'].low()

        if price > high30:
            if self.position == 0:
                self.uid = Userchoose().choose(self.pid)
                self.position = 1
                self.price = price
            elif self.position == -1:
                self.position = 1
                self.price = price

        elif price < low30:
            if self.position == 0:
                self.uid = Userchoose().choose(self.pid)
                self.position = -1
                self.price = price
            elif self.position == 1:
                self.position = -1
                self.price = price

        elif price > high20:
            if self.position == -1:
                self.position = 0
                Userchoose().reset(self.uid, self.pid)
                self.price = price

        elif price < low20:
            if self.position == 1:
                self.position = 0
                Userchoose().reset(self.uid, self.pid)
                self.price = price

        self.df = updatedata(self.df, ticker)
示例#6
0
    def algorithm(self, ticker):
        """

        :param ticker: 订阅的数据
        :return:
        """
        price = np.float64(ticker['close'])
        high10 = self.df.iloc[-10 * 30:]['high'].max()
        low10 = self.df.iloc[-10 * 30:]['low'].min()
        cci_val = cci(self.df, n=14 * 30)
        if cci_val < -100:
            self.status = -1
            if self.position == -1:
                self.position = 0
                Userchoose().reset(self.uid, self.pid)
        elif cci_val > 100:
            self.status = 1
            if self.position == 1:
                self.position = 0
                Userchoose().reset(self.uid, self.pid)
        if self.position == 0:
            if (self.status == -1) and (price > high10):
                self.position = 1
                self.stoploss = low10
                self.uid = Userchoose().choose(self.pid)
            elif (self.status == 1) and (price < low10):
                self.postion = -1
                self.stoploss = high10
                self.uid = Userchoose().choose(self.pid)
        elif (self.position == 1) and (price < self.stoploss):
            self.position = 0
            Userchoose().reset(self.uid, self.pid)
        elif (self.position == -1) and (price > self.stoploss):
            self.postion = 0
            Userchoose().reset(self.uid, self.pid)
        else:
            pass
        # 更新分钟K线数据
        self.df = updatedata(self.df, ticker)
示例#7
0
    def algorithm(self, ticker):
        """

        :param ticker: 订阅的数据
        :return:
        """
        price = np.float64(ticker['close'])
        high10 = self.df.iloc[-10 * 5:]['high'].max()
        low10 = self.df.iloc[-10 * 5:]['low'].min()
        ma250 = ma(self.df, n=250 * 5)
        angle = ma250.iloc[-1] - ma250.iloc[-2]

        if (angle > 0) and (price < ma250.iloc[-1]):
            self.status = -1
        elif (angle < 0) and (price > ma250.iloc[-1]):
            self.status = 1
        if self.position == 0:
            if (self.status == -1) and (price > high10):
                self.position = 1
                self.stoploss = low10
                self.uid = Userchoose().choose(self.pid)
            elif (self.status == 1) and (price < low10):
                self.position = -1
                self.stoploss = high10
                self.uid = Userchoose().choose(self.pid)
        elif (self.position == 1) and (price < self.stoploss):
            self.position = 0
            self.stoploss = 0
            Userchoose().reset(self.uid, self.uid)
        elif (self.position == -1) and (price > self.stoploss):
            self.position = 0
            self.stoploss = 0
            Userchoose().reset(self.uid, self.pid)
        else:
            pass
        # 更新分钟K线数据
        self.df = updatedata(self.df, ticker)
示例#8
0
    def algorithm(self, ticker):
        """

        :param ticker: socket 收到的ticker数据,用pandas包装
        :return:
        """
        date = datetime.now()
        price = np.float64(ticker['close'])
        if self.position == 0:

            if price > self.breakBuyprice:
                self.position = 1
                self.rBreak = 1
                self.stopLoss = self.reverseBuyprice
                self.uid = Userchoose().choose(self.pid)

            elif price < self.breakSellprice:
                self.position = -1
                self.rBreak = -1
                self.stopLoss = self.reverseSellprice
                self.opentime = date
                self.uid = Userchoose().choose(self.pid)
                content = "空仓的情况下,盘中价格在{}跌破突破卖出价 {},采取趋势策略,在该点位开仓做空,止损位置为反转" \
                          "卖出价 {}".format(str_date, self.breakSellprice, self.reverseSellprice)

            elif (price > self.observeBuyprice) and (price <
                                                     self.breakBuyprice):
                self.upperObserveSell = 1

            elif (price < self.observeSellprice) and (price <
                                                      self.breakSellprice):
                self.lowerObserveBuy = 1

            elif (self.upperObserveSell
                  == 1) and (price < self.breakSellprice):
                self.position = -1
                self.stopLoss = self.breakBuyprice
                self.opentime = date
                self.uid = Userchoose().choose(self.pid)
                content = "空仓情况下,日内最高价超过观察卖出价{}后,盘中价格出现回落,且在{}进一步跌破反转卖出价{}" \
                          "构成的支撑线时,采取反转策略,即在该点位做空,止损位置为突破买入价{}".format(self.observeSellprice, str_date,
                                                                       self.reverseSellprice, self.breakBuyprice)

            elif (self.lowerObserveBuy
                  == 1) and (price > self.reverseBuyprice):
                self.position = 1
                self.stopLoss = self.breakSellprice
                self.opentime = date
                self.uid = Userchoose().choose(self.pid)
                content = "空仓情况下,当日内最高价低于观察买入价{}后,盘中价格出现反弹,且进一步在{}超过反转买入价{}" \
                          "构成的阻力线时,采取反转策略,即在该点位做多,止损位置为突破卖出价{}".format(self.observeBuyprice, str_date,
                                                                       self.reverseBuyprice, self.breakSellprice)

            else:
                pass

        else:

            if (self.position == 1) and (self.rBreak != 1):

                if price > self.observeSellprice:
                    self.upperObserveSell = 1

                elif (self.upperObserveSell
                      == 1) and (price < self.reverseSellprice):
                    self.position = -1
                    self.stopLoss = self.breakBuyprice
                    self.opentime = date
                    content = "持有多单情况下,当日内最高价超过观察卖出价{}后,盘中价格出现回落,且进一步在{}跌破反转卖" \
                              "出价{}构成的支撑线时,采取反转策略,即在该点位反手做空," \
                              "止损位置为突破买入价{}".format(self.observeSellprice, str_date, self.reverseSellprice,
                                                    self.breakBuyprice)

                else:
                    pass

            elif (self.position == -1) and (self.rBreak != -1):

                if price < self.observeBuyprice:
                    self.lowerObserveBuy = 1

                elif (self.lowerObserveBuy
                      == 1) and (price > self.reverseBuyprice):
                    self.position = 1
                    self.stopLoss = self.breakSellprice
                    self.opentime = date
                    content = "持有空单情况下,当日内最低价低于观察买入价{}后,盘中价格出现反弹,且进一步在{}超过反转买" \
                              "入价{}构成的阻力线时,采取反转策略,即在该点位反手做多," \
                              "止损位置为突破卖出价{}".format(self.observeBuyprice, str_date, self.reverseBuyprice,
                                                    self.breakSellprice)

                else:
                    pass

            elif (date >= datetime(year=self.opentime.year,
                                   month=self.opentime.month,
                                   day=self.opentime.day,
                                   hour=23,
                                   minute=55,
                                   second=0)) and self.position:
                str_time = date.strftime('%Y-%m-%d %H:%M')
                self.stopLoss = 0
                if self.position == 1:
                    self.opentime = 0
                    self.position = 0
                    Userchoose().reset(self.uid, self.pid)
                    if self.rBreak == 1:
                        self.rBreak = 0
                        content = "持有的{}价位的多单,以收盘前5分钟时间{} ({})的价格{}平仓".format(
                            str_date, self.breakBuyprice, str_time, price)

                    else:
                        content = "持有的{}价位的多单,以收盘前5分钟时间{} ({})的价格{}平仓".format(
                            str_date, self.reverseBuyprice, str_time, price)

                else:
                    self.position = 0
                    self.opentime = 0
                    Userchoose().reset(self.uid, self.pid)
                    if self.rBreak == -1:
                        self.rBreak = 0
                        content = "持有以{}价位的空单,以收盘前5分钟时间{} ({})的价格{}平仓".format(
                            str_date, self.breakSellprice, str_time, price)

                    else:
                        content = "持有以{}价位的空单,以收盘前5分钟时间{} ({})的价格{}平仓".format(
                            str_date, self.reverseSellprice, str_time, price)

            else:

                if (self.position == 1) and (price < self.stopLoss):
                    self.position = 0
                    self.opentime = 0
                    stoploss = self.stopLoss
                    self.stopLoss = 0
                    Userchoose().reset(self.uid, self.pid)
                    if self.rBreak == 1:
                        self.rBreak = 0
                        content = "持有以{}价位的多单,目前在{}价格跌破止损价位{},以市价单止损平仓".format(
                            str_date, self.breakBuyprice, stoploss)

                    else:
                        content = "持有以{}价位的多单,目前在{}价格跌破止损价位{},以市价单止损平仓".format(
                            str_date, self.reverseBuyprice, stoploss)

                elif (self.position == -1) and (price > self.stopLoss):
                    self.position = 0
                    self.opentime = 0
                    stoploss = self.stopLoss
                    self.stopLoss = 0
                    Userchoose().reset(self.uid, self.pid)
                    if self.rBreak == -1:
                        self.rBreak = 0
                        content = "持有以{}价位的空单,目前在{}价格突破止损价位{},以市价单止损平仓".format(
                            str_date, self.breakSellprice, stoploss)

                    else:
                        content = "持有以{}价位的空单,目前在{}价格突破止损价位{},以市价单止损平仓".format(
                            str_date, self.reverseSellprice, stoploss)

                else:
                    pass

        self.df = updatedata(self.df, ticker)