# Risk Parity

> Risk Parity is a library of reusable functions and constants for other scripts.

Source: https://algobarsx.com/docs/ex-19-risk-parity-library/

```algobarsx
library "Risk Parity"

const MAX_WEIGHT = 40%

type Asset:
    symbol: symbol
    volatility: number
    weight: percent = 0%

fn inverse_vol_weights(assets: list<Asset>) -> list<percent>:
    total = 0.0
    for a in assets:
        total += 1 / a.volatility
    weights = assets.map(a => (1 / a.volatility) / total * 100%)
    return weights.map(w => min(w, MAX_WEIGHT))

fn lots_for_weight(balance: money, weight: percent, contract_value: money) -> lots:
    return (weight of balance) / contract_value * 1 lot
```
What this script says

Risk Parity is a library of reusable functions and constants for other scripts.

It defines the constant `MAX_WEIGHT` as 40%.

It defines `inverse_vol_weights(assets)`, which returns `list<percent>` and `lots_for_weight(balance, weight, contract_value)`, which returns a size in lots.
