net.sourceforge.jasa.agent
Class AbstractTradingAgent

java.lang.Object
  extended by AbstractAgent
      extended by net.sourceforge.jasa.agent.AbstractTradingAgent
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable, TradingAgent, MarketEventListener
Direct Known Subclasses:
FixedDirectionTradingAgent, MarketMakerAgent, SimpleTradingAgent

public abstract class AbstractTradingAgent
extends AbstractAgent
implements TradingAgent, java.io.Serializable, java.lang.Cloneable

An abstract class representing a simple agent trading in a round-robin market. Traders of this type deal in a single commodity for which they have a well-defined valuation.

 

Field Summary
protected  Account account
          The amount of money this agent posseses.
protected  Order currentOrder
          The current position for this trader.
protected  AgentGroup group
          The grouping that this agent belongs to.
protected  double initialFunds
          The initial amount of money for this agent
protected  int initialStock
          The initial stock of this agent
protected  boolean lastOrderFilled
          Did the last order we place in the market result in a transaction?
protected  double lastPayoff
          The profit made in the last round.
protected  java.util.Set<Market> markets
           
protected  Inventory stock
          The inventory of the agent.
protected  double totalPayoff
          The total profits to date
protected  UtilityFunction utilityFunction
          The utility function of this agent.
protected  ValuationPolicy valuer
          The valuer for this agent.
 
Constructor Summary
AbstractTradingAgent(EventScheduler scheduler)
           
AbstractTradingAgent(int stock, double funds, double privateValue, EventScheduler scheduler)
           
AbstractTradingAgent(int stock, double funds, double privateValue, TradingStrategy strategy, EventScheduler scheduler)
           
AbstractTradingAgent(int stock, double funds, EventScheduler scheduler)
           
 
Method Summary
abstract  boolean active()
          Determine whether or not this trader is active.
 double calculatePayoff(Market auction, int quantity, double price)
           
 double calculateProfit(Market auction, int quantity, double price)
           
protected  java.lang.Object clone()
           
 int determineQuantity(Market auction)
           
 double equilibriumProfits(Market auction, double equilibriumPrice, int quantity)
          Calculate the hypothetical surplus this agent will receive if the market had cleared uniformly at the specified equilibrium price and quantity.
 double equilibriumProfitsEachDay(Market auction, double equilibriumPrice, int quantity)
           
 void eventOccurred(SimEvent ev)
           
 Account getAccount()
           
 Inventory getCommodityHolding()
           
 Order getCurrentOrder()
           
 double getFunds()
           
 AgentGroup getGroup()
           
 double getLastPayoff()
          Return the profit made in the most recent market round.
 Market getMarket()
           
 java.util.Collection<Market> getMarkets()
           
 double getPayoff()
           
 int getStock()
           
 double getTotalPayoff()
           
 TradingStrategy getTradingStrategy()
           
 UtilityFunction getUtilityFunction()
           
 double getValuation(Market auction)
           
 ValuationPolicy getValuationPolicy()
           
 int getVolume(Market auction)
           
 void giveFunds(AbstractTradingAgent recipient, double amount)
           
 void initialise()
           
 boolean isBuyer(Market auction)
           
 boolean isInteracted()
           
 boolean isSeller(Market auction)
           
 boolean lastOrderFilled()
           
 void onAgentArrival(AgentArrivalEvent event)
           
 void onAgentArrival(Market market, AgentArrivalEvent event)
          Place an order in the market as determined by the agent's strategy.
 void onEndOfDay(MarketEvent event)
           
 void onMarketClosed(MarketEvent event)
           
 void onMarketOpen(MarketEvent event)
           
 void orderFilled(Market auction, Order shout, double price, int quantity)
           
 void pay(double amount)
          This method is invoked by a buyer on a seller when it wishes to transfer funds.
 java.lang.Object protoClone()
           
 boolean register(Market market)
           
 void reset()
           
 void setGroup(AgentGroup group)
           
 void setMarket(Market market)
           
 void setMarkets(java.util.Collection<Market> markets)
           
 void setPrivateValue(double privateValue)
           
 void setUtilityFunction(UtilityFunction utilityFunction)
           
 void setValuationPolicy(ValuationPolicy valuer)
           
 void subscribeToEvents()
           
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

stock

protected Inventory stock
The inventory of the agent.


initialStock

protected int initialStock
The initial stock of this agent


account

protected Account account
The amount of money this agent posseses.


initialFunds

protected double initialFunds
The initial amount of money for this agent


valuer

protected ValuationPolicy valuer
The valuer for this agent.


utilityFunction

protected UtilityFunction utilityFunction
The utility function of this agent.


lastPayoff

protected double lastPayoff
The profit made in the last round.


totalPayoff

protected double totalPayoff
The total profits to date


lastOrderFilled

protected boolean lastOrderFilled
Did the last order we place in the market result in a transaction?


