edu.cuny.cat.stat
Class HistoricalReport

java.lang.Object
  extended by edu.cuny.cat.stat.HistoricalReport
All Implemented Interfaces:
AuctionEventListener, GameReport, edu.cuny.obj.Resetable, edu.cuny.stat.Report<AuctionEvent>, java.io.Serializable, java.util.EventListener

public class HistoricalReport
extends java.lang.Object
implements GameReport, java.io.Serializable, edu.cuny.obj.Resetable

A report that keeps a historical record of the shouts in the market that lead to the last N transactions. This logger is used to keep historical data that is used by various different trading strategies, especially GD.

Since GDStrategy uses this report to compute the number of shouts above or below a certain price, which leads to slow simulation, SortedView and IncreasingQueryAccelerator are introduced to speed up GDStrategy's queries based on the pattern of prices of concern.

Parameters

base .memorysize
int > 0 (5 by default)
(the length of most recent history to be recorded)

Default Base

historical_report

Version:
$Revision: 1.32 $
Author:
Steve Phelps
See Also:
GDStrategy, Serialized Form

Nested Class Summary
 class HistoricalReport.IncreasingQueryAccelerator
          a class to speed up queries from GDStrategy regarding the number of shouts above or below a certain price.
 class HistoricalReport.ShoutComparator
           
 class HistoricalReport.SortedView
          a class providing sorted lists of shouts.
 
Field Summary
protected  HistoricalReport.IncreasingQueryAccelerator accelerator
          the object that helps to save time in querying about shouts in the history.
protected  java.util.LinkedList<Shout> asks
          asks in the order they arrive.
protected  java.util.LinkedList<Shout> bids
          bids in the order they arrive.
protected  int currentMemoryCell
           
static int DEFAULT_MEMORYSIZE
          the default size of the memory to contain shouts in terms of the number of transactions covered.
protected  double highestBidPrice
           
protected  Shout highestUnmatchedBid
           
protected  boolean isDebugging
          flag used to control whether to do additional debugging.
protected static org.apache.log4j.Logger logger
           
protected  double lowestAskPrice
           
protected  Shout lowestUnmatchedAsk
           
protected  java.util.Set<Shout> matchedShouts
          shouts in the memory that have been matched.
protected  int[] memoryAsks
          records the numbers of asks placed between transactions in the memory, each entry for the interval between two subsequent transactions.
protected  int[] memoryBids
          records the numbers of bids placed between transactions in the memory, each entry for the interval between two subsequent transactions.
protected  int memorySize
          the size of the memory to contain shouts in terms of the number of transactions covered.
protected  java.util.Observable observableProxy
          used to make this report observable so that accelerator can reset.
static java.lang.String P_DEBUG
           
static java.lang.String P_DEF_BASE
           
static java.lang.String P_MEMORYSIZE
           
static java.lang.String P_ROUNDRESET
           
protected  boolean roundReset
          flag used to control whether to clear the record of matched shouts each round
protected  java.util.Map<java.lang.String,Shout> shoutMap
          a mapping from shout IDs to those shouts in the memory.
protected  org.apache.commons.collections15.bag.TreeBag<Shout> sortedShouts
          shouts sorted based on price and id if prices are equal.
protected  java.lang.String traderId
          the ID of the GD trader that uses this report; for debugging purpose only
 
Fields inherited from interface edu.cuny.cat.stat.GameReport
ACCEPTED, ASK, BID, CONVERGENCE_COEFFICIENT, EFFICIENCY, EQUILIBRIUM, FEE, Formatter, GLOBAL, MARKETSHARE, MAX, MEAN, MIN, PLACED, PRICE, PROFIT, PROFIT_DISPERSION, QUANTITY, SCORE, SHOUT, SPECIALIST, STDEV, TOTAL, TRADER, TRANSACTION, TRANSACTIONRATE, VALUE
 
Constructor Summary
HistoricalReport()
           
 
Method Summary
 void addObserver(java.util.Observer o)
           
protected  void addToSortedShouts(Shout shout)
           
 void checkConsistency()
           
 void deleteObserver(java.util.Observer o)
           
 void disableIncreasingQueryAccelerator()
           
 void eventOccurred(AuctionEvent event)
           
 java.util.List<Shout> getAsks()
           
 java.util.List<Shout> getBids()
           
 double getHighestAcceptedAskPrice()
           
 double getHighestBidPrice()
           
 double getHighestUnacceptedBidPrice()
           
 HistoricalReport.IncreasingQueryAccelerator getIncreasingQueryAccelerator()
           
 double getLowestAcceptedBidPrice()
           
 double getLowestAskPrice()
           
 double getLowestUnacceptedAskPrice()
           
