Ejemplo n.º 1
0
    async def scan(self,
                   start: Frame,
                   end: Frame,
                   signal_func: Callable,
                   frame_type: FrameType = FrameType.DAY):
        frames = tf.get_frames(start, end, frame_type)
        results = []
        for frame in frames:
            if frame_type in tf.day_level_frames:
                frame = tf.int2date(frame)
            else:
                frame = tf.int2time(frame)
            result = await signal_func(frame,
                                       frame_type=frame_type,
                                       win=60,
                                       adv=0.0)
            results.extend(result)

        df = DataFrame(data=results, columns=['date', 'code', 'pc'])
        df.to_csv("/tmp/hrp.csv")
Ejemplo n.º 2
0
    async def test_test_signal(self):
        plot = Momentum()

        results = {}
        async def on_trade_signal(results, msg):
            results[msg.get('fire_on')] = {
                "flag": msg.get('flag'),
                "frame_type": msg.get('frame_type')
            }

        emit.register(Events.sig_trade, functools.partial(on_trade_signal, results))
        for frame in tf.get_frames(arrow.get('2020-8-24 11:00'),
                                   arrow.get('2020-8-28 15:00'),
                                   FrameType.MIN30):
            frame = tf.int2time(frame)
            await plot.evaluate('000001.XSHG', '30m', frame, flag='both')

        self.assertDictEqual({
            202008261000: {"flag": "short", "frame_type": '30m'},
            202008271130: {"flag": "long", "frame_type": '30m'}
        }, results)
Ejemplo n.º 3
0
    async def scan(self,
                   start: Frame,
                   end: Frame,
                   signal_func: Callable,
                   frame_type: FrameType = FrameType.DAY):
        frames = tf.get_frames(start, end, frame_type)
        results = []
        for frame in frames:
            if frame_type in tf.day_level_frames:
                frame = tf.int2date(frame)
            else:
                frame = tf.int2time(frame)
            result = await signal_func(frame, frame_type=frame_type)
            results.extend(result)

        df = DataFrame(data=results,
                       columns=[
                           'date', 'code', 't1', 't2', 't3', 't4', 'slope_60',
                           'pct', "fired"
                       ])
        df.to_csv("/tmp/two.csv")
Ejemplo n.º 4
0
    def test_get_frames(self):
        days = [
            20200117,
            20200120,
            20200121,
            20200122,
            20200123,
            20200203,
            20200204,
            20200205,
            20200206,
            20200207,
            20200210,
            20200211,
        ]

        for i in range(len(days)):
            start = tf.int2date(days[0])
            end = tf.int2date(days[i])

            actual = tf.get_frames(start, end, FrameType.DAY)
            logger.debug(
                "get_frames(%s, %s, %s)->%s", start, end, FrameType.DAY, actual
            )
            self.assertListEqual(days[0 : i + 1], list(actual))

        X = [
            (202002041030, 1, [202002041030]),
            (202002041030, 2, [202002041000, 202002041030]),
            (202002041030, 3, [202002031500, 202002041000, 202002041030]),
            (202002041030, 4, [202002031430, 202002031500, 202002041000, 202002041030]),
            (
                202002041030,
                5,
                [202002031400, 202002031430, 202002031500, 202002041000, 202002041030],
            ),
            (
                202002041030,
                6,
                [
                    202002031330,
                    202002031400,
                    202002031430,
                    202002031500,
                    202002041000,
                    202002041030,
                ],
            ),
            (
                202002041030,
                7,
                [
                    202002031130,
                    202002031330,
                    202002031400,
                    202002031430,
                    202002031500,
                    202002041000,
                    202002041030,
                ],
            ),
            (
                202002041030,
                8,
                [
                    202002031100,
                    202002031130,
                    202002031330,
                    202002031400,
                    202002031430,
                    202002031500,
                    202002041000,
                    202002041030,
                ],
            ),
            (
                202002041030,
                9,
                [
                    202002031030,
                    202002031100,
                    202002031130,
                    202002031330,
                    202002031400,
                    202002031430,
                    202002031500,
                    202002041000,
                    202002041030,
                ],
            ),
            (
                202002041030,
                10,
                [
                    202002031000,
                    202002031030,
                    202002031100,
                    202002031130,
                    202002031330,
                    202002031400,
                    202002031430,
                    202002031500,
                    202002041000,
                    202002041030,
                ],
            ),
            (
                202002041030,
                11,
                [
                    202001231500,
                    202002031000,
                    202002031030,
                    202002031100,
                    202002031130,
                    202002031330,
                    202002031400,
                    202002031430,
                    202002031500,
                    202002041000,
                    202002041030,
                ],
            ),
        ]

        for i, (end, n, expected) in enumerate(X):
            start = tf.int2time(expected[0])
            end = tf.int2time(end)
            actual = tf.get_frames(start, end, FrameType.MIN30)
            logger.debug(
                "get_frames(%s, %s, %s)->%s", start, end, FrameType.MIN30, actual
            )
            self.assertListEqual(expected, actual)