Exemplo n.º 1
0
    def Run(self, budget, symbol, quotes, start, end):
        correct_quote = self._correctQuote(symbol, quotes, start)
        average_rate = ((correct_quote.high + correct_quote.low) / 2)
        t = Trades()
        integralAmount = int(budget / average_rate)
        t.buy(Trade(start, integralAmount, symbol, average_rate))
        if(integralAmount * average_rate != budget):
            t.buy(Trade(start, -integralAmount * average_rate + budget, "cash", 1.0))

        return t
Exemplo n.º 2
0
    def Run(self, budget, symbol, quotes, start, end):
        repeat = int(budget / self._amount)
        t = Trades()
        for i in range(repeat):

            time = start + i * self._spacing
            correct_quote = self._correctQuote(symbol, quotes, time)
            average_rate = ((correct_quote.high + correct_quote.low) / 2)
            integralAmount = int(self._amount / average_rate)
            t.buy(Trade(time, integralAmount, symbol, average_rate))
            if (integralAmount * average_rate != self._amount):
                t.buy(
                    Trade(time, -integralAmount * average_rate + self._amount,
                          "cash", 1.0))

        return t
Exemplo n.º 3
0
def test_increasingrate_doublebuy():
    t = Trades()
    t.buy(Trade(0.0, 1, "x", 1.0))
    t.buy(Trade(1.0, 1, "x", 2.0))

    assert t.value_of_this_stock(1.5, "x", 2.0) == 4.0
Exemplo n.º 4
0
def test_value_of_this_stock():
    t = Trades()
    t.buy(Trade(0.0, 1, "x", 2.0))

    assert t.value_of_this_stock(1.0, "x", 2.1) == 2.1
Exemplo n.º 5
0
def test_revenuebeforelastTrade():
    t = Trades()
    t.sell(Trade(0.0, -1, "S", 1.0))
    t.sell(Trade(1.0, -1, "S", 1.0))

    assert -1.0 == t.revenue(0.1)
Exemplo n.º 6
0
def test_sellTwodifferent_revenueminusTwo():
    t = Trades()
    t.sell(Trade(0.0, -1, "S", 1.0))
    t.sell(Trade(0.0, -1, "D", 1.0))

    assert -2.0 == t.revenue(1)
Exemplo n.º 7
0
def test_expensebeforelastTrade():
    t = Trades()
    t.buy(Trade(0.0, 1, "S", 1.0))
    t.buy(Trade(1.0, 1, "S", 1.0))

    assert 1.0 == t.expense(0.1)
Exemplo n.º 8
0
def test_buyOne_expenseIsOne():
    t = Trades()
    t.buy(Trade(0.0, 1, "S", 1.0))

    assert 1.0 == t.expense(0.1)
Exemplo n.º 9
0
def test_buyTwodifferent_expenseTwo():
    t = Trades()
    t.buy(Trade(0.0, 1, "S", 1.0))
    t.buy(Trade(0.0, 1, "D", 1.0))

    assert 2.0 == t.expense(1)
Exemplo n.º 10
0
def test_buyOnesellOne_sameDate():
    t = Trades()
    t.buy(Trade(0.0, 1, "S", 1.0))
    t.sell(Trade(0.0, -1, "S", 1.0))

    assert 0.0 == t.expense(1) + t.revenue(1)
Exemplo n.º 11
0
def test_buyOneSellOne_revenueIsminusOne():
    t = Trades()
    t.buy(Trade(0.0, 1, "S", 1.0))
    t.sell(Trade(1.0, -1, "S", 1.0))

    assert -1.0 == t.revenue(2)
Exemplo n.º 12
0
def test_buyOneSellOne_expenseIsOne():
    t = Trades()
    t.buy(Trade(0.0, 1, "S", 1.0))
    t.sell(Trade(1.0, -1, "S", 1.0))

    assert 1.0 == t.expense(2)
Exemplo n.º 13
0
def test_sellAtLeastOne():
    t = Trades()
    with pytest.raises(Exception):
        t.sell(Trade(0.0, 0, "S", 1.0))
Exemplo n.º 14
0
def test_buyAtLeastOne():
    t = Trades()
    with pytest.raises(Exception):
        t.buy(Trade(0.0, 0, "S", 1.0))
Exemplo n.º 15
0
def test_buyOne_expenseIsZeroBeforeBuy():
    t = Trades()
    t.buy(Trade(0.0, 1, "S", 1.0))

    assert 0.0 == t.expense(date=-1)
Exemplo n.º 16
0
def test_possible_profit_of_this_stock():
    t = Trades()
    t.buy(Trade(0.0, 1, "x", 1.0))
    t.buy(Trade(1.0, 1, "x", 2.0))

    assert t.possible_profit_of_this_stock(1.5, "x", 2.0) == 1.0