-
Notifications
You must be signed in to change notification settings - Fork 35
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
Vkhomyakov (Sourcery refactored) #70
Conversation
row.update({ti: value}) | ||
row[ti] = value | ||
row.update(period=None, property="Inception date") | ||
if hasattr(self, "inflation"): | ||
row.update({self.inflation: self.inflation_first_date.strftime("%Y-%m")}) | ||
row[self.inflation] = self.inflation_first_date.strftime("%Y-%m") | ||
description = pd.concat([description, pd.DataFrame(row, index=[0])], ignore_index=True) | ||
# last asset date | ||
row = {} | ||
for ti in self.symbols: | ||
# short_ticker = ti.split(".", 1)[0] | ||
value = self.assets_last_dates[ti].strftime("%Y-%m") | ||
row.update({ti: value}) | ||
row[ti] = value | ||
row.update(period=None, property="Last asset date") | ||
if hasattr(self, "inflation"): | ||
row.update({self.inflation: self.inflation_last_date.strftime("%Y-%m")}) | ||
row[self.inflation] = self.inflation_last_date.strftime("%Y-%m") |
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.
Function AssetList.describe
refactored with the following changes:
- Add single value to dictionary directly rather than using update() [×4] (
simplify-dictionary-update
)
if rolling_window: | ||
rolling_cagr = helpers.Frame.get_rolling_fn( | ||
self.assets_ror, | ||
window=rolling_window, | ||
fn=helpers.Frame.get_cagr, | ||
window_below_year=False, # small windows below 12 months are not allowed (CAGR is not defined) | ||
) | ||
return rolling_cagr.subtract(rolling_cagr.iloc[:, 0], axis=0).iloc[:, 1:] | ||
else: | ||
if not rolling_window: | ||
return helpers.Index.tracking_difference_annualized(self.tracking_difference()) | ||
rolling_cagr = helpers.Frame.get_rolling_fn( | ||
self.assets_ror, | ||
window=rolling_window, | ||
fn=helpers.Frame.get_cagr, | ||
window_below_year=False, # small windows below 12 months are not allowed (CAGR is not defined) | ||
) | ||
return rolling_cagr.subtract(rolling_cagr.iloc[:, 0], axis=0).iloc[:, 1:] |
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.
Function AssetList.tracking_difference_annualized
refactored with the following changes:
- Swap if/else branches (
swap-if-else-branches
) - Remove unnecessary else after guard condition (
remove-unnecessary-else
)
# Max recovery period date should not be in the border (means it's not recovered) | ||
max_period = s2.max() if s2.idxmax().to_timestamp() != self.last_date else np.NAN | ||
return max_period | ||
return s2.max() if s2.idxmax().to_timestamp() != self.last_date else np.NAN |
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.
Function Portfolio.recovery_period
refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable
)
This removes the following comments ( why? ):
# Max recovery period date should not be in the border (means it's not recovered)
elif distr in ["norm", "lognorm"]: | ||
elif distr in {"norm", "lognorm"}: |
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.
Function Portfolio.percentile_inverse_cagr
refactored with the following changes:
- Use set when checking membership of a collection of literals (
collection-into-set
)
returns_dict.update({percentile: percentile_returns_list}) | ||
returns_dict[percentile] = percentile_returns_list |
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.
Function Portfolio.percentile_history_cagr
refactored with the following changes:
- Add single value to dictionary directly rather than using update() (
simplify-dictionary-update
)
results.update({percentile: value}) | ||
results[percentile] = value |
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.
Function Portfolio.percentile_distribution_cagr
refactored with the following changes:
- Add single value to dictionary directly rather than using update() (
simplify-dictionary-update
)
elif distr in ["norm", "lognorm"]: | ||
elif distr in {"norm", "lognorm"}: | ||
results = {} | ||
wealth_indexes = self._monte_carlo_wealth(distr=distr, years=years, n=n) | ||
for percentile in percentiles: | ||
value = wealth_indexes.iloc[-1, :].quantile(percentile / 100) | ||
results.update({percentile: value}) | ||
results[percentile] = value |
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.
Function Portfolio.percentile_wealth
refactored with the following changes:
- Use set when checking membership of a collection of literals (
collection-into-set
) - Add single value to dictionary directly rather than using update() (
simplify-dictionary-update
)
Pull Request #69 refactored by Sourcery.
If you're happy with these changes, merge this Pull Request using the Squash and merge strategy.
NOTE: As code is pushed to the original Pull Request, Sourcery will
re-run and update (force-push) this Pull Request with new refactorings as
necessary. If Sourcery finds no refactorings at any point, this Pull Request
will be closed automatically.
See our documentation here.
Run Sourcery locally
Reduce the feedback loop during development by using the Sourcery editor plugin:
Review changes via command line
To manually merge these changes, make sure you're on the
vkhomyakov
branch, then run:Help us improve this pull request!