I am working with pandas and I wish to sample 2 stocks from each trade date and store as part of the dataset the average "Stock_Change" and the average "Vol_Change" for the given day in question. The actual data is much larger spanning years and hundreds of names. My sample will be of 100 names, I just use 2 for the purposes of this question.
Sample data set:
In [7]:
df
Out[7]:
Date Symbol Stock_Change Vol_Change
0 1/1/2008 A -5% 7%
1 1/2/2008 B -6% 17%
2 1/3/2008 C -5% 7%
3 1/4/2008 D 5% 13%
4 1/5/2008 E -3% -10%
5 1/1/2008 A 3% -17%
6 1/2/2008 B 8% 34%
7 1/3/2008 C 3% 17%
8 1/4/2008 D 6% 24%
9 1/5/2008 E 2% 16%
10 1/1/2008 A 2% 5%
11 1/2/2008 B 1% 39%
12 1/3/2008 C 5% -17%
13 1/4/2008 D -1% 37%
14 1/5/2008 E -6% 23%
15 1/1/2008 A 3% 31%
16 1/2/2008 B -7% 16%
17 1/3/2008 C -6% 29%
18 1/4/2008 D 0% 9%
19 1/5/2008 E 0% -2%
20 1/1/2008 A 4% -4%
21 1/2/2008 B -6% 16%
22 1/3/2008 C -8% 7%
23 1/4/2008 D 9% 16%
24 1/5/2008 E 6% 18%
25 1/1/2008 A 0% 22%
26 1/2/2008 B 8% -13%
27 1/3/2008 C 7% 18%
28 1/4/2008 D 3% 32%
29 1/5/2008 E 1% 29%
30 1/1/2008 A -8% -10%
31 1/2/2008 B -9% 23%
32 1/3/2008 C -9% 26%
33 1/4/2008 D 2% -1%
34 1/5/2008 E -5% 11%
35 1/1/2008 A -2% 36%
36 1/2/2008 B 3% 17%
37 1/3/2008 C 0% -5%
38 1/4/2008 D 8% -13%
39 1/5/2008 E 7% 18%
One other point, the samples can not contain the same security more than once (sample without replacement). My guess is that this a good R question but I don't know the last thing about R . .
I have no idea of even how to start this question.
thanks in advance for any help.
Aucun commentaire:
Enregistrer un commentaire