net.sourceforge.jasa.market
Class MarketSimulation

java.lang.Object
  extended by AbstractSimulation
      extended by net.sourceforge.jasa.market.MarketSimulation
All Implemented Interfaces:
java.io.Serializable, Market, QuoteProvider

public class MarketSimulation
extends AbstractSimulation
implements java.io.Serializable, Market

A simulation of an order-driven market.

 

Field Summary
protected  Account account
          Records the surplus of the mechanism if it is not budget-balanced.
protected  int age
           
protected  Auctioneer auctioneer
          The auctioneer for this market.
protected  boolean closed
          Is the market currently closed.
protected  TimingCondition closingCondition
           
protected  int day
          The current trading day (period)
protected  TimingCondition dayEndingCondition
           
protected  boolean endOfRound
           
static java.lang.String ERROR_SHOUTSVISIBLE
           
protected  double initialPrice
          The initial price in the market.
protected  double lastTransactionPrice
          The price of the most recent transaction.
protected  int round
          The current "round".
 
Constructor Summary
MarketSimulation()
           
MarketSimulation(SimulationController controller)
           
 
Method Summary
protected  void activate(TradingAgent agent)
           
 void begin()
          Begin the simulation.
 void beginRound()
           
protected  void checkEndOfDay()
           
 void clear(Order ask, Order bid, double transactionPrice)
          Match a buy order with a sell order at the specified price and inform both parties of the resulting transaction.
 void clear(Order ask, Order bid, double buyerCharge, double sellerPayment, int quantity)
          Match a buy order with a sell order and inform both parties of the resulting transaction.
 void close()
          Close the market.
 boolean closed()
          Returns true if the market is closed.
 void end()
          End the simulation.
protected  void endDay()
          Terminate the current trading period (day)
 void endRound()
          End the current simulation tick.
 int getAge()
           
 TimingCondition getAuctionClosingCondition(java.lang.Class conditionClass)
           
 Auctioneer getAuctioneer()
          Return the current auctioneer for this market.
 double getCurrentPrice()
          Return the current price.
 int getDay()
           
 TimingCondition getDayEndingCondition(java.lang.Class conditionClass)
           
 double getInitialPrice()
           
 Order getLastAsk()
          Get the most recent ask (sell order) placed in the market.
 Order getLastBid()
          Get the most recent bid (buy order) placed in the market.
 Order getLastOrder()
          Return the most recent order placed in the market.
 double getLastTransactionPrice()
          Return the price of the most transaction that occurred in the market.
 int getLengthOfDay()
          Return the duration in ticks of a single trading day.
 int getMaximumDays()
          Return the maximum number of trading days in the simulation.
 int getMaximumRounds()
          Get the absolute duration of the entire simulation in ticks.
 int getNumberOfRegisteredTraders()
          Return the total number of traders registered in the market.
 int getNumberOfTraders()
          Return the number of traders currently active in the market.
 MarketQuote getQuote()
           
 int getRemainingTime()
          Return the time remaining before the market closes.
 int getRound()
          Get the current round number
 SimulationTime getSimulationTime()
           
protected  TimingCondition getTimingCondition(TimingCondition cond, java.lang.Class conditionClass)
           
 java.util.Iterator<Agent> getTraderIterator()
           
 Population getTraders()
           
 void informAuctionClosed()
           
 void informAuctionOpen()
           
 void informEndOfDay()
           
 void informRoundClosed()
           
 void informRoundClosing()
           
 void informRoundOpening()
           
 void initialise()
           
 void initialiseCounters()
           
 boolean isClosed()
          Check whether the market is open.
 boolean orderAccepted(Order shout)
          Determines whether or not the given shout was matched in the current round of trading.
 void placeOrder(Order order)
          Submit a new order to the market.
 void printState()
          Report the state of the market.
 void register(TradingAgent trader)
           
 void remove(AbstractTradingAgent abstractTradingAgent)
           
 void remove(TradingAgent trader)
          Remove a trader from the market.
 void removeOrder(Order shout)
          Remove an order from the market.
 void reset()
           
 void run()
          Run the simulation.
 void runSingleRound()
           
 void setAuctionClosingCondition(TimingCondition cond)
           
 void setAuctioneer(Auctioneer auctioneer)
          Configure the Auctioneer for this market.
 void setDayEndingCondition(TimingCondition cond)
           
 void setInitialPrice(double initialPrice)
          Set the price which will be used at the opening of the market.
 void setLastTransactionPrice(double lastTransactionPrice)
           
 void setLengthOfDay(int lengthOfDay)
          Configure the maximum duration of a trading day in ticks.
 void setMaximumDays(int maximumDays)
          Configure the maximum number of days in the simulation.
 void setMaximumRounds(int maximumRounds)
          Configure the absolute duration of the entire simulation in ticks.
 void step()
          Step through a single tick of the simulation.
 void terminate()
           
 boolean transactionsOccurred()
          Determines whether or not any transactions have occured in the current round of trading.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface net.sourceforge.jasa.market.Market
