Exemplo n.º 1
0
    def test_ts(self):
        universe = make_randomwalk()
        strategy = RandomStrategy().run(universe)
        trades = strategy.trades

        assert_equal(strategy.wealth().values, ts.wealth(trades, universe))
        assert_equal(strategy.drawdown().values, ts.drawdown(trades, universe))
Exemplo n.º 2
0
    def test_handmade(self):
        universe = pd.DataFrame({"A": [0.0, 3.0, 1.0, 4.0, 1.0, 5.0, 9.0, 2.0]})
        trades = [trade("A").execute(universe)]

        result = ts.drawdown(trades, universe)
        expected = np.array([0.0, 0.0, -2.0, 0.0, -3.0, 0.0, 0.0, -7.0])

        assert_equal(result, expected)
Exemplo n.º 3
0
    def test(self):
        np.random.seed(42)
        universe = make_randomwalk()
        strategy = RandomStrategy().run(universe)

        drawdown = ts.drawdown(strategy.trades, universe)

        assert np.min(drawdown) == max_drawdown(strategy.trades, universe)
Exemplo n.º 4
0
    def test_monotonous(self):
        """
        result = 0 if wealth is monotonously increasing
        """
        universe = pd.DataFrame({"A": np.linspace(1, 2, 100)})
        trades = [trade("A").execute(universe)]

        result = ts.drawdown(trades, universe)
        expected = np.zeros_like(result)

        assert_equal(result, expected)
Exemplo n.º 5
0
    def test_zero(self):
        """
        result = 0 if trade is zero
        """
        universe = make_randomwalk()
        strategy = RandomStrategy(min_lot=0, max_lot=0).run(universe)

        result = ts.drawdown(strategy.trades, universe)
        expected = np.zeros_like(result)

        assert_equal(result, expected)