Welcome to the Polkamarkets V2 Documentation!

# Introduction

Before we dive into how outcome prices were programmed to be determined on the Polkamarkets Protocol, you should bear in mind the following facts:
• Whenever you’re trading, you’re effectively buying and selling shares of an outcome at the current price.
• An outcome is always guaranteed a price between 0 and 1 unit in the market’s token (which can be any ERC-20 token).
• The sum of the price of all outcomes is always 1.
• After the market resolves, the winning outcome will have a price value of 1, while the price of all the losing outcomes will be 0.

# The AMM constant formula

Polkamarkets is autonomous and uses an Autonomous Market Making (AMM) algorithm to ensure that trades are covered, similar to how decentralized exchanges like Uniswap work.
The price of each outcome is determined by the distribution of shares in the different pools that compose each market:
• The number of shares in the Liquidity Pool
• The number of shares in the pool of each Outcome
The number of shares in each pool is determined using this all-important constant function:
So, for example, in a market with two outcomes, the function would be:
Whereas in a market with five outcomes, the function would be:
Now let's explore how market prices are calculated at the time of creation, and then when a trade happens.

# Initial outcome price calculation

When a market is created, the Market Creator is required to provide liquidity for the market. This action will fund the Liquidity Pool of the market, and the number of shares in each pool will be determined using the above formula.
👉
For example, Alice creates a market with two outcomes and funds the Liquidity Pool with 1000 USDC. The formula determines that there will be 1000 shares in the Liquidity Pool, 1000 shares in the Outcome A pool, and 1000 shares in the Outcome B pool:
.
 Pool Shares Liquidity 1000 Outcome A 1000 Outcome B 1000
Now that we know the number of shares in each pool, we can determine the price of each outcome to be the proportion of those shares.

## Initial price calculation in a binary outcome market

In a binary outcome market (a market with only two outcomes), the formula used to determine outcome prices is the following:
👉
In our example, when Alice funded the market with 1000 USDC, resulting in there being 1000 shares in each Outcome pool, we get the following initial price for each outcome:

## Initial price calculation in a multiple outcome market

In a market with multiple outcomes, the formula becomes a bit more complex. Before we can calculate the outcome prices, we must first calculate their relative weight.
To calculate the Price Weight for a given outcome, we multiply the number of shares available in the pool of every other outcome.
Once we have the Price Weight of every Outcome, we can determine the price on an outcome.
👉
Example: Charlie created a market with four different outcomes and added 1000 USDC in liquidity. The share pools are calculated using the AMM constant, where
So we have:
 Pool Shares Liquidity 1000 Outcome A 1000 Outcome B 1000 Outcome C 1000 Outcome D 1000
Now that we know the number of shares in each pool, we can calculate the Price Weight for each outcome.
The formula for doing this is:
So we obtain the following Outcome Price Weights:
And now that we know the number the Price Weight for each Outcome, we can calculate the price for each outcome, using the following formula:
This gives us the following outcome prices:

# Price calculation at the time of a trade

When a trade happens, a number of shares of a particular outcome is bought or sold, which means that shares are added or removed from that outcome's pool, and that shares are added to or removed from the prediction market participant's balance.
As the distribution of shares available in the overall pool changes, so changes the price of each outcome.
Let’s take a detailed look at how the prices are impacted when a participant decides to buy shares of an outcome.

## In a binary outcome market

👉
Continuing with our binary outcome example, Bob decides to buy 300 USDC worth of shares of Outcome A in the market created by Alice. Another way to say this is that Bob will add USDC to the market, and get outcome shares in return. So let's determine how many shares of Outcome A Bob will get, and how this trade impacted the outcome prices. First, let's take into account the 2% trading fee that Bob pays to the Liquidity Provider. In fact Bob adds 300 USDC - 2% = 294 USDC to the market, so we add 294 shares to each outcome pool.
Now we temporarily have:
 Pool Shares Outcome A 1294 Outcome B 1294 Liquidity 1000
At this moment, the constant formula is broken, as
. To fix this, we recalculate the amount of shares that should be in the Outcome A pool, as we know exactly how many shares there are in the Outcome B pool, and in the Liquidity Pool.
So we get:
 Pool Shares Outcome B 1294 Liquidity 1000 Outcome A (rounded)
