Ejemplo n.º 1
0
 def setUp(self):
     self.events = queue.Queue()
     self.status = dict()
     self.portfolio = PortfolioLocal(self.status)
     self.execution = SimulatedExecutionHandler(self.status)
     self.manager = Manager(self.status, self.events, self.execution,
                            self.portfolio, None)
     self.event_src = DukascopyCSVPriceHandler("EUR_USD", self.events)
Ejemplo n.º 2
0
 def setUp(self):
     self.events = queue.Queue()
     self.status = dict()
     self.portfolio = PortfolioLocal(self.status)
     self.execution = SimulatedExecutionHandler(self.status)
     self.manager = Manager(self.status, self.events,
                            self.execution, self.portfolio, None)
     self.event_src = DukascopyCSVPriceHandler("EUR_USD", self.events)
Ejemplo n.º 3
0
class TestHelloUnitTest(unittest.TestCase):
    def setUp(self):
        self.events = queue.Queue()
        self.status = dict()
        self.portfolio = PortfolioLocal(self.status)
        self.execution = SimulatedExecutionHandler(self.status)
        self.manager = Manager(self.status, self.events, self.execution,
                               self.portfolio, None)
        self.event_src = DukascopyCSVPriceHandler("EUR_USD", self.events)

    def simulate(self):
        while not self.events.empty():
            self.manager.perform_trade(self.events.get(False))

        print("Total Order Count: %s" % self.portfolio.order_count)
        print("Realized P&L     : %s" % round(self.status["realized_pnl"], 5))
        print(
            "Profit Factor    : %s" %
            round(self.portfolio.total_profit / self.portfolio.total_loss, 5))

    def assertResult(self, count, pnl, pfac):
        self.assertEqual(count, self.portfolio.order_count)
        self.assertEqual(pnl, round(self.status["realized_pnl"], 5))
        self.assertEqual(
            pfac,
            round(self.portfolio.total_profit / self.portfolio.total_loss, 5))

    def test_sma(self):
        self.event_src.file_path = \
        "../data/EURUSD_Candlestick_15_s_BID_16.07.2015-16.07.2015.csv"
        self.event_src.stream_to_queue()

        strategy = SMA(self.status)
        strategy.mean_period_short = 20
        strategy.mean_period_long = 40
        self.manager.strategy = strategy
        self.simulate()

        self.assertResult(103, 19.3, 1.14339)

    def test_sma2(self):
        self.event_src.file_path = \
        "../data/EURUSD_Candlestick_15_s_BID_16.07.2015-16.07.2015.csv"
        self.event_src.stream_to_queue()

        strategy = SMA(self.status)
        strategy.mean_period_short = 40
        strategy.mean_period_long = 80
        self.manager.strategy = strategy
        self.simulate()

        self.assertResult(59, 58.6, 1.98157)

    def test_sma3(self):
        self.event_src.file_path = \
        "../data/EURUSD_Candlestick_15_s_BID_16.07.2015-16.07.2015.csv"
        self.event_src.stream_to_queue()

        strategy = SMA(self.status)
        strategy.mean_period_short = 20
        strategy.mean_period_long = 80
        self.manager.strategy = strategy
        self.simulate()

        self.assertResult(59, -14.2, 0.85899)

    def test_sma4(self):
        self.event_src.file_path = \
        "../data/EURUSD_Candlestick_15_s_BID_16.07.2015-16.07.2015.csv"
        self.event_src.stream_to_queue()

        strategy = SMA(self.status)
        strategy.mean_period_short = 40
        strategy.mean_period_long = 120
        self.manager.strategy = strategy
        self.simulate()

        self.assertResult(27, 35, 1.07973)

    def test_sma5(self):
        self.event_src.file_path = \
        "../data/EURUSD_Candlestick_15_s_BID_16.07.2015-16.07.2015.csv"
        self.event_src.stream_to_queue()

        strategy = SMA(self.status)
        strategy.mean_period_short = 30
        strategy.mean_period_long = 60
        self.manager.strategy = strategy
        self.simulate()

        self.assertResult(67, 11.4, 1.13029)
