Beispiel #1
0
    def buy(self, product):
        # if not enough money in wallet, don't proceed
        if self.wallet < product.price:
            return

        # purchase the product from market
        
        Market.buy(self, product)

        # add product to the owned products list
        self.owned_products.add(product)
    def buy(self, products):
        # enable buyer to buy more than one products
        amount = 0
        for product in products:
            amount += product.stock_price

        # if not enough money in wallet, don't proceed
        if self.wallet < amount:  # enable buyer to buy more than one products
            logging.info(
                "[Customer]: (%s,%d) didn't have enough money to buy Products:[%s] from seller %s",
                self.name, self.tick_count, products[0].product_name,
                products[0].seller_id)
            return

        # if there is not enough stock, no transaction
        if products[0].stock_quantity <= 0:
            logging.info(
                "[Customer]: (%s,%d) Seller didn't have enough stock to sell the products:[%s], "
                "so the customer didn't buy", products[0].seller_id,
                self.tick_count, products[0].product_name)
            return
        if products[0].stock_quantity < len(products):
            logging.info(
                "[Customer]: (%s,%d) Seller didn't have enough stock to sell the products:[%s], "
                "so the customer didn't buy", products[0].seller_id,
                self.tick_count, products[0].product_name)
            return

        products_str = ', '.join(x.product_name for x in products)
        logging.info(
            "[Customer]: (%s,%d) buy the Products:[%s] from seller%s with price %d",
            self.name, self.tick_count, products_str, products[0].seller_id,
            amount)

        # purchase the product from market
        Market.buy(self, products)

        # add product to the owned products list
        for product in products:
            self.owned_products.add(product)
Beispiel #3
0
    def consider(self, product):
        # if not enough money in wallet, don't proceed
        if self.wallet < product.price:
            print('Out of money ' + self.name)
            return

        decision = self.purchase_decision(product)
        if not decision:
            return
            # purchase the product from market

        seller = Market.buy(self, product)
        if seller != 0:
            self.dataCenter.data_ranking(obj_data=[self, product, seller], data_type='customer')
            self.owned_products.add(product)
Beispiel #4
0
    def buy(self, product_list):
        """
        Consumer decided to buy a 'product'.
        :param product_list: list of products
        :return: none
        """
        # if not enough money in wallet, don't proceed
        total_price = sum(product.price for product in product_list)
        if self.wallet < total_price:
            return

        # purchase the product from market
        if Market.buy(self, product_list):
            # add product to the owned products list
            for product in product_list:
                self.owned_products.append(product)
Beispiel #5
0
                                                     purge_ratio=0.1)
    market = Market(x_test, p=p)
    x, y = tools.build_ar_x_y(x_train, p=p, rest=2)
    x = np.array(x).reshape((-1, p, 30))
    y = np.array(y).reshape((-1, 30, 1))
    models = [
        RidgeCV(alphas=[0.2, 0.3, 0.6], cv=6, fit_intercept=True)
        for i in range(30)
    ]
    for i in range(30):
        models[i].fit(get_ith_col_x(x, i), get_ith_col_y(y, i))

    # model = Lstm(time_steps=p, input_size=30, output_size=30)
    # model.load_data(x, y, units=50, epochs=20, batch_size=50)

    market.buy(P.items())
    trades = []
    y_preds = []
    cash_y = []
    cash_x = []
    for prices in market.iterate(tick_names=False):
        y_pred = [
            m.predict(get_ith_col_x(np.array(prices).reshape((-1, p, 30)), i))
            for i, m in enumerate(models)
        ]
        y_pred = np.array(y_pred).flatten()
        y_preds.append(y_pred)
        returns = np.divide(
            np.subtract(np.array(y_pred), np.array(prices[-1])),
            np.array(prices[-1]))
        returns = returns.flatten()
Beispiel #6
0
from good import Good
from market import Market
from universe import Universe
from simulation import Simulation

universe = Universe()
simulation = Simulation(universe)
simulation.run()

# Some basic market stuff
foodMarket = Market(Good.food, 100.0, 1.0, 0)
print("Current food price: " + str(foodMarket.current_price()))
print("Sold food for: " + str(foodMarket.sell_one()))
print("Sold food for: " + str(foodMarket.sell_one()))
print("Sold food for: " + str(foodMarket.sell_one()))
print("Bought 3 food for: " + str(foodMarket.buy(3)))
print("Sold 10 food for: " + str(foodMarket.sell(10)))
print("Current food price: " + str(foodMarket.current_price()))
print("Done")