[R-SIG-Finance] merge zoo with many entries per date with lagged self using ticker

Gabor Grothendieck ggrothendieck at gmail.com
Sat Nov 13 22:38:02 CET 2010


On Sat, Nov 13, 2010 at 3:49 PM, richard.c.herron at gmail.com
<richard.c.herron at gmail.com> wrote:
> I have a zoo with monthly entries. For each month there are many entries,
> but only one entry per ticker. To to track the performance of decile
> portfolios I want to merge each entry with future dates of itself (i.e.,
> lag). For example, here's AAPL
>
>> head(temp[which(temp$symbol=="AAPL1C"),])
>       symbol oi          ret           decile
> 200806 AAPL1C  8710943.20 -1.129018e-01 10
> 200807 AAPL1C  7540246.46 -2.437297e-03 10
> 200808 AAPL1C 11366863.59  1.703864e-01 10
> 200809 AAPL1C  9500119.05 -3.689558e-01 10
> 200810 AAPL1C   114082.48 -4.406700e-02  1
> 200811 AAPL1C   723159.24 -1.437163e-01  6
>
> and it's future self
>
>> head(temp.lag[which(temp.lag$symbol=="AAPL1C"),])
>       symbol oi          ret           decile
> 200806 AAPL1C  7540246.46 -2.437297e-03 10
> 200807 AAPL1C 11366863.59  1.703864e-01 10
> 200808 AAPL1C  9500119.05 -3.689558e-01 10
> 200809 AAPL1C   114082.48 -4.406700e-02  1
> 200810 AAPL1C   723159.24 -1.437163e-01  6
> 200811 AAPL1C  1006345.25 -1.005402e-01  8
>
> When I try to merge these two, I get the warning (of course) that I can't
> merge zoos with duplicate dates.
>
> Is there a way to merge on the "symbol" column, too?
>
> I could lag, convert both back to dataframe, join, then go back to zoo. Is
> there a better way?
>

Some clarification would be useful.  What is the output that is desired?

-- 
Statistics & Software Consulting
GKX Group, GKX Associates Inc.
tel: 1-877-GKX-GROUP
email: ggrothendieck at gmail.com



More information about the R-SIG-Finance mailing list