Home Reference Source
public class | source

Simulation

single-market-robot-simulation Simulation

Constructor Summary

Public Constructor
public

constructor(config: Object)

Create Simulation with given configuration

Member Summary

Public Members
public

caseid to report as first column of each log

public

copy of config as passed to constructor

public

current period number when running simulation

public

trade prices for current period

Method Summary

Public Methods
public
public

calculate potentialEndOfPeriod and reason

public

run(options: Object): Promise<Object, Error>

run simulation

public

runs a periods of the simulation

Private Methods
private

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.

private

Initialize agents in simulation called by constructor

private

initialize simulation data logging.

private

Initalize single market for trading X in Simulation called by constructor

private

logOrder(prefix: *, orderArray: *)

called to log each compliant order

private

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

private

logTrade(tradespec: *)

called to log each trade in simulation

private

newBuyerAgent(i: number, common: Object): *

Create a new Buyer agent for the simulation called by initAgents() for each buyer

private

newSellerAgent(i: number, common: Object): *

Create a new Seller agent for the simulation called by initAgents() for each seller

private

teach an agent tasks such as how to send buy and sell orders to market, how to find "Juicy" price for KaplanSniperAgent, etc.

Public Constructors

public constructor(config: Object) source

Create Simulation with given configuration

Params:

NameTypeAttributeDescription
config Object
config.periods number

number of periods in this simulation

config.periodDuration number

duration of each period

config.tradeClock number
  • optional

trade clock duration: end period early if a trade does not occur in this time interval

config.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

config.buyerAgentType 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.

config.sellerAgentType 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.

config.buyerRate number[]
  • optional
  • default: 1.0

poisson arrival rate in wakes/sec for each buyer agent, defaults to 1.0 for all agents

config.sellerRate number[]
  • optional
  • default: 1.0

poisson arrival rate in wakes/sec for each seller agent, defaults to 1.0 for all agents

config.buyerValues 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.

config.sellerCosts 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.

config.numberOfBuyers number
  • optional

number of buyers; if unprovided, assigns 1 buyer per entry in .buyerValues

config.numberOfSellers number
  • optional

number of sellers; if unprovided, assigns 1 seller per entry in .sellerCosts

config.xMarket Object

configuration options for x Market forwarded to market-example-contingent constructor

config.integer boolean
  • optional

Set true if agent prices should be integers. Sent to agent constructor. Used by some random agents, such as ZIAgent.

config.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.

config.keepPreviousOrders boolean
  • optional

Set true if agents should not set cancelReplace flag on orders

config.L number

Minimum suggested agent price. Sets .minPrice in agent constructor options

config.H number

Maximum suggested agent price. Sets .maxPrice in agent constructor options

config.silent boolean
  • optional

If true, suppress console.log messages providing total number of agents, etc.

config.withoutOrderLogs boolean
  • optional

If true, suppresses buyorderlog and sellorderlog

Public Members

public caseid: number source

caseid to report as first column of each log

public config: Object source

copy of config as passed to constructor

public period: number source

current period number when running simulation

public periodTradePrices: number[] source

trade prices for current period

Public Methods

public initProfitLogHeader() source

public potentialEndOfPeriod(): Object source

calculate potentialEndOfPeriod and reason

Return:

Object

{endTime,reason} endTime(number) and reason(string) for end of period

public run(options: Object): Promise<Object, Error> source

run simulation

Params:

NameTypeAttributeDescription
options Object
  • optional
options.sync boolean
  • optional
  • default: false

true to run synchronously, returns simulation object (not a Promise)

options.update function(sim: Object)
  • optional

update Optional end of period function

options.delay number
  • optional
  • default: 20

delay timeout between periods in ms. Only effective in asynchronous mode.

options.deadline number
  • optional
  • default: 0

deadline to compare with Date.now() -- If over deadline, return available data. 0 disables.

Return:

Promise<Object, Error>

resolves to simulation object

public runPeriod(sync: boolean): Promise<Object, Error> source

runs a periods of the simulation

Params:

NameTypeAttributeDescription
sync boolean

true indicates call is synchronous, return value will be simulation object; false indicates async, return value is Promise

Return:

Promise<Object, Error>

Resolves to simulation object when one period of simulation is complete.

Private Methods

private getMaximumPossibleGainsFromTrade(): * source

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.

Return:

*

private initAgents() source

Initialize agents in simulation called by constructor

private initLogs() source

initialize simulation data logging. called automatically by constructor

private initMarket() source

Initalize single market for trading X in Simulation called by constructor

private logOrder(prefix: *, orderArray: *) source

called to log each compliant order

Params:

NameTypeAttributeDescription
prefix *
orderArray *

private logPeriod() source

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

private logTrade(tradespec: *) source

called to log each trade in simulation

Params:

NameTypeAttributeDescription
tradespec *

private newBuyerAgent(i: number, common: Object): * source

Create a new Buyer agent for the simulation called by initAgents() for each buyer

Params:

NameTypeAttributeDescription
i number

counter for agents 0,1,2,...

common Object

Settings to send to agent constructor

Return:

*

private newSellerAgent(i: number, common: Object): * source

Create a new Seller agent for the simulation called by initAgents() for each seller

Params:

NameTypeAttributeDescription
i number

counter for agents 0,1,2,...

common Object

Settings to send to agent constructor

Return:

*

private teachAgent(A: Object) source

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()

Params:

NameTypeAttributeDescription
A Object

a new agent that needs to learn the task methods