currentOrder

protected Order currentOrder
The current position for this trader.


group

protected AgentGroup group
The grouping that this agent belongs to.


markets

protected java.util.Set<Market> markets
Constructor Detail

AbstractTradingAgent

public AbstractTradingAgent(int stock,
                            double funds,
                            double privateValue,
                            EventScheduler scheduler)
Parameters:
stock - The quantity of stock for this trader.
funds - The amount of money for this trader.
privateValue - The private value of the commodity traded by this trader.
isSeller - Whether or not this trader is a seller.

AbstractTradingAgent

public AbstractTradingAgent(int stock,
                            double funds,
                            double privateValue,
                            TradingStrategy strategy,
                            EventScheduler scheduler)

AbstractTradingAgent

public AbstractTradingAgent(int stock,
                            double funds,
                            EventScheduler scheduler)

AbstractTradingAgent

public AbstractTradingAgent(EventScheduler scheduler)
Method Detail

getTradingStrategy

public TradingStrategy getTradingStrategy()

onAgentArrival

public void onAgentArrival(Market market,
                           AgentArrivalEvent event)
Place an order in the market as determined by the agent's strategy.


subscribeToEvents

public void subscribeToEvents()

eventOccurred

public void eventOccurred(SimEvent ev)

onEndOfDay

public void onEndOfDay(MarketEvent event)

onMarketOpen

public void onMarketOpen(MarketEvent event)

onMarketClosed

public void onMarketClosed(MarketEvent event)

getCurrentOrder

public Order getCurrentOrder()

getAccount

public Account getAccount()
Specified by:
getAccount in interface TradingAgent

giveFunds

public void giveFunds(AbstractTradingAgent recipient,
                      double amount)

pay

public void pay(double amount)
This method is invoked by a buyer on a seller when it wishes to transfer funds.

Parameters:
amount - The total amount of money to give to the seller

getFunds

public double getFunds()

getStock

public int getStock()

initialise

public void initialise()

reset

public void reset()

getValuation

public double getValuation(Market auction)
Specified by:
getValuation in interface TradingAgent

setPrivateValue

public void setPrivateValue(double privateValue)

getLastPayoff

public double getLastPayoff()
Return the profit made in the most recent market round. This can be used as, e.g. input to a re-inforcement learning algorithm.


getTotalPayoff

public double getTotalPayoff()

determineQuantity

public int determineQuantity(Market auction)

protoClone

public java.lang.Object protoClone()

calculatePayoff

public double calculatePayoff(Market auction,
                              int quantity,
                              double price)

orderFilled

public void orderFilled(Market auction,
                        Order shout,
                        double price,
                        int quantity)
Specified by:
orderFilled in interface TradingAgent

lastOrderFilled

public boolean lastOrderFilled()

getValuationPolicy

public ValuationPolicy getValuationPolicy()

setValuationPolicy

public void setValuationPolicy(ValuationPolicy valuer)

getUtilityFunction

public UtilityFunction getUtilityFunction()
Specified by:
getUtilityFunction in interface TradingAgent

setUtilityFunction

public void setUtilityFunction(UtilityFunction utilityFunction)
Specified by:
setUtilityFunction in interface TradingAgent

getGroup

public AgentGroup getGroup()

setGroup

public void setGroup(AgentGroup group)

getCommodityHolding

public Inventory getCommodityHolding()
Specified by:
getCommodityHolding in interface TradingAgent

getMarkets

public java.util.Collection<Market> getMarkets()

setMarkets

public void setMarkets(java.util.Collection<Market> markets)

setMarket

public void setMarket(Market market)

getMarket

public Market getMarket()

register

public boolean register(Market market)
Specified by:
register in interface TradingAgent

equilibriumProfitsEachDay

public double equilibriumProfitsEachDay(Market auction,
                                        double equilibriumPrice,
                                        int quantity)

clone

protected java.lang.Object clone()
                          throws java.lang.CloneNotSupportedException
Throws:
java.lang.CloneNotSupportedException

getPayoff

public double getPayoff()

onAgentArrival

public void onAgentArrival(AgentArrivalEvent event)

isInteracted

public boolean isInteracted()

getVolume

public int getVolume(Market auction)

isBuyer

public boolean isBuyer(Market auction)

isSeller

public boolean isSeller(Market auction)

calculateProfit

public double calculateProfit(Market auction,
                              int quantity,
                              double price)
Specified by:
calculateProfit in interface TradingAgent

equilibriumProfits

public double equilibriumProfits(Market auction,
                                 double equilibriumPrice,
                                 int quantity)
Calculate the hypothetical surplus this agent will receive if the market had cleared uniformly at the specified equilibrium price and quantity.


active

public abstract boolean active()
Determine whether or not this trader is active. Inactive traders do not place shouts in the market, but do carry on learning through their strategy.

Returns:
true if the trader is active.