Class: Simulation

Simulation(config)

single-market-robot-simulation Simulation

Constructor

new Simulation(config)

Create Simulation with given configuration
Parameters:
Name Type Description
config Object
Properties
Name Type Attributes Default Description
periods number number of periods in this simulation
periodDuration number duration of each period
tradeClock number <optional>
trade clock duration: end period early if a trade does not occur in this time interval
orderClock number <optional>
order clock duration: end period early if a valid (not rejected) buy or sell order does not occur in this time interval
buyerAgentType Array.<string> string array (choose from "ZIAgent","UnitAgent","OneupmanshipAgent","KaplanSniperAgent" or types registered with agentRegister()) giving a rotation of types of agents to use when creating the buyer agents.
sellerAgentType Array.<string> string array (choose from "ZIAgent","UnitAgent","OneupmanshipAgent","KaplanSniperAgent" or types registered with agentRegister()) giving a rotation of types of agents to use when creating the seller agents.
buyerRate Array.<number> <optional>
1.0 poisson arrival rate in wakes/sec for each buyer agent, defaults to 1.0 for all agents
sellerRate Array.<number> <optional>
1.0 poisson arrival rate in wakes/sec for each seller agent, defaults to 1.0 for all agents
buyerValues Array.<number> Numeric array giving aggregate market demand for X. Becomes agents' values for units. Each period a new set of these values is distributed among buyer agents.
sellerCosts Array.<number> Numeric array giving aggregate market supply for X. Becomes agents' costs for units. Each period a new set of these costs is distributed among seller agents.
numberOfBuyers number <optional>
number of buyers; if unprovided, assigns 1 buyer per entry in .buyerValues
numberOfSellers number <optional>
number of sellers; if unprovided, assigns 1 seller per entry in .sellerCosts
xMarket Object configuration options for x Market forwarded to market-example-contingent constructor
integer boolean <optional>
Set true if agent prices should be integers. Sent to agent constructor. Used by some random agents, such as ZIAgent.
ignoreBudgetConstraint boolean <optional>
Set true if agents should ignore their values/costs and pretend they have maximum value or minimum cost. Sent to agent constructors.
keepPreviousOrders boolean <optional>
Set true if agents should not set cancelReplace flag on orders
L number Minimum suggested agent price. Sets .minPrice in agent constructor options
H number Maximum suggested agent price. Sets .maxPrice in agent constructor options
silent boolean <optional>
If true, suppress console.log messages providing total number of agents, etc.
withoutOrderLogs boolean <optional>
If true, suppresses buyorderlog and sellorderlog
Source:

Classes

Simulation

Members

caseid :number

caseid to report as first column of each log
Type:
  • number
Source:

period :number

current period number when running simulation
Type:
  • number
Source:

periodTradePrices :Array.<number>

trade prices for current period
Type:
  • Array.<number>
Source:

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.
Source:

(private) initAgents()

Initialize agents in simulation called by constructor
Source:

(private) initLogs()

initialize simulation data logging. called automatically by constructor
Source:

(private) initMarket()

Initalize single market for trading X in Simulation called by constructor
Source:

(private) logOrder()

called to log each compliant order
Source:

(private) logPeriod()

Perform end-of-period simulation logging of profits, open/high/low/close trade prices, etc. called automatically
Source:

(private) logTrade()

called to log each trade in simulation
Source:

(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
Source:

(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
Source:

potentialEndOfPeriod() → {Object}

calculate potentialEndOfPeriod and reason
Source:
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
Name Type Attributes Default Description
sync boolean <optional>
false true to run synchronously, returns simulation object (not a Promise)
update function <optional>
update Optional end of period function
delay number <optional>
20 delay timeout between periods in ms. Only effective in asynchronous mode.
deadline number <optional>
0 deadline to compare with Date.now() -- If over or equal to deadline, return available data. 0 disables.
Source:
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
Source:
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
Source: