I have created the follwing dictionary:
for k, er in dicio.items():
#dicio[k]['Return %'] = er.iloc[:, 0].pct_change(-1)*100
dicio[k]['Day'] = er.index.day
dicio
{'WDOFUT': WDOFUT Day
Data
2020-09-11 5325.0 11
2020-09-10 5325.0 10
2020-09-09 5312.5 9
2020-09-08 5366.0 8
2020-09-04 5303.0 4
... ... ...
1994-07-08 NaN 8
1994-07-07 NaN 7
1994-07-06 NaN 6
1994-07-05 NaN 5
1994-07-04 NaN 4
[6482 rows x 2 columns],
'WEGE3': WEGE3 Day
Data
2020-09-11 62.42 11
2020-09-10 62.42 10
2020-09-09 64.93 9
2020-09-08 63.00 8
2020-09-04 64.49 4
... ... ...
1994-07-08 NaN 8
1994-07-07 NaN 7
1994-07-06 NaN 6
1994-07-05 NaN 5
1994-07-04 NaN 4
[6482 rows x 2 columns],
'YDUQ3': YDUQ3 Day
Data
2020-09-11 27.31 11
2020-09-10 27.31 10
2020-09-09 27.99 9
2020-09-08 28.75 8
2020-09-04 27.78 4
... ... ...
1994-07-08 NaN 8
1994-07-07 NaN 7
1994-07-06 NaN 6
1994-07-05 NaN 5
1994-07-04 NaN 4
[6482 rows x 2 columns]}
I can group by day, but it is only taking the last item of the dictionary (YDUQ3):
grouped_by_day = dicio[k].groupby('Day')
grouped_by_day.describe()
YDUQ3
count mean std min 25% 50% 75% max
Day
1 86.0 13.974651 9.391865 2.96 5.4450 11.770 21.2000 39.75
2 95.0 15.022842 10.624683 2.57 5.6900 13.290 21.4050 49.19
3 102.0 15.262549 11.061839 2.44 5.8950 12.800 21.8575 53.85
................................................
29 96.0 14.498229 10.321219 2.61 5.4150 12.975 21.0425 50.88
30 92.0 14.914674 10.701043 2.61 5.5125 13.120 21.7150 51.32
31 51.0 15.339608 10.676544 2.96 6.1350 13.420 21.7150 51.73
I can see the daily-grouped dictionary displayed below, but only for the last item (I need all):
list(grouped_by_day)
[(1,
YDUQ3 Day
Data
2020-09-01 27.89 1
2020-07-01 34.41 1
2020-06-01 29.82 1
2020-04-01 21.30 1
2019-11-01 39.75 1
... ... ...
1995-02-01 NaN 1
1994-12-01 NaN 1
1994-11-01 NaN 1
1994-09-01 NaN 1
1994-08-01 NaN 1
[182 rows x 2 columns]),
......................
......................
(31,
YDUQ3 Day
Data
2020-08-31 26.95 31
2020-07-31 33.89 31
2020-03-31 21.76 31
2020-01-31 51.73 31
2019-10-31 38.52 31
... ... ...
1995-05-31 NaN 31
1995-03-31 NaN 31
1995-01-31 NaN 31
1994-10-31 NaN 31
1994-08-31 NaN 31
[113 rows x 2 columns])]
Question:
How can I get the 3 items of the dictionary displayed? (dicio[k] is taking only one key (last one))
I would like to add up Return % for all same days together.
If 10 year span there will be ~120 days 01, ~120 days 02 and so on.
Each symbol will have a 31 x ~120 dictionary where we can select the highest day of cumulative return and the lowest day of cumulative return.
Then I would like to display the entire portfolio of stocks highest/lowest returns and their days of occurrence.