getPopulation
 

Field Detail

auctioneer

protected Auctioneer auctioneer
The auctioneer for this market.


closed

protected boolean closed
Is the market currently closed.


round

protected int round
The current "round". A round, a.k.a. a "tick", represents a discrete unit of time. The round attribute thus corresponds to the simulation clock.


age

protected int age

account

protected Account account
Records the surplus of the mechanism if it is not budget-balanced.


day

protected int day
The current trading day (period)


closingCondition

protected TimingCondition closingCondition

dayEndingCondition

protected TimingCondition dayEndingCondition

endOfRound

protected boolean endOfRound

lastTransactionPrice

protected double lastTransactionPrice
The price of the most recent transaction.


initialPrice

protected double initialPrice
The initial price in the market.


ERROR_SHOUTSVISIBLE

public static final java.lang.String ERROR_SHOUTSVISIBLE
See Also:
Constant Field Values
Constructor Detail

MarketSimulation

public MarketSimulation(SimulationController controller)

MarketSimulation

public MarketSimulation()
Method Detail

initialiseCounters

public void initialiseCounters()

initialise

public void initialise()

reset

public void reset()

informAuctionClosed

public void informAuctionClosed()

informEndOfDay

public void informEndOfDay()

informAuctionOpen

public void informAuctionOpen()

informRoundOpening

public void informRoundOpening()

beginRound

public void beginRound()

getRound

public int getRound()
Get the current round number

Specified by:
getRound in interface Market

getAge

public int getAge()
Specified by:
getAge in interface Market

getDay

public int getDay()
Specified by:
getDay in interface Market

getAuctioneer

public Auctioneer getAuctioneer()
Description copied from interface: Market
Return the current auctioneer for this market.

Specified by:
getAuctioneer in interface Market

getLastBid

public Order getLastBid()
                 throws ShoutsNotVisibleException
Get the most recent bid (buy order) placed in the market.

Throws:
ShoutsNotVisibleException

getLastAsk

public Order getLastAsk()
                 throws ShoutsNotVisibleException
Get the most recent ask (sell order) placed in the market.

Throws:
ShoutsNotVisibleException

run

public void run()
Run the simulation.


begin

public void begin()
Begin the simulation.


end

public void end()
End the simulation.


step

public void step()
Step through a single tick of the simulation.


endRound

public void endRound()
End the current simulation tick.


isClosed

public boolean isClosed()
Check whether the market is open.

Returns:

runSingleRound

public void runSingleRound()

informRoundClosing

public void informRoundClosing()

informRoundClosed

public void informRoundClosed()

checkEndOfDay

protected void checkEndOfDay()

close

public void close()
Close the market.

Specified by:
close in interface Market

endDay

protected void endDay()
Terminate the current trading period (day)


getRemainingTime

public int getRemainingTime()
Return the time remaining before the market closes.

Specified by:
getRemainingTime in interface Market

getLengthOfDay

public int getLengthOfDay()
Return the duration in ticks of a single trading day.

Returns:

setLengthOfDay

public void setLengthOfDay(int lengthOfDay)
Configure the maximum duration of a trading day in ticks.

Parameters:
lengthOfDay -

getMaximumDays

public int getMaximumDays()
Return the maximum number of trading days in the simulation.

Returns:

setMaximumRounds

public void setMaximumRounds(int maximumRounds)
Configure the absolute duration of the entire simulation in ticks.

Parameters:
maximumRounds -

getMaximumRounds

public int getMaximumRounds()
Get the absolute duration of the entire simulation in ticks.

Returns:

setMaximumDays

public void setMaximumDays(int maximumDays)
Configure the maximum number of days in the simulation.

Parameters:
maximumDays -

getTimingCondition

