prob = 100
        elif tinyrollingmean < lowerband:
            prob = 0
        else:
            prob = ((tinyrollingmean - lowerband)/(upperband - lowerband))*100
        
        if ((30 > prob) and (sum(self.repeating) != -5)):
            self.repeating.append(-1)
            if (prob == 0):
                orders.append(Order(event.instrument, -1, 0))
            orders.append(Order(event.instrument, -1, 0))

        if ((70 < prob) and (sum(self.repeating) != 5)):
            self.repeating.append(1)
            if (prob == 1):
                orders.append(Order(event.instrument, 1, 0))
            orders.append(Order(event.instrument, 1, 0))

        if len(orders) > 0:
            for order in orders:
                print(order.print())

        return orders

    def fill(self, id, instrument, price, quantity, status):
        super().fill(id, instrument, price, quantity, status)
        self.side += quantity
        print(self.position)

print(evaluateHist(BrainyApeTrade(), {'IBOV': '^BVSP.csv'}))
Ejemplo n.º 2
0
    return avg_high / avg_low if avg_low else 0

  def _calculate_rsi(self):
    rs = self._get_rs()
    rsi = 100 - 100 /(1 + rs)
    return rsi

  def push(self, event):
    orders = []
    price = event.price[3]
    self.prices.append(price)
    if len(self.prices) > 0:
      rsi = self._calculate_rsi()
      if rsi >= self.OVERBOUGHT:
        if self.signal == 1:
          orders.append(Order(event.instrument, -1, 0))
          orders.append(Order(event.instrument, -1, 0))
        if self.signal == 0:
          orders.append(Order(event.instrument, -1, 0))
        self.signal = -1
      elif rsi <= self.OVERSOLD:
        if self.signal == -1:
          orders.append(Order(event.instrument, 1, 0))
          orders.append(Order(event.instrument, 1, 0))
        if self.signal == 0:
          orders.append(Order(event.instrument, 1, 0))
        self.signal = 1
    return orders

print(evaluateHist(RSI(), {'IBOV':'^BVSP.csv'}))
    def _create_sell_order(self, event):
        orders = []
        self.count_sell = 0
        if self.signal == 1:
            orders.append(Order(event.instrument, -1, 0))
            orders.append(Order(event.instrument, -1, 0))
        self.signal = -1
        return orders

    def push(self, event):
        orders = []
        price = event.price[3]
        if self.prev:
            self._update_counts(price)
        if self.count_buy == self.max_count:
            orders = self._create_buy_order(event)
        if self.count_sell == self.max_count:
            orders = self._create_sell_order(event)
        self.prev = price
        return orders


print(evaluateHist(RSI(), {'IBOV': '^BVSP.csv'}))
print(evaluateHist(MarceloStrategy(), {'IBOV': '^BVSP.csv'}))
print(
    evaluateIntr(MarketMaker(), {
        'USDBRL': 'USDBRL.csv',
        'PETR3': 'PETR3.csv',
        'PBR': None
    }))
Ejemplo n.º 4
0
        self.std = 0
        self.ref = 0

    def push(self, event):
        price = event.price[3]
        self.prices.append(price)
        orders = []

        if len(self.prices) >= self.sizeq:
            maq = sum(self.prices[-self.sizeq:]) / self.sizeq
        if len(self.prices) == self.sizes:
            mas = sum(self.prices) / self.sizes

            if maq > mas and self.signal != 1:
                if self.signal == -1:
                    orders.append(Order(event.instrument, 1, 0))
                orders.append(Order(event.instrument, 1, 0))
                self.signal = 1
            elif maq < mas and self.signal != -1:
                if self.signal == 1:
                    orders.append(Order(event.instrument, -1, 0))
                orders.append(Order(event.instrument, -1, 0))
                self.signal = -1

            del self.prices[0]

        return orders


print(evaluateHist(BuynHold(), {'IBOV': '^BVSP.csv'}))
print(evaluateHist(MAVG(), {'IBOV': '^BVSP.csv'}))
Ejemplo n.º 5
0
            else:
                if not buy:
                    result = [order, order]
        return result

    def pushPetr(self, event):
        self.petr = event.price[2]
        return []

    def push(self, event):
        if event.instrument == STOCK:
            return self.pushStock(event)
        elif event.instrument == COIN:
            return self.pushCoin(event)
        elif event.instrument == PETR:
            return self.pushPetr(event)
        else:
            raise ValueError('Event instrument not accepted')
        return []


print(evaluateHist(SAR(), {'IBOV': '^BVSP.csv'}))
print(evaluateHist(PedroStrategy(), {'IBOV': 'dataPedro/test_data.csv'}))
print(
    evaluateIntr(PedroIntr(), {
        STOCK: ['dataPedro/ADR.csv', ',', '%d/%m/%y %H:%M'],
        COIN: ['USDBRL.csv', ';', '%d/%m/%Y %H:%M:%S'],
        PETR: [PETR, ';', '%d/%m/%Y %H:%M:%S'],
    },
                 has_config=True))