So in fact, Bob purchased the difference between the 1294 total shares of Outcome A that now exist and the 773 shares that remain in the pool. Therefore, Bob bought
shares of Outcome A for his 300 USDC trade (minus 2% paid in fees). And what's the impact of this trade on the price of the outcomes? To complete Bob's trade, the price of each outcome is recalculated. The formula for this is the same that is used when a market is first created:
Which, in the case of Bob's trade, has the following values.
The fact that Bob purchased shares of Outcome A changed the price of the outcomes, effectively increasing the price of Outcome A. The price now represents the sentiment of the market: participants believe that Outcome A is more valuable, therefore more likely to happen, than Outcome B.

## In a multiple outcome market

👉
Continuing with our multiple outcome market example, Dylan decides to buy 300 USDC worth of shares of Outcome A in the multiple outcome market created by Charlie. Another way to say this is that Dylan will add USDC to the market, and get outcome shares in return. So let's determine how many shares of Outcome A Dylan will get, and how this trade impacted the outcome prices. First, let's take into account the 2% trading fee that Dylan pays to the Liquidity Providers. Dylan adds 300 USDC - 2% = 294 USDC to the market, so we add 294 shares to each outcome pool.
Now we temporarily have:
 Pool Shares Liquidity 1000 Outcome A 1294 Outcome B 1294 Outcome C 1294 Outcome D 1294
At this moment, the constant formula is broken, as
. To fix this, we recalculate the amount of shares that should be in the Outcome A pool, as we know exactly how many shares there are in the Outcome B pool, and in the Liquidity Pool.
So we get:
 Pool Shares Liquidity 1000 Outcome A (rounded) Outcome B 1294 Outcome C 1294 Outcome D 1294
Dylan purchased the difference between the 1294 total shares of Outcome A that now exist and the 461.53 shares that remain in the pool. Therefore, Dylan bought
shares of Outcome A for his 300 USDC trade (minus 2% paid in fees). And what's the impact of this trade on the price of the outcomes? To complete Dylan’s trade, the Price Weight of each Outcome is recalculated, and then the price of each outcome.
The formulas for this is the same that is used when a market is first created.
First, the Price Weight for each Outcome is recalculated using the formula:
Which gives us:
 Outcome Outcome Price Weight Outcome A Outcome B Outcome C Outcome D
Then, we can use each Outcome Price Weight to determine the price of each outcome using the formula:
Which, in the case of Dylan’s trade, give us the following values:
 Outcome Outcome Price Outcome A ≈ 0.48 (rounded) Outcome B Outcome C Outcome D
Many thanks to Polkamarkets Discord member NFT_Trader for contributing this example.
{"ft_lang_label":"__label__en","ft_lang_prob":0.9156811,"math_prob":0.96804446,"size":7716,"snap":"2023-40-2023-50","text_gpt3_token_len":1763,"char_repetition_ratio":0.2029305,"word_repetition_ratio":0.31463948,"special_character_ratio":0.22641265,"punctuation_ratio":0.0925314,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.9949863,"pos_list":[0],"im_url_duplicate_count":[null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2023-10-01T22:47:30Z\",\"WARC-Record-ID\":\"<urn:uuid:25cda6f0-6132-4340-b965-54c4cf43c780>\",\"Content-Length\":\"417805\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:81c242a9-a1a0-49d2-b064-b9bf4f60215d>\",\"WARC-Concurrent-To\":\"<urn:uuid:43b03ee0-cf0e-4968-aca6-9307851317c6>\",\"WARC-IP-Address\":\"76.76.21.21\",\"WARC-Target-URI\":\"https://help.polkamarkets.com/how-polkamarkets-works/trading-and-price-calculation\",\"WARC-Payload-Digest\":\"sha1:ORISRYJ7GWKNU76AU6NYL3EQYEOOFUZ6\",\"WARC-Block-Digest\":\"sha1:HMNJYFURUIZC5F2HPUO3C4DBLOGK4NNP\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2023/CC-MAIN-2023-40/CC-MAIN-2023-40_segments_1695233510941.58_warc_CC-MAIN-20231001205332-20231001235332-00245.warc.gz\"}"}