I have a dataframe of the following type:
dummy1 ret
Date Index
1998-01-01 AAPL US 0.0 0.000
AEX 0.0 0.000
AMZN US 0.0 0.000
AS51 0.0 0.000
AS51 1Y 100 VOL BVOL 0.0 NaN
... ...
2016-12-29 W A Comdty 0.0 NaN
WIV 0.0 0.007
WZ1 Comdty 0.0 0.005
XLE US 0.0 -0.002
ZARUSD Curncy 0.0 0.018
The variable dummy1 is 1 on specific dates which are not always the same for the various identifiers contained in the Index
layer of the Multiindex, and zero otherwise. My goal is to create a new dummy variable (or indicator variable) say dummy2 which is 1 on the previous business day when dummy1 is equal to 1. So, dummy2 must equal 1 the day before dummy1 equals 1. How can I do it? If I had to extract the list of dates in which dummy1 is equal to 1, using pd.offest.BusinessDays(n=1)
could be an idea but my concern is that then I would lose track of the index of the dataframe, which is crucial because, as mentioned above, dummy1 is 1 not at the same time (i.e. date) for different values of Index
.