Inherits From:
Declared In:

Class Description

The World is a class that is mainly used to serve the information needs of BFagents. The WOrld takes price data and converts it into a number of trends, averages, and so forth.

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.

Symbolic Constants




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.




Macro: Number of moving averages




Macro: The longest allowed Moving Average

Instance Variables

double intrate;
double dividendscale;
int pupdown[UPDOWNLOOKBACK];
int dupdown[UPDOWNLOOKBACK];
int history_top;
int updown_top;
double price;
double oldprice;
double dividend;
double olddividend;
double saveddividend;
double savedprice;
double riskNeutral;
double profitperunit;
double returnratio;
int malength[NMAS];
int nworldbits;
int * realworld;
BOOL exponentialMAs;
id priceMA[NMAS];
id divMA[NMAS];
id oldpriceMA[NMAS];
id olddivMA[NMAS];
double * divhistory;
double * pricehistory;

intrateinterest rate
dividendscaleThe baseline dividend that is set by initWithBaseline:
pupdownarray, dimension UPDOWNLOOKBACK
dupdownarray, dimension UPDOWNLOOKBACK
history_topindex value of current input into history arrays
updown_topnumber of time steps to look back to form pupdown and dupdown bits
pricemarket clearning price
oldpriceprevious price
olddividendprevious dividend
saveddividendNo description.
savedpriceNo description.
profitperunitprice - oldprice + dividend
malengthFor 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.
nworldbitsThe number of aspects of the world that are recorded as bits
realworldAn 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)
exponentialMAsIndicator variable, YES if the World is supposed to report back exponentially weighted moving averages
priceMAMovingAverage objects which hold price information. There are NMAS of these, and have various widths for the moving averages
divMAMovingAverage objects which hold dividend moving averages.
oldpriceMAMovingAverage objects which hold lagged price moving averages
olddivMAMovingAverage objects which hold lagged dividend moving averages
divhistorydividend history array, goes back MAXHISTORY points
pricehistoryprice history array

Method Types

+ descriptionOfBit:
+ nameOfBit:
+ bitNumberOf:
- setintrate:
- setExponentialMAs:
- getNumWorldBits
- initWithBaseline:
- setPrice:
- getPrice
- getProfitPerUnit
- setDividend:
- getDividend
- getRiskNeutral
- updateWorld
- getRealWorld:
- pricetrend:

Class Methods


+ (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.

Instance Methods


- (double)getDividend

Returns the most recent dividend, used by many.


- (int)getNumWorldBits

Returns numworldbits; used by the BFagent.


- (double)getPrice

Returns the price, used by many classes.


- (double)getProfitPerUnit

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.


- (double)getRiskNeutral

Returns the risk neutral price. It is just dividend/intrate.


- initWithBaseline:(double)base

No method description.


- (int)pricetrend:(int)n

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)."


- setDividend:(double)d

Sets the global value of "dividend". All dividend changes should use this method. It checks for illegal changes, as does -setPrice:.


- setExponentialMAs:(BOOL)aBool

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.


- setPrice:(double)p

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.


- setintrate:(double)rate

Interest rate set in ASMModelSwarm.


- updateWorld

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.

Version 1.1 Copyright ©2001. All Rights Reserved.