Home Reference Source Test Repository
import {KaplanSniperAgent} from 'market-agents/src/index.js'
public class | source

KaplanSniperAgent

Extends:

events~EventEmitterAgentTrader → KaplanSniperAgent

a reimplementation of a Kaplan Sniper Agent (JavaScript implementation by Paul Brewer)

see e.g. "High Performance Bidding Agents for the Continuous Double Auction" Gerald Tesauro and Rajarshi Das, Institute for Advanced Commerce, IBM

http://researcher.watson.ibm.com/researcher/files/us-kephart/dblauc.pdf

 for discussion of Kaplan's Sniper traders on pp. 4-5

Constructor Summary

Public Constructor
public

constructor(options: Object)

Create KaplanSniperAgent

Method Summary

Public Methods
public

askPrice(marginalCost: number, market: Object): number | undefined

Calculates price this agent is willing to accept.

public

bidPrice(marginalValue: number, market: Object): number | undefined

Calculates price this agent is willing to pay.

Inherited Summary

From class Agent
public

period: *

public

time, in JS ms since epoch, of agent wake

public

ends current period, causing agent to undertake end-of-period tasks such as production and redemption of units

public

init(newSettings: Object)

initialize an agent to new settings

public

initPeriod(period: number | Object)

re-initialize agent to the beginning of a new simulation period

public

percent of period used

public

guess at number of random Poisson wakes remaining in period

public

produces units in negative inventory with configured costs, usually called automatically at end-of-period.

public

redeem()

redeems units in positive inventory with configured values, usually called automatically at end-of-period.

public

transfer(myTransfers: Object, memo: Object)

increases or decreases agent's inventories of one or more goods and/or money

public

unitCostFunction(good: String, hypotheticalInventory: Object): number

agent's marginal cost of producing next unit

public

unitValueFunction(good: String, hypotheticalInventory: Object): number

agent's marginal value for redeeming next unit

public

wake(info: Object)

wakes agent so it can act, emitting wake, and sets next wakeTime from this.nextWake() unless period.endTime exceeded

From class Trader
public abstract

ask(market: Object, myPrice: number)

send a limit order to sell one unit to the indicated market at myPrice.

public abstract

askPrice(marginalCost: number, market: Object): number | undefined

calculate price this agent is willing to accept.

public abstract

bid(market: Object, myPrice: number)

send a limit order to buy one unit to the indicated market at myPrice.

public abstract

bidPrice(marginalValue: number, market: Object): number | undefined

calculate price this agent is willing to pay.

public

For each market in agent's configured markets, calculates agent's price strategy for buy or sell prices and then sends limit orders for 1 unit at those prices.

Public Constructors

public constructor(options: Object) source

Create KaplanSniperAgent

Override:

Trader#constructor

Params:

NameTypeAttributeDescription
options Object
  • optional

options passed to Trader and Agent constructors

options.desiredSpread number
  • optional
  • default: 10

desiredSpread for sniping; agent will accept trade if ||market.currentAskPrice()-market.currentBidPrice()||<=desiredSpread

Public Methods

public askPrice(marginalCost: number, market: Object): number | undefined source

Calculates price this agent is willing to accept. The returned price always equals either undefined or the price of market.currentBid(), triggering an immediate trade.

The KaplanSniperAgent will sell, if marginalCost<=market.currentBidPrice, during one of three conditions: (A) market bid price is greater than or equal to .getJuicyBidPrice(), which needs to be set at the simulation level to the previous period high trade price (B) when spread = (market ask price - market bid price) is less than or equal to agent's desiredSpread (default: 10) (C) when period is ending

Override:

Trader#askPrice

Params:

NameTypeAttributeDescription
marginalCost number

The marginal cost of producing the next unit. Sets the minimum price for trading.

market Object

The market for which an ask is being prepared. An object with currentBidPrice() and currentAskPrice() methods.

Return:

number | undefined

agent's sell price or undefined

public bidPrice(marginalValue: number, market: Object): number | undefined source

Calculates price this agent is willing to pay. The returned price always equals either undefined or the price of market.currentAsk(), triggering an immediate trade.

The KaplanSniperAgent will buy, if market.currentAskPrice<=marginalValue, during one of three conditions: (A) market ask price is less than or equal to .getJuicyAskPrice(), which needs to be set at the simulation level to the previous period low trade price (B) when spread = (market ask price - market bid price) is less than or equal to agent's desiredSpread (default: 10) (C) when period is ending

Override:

Trader#bidPrice

Params:

NameTypeAttributeDescription
marginalValue number

The marginal value of redeeming the next unit. Sets the maximum price for trading.

market Object

The market for which a bid is being prepared. An object with currentBidPrice() and currentAskPrice() methods.

Return:

number | undefined

agent's buy prce or undefined