Ejemplo n.º 4
0
class TestHelloUnitTest(unittest.TestCase):

    def setUp(self):
        self.events = queue.Queue()
        self.status = dict()
        self.portfolio = PortfolioLocal(self.status)
        self.execution = SimulatedExecutionHandler(self.status)
        self.manager = Manager(self.status, self.events,
                               self.execution, self.portfolio, None)
        self.event_src = DukascopyCSVPriceHandler("EUR_USD", self.events)

    def simulate(self):
        while not self.events.empty():
            self.manager.perform_trade(self.events.get(False))

        print("Total Order Count: %s" % self.portfolio.order_count)
        print("Realized P&L     : %s" % round(self.status["realized_pnl"], 5))
        print("Profit Factor    : %s" % round(
            self.portfolio.total_profit/self.portfolio.total_loss, 5))

    def assertResult(self, count, pnl, pfac):
        self.assertEqual(count, self.portfolio.order_count)
        self.assertEqual(pnl, round(self.status["realized_pnl"], 5))
        self.assertEqual(pfac, round(
            self.portfolio.total_profit/self.portfolio.total_loss, 5))

    def test_sma(self):
        self.event_src.file_path = \
        "../data/EURUSD_Candlestick_15_s_BID_16.07.2015-16.07.2015.csv"
        self.event_src.stream_to_queue()

        strategy = SMA(self.status)
        strategy.mean_period_short = 20
        strategy.mean_period_long = 40
        self.manager.strategy = strategy
        self.simulate()

        self.assertResult(103, 19.3, 1.14339)

    def test_sma2(self):
        self.event_src.file_path = \
        "../data/EURUSD_Candlestick_15_s_BID_16.07.2015-16.07.2015.csv"
        self.event_src.stream_to_queue()

        strategy = SMA(self.status)
        strategy.mean_period_short = 40
        strategy.mean_period_long = 80
        self.manager.strategy = strategy
        self.simulate()

        self.assertResult(59, 58.6, 1.98157)

    def test_sma3(self):
        self.event_src.file_path = \
        "../data/EURUSD_Candlestick_15_s_BID_16.07.2015-16.07.2015.csv"
        self.event_src.stream_to_queue()

        strategy = SMA(self.status)
        strategy.mean_period_short = 20
        strategy.mean_period_long = 80
        self.manager.strategy = strategy
        self.simulate()

        self.assertResult(59, -14.2, 0.85899)

    def test_sma4(self):
        self.event_src.file_path = \
        "../data/EURUSD_Candlestick_15_s_BID_16.07.2015-16.07.2015.csv"
        self.event_src.stream_to_queue()

        strategy = SMA(self.status)
        strategy.mean_period_short = 40
        strategy.mean_period_long = 120
        self.manager.strategy = strategy
        self.simulate()

        self.assertResult(27, 35, 1.07973)

    def test_sma5(self):
        self.event_src.file_path = \
        "../data/EURUSD_Candlestick_15_s_BID_16.07.2015-16.07.2015.csv"
        self.event_src.stream_to_queue()

        strategy = SMA(self.status)
        strategy.mean_period_short = 30
        strategy.mean_period_long = 60
        self.manager.strategy = strategy
        self.simulate()

        self.assertResult(67, 11.4, 1.13029)
Ejemplo n.º 5
0
#    strategy = SMABOL(status)
#    strategy = SMARSIOLS(status)
#    strategy = WMA(status)
#    strategy = SMAOLS(status)
#    strategy = SMA(status)
#    strategy = RSI(status)
#    strategy = SMARSI(status)
#    strategy = Granville(status)
#    strategy = Momentum(status)
#    strategy = BolingerBand(status)

    manager = Manager(status, events, execution,
                      portfolio, strategy, timeseries)

    print("=== Backtesting Start =================================== ")

    #    event_src = MetatraderCSVPriceHandler("EUR_USD", events)
    event_src = DukascopyCSVPriceHandler("EUR_USD", events,
#                                         "data/EURUSD_Ticks_24.07.2015-3H.csv")
                                         "data/EURUSD_Ticks_28.07.2015-3H-2.csv")
#                                         "data/EURUSD_Ticks_29.07.2015-4H.csv")

    event_src.stream_to_queue()

    simulating(events, manager)

    print("=== End .... v(^_^)v  =================================== ")

    show_result()
    plot_data()