protected TimingCondition getTimingCondition(TimingCondition cond,
                                             java.lang.Class conditionClass)

getAuctionClosingCondition

public TimingCondition getAuctionClosingCondition(java.lang.Class conditionClass)

getDayEndingCondition

public TimingCondition getDayEndingCondition(java.lang.Class conditionClass)

setAuctionClosingCondition

public void setAuctionClosingCondition(TimingCondition cond)

setDayEndingCondition

public void setDayEndingCondition(TimingCondition cond)

getSimulationTime

public SimulationTime getSimulationTime()

clear

public void clear(Order ask,
                  Order bid,
                  double transactionPrice)
Match a buy order with a sell order at the specified price and inform both parties of the resulting transaction.

Specified by:
clear in interface Market
Parameters:
transactionPrice - The price of the transaction.

clear

public void clear(Order ask,
                  Order bid,
                  double buyerCharge,
                  double sellerPayment,
                  int quantity)
Match a buy order with a sell order and inform both parties of the resulting transaction. The buyer and seller transact at different prifces specified by the corresponding parameters.

Specified by:
clear in interface Market
Parameters:
buyerCharge - The price that the buyer must pay.
sellerPayment - The price that the seller must pay.
quantity - The volume of the transaction.
ask - The sell order involved in the transaction
bid - The buy order involved in the transaction.

orderAccepted

public boolean orderAccepted(Order shout)
                      throws ShoutsNotVisibleException
Determines whether or not the given shout was matched in the current round of trading.

Specified by:
orderAccepted in interface Market
Throws:
ShoutsNotVisibleException

transactionsOccurred

public boolean transactionsOccurred()
                             throws ShoutsNotVisibleException
Determines whether or not any transactions have occured in the current round of trading.

Specified by:
transactionsOccurred in interface Market
Throws:
ShoutsNotVisibleException

remove

public void remove(TradingAgent trader)
Remove a trader from the market.


getNumberOfTraders

public int getNumberOfTraders()
Return the number of traders currently active in the market.

Specified by:
getNumberOfTraders in interface Market

getNumberOfRegisteredTraders

public int getNumberOfRegisteredTraders()
Return the total number of traders registered in the market.


activate

protected void activate(TradingAgent agent)

getTraders

public Population getTraders()

setAuctioneer

public void setAuctioneer(Auctioneer auctioneer)
Configure the Auctioneer for this market. The auctioneer is responsible for matching orders and clearing the market.

Parameters:
auctioneer -

closed

public boolean closed()
Description copied from interface: Market
Returns true if the market is closed.

Specified by:
closed in interface Market

getLastOrder

public Order getLastOrder()
                   throws ShoutsNotVisibleException
Description copied from interface: Market
Return the most recent order placed in the market.

Specified by:
getLastOrder in interface Market
Throws:
ShoutsNotVisibleException

getQuote

public MarketQuote getQuote()
Specified by:
getQuote in interface QuoteProvider

removeOrder

public void removeOrder(Order shout)
Description copied from interface: Market
Remove an order from the market.

Specified by:
removeOrder in interface Market

placeOrder

public void placeOrder(Order order)
                throws AuctionException
Submit a new order to the market.

Specified by:
placeOrder in interface Market
Parameters:
shout - The new shout in the market.
Throws:
AuctionException

printState

public void printState()
Description copied from interface: Market
Report the state of the market.

Specified by:
printState in interface Market

register

public void register(TradingAgent trader)

getTraderIterator

public java.util.Iterator<Agent> getTraderIterator()
Specified by:
getTraderIterator in interface Market

getLastTransactionPrice

public double getLastTransactionPrice()
Description copied from interface: Market
Return the price of the most transaction that occurred in the market.

Specified by:
getLastTransactionPrice in interface Market
Returns:

setLastTransactionPrice

public void setLastTransactionPrice(double lastTransactionPrice)

getCurrentPrice

public double getCurrentPrice()
Description copied from interface: Market
Return the current price. This is typically a mid-price or a recent transaction price.

Specified by:
getCurrentPrice in interface Market

remove

public void remove(AbstractTradingAgent abstractTradingAgent)
Specified by:
remove in interface Market

getInitialPrice

public double getInitialPrice()

setInitialPrice

public void setInitialPrice(double initialPrice)
Set the price which will be used at the opening of the market.

Parameters:
initialPrice - The initial price.

terminate

public void terminate()