> For the complete documentation index, see [llms.txt](https://apollox-finance.gitbook.io/apollox-finance/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://apollox-finance.gitbook.io/apollox-finance/welcome/trading-on-v2/mad-perpetual-contracts/madcakeusd/index-details.md).

# Index Details

**APX V2 MADCAKEUSD Index Details**

How does it work?

$$
drift = （\frac{\mathrm{cakeCurrentPrice}}{\mathrm{cakeLastSecondPrice}} - 1）\*3
$$

$$
\sigma = \frac{expected vol}{\sqrt{3600*24*365}}
$$

$$
norm = \text{norminv}\left(Random, 0, 1\right)
$$

$$
S\_{n+1} =S\_{n} \* e^{\left\[\left({drift} - \frac{\sigma^2}{2}\right) \* dt + \sigma \* \sqrt{dt} \* norm\right]}
$$

where:

* Initial Sn=1000 &#x20;
* dt=1
* expected vol：100%(expected vol is the expected time volatility of the MADCAKE)
* the "Random number" is calculated based on the current **CAKE price with 8 decimal places of precision**

```python
import hashlib
from decimal import Decimal

# Assume the current Cakecoin price is 2.56788991
Cakecoin_price = Decimal("2.56788991")

# Calculate the SHA-256 hash of the Cakecoin price
price_hash = hashlib.sha256(str(Cakecoin_price).encode("utf-8")).hexdigest()

# Extract the first 4 hexadecimal digits from the hash
hash_substring = price_hash[:4]

# Convert the hexadecimal string to an integer
hash_integer = int(hash_substring, 16)

# Divide the integer by 65535 (the decimal value of the hexadecimal number FFFF), to get a number between 0 and 1
random_number = hash_integer / 65536

print(random_number)
```

If the random number is counted as 0, MADCAKE price will stay the same
