Example #1
0
    def most_profitable_pop_job(self, include=None, day_range=10):
        "Returns the most profitable pop_job in a given day range"
        best = float('-inf')
        best_pop_job = None

        if include is None:
            include = PopJob.all()

        for pop_job in include:
            avg_profit = self.history.profit.average(pop_job, day_range=day_range)

            if avg_profit > best:
                best_pop_job = pop_job
                best = avg_profit

        return best_pop_job
Example #2
0
    def __init__(self, manager, location):
        self.manager = manager
        self.location = location

        # dictionary of list of orders by Good
        # stores the current buy and sell orders this market is processing
        self.buy_orders = {}
        self.sell_orders = {}

        # stores historical economic data for past transactions
        self.history = TradeHistory()

        # fill the trade history with a bunch of fake data
        for good in Good.all():
            self.history.register(good)
            self.history.prices.add(good, 1.0)
            self.history.buy_orders.add(good, 1.0)
            self.history.sell_orders.add(good, 1.0)
            self.history.trades.add(good, 1.0)
            self.buy_orders[good] = []
            self.sell_orders[good] = []

        for pop_job in PopJob.all():
            self.history.profit.register(pop_job)