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

removing deprecated pd.TimeGrouper and using the .xs multi level indexing versus [] #625

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

Conversation

derekwong9
Copy link

the capacity tearsheet had several errors when following the format of market_data as found in the /pyfolio/tests

dates = pd.date_range(start='2015-01-01', freq='D', periods=3)
positions = pd.DataFrame([[1.0, 3.0, 0.0],
                       [0.0, 1.0, 1.0],
                       [3.0, 0.0, 1.0]],
                      columns=['A', 'B', 'cash'], index=dates)

transactions = pd.DataFrame(data=[[1, 100000, 10, 'A']] * len(dates),
                         columns=['sid', 'amount', 'price', 'symbol'],
                         index=dates)

volume = pd.DataFrame([[1.0, 3.0],
                    [2.0, 2.0],
                    [3.0, 1.0]],
                   columns=['A', 'B'], index=dates)
volume.index.name = 'dt'
volume = volume * 1000000
volume['market_data'] = 'volume'
price = pd.DataFrame([[1.0, 1.0]] * len(dates),
                  columns=['A', 'B'], index=dates)
price.index.name = 'dt'
price['market_data'] = 'price'
market_data = pd.concat([volume, price]).reset_index().set_index(
    ['dt', 'market_data'])

using this example you have a 2 level index whereby you are then calling market data, originally the indexer was ['price'] which was causing errors and non-explicit. using the .xs makes it much clearer and also functional.

pd.TimeGrouper has been deprecated and has been replaced by pd.Grouper, the parameter remains the same of 'D' for pd.Grouper(freq='D')

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.

2 participants