Public API

ABMPredictionMarkets.AMMOrderType
AMMOrder <: AbstractOrder

An object representing a bid, ask, or share.

Fields

  • id::Int: agent id
  • option_id: option id
  • cost::Float64: total cost of order
  • n_shares: the number of shares in the order

Constructors

AMMOrder(id, option, cost, n_shares)

AMMOrder(; id, option, cost, n_shares)
source
ABMPredictionMarkets.CDAType
CDA <: AbstractCDA

Holds data and order book for a continuous double auction prediction market simulation.

Fields

  • order_books::Vector{Vector{Order}}: outstanding orders (bids and asks). Each sub-vector corresponds to a different market
  • market_prices::Vector{Vector{Float64}}: the market price in dollars after each interaction. The market price stays the same if a transaction does not occur. Each sub-vector corresponds to a different market
  • trade_volume::Vector{Vector{Int}}: each elements represents the number of trades made per step
  • iteration_ids::Vector{Vector{Int}}`: iteration number on which market prices are recorded
  • times::Vector{Int} = Int[]: times at which specific events may occur

Constructors

CDA(; order_book)
source
ABMPredictionMarkets.CPMMType
CPMM <: AbstractCPMM

Holds reserves and data for a constant product market maker prediction market simulation.

Fields

  • yes_reserves::Vector{Float64}: reserves for "yes" shares. Each element corresponds to a different market
  • no_reserves::Vector{Float64}: reserves for "no" shares. Each element corresponds to a different market
  • market_prices::Vector{Vector{Float64}}: the market price in dollars after each interaction. The market price stays the same if a transaction does not occur. Each sub-vector corresponds to a different market
  • trade_volume::Vector{Vector{Int}}: each elements represents the number of trades made per step
  • iteration_ids::Vector{Vector{Int}}`: iteration number on which market prices are recorded
  • times::Vector{Int} = Int[]: times at which specific events may occur

Constructors

CPMM(; yes_reserves, no_reserves, times = Int[])
source
ABMPredictionMarkets.DiscreteDirichletType
DiscreteDirichlet{T} <: ContinuousMultivariateDistribution

A discrete version of Dirchlet distribution which sums to 100.

Fields

  • μ::Vector{T}: mean probabilities which sum to 1
  • η::T: a scalar multiple of μ inversely related to variance.
source
ABMPredictionMarkets.LSRType
LSR <: AbstractLSR

An automated market maker using the logarithmic scoring rule.

