- Inherits From:
- Declared In:
One instance of this object is created to manage the "world" variables -- the globally-visible variables that reflect the market itself, including the moving averages and the world bits. Everything is based on just two basic variables, price and dividend, which are set only by the -setPrice: and -setDividend: messages.
The World also manages the list of bits, translating between bit names and bit numbers, and providing descriptions of the bits' functions. These are done by class methods because they are needed before the instnce is instantiated.
Description:Macro: Number of up/down movements to store for price and dividend, including the current values. Used for pup, pup1, ... pup[UPDOWNLOOKBACK-1], and similarly for dup[n], and for -pricetrend:. The argument to -pricetrend: must be UPDOWNLOOKBACK or less.
Description:Macro: Number of moving averages
Description:Macro: The longest allowed Moving Average
int * realworld;
double * divhistory;
double * pricehistory;
intrate interest rate dividendscale The baseline dividend that is set by initWithBaseline: pupdown array, dimension UPDOWNLOOKBACK dupdown array, dimension UPDOWNLOOKBACK history_top index value of current input into history arrays updown_top number of time steps to look back to form pupdown and dupdown bits price market clearning price oldprice previous price dividend dividend olddividend previous dividend saveddividend No description. savedprice No description. riskNeutral dividend/intrate profitperunit price - oldprice + dividend returnratio profitperunit/oldprice malength For each MA, we must specify the length over which the average is calculated. This array has one integer for each of the moving averages we plan to keep, and it is used to set the widths covered by the moving averages. nworldbits The number of aspects of the world that are recorded as bits realworld An array (dynamically allocated, sorry) of ints, one for each bit being monitored. This is kept up-to-date. There's a lot of pointer math going on with this and I don't feel so glad about it (PJ: 2001-11-01) exponentialMAs Indicator variable, YES if the World is supposed to report back exponentially weighted moving averages priceMA MovingAverage objects which hold price information. There are NMAS of these, and have various widths for the moving averages divMA MovingAverage objects which hold dividend moving averages. oldpriceMA MovingAverage objects which hold lagged price moving averages olddivMA MovingAverage objects which hold lagged dividend moving averages divhistory dividend history array, goes back MAXHISTORY points pricehistory price history array
- + descriptionOfBit:
- + nameOfBit:
- + bitNumberOf:
- - setintrate:
- - setExponentialMAs:
- - getNumWorldBits
- - initWithBaseline:
- - setPrice:
- - getPrice
- - getProfitPerUnit
- - setDividend:
- - getDividend
- - getRiskNeutral
- - updateWorld
- - getRealWorld:
- - pricetrend:
+ (int)bitNumberOf:(const char *)name
Converts a bit name to a bit number. Supplies the number of a bit given its name. Unknown names return NULLBIT. Relatively slow (linear search). Could be made faster with a hash table etc, but that's not worth it for the intended usage.
+ (const char *)descriptionOfBit:(int)n
Supplies a description of the specified bit, taken from the bitnamelist table below. Also works for NULLBIT.
+ (const char *)nameOfBit:(int)n
Supplies the name of the specified bit, taken from the bitnamelist table below. Also works for NULLBIT. Basically, it converts a bit number to a bit name.
Returns the most recent dividend, used by many.
Returns numworldbits; used by the BFagent.
Returns the price, used by many classes.
Returns profitperunit, used by Specialist.
- getRealWorld:(int *)anArray
Returns the real world array of bits. Used by BFagent to compare their worlds to the real world.
Returns the risk neutral price. It is just dividend/intrate.
No method description.
Returns +1, -1, or 0 according to whether the price has risen monotonically, fallen monotonically, or neither, at the last n updates. Causes an error if nperiods is too large (see UPDOWNLOOKBACK)."
Sets the global value of "dividend". All dividend changes should use this method. It checks for illegal changes, as does -setPrice:.
Turns on the use of exponential MAs in calculations. Can be turned on in GUI or ASMModelSwarm.m. If not, simple averages of the last N periods.
Sets the market price to "p". All price changes (besides trial prices) should use this method. Also computes profitperunit and returnratio. Checks internally for illegal changes of "price", giving us the effective benefit of encapsulation with the simplicity of use of a global variable.
Interest rate set in ASMModelSwarm.
Updates the history records, moving averages, and world bits to reflect the current price and dividend. Note that this is called in each period after a new dividend has been declared but before the bidding and price adjustment. The bits seen by the agents thus do NOT reflect the trial price. The "price" here becomes the "oldprice" by the end of the period. It is called once per period. (This could be done automatically as part of -setDividend:).
The dividend used here is at present the latest value, though it could be argued that it should be the one before, to match price. For the p*r/d bits we do use the old one.