Пример #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
Пример #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
Пример #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
Пример #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
Пример #5
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)
Пример #6
0
def test_buyOne_expenseIsOne():
    t = Trades()
    t.buy(Trade(0.0, 1, "S", 1.0))

    assert 1.0 == t.expense(0.1)
Пример #7
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)
Пример #8
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)
Пример #9
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)
Пример #10
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)
Пример #11
0
def test_buyAtLeastOne():
    t = Trades()
    with pytest.raises(Exception):
        t.buy(Trade(0.0, 0, "S", 1.0))
Пример #12
0
def test_buyOne_expenseIsZeroBeforeBuy():
    t = Trades()
    t.buy(Trade(0.0, 1, "S", 1.0))

    assert 0.0 == t.expense(date=-1)
Пример #13
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