示例#1
0
    def test(self):
        future_prices = get_unresolved_future_prices()
        evaluate_winners_and_losers(future_prices[0])

        p = Prediction.objects.order_by('id')
        p_true_1 = p[0]
        p_false = p[1]
        p_true_2 = p[2]

        rc_true_1 = Received_Amount.objects.filter(prediction=p_true_1)[0]
        rc_false = Received_Amount.objects.filter(prediction=p_false)[0]
        rc_true_2 = Received_Amount.objects.filter(prediction=p_true_2)[0]

        # There should be three returned amounts
        r = Returned_Amount.objects.all()
        self.assertEqual(r.count(), 3)
        expected_total_returned = 1 * decimal.Decimal(1 - COMMISSION) + 1 + 1
        actual_total_returned = r[0].amount + r[1].amount + r[2].amount
        self.assertEqual(expected_total_returned, actual_total_returned)

        # The return from received_amount 1 should be returned to prediction 2 (loser)
        r = Returned_Amount.objects.filter(from_received_amount=rc_true_1)
        self.assertEqual(r[0].to_prediction, p_false)

        # The return from received_amount 2 should be returned to prediction 2 (winner)
        r = Returned_Amount.objects.filter(from_received_amount=rc_false)
        self.assertEqual(r[0].to_prediction, p_false)

        # The return from received_amount 3 should be returned to prediction 3 (loser no winner to match)
        r = Returned_Amount.objects.filter(from_received_amount=rc_true_2)
        self.assertEqual(r[0].to_prediction, p_true_2)
示例#2
0
    def test(self):
        future_prices = get_unresolved_future_prices()
        evaluate_winners_and_losers(future_prices[0])

        p = Prediction.objects.order_by('id')
        p_true_1 = p[0]
        p_false = p[1]
        p_true_2 = p[2]

        rc_true_1 = Received_Amount.objects.filter(prediction=p_true_1)[0]
        rc_false = Received_Amount.objects.filter(prediction=p_false)[0]
        rc_true_2 = Received_Amount.objects.filter(prediction=p_true_2)[0]

        # There should be three returned amounts
        r = Returned_Amount.objects.all()
        self.assertEqual(r.count(), 3)
        expected_total_returned = 1 * decimal.Decimal(1-COMMISSION) + 1 + 1
        actual_total_returned = r[0].amount+r[1].amount+r[2].amount
        self.assertEqual(expected_total_returned, actual_total_returned)

        # The return from received_amount 1 should be returned to prediction 2 (loser)
        r = Returned_Amount.objects.filter(from_received_amount=rc_true_1)
        self.assertEqual(r[0].to_prediction, p_false)

        # The return from received_amount 2 should be returned to prediction 2 (winner)
        r = Returned_Amount.objects.filter(from_received_amount=rc_false)
        self.assertEqual(r[0].to_prediction, p_false)

        # The return from received_amount 3 should be returned to prediction 3 (loser no winner to match)
        r = Returned_Amount.objects.filter(from_received_amount=rc_true_2)
        self.assertEqual(r[0].to_prediction, p_true_2)
示例#3
0
    def test(self):
        p_true = Prediction.objects.filter(
            price_will_be_less_than_target=True)[0]
        p_false = Prediction.objects.filter(
            price_will_be_less_than_target=False)[0]

        received_amount_true = Received_Amount.objects.filter(
            prediction=p_true)[0]
        received_amount_false = Received_Amount.objects.filter(
            prediction=p_false)[0]

        future_prices = get_unresolved_future_prices()
        evaluate_winners_and_losers(future_prices[0])

        r = Returned_Amount.objects.all()
        self.assertEqual(r.count(), 2)

        expected_total_returned = received_amount_true.amount + received_amount_false.amount
        actual_total_returned = r[0].amount + r[1].amount
        self.assertEqual(expected_total_returned, actual_total_returned)

        r = Returned_Amount.objects.filter(
            from_received_amount=received_amount_true)[0]
        self.assertEqual(r.to_prediction, p_true)

        r = Returned_Amount.objects.filter(
            from_received_amount=received_amount_false)[0]
        self.assertEqual(r.to_prediction, p_false)
