Пример #1
0
    def settle(self):
        enough_buys = len(self._buy_offers) > 0
        enough_sells = len(self._sell_offers) > 0
        if enough_buys:
            demand_curve = self._aggregate(self._buy_offers)
        else:
            _log.debug("There are no buy offers.")
        if enough_sells:
            supply_curve = self._aggregate(self._sell_offers)
        else:
            _log.debug("There are no sell offers.")

        if enough_buys and enough_sells:
            intersection = PolyLine.intersection(demand_curve, supply_curve)
        else:
            intersection = None, None, {}

        quantity = intersection[0]
        price = intersection[1]
        aux = PolyLine.compare(demand_curve, supply_curve)

        return quantity, price, aux
Пример #2
0
    def settle(self):
        enough_buys = len(self._buy_offers) > 0
        enough_sells = len(self._sell_offers) > 0
        if enough_buys:
            demand_curve = self._aggregate(self._buy_offers)
        else:
            _log.debug("There are no buy offers.")
        if enough_sells:
            supply_curve = self._aggregate(self._sell_offers)
        else:
            _log.debug("There are no sell offers.")

        if enough_buys and enough_sells:
            intersection = PolyLine.intersection(demand_curve, supply_curve)
        else:
            intersection = None, None, {}

        quantity = intersection[0]
        price = intersection[1]
        aux = PolyLine.compare(demand_curve, supply_curve)

        return quantity, price, aux
Пример #3
0
def test_poly_line_no_intersection():
    demand1 = create_demand_curve()
    demand2 = create_demand_curve()
    intersection = PolyLine.intersection(demand1, demand2)
    assert len(intersection) == 2
Пример #4
0
def test_poly_line_intersection_yeilds_two():
    demand = create_demand_curve()
    supply = create_supply_curve()
    intersection = PolyLine.intersection(demand, supply)
    assert len(intersection) == 2
Пример #5
0
def test_poly_line_intersection_not_none():
    demand = create_demand_curve()
    supply = create_supply_curve()
    intersection = PolyLine.intersection(demand, supply)
    assert intersection is not None
Пример #6
0
def test_poly_line_no_intersection():
    demand1 = create_demand_curve()
    demand2 = create_demand_curve()
    intersection = PolyLine.intersection(demand1, demand2)
    assert len(intersection) == 2
Пример #7
0
def test_poly_line_intersection_yeilds_two():
    demand = create_demand_curve()
    supply = create_supply_curve()
    intersection = PolyLine.intersection(demand, supply)
    assert len(intersection) == 2
Пример #8
0
def test_poly_line_intersection_not_none():
    demand = create_demand_curve()
    supply = create_supply_curve()
    intersection = PolyLine.intersection(demand, supply)
    assert intersection is not None