def sell(self, quantity, seller): """Sell the specified quantity we assume that when we sell, somebody else buys it so the amount issued doesn't change @param quantity: @param seller: @return: the quantity sold and the realised amount """ # see how much this seller has current = network.get_asset_holding(self.simInfo, self, seller) # scale the quantity if necessary quantity = min(quantity, current) # don't allow negative sales if quantity <= 0.0: return 0.0, 0.0 newH = current - quantity # calculate the price fireSaleFactor = self.get_param('fireSaleFactor', 0.0) if fireSaleFactor > 0.0: priceFactor = math.exp(-fireSaleFactor * quantity / self.issued) newPrice = self.currentPrice * priceFactor self.set_price(newPrice) # update the holding network.set_asset_holding(self.simInfo, self, seller, newH) self.record_holding_history(seller, newH) return quantity, quantity * self.currentPrice
def buy(self, quantity, buyer): """Create a holding of the specified amount A holding is an edge in the asset network. The amount issued is the total created so far @param buyer: @param quantity: @return: the quantity actually bought and the consideration """ # don't allow negative purchases if quantity < 0.0: return 0.0, 0.0 # see if this buyer already has some current = network.get_asset_holding(self.simInfo, self, buyer) newH = current + quantity network.set_asset_holding(self.simInfo, self, buyer, newH) self.issued += quantity self.record_holding_history(buyer, newH) return quantity, quantity * self.currentPrice