protected  Shout getMappedShout(java.lang.String shoutId)
           
 java.util.Set<Shout> getMatchedShouts()
           
 int getMemorySize()
           
 int getNumberOfAsks(double price, boolean matched)
           
 int getNumberOfBids(double price, boolean matched)
           
 int getNumberOfShouts(java.util.List<Shout> shouts, double price, boolean matched)
           
 org.apache.commons.collections15.bag.TreeBag<Shout> getSortedShouts()
           
 java.util.Map<edu.cuny.stat.ReportVariable,?> getVariables()
           
 void initialize()
           
 boolean isDebugging()
           
protected  boolean isMatched(Shout shout)
           
protected  void markMatchedShout(Shout matched)
           
protected  java.lang.String prettyString(java.util.LinkedList<Shout> shouts, int[] counts)
           
protected  java.lang.String prettyString(java.util.LinkedList<Shout> shouts, int index, int length)
           
protected  java.lang.String prettyString(Shout shout)
           
protected  void printShortState()
          prints out the current state of this report in a concise way.
protected  void printState()
          prints out the current state of this report.
 void produceUserOutput()
           
protected  void removeNShouts(int n, java.util.LinkedList<Shout> shouts)
           
 void reset()
           
protected  void roundClosed(RoundClosedEvent event)
           
 void setDebugging(boolean isDebugging)
           
 void setMemorySize(int memorySize)
           
 void setup(edu.cuny.config.param.ParameterDatabase parameters, edu.cuny.config.param.Parameter base)
           
 java.util.Iterator<Shout> sortedShoutIterator()
           
 java.lang.String toString()
           
protected  void updateShoutLog(ShoutPostedEvent event)
          updates the log of shouts when a shout is posted in the market.
protected  void updateTransPriceLog(TransactionPostedEvent event)
          updates the log of transactions and shouts when a transaction is made in the market.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

logger

protected static org.apache.log4j.Logger logger

P_DEF_BASE

public static final java.lang.String P_DEF_BASE
See Also:
Constant Field Values

P_MEMORYSIZE

public static final java.lang.String P_MEMORYSIZE
See Also:
Constant Field Values

P_ROUNDRESET

public static final java.lang.String P_ROUNDRESET
See Also:
Constant Field Values

P_DEBUG

public static final java.lang.String P_DEBUG
See Also:
Constant Field Values

DEFAULT_MEMORYSIZE

public static final int DEFAULT_MEMORYSIZE
the default size of the memory to contain shouts in terms of the number of transactions covered.

See Also:
Constant Field Values

asks

protected java.util.LinkedList<Shout> asks
asks in the order they arrive.


bids

protected java.util.LinkedList<Shout> bids
bids in the order they arrive.


sortedShouts

protected org.apache.commons.collections15.bag.TreeBag<Shout> sortedShouts
shouts sorted based on price and id if prices are equal.


matchedShouts

protected java.util.Set<Shout> matchedShouts
shouts in the memory that have been matched.


shoutMap

protected java.util.Map<java.lang.String,Shout> shoutMap
a mapping from shout IDs to those shouts in the memory.


memorySize

protected int memorySize
the size of the memory to contain shouts in terms of the number of transactions covered.


currentMemoryCell

protected int currentMemoryCell

memoryBids

protected int[] memoryBids
records the numbers of bids placed between transactions in the memory, each entry for the interval between two subsequent transactions.


memoryAsks

protected int[] memoryAsks
records the numbers of asks placed between transactions in the memory, each entry for the interval between two subsequent transactions.


lowestAskPrice

protected double lowestAskPrice

highestBidPrice

protected double highestBidPrice

highestUnmatchedBid

protected Shout highestUnmatchedBid

lowestUnmatchedAsk

protected Shout lowestUnmatchedAsk

accelerator

protected HistoricalReport.IncreasingQueryAccelerator accelerator
the object that helps to save time in querying about shouts in the history.


observableProxy

protected java.util.Observable observableProxy
used to make this report observable so that accelerator can reset.


roundReset

protected boolean roundReset
flag used to control whether to clear the record of matched shouts each round


isDebugging

