Market¶
- class pams.Market(market_id, prng, simulator, name, logger=None)[source]¶
Market class.
If
transaction_feeis set (seepams.TransactionFee), the market charges transaction fees to the buyer and the seller of each execution and records the net transaction fees that it collects in each time step, whichget_transaction_fee_revenues()andget_transaction_fee_revenue()return, andget_cumulative_transaction_fee_revenue()returns their sum up to a time step. A logger can read them throughlog.marketinpams.logs.Logger.process_market_step_end_log(), and an event can read them throughmarketinpams.events.EventABC.hooked_after_step_for_market(), e.g.,class TransactionFeeRevenueLogger(Logger): def process_market_step_end_log(self, log: MarketStepEndLog) -> None: market = log.market print( market.name, market.get_transaction_fee_revenue(), # in this time step market.get_cumulative_transaction_fee_revenue(), # up to this time step )
See also
pams.index_market.IndexMarket: IndexMarket
- change_fundamental_price(scale)[source]¶
Change fundamental price.
- Parameters:
scale (float) – scale.
- Return type:
None- Returns:
None
- convert_to_price(tick_level)[source]¶
Convert tick to price.
- Parameters:
tick_level (int) – tick level.
- Returns:
price.
- Return type:
float
- convert_to_tick_level(price, is_buy)[source]¶
Convert price to tick level.
If it is buy order price, it is rounded lower. If it is sell order price, it is rounded upper.
- Parameters:
price (float) – price.
is_buy (bool) – buy order or not.
- Returns:
price for tick level.
- Return type:
int
- convert_to_tick_level_rounded_lower(price)[source]¶
Convert price to tick level rounded lower.
- Parameters:
price (float) – price.
- Returns:
price for tick level rounded lower.
- Return type:
int
- convert_to_tick_level_rounded_upper(price)[source]¶
Convert price to tick level rounded upper.
- Parameters:
price (float) – price.
- Returns:
price for tick level rounded upper.
- Return type:
int
- get_best_buy_price()[source]¶
Get the best buy price.
- Returns:
the best buy price.
- Return type:
float, Optional
- get_best_sell_price()[source]¶
Get the best sell price.
- Returns:
the best sell price.
- Return type:
float, Optional
- get_buy_order_book()[source]¶
Get buy order book.
- Returns:
buy order book.
- Return type:
Dict[Optional[float], int]
- get_cumulative_transaction_fee_revenue(time=None)[source]¶
Get the transaction fees collected by this market from time step 0 to a time step.
This is the balance of the transaction fees of this market up to the time step, i.e., the sum of the transaction fee revenues (see
get_transaction_fee_revenues()) from time step 0 totime. Negative fees (rebates) reduce it, so it can be negative. It is 0.0 if the market has no transaction fee.- Parameters:
time (Union[int, None]) – time step.
- Returns:
cumulative transaction fee revenue.
- Return type:
float
- get_executed_total_price(time=None)[source]¶
Get executed total price.
- Parameters:
time (Union[int, None]) – time step.
- Returns:
total price.
- Return type:
float
- get_executed_total_prices(times=None)[source]¶
Get executed total prices.
- Parameters:
times (Union[Iterable[int], None]) – time steps.
- Returns:
total prices.
- Return type:
List[float]
- get_executed_volume(time=None)[source]¶
Get executed volume.
- Parameters:
time (Union[int, None]) – time step.
- Returns:
volume.
- Return type:
int
- get_executed_volumes(times=None)[source]¶
Get executed volumes.
- Parameters:
times (Union[Iterable[int], None]) – time steps.
- Returns:
volumes.
- Return type:
List[int]
- get_fundamental_price(time=None)[source]¶
Get fundamental price.
- Parameters:
time (Union[int, None]) – time step.
- Returns:
fundamental price.
- Return type:
float
- get_fundamental_prices(times=None)[source]¶
Get fundamental prices.
- Parameters:
times (Union[Iterable[int], None]) – time steps.
- Returns:
fundamental prices.
- Return type:
List[float]
- get_last_executed_price(time=None)[source]¶
Get price executed last step.
- Parameters:
time (Union[int, None]) – time step.
- Returns:
price.
- Return type:
float, Optional
- get_last_executed_prices(times=None)[source]¶
Get prices executed last steps.
- Parameters:
times (Union[Iterable[int], None]) – time steps.
- Returns:
prices.
- Return type:
List[Optional[float]]
- get_market_price(time=None)[source]¶
Get market price.
- Parameters:
time (Union[int, None]) – time step.
- Returns:
extracted data.
- Return type:
float
- get_market_prices(times=None)[source]¶
Get market prices.
- Parameters:
times (Union[Iterable[int], None]) – range of time steps.
- Returns:
extracted sequential data.
- Return type:
List[float]
- get_mid_price(time=None)[source]¶
Get middle price.
- Parameters:
time (Union[int, None]) – time step.
- Returns:
middle price.
- Return type:
float, Optional
- get_mid_prices(times=None)[source]¶
Get middle prices.
- Parameters:
times (Union[Iterable[int], None]) – time steps.
- Returns:
middle prices.
- Return type:
List[Optional[float]]
- get_n_buy_order(time=None)[source]¶
Get the number of buy order.
- Parameters:
time (Union[int, None]) – time step.
- Returns:
number of buy order.
- Return type:
int
- get_n_buy_orders(times=None)[source]¶
Get the number of buy orders.
- Parameters:
times (Union[Iterable[int], None]) – time steps.
- Returns:
number of buy orders.
- Return type:
List[int]
- get_n_sell_order(time=None)[source]¶
Get the number of sell order.
- Parameters:
time (Union[int, None]) – time step.
- Returns:
number of sell order.
- Return type:
int
- get_n_sell_orders(times=None)[source]¶
Get the number of sell orders.
- Parameters:
times (Union[Iterable[int], None]) – time steps.
- Returns:
number of sell orders.
- Return type:
List[int]
- get_sell_order_book()[source]¶
Get sell order book.
- Returns:
sell order book.
- Return type:
Dict[Optional[float], int]
- get_transaction_fee_revenue(time=None)[source]¶
Get the transaction fees collected by this market in a time step.
The transaction fee revenue of a time step is the sum of the transaction fees charged to the buyers and the sellers of the executions in that time step. Negative fees (rebates) reduce it, so it can be negative. It is 0.0 if the market has no transaction fee.
- Parameters:
time (Union[int, None]) – time step.
- Returns:
transaction fee revenue.
- Return type:
float
- get_transaction_fee_revenues(times=None)[source]¶
Get the transaction fees collected by this market in each time step.
The transaction fee revenue of a time step is the sum of the transaction fees charged to the buyers and the sellers of the executions in that time step. Negative fees (rebates) reduce it, so it can be negative. It is 0.0 if the market has no transaction fee.
- Parameters:
times (Union[Iterable[int], None]) – time steps.
- Returns:
transaction fee revenues.
- Return type:
List[float]
- get_vwap(time=None)[source]¶
Get VWAP.
- Parameters:
time (int, Optional) – time step.
- Returns:
VWAP.
- Return type:
float
- property is_running: bool¶
Get whether this market is running or not.
- Returns:
whether this market is running or not.
- Return type:
bool
- remain_executable_orders()[source]¶
Check if there are remain executable orders in this market.
When both sides have market orders and their total volumes differ, the excess market orders have to be absorbed by the limit orders of the other side. Otherwise, the execution price cannot be determined and nothing is executed (special quote), even if some orders could be matched.
- Returns:
whether some orders is executable or not.
- Return type:
bool
- setup(settings, *args, **kwargs)[source]¶
Setup market configuration from setting format.
- Parameters:
settings (Dict[str, Any]) – market configuration. Usually, automatically set from json config of simulator. This must include the parameters “tickSize” and either “marketPrice” or “fundamentalPrice”. This can include the parameter “outstandingShares” and “tradeVolume”.
*args – not used.
**kwargs – not used.
- Return type:
None- Returns:
None