-
Notifications
You must be signed in to change notification settings - Fork 16
Price Belief Updates
The following was generated by Gemini Code Assist
Okay, let's break down how price belief updates work within the InventoryItem class, based on the provided code and context.
The key to understanding this is to trace where UpdateSellerPriceBelief and UpdateBuyerPriceBelief are called. These are the methods responsible for adjusting an agent's perceived price for a particular commodity. Here's the crucial snippet from AuctionHouse.cs:
foreach (var ask in asks)
ask.agent.UpdateSellerPriceBelief(ask, rsc);
foreach (var bid in bids)
bid.agent.UpdateBuyerPriceBelief(bid, rsc);
This code, located within the RecordStats method of the AuctionHouse, is executed after a round of trading has been resolved. This means:
- Offers are Collected: Agents create Ask (sell) and Bid (buy) offers.
- Trades are Resolved: The TradeResolver (e.g., XEvenResolution, OmisTradeResolution) determines which trades occur and at what prices.
- Stats are Recorded: The RecordStats function is called to update the ResourceController (rsc) with the outcomes of the round.
- Price Beliefs are Updated: As part of RecordStats, each agent who made an Ask or Bid offer gets a chance to update their price beliefs based on the outcome of the market.
Now let's dive into how UpdateSellerPriceBelief and UpdateBuyerPriceBelief work at the EconAgent level:
- EconAgent.UpdateSellerPriceBelief( ) This method is called for agents who made an Ask (selling) offer. Let's look at its (simplified) purpose:
- The Goal: A seller's belief about the price of a commodity should be influenced by whether they were able to sell and at what price.
- Input:
- Ask ask: Information about the agent's own selling offer (commodity, quantity, price).
- ResourceController rsc: Information about the commodity's market performance this round.
- Logic (conceptual):
- The seller looks at the current avgClearingPrice of the resource. This is the actual market price.
- If there is no trade, then don't update.
- The agent compares its own offer price (ask.offerPrice) to the market price.
- If their price was too high, they reduce the price belief. The higher the difference from clearing price, the more it should reduce the price.
- If their price was below clearing price, increase price belief.
- EconAgent.UpdateBuyerPriceBelief( ) This method is called for agents who made a Bid (buying) offer.
- The Goal: A buyer's belief about the price of a commodity should be influenced by whether they were able to buy and at what price.
- Input:
- Bid bid: Information about the agent's own buying offer (commodity, quantity, price).
- ResourceController rsc: Information about the commodity's market performance this round.
- Logic (conceptual):
- The buyer looks at the avgClearingPrice of the resource.
- If there is no trade, then don't update.
- The agent compares its own offer price (bid.offerPrice) to the market price.
- If their price was too low, they increase the price belief. The higher the difference from clearing price, the more it should increase the price.
- If their price was above clearing price, decrease price belief.
- InventoryItem.UpdateSellerPriceBelief( ) and .UpdateBuyerPriceBelief This is where the actual price adjustment is done. In the EconAgent class, the following is called
inventory[rsc.name].UpdateSellerPriceBelief(ask, rsc);
inventory[rsc.name].UpdateBuyerPriceBelief(bid, rsc);
The following is performed by each of those functions.
public void UpdateSellerPriceBelief(Offer offer, ResourceController rsc)
{
var oldPrice = GetPrice();
if (rsc.trades[^1] == 0)
return;
priceBelief += (rsc.marketPrice - offer.offerPrice) * .1f;
Debug.Log(" " + agent.name + " " + name + " seller price belief: " + oldPrice.ToString("c2") + " -> " + GetPrice().ToString("c2")
+ " market price: " + rsc.marketPrice.ToString("c2"));
}
public void UpdateBuyerPriceBelief(Offer offer, ResourceController rsc)
{
var oldPrice = GetPrice();
if (rsc.trades[^1] == 0)
return;
priceBelief -= (rsc.marketPrice - offer.offerPrice) * .1f;
Debug.Log(" " + agent.name + " " + name + " buyer price belief: " + oldPrice.ToString("c2") + " -> " + GetPrice().ToString("c2")
+ " market price: " + rsc.marketPrice.ToString("c2"));
}
- Price Adjustment: The priceBelief is adjusted based on the difference between the market price (rsc.marketPrice) and the agent's offer price (offer.offerPrice).
- priceBelief += (rsc.marketPrice - offer.offerPrice) * .1f;
- priceBelief -= (rsc.marketPrice - offer.offerPrice) * .1f;
- The 0.1f acts as a learning rate. It controls how strongly the price belief changes in each round. A higher value means agents react more strongly to recent price information.
- if trades did not happen, then do not update price belief.
- Tracking and Debugging: The debug log statements show the old price, the new price, and the market price, allowing you to monitor how beliefs are changing.
- The above logic is reversed depending on whether the agent is selling or buying. If the agent was a buyer, and offered too little compared to the market price, they increase their price belief, and vice versa.
- Market Feedback: Price belief updates are driven by the actual market outcomes. Agents learn from what happened in the previous round.
- Learning Rate: The 0.1f learning rate is a crucial parameter. It determines how quickly agents adapt to changing market conditions.
- Offer-Based: Belief adjustments are specific to each offer made. It's not just a global "price belief" for a commodity; it's tailored to the agent's recent attempt to buy or sell that commodity.
- No Trade, No Update: if there was no trade, there is no price belief update.
- Price Belief is a Guiding Star: Price belief is what guides user agent to make new bids.
In essence, this system creates a dynamic where agents:
- Form initial price beliefs.
- Make offers based on those beliefs.
- Observe the outcomes of trades.
- Adjust their beliefs accordingly.
- Repeat. This process allows the agents to become more informed participants in the market over time.