Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(scripts): add workflow for updating the efficient frontier #107

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

kyhoon
Copy link
Contributor

@kyhoon kyhoon commented Oct 19, 2022

adds the entrypoint file and the functions to allow automatic updates of the efficient frontier visualization.
Currently only supports the stablecoin assets, will open another PR to support the other asset pools.

@kyhoon kyhoon requested a review from huggingbot October 19, 2022 00:26
return daily_returns.values, name


def update_returns():
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seems odd this is called update_returns when it really is getting and formatting data.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good point, will change it to get_returns() or process_returns()

MAX_DELAY = 3.0
MAX_RETRIES = 3

while True:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why have this code in a while loop if it just runs once?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah this was a dirty fix for the case when the status code != 200

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could potentially run into an infinite loop if the status code != 200. Probably a good idea to include a max retry count

df = df[start_date:end_date]

# convert to daily returns
daily_returns = (1 + df.apy) ** (1 / 365.2425) - 1
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why 1 / 365.2425 ? Isn't it just ** 365 ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah this is because the returns from defillama are measured in yearly values, so I converted them to daily by taking the 365.2425-th root

packages/scripts/efficient_frontier/main.py Show resolved Hide resolved

def main_chart(returns):
# aggregate to yearly values
T = 365.2425
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dupe line as L66. Probably can abstract into a separate function to be shared

frontier_chart, frontier_data = main_chart(data)

# login to datapane
dp.login(token=os.environ["DATAPANE_TOKEN"])
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Think it's good to login first before parsing the data. Had the script throwing KeyError: 'DATAPANE_TOKEN' after waiting for half an hour

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants