Esempio n. 1
0
    def select_q_val(self, time, start_time, start_action):
        rec = self.select_q(time, start_time, start_action)
        q = None

        if rec:
            q = QValue()
            q.set_q_records(rec)

        # print('selectq', time, start_time, start_action, q)

        return q
Esempio n. 2
0
    def test_q_set_rec(self):
        r = (100, 101, 1, 2, 3, 4, 5, 6)

        q = QValue()
        q.set_q_records(r)

        self.assertEqual(q.time, 100)
        self.assertEqual(q.start_time, 101)
        self.assertEqual(q.start_action, 1)
        self.assertEqual(q[ACTION.NOP], 2)
        self.assertEqual(q[ACTION.BUY], 3)
        self.assertEqual(q[ACTION.BUY_NOW], 4)
        self.assertEqual(q[ACTION.SELL], 5)
        self.assertEqual(q[ACTION.SELL_NOW], 6)
Esempio n. 3
0
    def select_q_values(self, time, action):
        '''
        :param time time to select
        :param action
        :return: q values for NOP, buy, sell, BUY, SELL
        '''
        select_q_sql = """select time, start_time, start_action, nop_q, buy_q, buy_now_q, sell_q, sell_now_q
                                from q where start_time = ? and start_action= ? order by start_time, time
            """
        self.cursor.execute(select_q_sql, (
            time,
            action,
        ))
        rec = self.cursor.fetchone()

        q = QValue()
        q.set_q_records(rec)

        return q
Esempio n. 4
0
    def update_q_on_nop(self):
        q_list = self.list_q(start_time=0, start_action=ACTION.NOP, asc=False)

        last_q = None

        for q_rec in q_list:
            q = QValue()
            q.set_q_records(q_rec)

            # todo check if redundunt q values is not produced.
            if last_q and not q.is_same_q_except_nop(last_q):
                t = last_q.time - q.time
                last_max_q = last_q.max_q() * Q_FIRST_DISCOUNT_RATE * (
                    Q_DISCOUNT_RATE**t)

                q[ACTION.NOP] = last_max_q
                self.insert_q(time=q.time,
                              start_time=0,
                              start_action=ACTION.NOP,
                              q_value=q)

                last_q = q

        self.commit()