Fields

  • elasticity: elasticity parameter where higher values correspond to less elasticity
  • n_shares::Vector{Vector{Int}}: each sub-vector corresponds to the number of shares for each option in a given market
  • market_prices::Vector{Vector{Vector{Float64}}}: the market price in dollars after each interaction. The market price stays the same if a transaction does not occur. Each sub-vector corresponds to a different market at a different iteration.
  • n_decimals::Int: decimal places for rounding in favor of the automated market maker
  • trade_volume::Vector{Vector{Int}}: each elements represents the number of trades made per step
  • iteration_ids::Vector{Vector{Int}}`: iteration number on which market prices are recorded
  • times::Vector{Int} = Int[]: times at which specific events may occur

Constructors

LSR(; elasticity, n_options, info_times)

References

Berg, H., & Proebsting, T. A. (2009). Hanson’s automated market maker. The Journal of Prediction Markets, 3(1), 45-59.

Hanson, R. (2003). Combinatorial information market design. Information Systems Frontiers, 5, 107-119.

source
ABMPredictionMarkets.OrderType
Order <: AbstractOrder

An object representing a bid, ask, or share.

Fields

  • id::Int: agent id
  • yes::Bool: true if represents a yes share
  • price::Int: the price of a single share, price ∈ [0,100]
  • quantity::Int: the number of shares at a given price
  • type::Symbol: object type type ∈ [bid,ask,share]

Constructors

Order(id, yes, price, quantity, type)

Order(; id, yes, price, quantity, type)
source
ABMPredictionMarkets.agent_step!Method
agent_step!(agent, ::MarketAgent, ::AbstractPredictionMarket, model)

The agent submits a new order for a bid or ask in each market. The order is checked against potential sellers (buyers), and an exchange is made if one is found. Otherwise, the order is added to the order book.

Arguments

  • agent: an agent participating in the prediction market
  • ::MarketAgent: variant of agent possibly of the same type as agent
  • ::AbstractPredictionMarket: a prediction market type
  • model: an abm object for the prediction market simulation
source
ABMPredictionMarkets.compute_trade_volumeMethod
compute_trade_volume(trade_volume, interval_length)

Computes trade volume for a set of time intervals

Arguments

  • trade_volume: indicates number of trades per step
  • interval_length: the length of the interval in which trade volume is computed
source
ABMPredictionMarkets.compute_unpacking_factorMethod
compute_unpacking_factor(model)

Computes the ratio of sum of subevents probabilities to the event probability for a 2×2 partition. Event e is indexed by 1 and subevents e₁ and e₂ are indexed by 2 and 3. Probability theory requires p(e) = p(e₁) + p(e₂).

Arguments

  • model: an abm object for the prediction market simulation
source
ABMPredictionMarkets.summarize_by_iterationMethod
summarize_by_iteration(values, iteration_ids; fun = x -> x[end])

Summarize by iteration using fun

Arguments

  • values: a vector of values after each agent step
  • iteration_ids: a vector containing the indices of iterations for each agent step

Keywords

  • fun = x -> x[end]: a function applied to market prices of each iteration. By default,

the ending price is used.

source

Plotting

ABMPredictionMarkets.plot_depth_chartFunction
plot_depth_chart(order_book::Vector{Order}; kwargs...)

Creates a market depth chart to analyze supply and demand dynamics. The red area on the left represents the reversed cumulative distribution for bids. The blue area on the right represents the cumulative distribution for asks. The mid market price is represented by vertical black line.

Arguments

  • order_book::Vector{Order}: a vector of orders (bids and asks) representing the order book (i.e. outstanding orders)

Keywords

  • config...: optional keyword arguments to the function plot
source
ABMPredictionMarkets.plot_dashboardFunction
plot_dashboard(
    model;
    title = make_title(model.market_prices),
    size = (1200, 1000),
    depth_chart_layout = make_layout(model.market_prices),
    outer_layout = [
        (label = :a, width = :auto, height = 0.70),
        (label = :b, width = :auto, height = 0.30)
    ],
    add_unpacking_factor = false,
    n_days = 1,
    depth_chart_config = (),
    price_chart_config = (),
)

Plots an animated dashboard containing the following:

  1. A depth chart for each market.
  2. Historical price for each market.
  3. Optional unpacking factor based on two market sets.

Arguments

  • model: an abm object for the prediction market simulation

Keywords

  • title: a 1×n vector of labels for each market. By default, each element is eᵢ
  • depth_chart_layout: the layout of the depth charts. By default, the smallest possible 2D grid is used.
  • size = (1200, 1000): size of dashboard animation
  • outer_layout: the layout for the dashboard
  • add_unpacking_factor = false: includes unpacking factor plot if true. If set to true, default layouts will need to be overwritten.
  • n_days = 1: the number of days to simulate the prediction market
  • depth_chart_config = (): optional keyword arguments for the depth charts
  • price_chart_config = (): optional keyword arguments for price charts
source

Internal Functions

ABMPredictionMarkets.add_shares!Method
add_shares!(shares, share)

Adds a share to a vector of shares. A new element is add if the shares do not have an entry with the target price. If an entry with the target price exists, the quantity is added to that entry

Arguments

  • shares: a vector of current shares
  • share: a share to be added to shares
source
ABMPredictionMarkets.askMethod
ask(agent, ::MarketAgent, ::AbstractCDA, model, bidx)

Generates an ask amount according to

v ~ Uniform(p, + 1, p + δ),

where p is the maximum share price.

Arguments

  • agent: an agent participating in the prediction market
  • ::MarketAgent: variant of agent possibly of the same type as agent
  • ::AbstractPredictionMarket: a prediction market type
  • model: an abm object for the prediction market simulation
  • bidx: the index of the current order book
source
ABMPredictionMarkets.ask_bid_match!Method
ask_bid_match!(proposal, model, bidx, i)

For agent i and agent j, let b be the bid amount, a be the ask amount, and e be the event. If bₑᵢ = aₑⱼ, then exchange.

Argument

  • proposal: a proposal bid or ask
  • model: an abm object for the prediction market simulation
  • bidx: the index of the current order book
  • i: the index for the current entry of the order book
source
ABMPredictionMarkets.ask_match!Method
ask_match!(proposal, model, bidx, i)

For agent i and agent j, let a be the ask amount, and e be the event. If aₑᵢ + a¬ₑⱼ = 1, then remove shares and deduct ask amounts for i and j .

Argument

  • proposal: a proposal bid
  • model: an abm object for the prediction market simulation
  • i: the index for the current entry of the order book
source
ABMPredictionMarkets.bidMethod
bid(agent, ::MarketAgent, ::AbstractCDA, model, bidx)

Generates an ask amount according to

v ~ Uniform(p - δ, p - 1),

where p is the agent's subject probability of the event, expressed on a scale ranging from 0 100 (cents). The bid price is subtracted from money and added to the bid reserve to ensure the agent has sufficient funds when making bids in multiple markets.

Arguments

  • agent: an agent participating in the prediction market
  • ::MarketAgent: variant of agent possibly of the same type as agent
  • ::AbstractPredictionMarket: a prediction market type
  • model: an abm object for the prediction market simulation
  • bidx: the index of the current order book
source
ABMPredictionMarkets.bid_match!Method
bid_match!(proposal, model, bidx, i)

For agent i and agent j, let b be the bid amount, and e be the event. If bₑᵢ + b¬ₑⱼ = 1, then create new shares for i and j.

Argument

  • proposal: a proposal bid
  • model: an abm object for the prediction market simulation
  • bidx: the index of the current order book
  • i: the index for the current entry of the order book
source
ABMPredictionMarkets.compute_optimal_purchaseMethod
compute_optimal_purchase(agent, market::CPMM, belief, midx, yes)

Computes the optimal amount of money to spend on shares based on a logarithmic utility function.

Arguments

  • market::AbstractCPMM: an abstract constant product market maker object
  • cost: the total cost of the shares
  • midx: market index
  • yes::Bool: corresponds to a yes share if true; otherwise, corresponds to a no share
source
ABMPredictionMarkets.compute_priceMethod
compute_price(market::AbstractCPMM, midx, yes::Bool)

Returns the current price of the specified share.

Arguments

  • market::AbstractCPMM: an abstract constant product market maker object
  • midx: market index
  • yes::Bool: corresponds to a yes share if true; otherwise, corresponds to a no share
source
ABMPredictionMarkets.compute_returnsMethod
compute_returns(shares, p_true)

Computes the expected return of a vector of shares.

Arguments

  • shares: a vector of shares
  • p_true: the true probability of the event
source
ABMPredictionMarkets.cost_to_priceMethod
cost_to_price(cost, price, elasticity)

Finds the total cost of a transaction to move the current price to a new price.

Arguments

  • cost: the total dollar amount of an exchange of shares
  • price: the current price of a given share
  • elasticity: the elasticity parameter
source
ABMPredictionMarkets.cost_to_sharesMethod
cost_to_shares(market::AbstractCPMM, cost, midx)

Computes the number of shares required to achieve a given cost.

Arguments

  • market::AbstractCPMM: an abstract constant product market maker object
  • cost: the total cost of the shares
  • midx: market index
  • yes::Bool: corresponds to a yes share if true; otherwise, corresponds to a no share
source
ABMPredictionMarkets.cost_to_sharesMethod
cost_to_shares(cost, price, elasticity)

Finds the number of shares that can be purchased at a given total cost.

Arguments

  • cost: the toal dollar amount of an exchange of shares
  • price: the current price of a given share
  • elasticity: the elasticity parameter
source
ABMPredictionMarkets.create_orderMethod
create_order(agent, ::MarketAgent, ::AbstractCDA, model, bidx)

Creates and returns a bid or ask. The function bid is called if the agent has no shares. The function ask is called if the agent has no money. If the agent has money and shares, bid and ask are called with equal probability.

Arguments

  • agent::MarketAgent: an agent participating in the prediction market
  • ::MarketAgent: variant of agent possibly of the same type as agent
  • ::AbstractPredictionMarket: a prediction market type
  • model: an abm object for the prediction market simulation
  • bidx: the index of the current order book
source
ABMPredictionMarkets.get_market_infoMethod
get_market_info(order_book; yes)

Returns the maximum bid and minimum ask in the order book.

Arguments

  • order_book: a vector of outstanding orders

Keywords

  • yes: returns maximum bid and minimum ask for yes orders if true
source
ABMPredictionMarkets.get_reservesMethod
get_reserves(market::AbstractCPMM, midx)

Returns the liquidity reserves for a given market.

Arguments

  • market::AbstractCPMM: an abstract constant product market maker object
  • midx: market index

Returns

  • reserves::Tuple: yes reserves, no reserves
source
ABMPredictionMarkets.price_to_costMethod
price_to_cost(market::AbstractCPMM, target_price, midx, yes::Bool)

Computes the total cost required to achieve a target price.

Arguments

  • market::AbstractCPMM: an abstract constant product market maker object
  • target_price: the desired price after transaction
  • midx: market index
  • yes::Bool: corresponds to a yes share if true; otherwise, corresponds to a no share
source
ABMPredictionMarkets.price_to_costMethod
price_to_cost(target_price, price, elasticity)

Finds the number of shares needed to change to a new price.

Arguments

  • target_price: the new price after purchacing shares
  • price: the current price of a given share
  • elasticity: the elasticity parameter
source
ABMPredictionMarkets.price_to_sharesMethod
price_to_shares(target_price, price, elasticity)

Finds the number of shares needed to change to a new price.

Arguments

  • target_price: the new price after purchacing shares
  • price: the current price of a given share
  • elasticity: the elasticity parameter
source
ABMPredictionMarkets.remove_orders!Method
 remove_orders!(agent::MarketAgent, model, bidx)

Removes orders from the specified order book and transfers funds from the bid reserve to the agent's money fund.

Arguments

  • agent::MarketAgent: an agent participating in the prediction market
  • model: an abm object for the prediction market simulation
  • bidx: the index of the current order book
source
ABMPredictionMarkets.sample_askMethod
sample_ask(p, δ)

Samples an amount to ask.

v ~ Uniform(p, + 1, p + δ),

where p is typically the maximum share price.

Arguments

  • p: is typically the maximum share price. p ∈ [0, 100]
  • δ: the range of noise added to ask price. δ ≥ 1.
source
ABMPredictionMarkets.sample_bidMethod
sample_bid(judgment, δ)

Samples an amount to ask.

v ~ Uniform(judgment, - δ, judgment - 1),

where judgment is the agent's subjective probability.

Arguments

  • judgment: s the agent's subjective probability. judgment ∈ [0, 100]
  • δ: the range of noise added to ask price. δ ≥ 1.
source
ABMPredictionMarkets.set_elasticityMethod
set_elasticity(total_money, n_events, upper_price)

Sets the elasticity parameter to a value such that an upper price is achieved if all money in a market allocated to a given event.

Arguments

  • total_money: total money in a given market across all participants
  • n_events: the number of events that can be purchased in a given market
  • upper_price: the maximum price, achieved if all money is placed on a single event
source
ABMPredictionMarkets.shares_to_costMethod
shares_to_cost(market::AbstractCPMM, n_shares, midx)

Computes the total cost associated with a given number of shares of shares.

Arguments

  • market::AbstractCPMM: an abstract constant product market maker object
  • n_shares: the number of shares
  • midx: market index
  • yes::Bool: corresponds to a yes share if true; otherwise, corresponds to a no share
source
ABMPredictionMarkets.shares_to_costMethod
shares_to_cost(price, n_shares, elasticity)

Finds the cost given a number of shares and current price.

Arguments

  • price: the current price of a given share
  • n_shares: the number of shares purchased
  • elasticity: the elasticity parameter
source
ABMPredictionMarkets.shares_to_priceMethod
shares_to_price(price, n_shares, elasticity)

Finds the new price given a number of shares and current price.

Arguments

  • price: the current price of a given share
  • n_shares: the number of shares purchased
  • elasticity: the elasticity parameter
source
ABMPredictionMarkets.to_betaMethod
to_beta(μ, σ)

Returns α and β parameters of beta distribution corresponding to the desired mean and standard deviation.

Arguments

  • μ: the desired mean of the beta distribution
  • σ: the desired standard deviation of the beta distribution
source
ABMPredictionMarkets.transact!Method
transact!(proposal, ::AbstractCDA, model, bidx)

Attempts to find a possible trade for a submitted proposal (bid or ask). Returns true if the proposal trade was performed. Otherwise, false is returned. If the proposed trade is not completed, the proposal is added to the order book.

Arguments

  • proposal: a proposal bid or ask
  • ::AbstractCDA: a double continuous auction prediction market
  • model: an abm object for the prediction market simulation
  • bidx: the index of the current order book
source
ABMPredictionMarkets.update_reserves!Method
update_reserves!(market::AbstractCPMM, n_shares, cost, midx, yes::Bool)

Updates the reserves given a transaction with a specified number of shares and total cost.

Arguments

  • market::AbstractCPMM: an abstract constant product market maker object
  • n_shares: the number of shares
  • cost: the total cost of the shares
  • midx: market index
  • yes::Bool: corresponds to a yes share if true; otherwise, corresponds to a no share
source