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

Rebalance and user friendliness updates #7

Merged
merged 6 commits into from
Aug 15, 2020
Merged

Rebalance and user friendliness updates #7

merged 6 commits into from
Aug 15, 2020

Conversation

ojustino
Copy link
Owner

I originally just wanted to provide a way to start certain assets off with a nonzero number of shares, but a combination of learning more about pandas and getting some distance from the last set of commits led me to make the following changes:

  • Users can now specify an initial number of shares for assets through PortfolioMaker instead of being forced to start at 0.
  • Users can specify the index of their desired rebalance date instead of being forced to use the penultimate market day of eligible months.
  • Wrote append_date, a HistoricalSimulator method that allows users to append a day's worth of prices. Since you can't get same-day prices from Tiingo during market hours, this helps with executing real-life rebalances.
  • Switched to pandas.Timestamp-based indexing HistoricalSimulator and all Strategy classes, which should be more intuitive than needing to match indices to dates.
  • Created a new default Strategy class, BuyAndHoldStrategy, for simpler, core-only portfolios.
  • Added a verbose argument to HistoricalSimulator so Strategy class instances can be quieter when needed.

ojustino added 6 commits July 16, 2020 20:24
These changes in simulator.py and portfolio_maker.py help with real life
rebalance use cases by accounting for shares owned before the simulation
period. Made corresponding updates and corrected typo in
HistoricalSimulator.portfolio_value().
HistoricalSimulator() now has a 'target_rb_date' argument for users to
select the index of their preferred rebalance day in relevant months.
HistoricalSimulator._calc_rebalance_info() and its associated methods
have been changed accordingly (and are now more correct than before).
Updated example.ipynb as well.
Again focused on helping real life rebalances,
HistoricalSimulator.append_a_date() allows users to pass a new date and
a dictionary of ticker symbols and new prices that will then be included
in the simulation. Made a notebook to demonstrate the process.
Equipped some new pandas magic now that I'm more familiar with the
package. Crucially, indexing asset dataFrames by date instead of integer
index should make slicing much more intuitive, which should also
simplify the Strategy creation process. Making this switch required many
small/medium changes throughout HistoricalSimulator and the existing
Strategy classes, hence this commit's size.

Highlights include:

- Shifted from using datetime to pandas' Timestamp for date-related
  attributes due to its flexibility and speed.
- Made asset and rebalance-related dataFrames timezone-naive to improve
  ease of indexing.
- Combined HistoricalSimulator's rb_indices and sat_only into one
  date-indexed dataFrame of rebalance information, rb_info.
- Added another abstract method to HistoricalSimulator for refreshing
  Strategy-specific class attributes after running append_date().
Added a simpler class to strategies.py and made an example notebook for
it, rebalance.ipynb. Also updated example.ipynb to incorporate the
previous commit's changes.
@ojustino ojustino merged commit 6f431c7 into master Aug 15, 2020
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.

1 participant