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 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 |
initLogs() 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 |
teachAgent(A: Object) 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:
Name | Type | Attribute | Description |
config | Object | ||
config.periods | number | number of periods in this simulation |
|
config.periodDuration | number | duration of each period |
|
config.tradeClock | number |
|
trade clock duration: end period early if a trade does not occur in this time interval |
config.orderClock | number |
|
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[] |
|
poisson arrival rate in wakes/sec for each buyer agent, defaults to 1.0 for all agents |
config.sellerRate | number[] |
|
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 |
|
number of buyers; if unprovided, assigns 1 buyer per entry in .buyerValues |
config.numberOfSellers | number |
|
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 |
|
Set true if agent prices should be integers. Sent to agent constructor. Used by some random agents, such as ZIAgent. |
config.ignoreBudgetConstraint | boolean |
|
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 |
|
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 |
|
If true, suppress console.log messages providing total number of agents, etc. |
config.withoutOrderLogs | boolean |
|
If true, suppresses buyorderlog and sellorderlog |
Public Members
Public Methods
public initProfitLogHeader() source
public run(options: Object): Promise<Object, Error> source
run simulation
Params:
Name | Type | Attribute | Description |
options | Object |
|
|
options.sync | boolean |
|
true to run synchronously, returns simulation object (not a Promise) |
options.update | function(sim: Object) |
|
update Optional end of period function |
options.delay | number |
|
delay timeout between periods in ms. Only effective in asynchronous mode. |
options.deadline | number |
|
deadline to compare with Date.now() -- If over deadline, return available data. 0 disables. |
public runPeriod(sync: boolean): Promise<Object, Error> source
runs a periods of the simulation
Params:
Name | Type | Attribute | Description |
sync | boolean | true indicates call is synchronous, return value will be simulation object; false indicates async, return value is Promise |
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 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:
Name | Type | Attribute | Description |
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:
Name | Type | Attribute | Description |
tradespec | * |
private newBuyerAgent(i: number, common: Object): * source
Create a new Buyer agent for the simulation called by initAgents() for each buyer
Return:
* |
private newSellerAgent(i: number, common: Object): * source
Create a new Seller agent for the simulation called by initAgents() for each seller
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:
Name | Type | Attribute | Description |
A | Object | a new agent that needs to learn the task methods |