# Price Probability Distribution

The following functions can be used for estimating
the future price development from the current trading prices of option
contracts. The result is a distribution of the cumulative price probability
at expiration time. The height of a bar in the image below is the probability
that the underlying price will end up at or below the given price level, in the
implied opinion of option traders.

SPY 2018,
cumulative price probability distribution ## contractCPD (int Days): int

Generates a cumulative probabililty distribution of the current asset price at
the given number of days in the future, and stores it internally. Returns the
number of option contracts used for the distribution. The
contractUpdate function must be called before.
** **
## cpd(var Price): var

Returns the cumulative probability of the given price in **0..100**
range.
The future price will be at or below the given
value with the returned probability in percent. The **contractCPD**
function must be called before.
## cpdv(var Percentile): var

Returns the price at the given percentile of the distribution. F.i. **cpdv(50)**
returns the median of the price distribution, with equal probability of a higher
or lower price. The **contractCPD**
function must be called before.

### Parameters:

**Days** |
Minimum number of calendar days for which the price distribution is
estimated. Determines the expiration date of the used options. |

**Price** |
Underlying asset price to be estimated. |

**Percentile ** |
Probability that the future price is at or below the returned value. |

### Remarks:

- The probability distribution is derived from ask, bid, and strike prices
of all option contracts at the determined expiration date. The algorithm and
usage examples are described on
financial-hacker.com/the-mechanical-turk.
- For comparing price predictions with the current price in the backtest,
make sure to use the unadjusted price. If in doubt, use underlying prices
from the historical options chain by setting
**History = ".t8";**
before selecting the asset.
**contractCPD** loads the prices of all contract with the
given expiration and can be very slow with some brokers (up to 30 minutes
with IB). For speeding up price requests, call **
brokerCommand(SET_PRICETYPE,8);** when supported by the broker.

### Example:

void main()
{
StartDate = 20170101;
BarPeriod = 1440;
PlotScale = 10;
assetList("AssetsIB");
assetHistory("SPY",FROM_STOOQ|UNADJUSTED);
asset("SPY");
Multiplier = 100;
*// load today's contract chain*
contractUpdate(Stock,0,CALL|PUT);
var PriceCurrent = Contracts->fUnl;
printf("\nCurrent price %.2f",PriceCurrent);
*// what's the SPY price in 45 days?*
contractCPD(45);
var Price = 0.;
int i;
for(i = 0; i < 150; i++) {
Price += 0.01*PriceCurrent;
plotBar("CPD",i,Price,cpd(Price),BARS|LBL2,RED);
}
printf(", projected price %.2f",cpdv(50));
}

### See also:

contract, cdf
► latest version online