[R-SIG-Finance] adding p&l streams

Josh Ulrich josh.m.ulrich at gmail.com
Mon Feb 9 20:06:08 CET 2009


require(zoo)
combined_pl <- na.locf(combined_pl, na.rm=FALSE)
combined_pl[is.na(combined_pl)] <- 0

HTH,
Josh
--
http://quantemplation.blogspot.com



On Mon, Feb 9, 2009 at 12:52 PM, brian meehan <dbmeehan at frontiernet.net> wrote:
> i have a group of time series of p&ls
>
> BEDH05U05_PL <- xts(yyy[,21], order.by = index(BEDH05U05_C['::2004-03']),
> frequency = NULL )
> BEDH04U04_PL <- xts(zzz[,21], order.by = index(BEDH04U04_C['::2003-03']),
> frequency = NULL )
>
> the p&ls are for only partially overlapping times...
>
>> tail(BEDH05U05_PL )
>
>           [,1]
> 2003-03-24 83.50
> 2003-03-25 83.50
> 2003-03-26 75.25
> 2003-03-27 75.25
> 2003-03-28 82.25
> 2003-03-31 82.25
>>
>> tail(BEDH04U04_PL )
>
>           [,1]
> 2004-03-24 56.25
> 2004-03-25 56.25
> 2004-03-26 55.50
> 2004-03-29 55.50
> 2004-03-30 54.25
> 2004-03-31 54.25
>
> i can combine the time series into a larger time series using
>
> combined_pl <- merge (BEDH05U05_PL, BEDH04U04_PL )
>
> i am trying to then add these two columns into a cumulative p&l. i tried
> using combined_pl [is.na(combined_pl )] <- 0  to remove the NA values but
> this doesnt solve the problem since when i hit the last p&l value in
> BEDH05U05_PL the remaining values are set to 0 since they are NA. is there a
> way to set all NA values until the first numerical value to 0 and then all
> NA values after the last numerical value to the last p&l? i wasnt able to
> find a fill forward type of function.
>
> thanks  - brian
>
> _______________________________________________
> R-SIG-Finance at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-sig-finance
> -- Subscriber-posting only.
> -- If you want to post, subscribe first.
>



More information about the R-SIG-Finance mailing list