Hello, i would like to form transaction based calendar time portfolios. The portfolios are formed by mimicking daily trades (adding and dropping stocks after certain holding period, e.g. a month).
I have trading data with many buy and sell trades in a day. If i understand it correctly, this is how daily portfolios are constructed:
Day 1 (Jan 1): calculate the average return of stocks bought by investors in the first day.
Day 2 (Jan 2): calculate the average return of stocks bought in day 1&2.
Day 3 (Jan 3): calculate the average return of stocks bought in day 1, 2 & 3.
Day 4 (Jan 4): and so on.
After a month (e.g. Feb 1), all the stocks from day 1 must be dropped, while adding new stocks from today's trade.
On the next day, stocks from Feb 2 are dropped, while adding new ones from this day.
On Feb 3, stocks from Jan 3 are dropped, while adding new ones from this day. and so on;
The results should be like this;
Date | Portfolios | Stocks bought | portfolio return |
Jan-01 | Portfolio day 1 | stock 1, stock 2, stock 3 | average return (stock 1,2&3) |
Jan-02 | Portfolio day 2 | stock 4, stock 5, stock 6 | average return (stock 1,2,3,4,5,&6) |
Jan-03 | Portfolio day 3 | stock 7, stock 8, stock 9 | average return (stock 1,2,3,4,5,6,7,8&9) |
| . | | continue wih the same pattern |
| . | | . |
| . | | . |
After one month (assuming 20 trading days in a month) |
| | | |
Feb-01 | Portfolio day 21 (assuming 20 trading days in a month) | stock 10, stock 11, stock 12 | average return (stock 4,5,6,7,8,9,10,11&12) stocks 1,2,&3 are dropped |
Feb-02 | Portfolio day 22 | stock 13, stock 14, stock 15 | average return (stock 7,8,9,10,11,12,13,14&15) stocks 4,5,&6 are dropped |
Feb-03 | Portfolio day 23 | stock 16, stock 17, stock 18 | average return (stock 10,11,12,13,14,15,16,17,&18) stocks 7,8,&9 are dropped |
| | | and so on |
So far i only know the codes for regular moving average, and do not know how to do it like this.
Any help would be greatly appreciated. Thank you in Advance!