-
Notifications
You must be signed in to change notification settings - Fork 2
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
✨ Add Metrics TimeSeries #90
Conversation
@@ -20,7 +20,7 @@ | |||
@dataclass | |||
class PortfolioAsset: | |||
allocation: float | |||
volatility: float | |||
metrics: dict[str, float] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's a good thing that this PR suggests a change on the backend only, so let's try to make it mergeable by itself, without needing to wait for the frontend changes.
To keep this new backend version compatible with the frontend, we need to keep the volatility
key here. Let's just add metrics
next to it.
@@ -24,4 +24,4 @@ def make_hist_price_series( | |||
(price.value for price in prices), | |||
index=pd.Index((price.timestamp for price in prices), name="timestamp"), | |||
name=f"{token_symbol} historical price", | |||
) | |||
).sort_index() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just for my knowledge, did you notice that the indices were not sorted before introducing this .sort_index()
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, they were sorted in descending order for Prices
.
The biggest consequence being that the std_dev
calculation was incorrect.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here is the summary representation of a given price dataframe before and after the change:
Indeed the std_dev calcuation, albeit being very similar, is not the same. Nevertheless, I guess the volatility calculation stays the same.
This index-sorting fix has fairly wide-ranging consequences. We might need to look into git history to look for when a bug was introduced (think git bisect). A good rule of thumb is thus to always move such a fix to a separate independent commit.
dfa494e
to
bbb002c
Compare
bbb002c
to
3c386ad
Compare
@@ -24,4 +24,4 @@ def make_hist_price_series( | |||
(price.value for price in prices), | |||
index=pd.Index((price.timestamp for price in prices), name="timestamp"), | |||
name=f"{token_symbol} historical price", | |||
) | |||
).sort_index() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here is the summary representation of a given price dataframe before and after the change:
Indeed the std_dev calcuation, albeit being very similar, is not the same. Nevertheless, I guess the volatility calculation stays the same.
This index-sorting fix has fairly wide-ranging consequences. We might need to look into git history to look for when a bug was introduced (think git bisect). A good rule of thumb is thus to always move such a fix to a separate independent commit.
This timeseries will have both `std_dev` and `returns` observations :bug: Validate `returns` and `std_dev` timeseries :bug: Sort the index of price series This fixes an issue where the std_dev ts would be incorrect, since the rolling window calcs are applied on a decending ordered ts. This means that the last seven days would not have std_dev observations, but the first seven would. :rewind: Reintroduce asset property for frontend
3c386ad
to
2f4f7a9
Compare
Summary
Fixes #80
Details
This PR exposes the historical 7-day avg standard deviation and historical returns to the
portfolio
endpoint.The
volatility
property of each asset in this endpoint response will be replaced withmetrics
containing the historical std_dev asvolatility
and returns asreturns
as timeseries.Further Improvements
The graph on the frontend will need to also plot these timeseries on the three timeframes (1-yr, 3-months, 1-month).