protected boolean isDebugging
flag used to control whether to do additional debugging.


traderId

protected java.lang.String traderId
the ID of the GD trader that uses this report; for debugging purpose only

Constructor Detail

HistoricalReport

public HistoricalReport()
Method Detail

addObserver

public void addObserver(java.util.Observer o)

deleteObserver

public void deleteObserver(java.util.Observer o)

setup

public void setup(edu.cuny.config.param.ParameterDatabase parameters,
                  edu.cuny.config.param.Parameter base)

initialize

public void initialize()

reset

public void reset()
Specified by:
reset in interface edu.cuny.obj.Resetable

setMemorySize

public void setMemorySize(int memorySize)

getMemorySize

public int getMemorySize()

isDebugging

public boolean isDebugging()

setDebugging

public void setDebugging(boolean isDebugging)

checkConsistency

public void checkConsistency()

removeNShouts

protected void removeNShouts(int n,
                             java.util.LinkedList<Shout> shouts)

markMatchedShout

protected void markMatchedShout(Shout matched)

prettyString

protected java.lang.String prettyString(java.util.LinkedList<Shout> shouts,
                                        int index,
                                        int length)
Parameters:
shouts -
index -
length -
Returns:
a string that prints out the specified shouts in the list in a pretty way.

prettyString

protected java.lang.String prettyString(java.util.LinkedList<Shout> shouts,
                                        int[] counts)
Parameters:
shouts -
counts -
Returns:
a string that prints out the shouts in the list and grouped according to the counts array in a pretty way.

prettyString

protected java.lang.String prettyString(Shout shout)
Parameters:
shout -
Returns:
a string that prints out the shout info in a pretty way.

printState

protected void printState()
prints out the current state of this report.


printShortState

protected void printShortState()
prints out the current state of this report in a concise way.


updateTransPriceLog

protected void updateTransPriceLog(TransactionPostedEvent event)
updates the log of transactions and shouts when a transaction is made in the market.

Parameters:
event -

updateShoutLog

protected void updateShoutLog(ShoutPostedEvent event)
updates the log of shouts when a shout is posted in the market.

Parameters:
event -

roundClosed

protected void roundClosed(RoundClosedEvent event)

getMappedShout

protected Shout getMappedShout(java.lang.String shoutId)

isMatched

protected boolean isMatched(Shout shout)

addToSortedShouts

protected void addToSortedShouts(Shout shout)

eventOccurred

public void eventOccurred(AuctionEvent event)
Specified by:
eventOccurred in interface AuctionEventListener

getHighestBidPrice

public double getHighestBidPrice()

getLowestAskPrice

public double getLowestAskPrice()

getHighestUnacceptedBidPrice

public double getHighestUnacceptedBidPrice()

getLowestAcceptedBidPrice

public double getLowestAcceptedBidPrice()

getLowestUnacceptedAskPrice

public double getLowestUnacceptedAskPrice()

getHighestAcceptedAskPrice

public double getHighestAcceptedAskPrice()

getBids

public java.util.List<Shout> getBids()

getAsks

public java.util.List<Shout> getAsks()

getMatchedShouts

public java.util.Set<Shout> getMatchedShouts()

getSortedShouts

public org.apache.commons.collections15.bag.TreeBag<Shout> getSortedShouts()

getNumberOfAsks

public int getNumberOfAsks(double price,
                           boolean matched)

getNumberOfBids

public int getNumberOfBids(double price,
                           boolean matched)

sortedShoutIterator

public java.util.Iterator<Shout> sortedShoutIterator()

getNumberOfShouts

public int getNumberOfShouts(java.util.List<Shout> shouts,
                             double price,
                             boolean matched)
Parameters:
shouts - the list of shouts to be considered for the counting
price - the sign of price controls whether higher shouts or lower shouts are needed; if it is positive, higher shouts are counted; otherwise lower shouts.
matched - whether only matched shouts are counted or not
Returns:
the number of shouts that meet the specified condition

produceUserOutput

public void produceUserOutput()
Specified by:
produceUserOutput in interface edu.cuny.stat.Report<AuctionEvent>

getVariables

public java.util.Map<edu.cuny.stat.ReportVariable,?> getVariables()

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

getIncreasingQueryAccelerator

public HistoricalReport.IncreasingQueryAccelerator getIncreasingQueryAccelerator()

disableIncreasingQueryAccelerator

public void disableIncreasingQueryAccelerator()