Skip to content

A defined contribution, closed, pension fund in ETH.

Notifications You must be signed in to change notification settings

subvisual/matusalem

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

68 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Matusalem

(futuristic hedge fund trader)

A defined contribution, closed, pension fund in ETH. It allocates funds using a strategy defined by a third-party, using a "Chicken Bonds"-like mechanism, with transparent risk analysis and strategy optimization..

Protocol

Motivation

  • Liquid staking protocols (Lido or Rocket Pool) are comparable to US Treasury bonds (as risk-free assets), enabling us to create a portfolio allocation similar to what pension funds do in the real world;
  • Chicken Bonds introduces a novel bonding mechanism which allows protocols to bootstrap liquidity at minimal cost and provides better user protection than existing bonding alternatives. We thought it might be cool to try to figure out how a mechanism like this could work in the context of a pension fund;
  • Given the latest shenanigans around LDI strategies in UK pension funds, we thought that creating a system with transparent risk analysis and modelling would be very awesome;
  • Users having a say in the governance of their capital allocation can be an interesting experiment;

Overview

ETH flows and Chicken Bond

  • Bond = ERC-721 representing the allocation strategy, minted by Strategist
  • Locked Bucket (fund deposited by Fund)
  • Reserve Bucket (Strategist collateral, yield from Locked Bucket)
  • $vOLD (virtual balance representing a claim of the Reserve Bucket)
  • $OLD (minted token that can claim ETH from Reserve Bucket at a redemption price)

Chicken in, Chicken out, Egg to Maturity outcomes

Screenshot 2022-10-30 at 05 01 06

Asset Analysis

(pandas running on bacalhau)

Obtaining historical prices

To generate a csv file with historical prices on a set of tokens you can run the python script: (we are using the Coingecko API so pay attention to the token id's.)

python prices.py uniswap wrapped-bitcoin maker filecoin aave curve-dao-token nexo the-graph sandclock euler

This will create a csv called prices.csv

Running data analysis on Bacalhau

Running this job on bacalhau will calculate correlation between tokens, standard deviations and average asset returns, while outputing this to a file called final_state.txt. It also generates an image of the correlations (see the example below to check the outputs).

This way it can run the computation for larger datasets, improving cost and efficiency.

docker build -t finiam/matusalem-analysis15 . --platform linux/amd64
docker push finiam/matusalem-analysis15

bacalhau docker run finiam/matusalem-analysis15

# example result that you can check
# bacalhau get 80c51fcb-87b0-4eba-a2d4-e2ca3c0eca82
# bacalhau describe 80c51fcb-87b0-4eba-a2d4-e2ca3c0eca82
# 
# https://ipfs.io/ipfs/QmW9h1vJ7CSvfcYRt1fFJeVmeu63uNAjkBkU78b2ieGjhH/outputs

Genetic Algorithms

Developing the Genetic Algorithms

Most part of the code is inspired in the book: Genetic Algorithms in Elixir by Sean Moriarity check here. It has a bunch of updates in order to adapt to optimizing to asset weights and the fitness function to calculate the Sharpe Ratio.

Running the simulation on Bacalhau

The simulation and calculations for Sharpe Ratio, are quite heavy if we want to run for a big enough population age. This way, we can take advantage of bacalhau. Using bacalhau to run these algorithms also ensures we have a verifiable and transparent strategy definition.

docker build -t finiam/matusalem-genetic2 . --platform linux/amd64
docker push finiam/matusalem-genetic2

bacalhau docker run finiam/matusalem-genetic2

# example result that you can check
# bacalhau get 4db92773-135f-4053-b7a7-292b2dc36c95
# bacalhau describe 4db92773-135f-4053-b7a7-292b2dc36c95

Current Problems

  • We went way over our heads with this project so we struggled to have a deliverable by the end of the event;
  • We are missing a way to trigger the Treasury contract on L1;
  • We couldn't get funds on the new Starknet testnet;
  • We faked the frontend wallet transactions, using sign instead to exemplify the flow.
  • We've just implemented a bare bones approach to the protocol that works for a simplified example;
  • The Genetic Algorithms work as expected and output a good result if we're using the overall expected returns for the portfolio, as the fitness function. However, when using the Sharpe Ratio as the fitness functions, the population doesn't evolve as expected, and it outputs a poor result;

Future Work

  • Add a chicken-bond like mechanism for the user's fund in the L2;
  • Prove that the model makes sense and it's not just a fun experiment;
  • Create a Manager to trigger rebalance functions and periodically trigger the consumption of L2 messages;
  • Generalize the implementation from the implemeted example to the expected protocol behaviour;
  • Actually integrate with the yield generating assets instead of mocks (i.e. Rocket Pool Staking, Euler Finance, Uniswap, etc);