示例#4
0
 def handle(self, *args, **options):
     if already_running():
         #self.stdout.write("Already running")
         return
     future_prices = get_unresolved_future_prices()
     for future_price in future_prices:
         evaluate_winners_and_losers(future_price)
     evaluate_amounts_received_after_window_closes()
示例#5
0
    def test(self):
        future_prices = get_unresolved_future_prices()
        evaluate_winners_and_losers(future_prices[0])

        p_true = Prediction.objects.filter(
            price_will_be_less_than_target=True)[0]
        rc_true = Received_Amount.objects.filter(prediction=p_true)[0]

        p_false_1 = Prediction.objects.filter(
            price_will_be_less_than_target=False, received_amount__amount=1)[0]
        rc_false_1 = Received_Amount.objects.filter(
            prediction__price_will_be_less_than_target=False, amount=1)[0]

        p_false_2 = Prediction.objects.filter(
            price_will_be_less_than_target=False, received_amount__amount=2)[0]
        rc_false_2 = Received_Amount.objects.filter(
            prediction__price_will_be_less_than_target=False, amount=2)[0]

        # There should be five returned amounts
        r = Returned_Amount.objects.all()
        self.assertEqual(r.count(), 5)
        expected_total_returned = 1 * (1 - COMMISSION) + 2 * (
            1 - COMMISSION) + (4 - 1 - 2) + 1 + 2
        actual_total_returned = r[0].amount + r[1].amount + r[2].amount + r[
            3].amount + r[4].amount
        self.assertEqual(expected_total_returned, actual_total_returned)

        # The return from prediction 2 should be returned to prediction 2 (winner)
        r = Returned_Amount.objects.filter(from_received_amount=rc_false_1)
        self.assertEqual(r[0].to_prediction, p_false_1)
        self.assertEqual(r[0].amount, 1)

        # The return from prediction 3 should be returned to prediction 3 (winner)
        r = Returned_Amount.objects.filter(from_received_amount=rc_false_2)
        self.assertEqual(r[0].to_prediction, p_false_2)
        self.assertEqual(r[0].amount, 2)

        # The return from prediction 1 should be split three ways
        r = Returned_Amount.objects.filter(from_received_amount=rc_true)
        self.assertEqual(r.count(), 3)
        # One returned to prediction 1 (loser remainder)
        r = Returned_Amount.objects.filter(from_received_amount=rc_true,
                                           to_prediction=p_true)
        self.assertEqual(r[0].to_prediction, p_true)
        self.assertEqual(r[0].amount, 1)
        # One returned to prediction 2 (loser)
        r = Returned_Amount.objects.filter(from_received_amount=rc_true,
                                           to_prediction=p_false_1)
        self.assertEqual(r[0].amount, 1 * (1 - COMMISSION))
        # One returned to prediction 3 (loser)
        r = Returned_Amount.objects.filter(from_received_amount=rc_true,
                                           to_prediction=p_false_2)
        self.assertEqual(r[0].amount, 2 * (1 - COMMISSION))
示例#6
0
    def test(self):
        p_true = Prediction.objects.all()[0]
        rc = Received_Amount.objects.filter(prediction=p_true)[0]

        future_prices = get_unresolved_future_prices()
        evaluate_winners_and_losers(future_prices[0])

        r = Returned_Amount.objects.all()
        self.assertEqual(r.count(), 1)
        self.assertEqual(r[0].to_prediction, p_true)

        expected_total_returned = rc.amount
        actual_total_returned = r[0].amount
        self.assertEqual(expected_total_returned, actual_total_returned)
