Skip to content

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