Risk Parity

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

functions and types

risk-parity.abx
1library "Risk Parity"
2
3const MAX_WEIGHT = 40%
4
5type Asset:
6symbol: symbol
7volatility: number
8weight: percent = 0%
9
10fn inverse_vol_weights(assets: list<Asset>) -> list<percent>:
11total = 0.0
12for a in assets:
13total += 1 / a.volatility
14weights = assets.map(a => (1 / a.volatility) / total * 100%)
15return weights.map(w => min(w, MAX_WEIGHT))
16
17fn lots_for_weight(balance: money, weight: percent, contract_value: money) -> lots:
18return (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.

Try this in the Terminal. AlgoBars is free: $0 a month, no card needed.

Create my free account