示例#7
0
    def test(self):
        p_true = Prediction.objects.all()[0]
        rc = Received_Amount.objects.filter(prediction=p_true)[0]

        future_prices = get_unresolved_future_prices()
        evaluate_winners_and_losers(future_prices[0])

        r = Returned_Amount.objects.all()
        self.assertEqual(r.count(), 1)
        self.assertEqual(r[0].to_prediction, p_true)

        expected_total_returned = rc.amount
        actual_total_returned = r[0].amount
        self.assertEqual(expected_total_returned, actual_total_returned)
示例#8
0
    def test(self):
        future_prices = get_unresolved_future_prices()
        evaluate_winners_and_losers(future_prices[0])

        p = Prediction.objects.all()[0]
        rc = Received_Amount.objects.filter(time__lt=p.future_price.time_to_match_price)[0]
       
        r = Returned_Amount.objects.all()
        self.assertEqual(r.count(), 1)

        r = Returned_Amount.objects.filter(to_prediction=p)
        self.assertEqual(r.count(), 1)

        r = Returned_Amount.objects.filter(from_received_amount=rc)
        self.assertEqual(r.count(), 1)
示例#9
0
    def test(self):
        future_prices = get_unresolved_future_prices()
        evaluate_winners_and_losers(future_prices[0])

        p = Prediction.objects.all()[0]
        rc = Received_Amount.objects.filter(
            time__lt=p.future_price.time_to_match_price)[0]

        r = Returned_Amount.objects.all()
        self.assertEqual(r.count(), 1)

        r = Returned_Amount.objects.filter(to_prediction=p)
        self.assertEqual(r.count(), 1)

        r = Returned_Amount.objects.filter(from_received_amount=rc)
        self.assertEqual(r.count(), 1)
示例#10
0
    def test(self):
        p_true = Prediction.objects.filter(price_will_be_less_than_target=True)[0]
        p_false = Prediction.objects.filter(price_will_be_less_than_target=False)[0]

        received_amount_true = Received_Amount.objects.filter(prediction=p_true).aggregate(Sum('amount'))["amount__sum"]
        received_amount_false = Received_Amount.objects.filter(prediction=p_false).aggregate(Sum('amount'))["amount__sum"]
        
        future_prices = get_unresolved_future_prices()
        evaluate_winners_and_losers(future_prices[0])

        r = Returned_Amount.objects.all()
        self.assertEqual(r.count(), 2)
        self.assertEqual(r[0].to_prediction, p_true)
        self.assertEqual(r[1].to_prediction, p_true)

        expected_total_returned = received_amount_true + received_amount_false * decimal.Decimal(1-COMMISSION)
        actual_total_returned = r[0].amount+r[1].amount
        self.assertEqual(expected_total_returned, actual_total_returned)
