Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save FernandoMartinelli/0c5122a940b02826024cc73773e3524f to your computer and use it in GitHub Desktop.
Save FernandoMartinelli/0c5122a940b02826024cc73773e3524f to your computer and use it in GitHub Desktop.
Preview of RatioFactor for Balancer pools (just add the pool weights to the assetWeights list)
assetWeights = [ [ 0.5, 0.5 ] ]
assetWeights.append([ 0.6, 0.4 ])
assetWeights.append([ 0.75, 0.25 ])
assetWeights.append([ 0.8, 0.2 ])
assetWeights.append([ 0.9, 0.1 ])
assetWeights.append([ 0.98, 0.02 ])
assetWeights.append([ 1.0/3.0, 1.0/3.0, 1.0/3.0 ])
assetWeights.append([ 0.25, 0.25, 0.25, 0.25 ])
assetWeights.append([ 0.2, 0.2, 0.2, 0.2, 0.2 ])
assetWeights.append([ 0.49, 0.49, 0.02 ])
assetWeights.append([ 0.45, 0.45, 0.1 ])
assetWeights.append([ 0.4, 0.4, 0.2 ])
assetWeights.append([ 0.4, 0.3, 0.3 ])
assetWeights.append([ 0, 0.3, 0.3 ])
assetWeights.append([ 0.4, 0.1, 0 ])
assetWeights.append([ 0.2, 0.2, 0, 0.2, 0 ])
assetWeights.append([ 0.9, 0.1 ])
assetWeights.append([ 0.15, 0.15, 0.7 ])
for assetWeight in assetWeights:
ratioFactorSum = 0
pairWeightSum = 0
n = len(assetWeight)
for i in range(0, n):
if assetWeight[i] != 0:
for j in range(i+1, n):
pairWeight = assetWeight[i] * assetWeight[j]
normalizedWeight1 = assetWeight[i] / (assetWeight[i] + assetWeight[j])
normalizedWeight2 = assetWeight[j] / (assetWeight[i] + assetWeight[j])
ratioFactorSum += (4 * normalizedWeight1 * normalizedWeight2) * pairWeight
pairWeightSum += pairWeight
ratioFactor = ratioFactorSum / pairWeightSum
print(str(assetWeight)+ ' => ' + str(round(ratioFactor,4)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment