Constructor
new Simulation(config)
Create Simulation with given configuration
Parameters:
Name | Type | Description | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
config |
Object |
Properties
|
Classes
Members
caseid :number
caseid to report as first column of each log
Type:
- number
period :number
current period number when running simulation
Type:
- number
periodTradePrices :Array.<number>
trade prices for current period
Type:
- Array.<number>
Methods
(private) getMaximumPossibleGainsFromTrade()
Calculate simple maxGainsFromTrade() from simulation configuration buyerValues and sellerCosts
by sorting buyers' units high value first, and sellers' costs low value first, and adding profitable pairs
Slice and sort first to be robust against values/costs being unsorted.
This is currently used only for logging purposes. No market or agent behavior should typically depend on this function.
(private) initAgents()
Initialize agents in simulation
called by constructor
(private) initLogs()
initialize simulation data logging.
called automatically by constructor
(private) initMarket()
Initalize single market for trading X in Simulation
called by constructor
(private) logOrder()
called to log each compliant order
(private) logPeriod()
Perform end-of-period simulation logging of profits, open/high/low/close trade prices, etc.
called automatically
(private) logTrade()
called to log each trade in simulation
(private) newBuyerAgent(i, common)
Create a new Buyer agent for the simulation
called by initAgents() for each buyer
Parameters:
Name | Type | Description |
---|---|---|
i |
number | counter for agents 0,1,2,... |
common |
Object | Settings to send to agent constructor |
(private) newSellerAgent(i, common)
Create a new Seller agent for the simulation
called by initAgents() for each seller
Parameters:
Name | Type | Description |
---|---|---|
i |
number | counter for agents 0,1,2,... |
common |
Object | Settings to send to agent constructor |
potentialEndOfPeriod() → {Object}
calculate potentialEndOfPeriod and reason
Returns:
{endTime,reason} endTime(number) and reason(string) for end of period
- Type
- Object
run(optionsopt) → {Promise.<Object, Error>}
run simulation
Parameters:
Name | Type | Attributes | Description | |||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
Object |
<optional> |
Properties
|
Returns:
resolves to simulation object
- Type
- Promise.<Object, Error>
runPeriod(sync) → {Promise.<Object, Error>}
runs a periods of the simulation
Parameters:
Name | Type | Description |
---|---|---|
sync |
boolean | true indicates call is synchronous, return value will be simulation object; false indicates async, return value is Promise |
Returns:
Resolves to simulation object when one period of simulation is complete.
- Type
- Promise.<Object, Error>
(private) teachAgent(A)
teach an agent tasks such as how to send buy and sell orders to market, how to find "Juicy" price for KaplanSniperAgent, etc.
called for each agent in newBuyerAgent() or newSellerAgent()
Parameters:
Name | Type | Description |
---|---|---|
A |
Object | a new agent that needs to learn the task methods |