示例#11
0
    def test(self):
        future_prices = get_unresolved_future_prices()
        evaluate_winners_and_losers(future_prices[0])

        p_true = Prediction.objects.filter(price_will_be_less_than_target=True)[0]
        rc_true = Received_Amount.objects.filter(prediction=p_true)[0]

        p_false_1 = Prediction.objects.filter(price_will_be_less_than_target=False, received_amount__amount=1)[0]
        rc_false_1 = Received_Amount.objects.filter(prediction__price_will_be_less_than_target=False, amount=1)[0]

        p_false_2 = Prediction.objects.filter(price_will_be_less_than_target=False, received_amount__amount=2)[0]
        rc_false_2 = Received_Amount.objects.filter(prediction__price_will_be_less_than_target=False, amount=2)[0]

        # There should be five returned amounts
        r = Returned_Amount.objects.all()
        self.assertEqual(r.count(), 5)
        expected_total_returned = 1 * (1-COMMISSION) + 2 * (1-COMMISSION) + (4 - 1 - 2) + 1 + 2
        actual_total_returned = r[0].amount+r[1].amount+r[2].amount+r[3].amount+r[4].amount
        self.assertEqual(expected_total_returned, actual_total_returned)

        # The return from prediction 2 should be returned to prediction 2 (winner)
        r = Returned_Amount.objects.filter(from_received_amount=rc_false_1)
        self.assertEqual(r[0].to_prediction, p_false_1)
        self.assertEqual(r[0].amount, 1)

        # The return from prediction 3 should be returned to prediction 3 (winner)
        r = Returned_Amount.objects.filter(from_received_amount=rc_false_2)
        self.assertEqual(r[0].to_prediction, p_false_2)
        self.assertEqual(r[0].amount, 2)

        # The return from prediction 1 should be split three ways
        r = Returned_Amount.objects.filter(from_received_amount=rc_true)
        self.assertEqual(r.count(), 3)
        # One returned to prediction 1 (loser remainder)
        r = Returned_Amount.objects.filter(from_received_amount=rc_true, to_prediction=p_true)
        self.assertEqual(r[0].to_prediction, p_true)
        self.assertEqual(r[0].amount, 1)
        # One returned to prediction 2 (loser)
        r = Returned_Amount.objects.filter(from_received_amount=rc_true, to_prediction=p_false_1)
        self.assertEqual(r[0].amount, 1*(1-COMMISSION))
        # One returned to prediction 3 (loser)
        r = Returned_Amount.objects.filter(from_received_amount=rc_true, to_prediction=p_false_2)
        self.assertEqual(r[0].amount, 2*(1-COMMISSION))
示例#12
0
    def test(self):
        p_true = Prediction.objects.filter(price_will_be_less_than_target=True)[0]
        p_false = Prediction.objects.filter(price_will_be_less_than_target=False)[0]

        received_amount_true = Received_Amount.objects.filter(prediction=p_true)[0]
        received_amount_false = Received_Amount.objects.filter(prediction=p_false)[0]

        future_prices = get_unresolved_future_prices()
        evaluate_winners_and_losers(future_prices[0])

        r = Returned_Amount.objects.all()
        self.assertEqual(r.count(), 2)

        expected_total_returned = received_amount_true.amount + received_amount_false.amount
        actual_total_returned = r[0].amount+r[1].amount
        self.assertEqual(expected_total_returned, actual_total_returned)

        r = Returned_Amount.objects.filter(from_received_amount=received_amount_true)[0]
        self.assertEqual(r.to_prediction, p_true)

        r = Returned_Amount.objects.filter(from_received_amount=received_amount_false)[0]
        self.assertEqual(r.to_prediction, p_false)
示例#13
0
    def test(self):
        p_true = Prediction.objects.filter(
            price_will_be_less_than_target=True)[0]
        p_false = Prediction.objects.filter(
            price_will_be_less_than_target=False)[0]

        received_amount_true = Received_Amount.objects.filter(
            prediction=p_true).aggregate(Sum('amount'))["amount__sum"]
        received_amount_false = Received_Amount.objects.filter(
            prediction=p_false).aggregate(Sum('amount'))["amount__sum"]

        future_prices = get_unresolved_future_prices()
        evaluate_winners_and_losers(future_prices[0])

        r = Returned_Amount.objects.all()
        self.assertEqual(r.count(), 2)
        self.assertEqual(r[0].to_prediction, p_true)
        self.assertEqual(r[1].to_prediction, p_true)

        expected_total_returned = received_amount_true + received_amount_false * decimal.Decimal(
            1 - COMMISSION)
        actual_total_returned = r[0].amount + r[1].amount
        self.assertEqual(expected_total_returned, actual_total_returned)
示例#14
0
 def test(self):
     future_prices = get_unresolved_future_prices()
     for f in future_prices:
         evaluate_winners_and_losers(f)
     r = get_unpaid_return_amounts()
     self.assertEqual(r.count(), 1)
示例#15
0
 def test(self):
     future_prices = get_unresolved_future_prices()
     for f in future_prices:
         evaluate_winners_and_losers(f)
     r = get_unpaid_return_amounts()
     self.assertEqual(r.count(), 1)