How to calculate the price of a LP token

Recall that LP tokens, for instance WBNB-CAKE LP tokens, are given to liquidity providers in exchange for the pair of tokens WBNB and CAKE they lock into the pool. How do we calculate the value, or price in dollar, of a WBNB-CAKE LP token? Perhaps counter-intuitively, the answer is not the mean price of WBNB and CAKE.

The price pLPp^{\mathrm{LP}} (in dollars) of a WBNB-CAKE LP token depends on five parameters: the price pWBNBp^{\mathrm{WBNB}} of WBNB, the price pCAKEp^{\mathrm{CAKE}} of CAKE, the quantity xCAKEx^{\mathrm{CAKE}} of CAKE in the pool, the quantity xWBNBx^{\mathrm{WBNB}} of WBNB in the pool, and the total number QQ of WBNB-CAKE LP tokens representing the pool.

The WBNB-CAKE LP tokens represent equal shares of the pool. So from the total value inside the pool we deduce the price of each WBNB-CAKE LP token:

pLP=pWBNB×xWBNB+pCAKE×xCAKEQp^{\mathrm{LP}}=\frac{p^{\mathrm{WBNB}}\times x^{\mathrm{WBNB}} + p^{\mathrm{CAKE}} \times x^{\mathrm{CAKE}}}{Q}