I'm sure I've done this before but for the life of me I can't remember how. I'm working with a tick data series in the following format: / Date Time Type Price Quantity 2010-02-22 9:00:00 BEST_ASK 64.246 1 2010-02-22 9:00:10 TRADE 64.246 100 2010-02-22 9:00:10 BEST_ASK 64.260 1 2010-02-22 9:00:10 BEST_BID 64.232 1 2010-02-22 9:00:10 BEST_ASK 64.260 1 2010-02-22 9:00:10 BEST_BID 64.232 2/ and I'm trying to add columns that give the most recent Bid, Ask, and Trade prices. So far I've done it using a for loop, but that's obviously way too slow. So I ran the following code: /StockA$LastBid = ifelse(StockA$Type=="BEST_BID",StockA$Price, 0) StockA$LastAsk = ifelse(StockA$Type=="BEST_ASK",StockA$Price, 0) StockA$LastTrade = ifelse(StockA$Type=="TRADE",StockA$Price, 0)/ and turned the table into this: / Date Time Type Price Quantity LastBid LastAsk LastTrade 2010-02-22 9:00:00 BEST_ASK 64.246 1 0.000 64.246 0.000 2010-02-22 9:00:10 TRADE 64.246 100 0.000 0.000 64.246 2010-02-22 9:00:10 BEST_ASK 64.260 1 0.000 64.260 0.000 2010-02-22 9:00:10 BEST_BID 64.232 1 64.232 0.000 0.000 2010-02-22 9:00:10 BEST_ASK 64.260 1 0.000 64.260 0.000 2010-02-22 9:00:10 BEST_BID 64.232 2 64.232 0.000 0.000/ Now is there a fast way to fill in the zeros between the observed prices? This is the part that kills me, since I'm pretty sure I've done something similar before, but I just can't remember what I did. -- View this message in context: http://r.789695.n4.nabble.com/Filling-a-time-series-with-Last-Ask-Last-Bid-etc-tp3909390p3909390.html Sent from the Rmetrics mailing list archive at Nabble.com.
Filling a time series with Last Ask, Last Bid, etc
3 messages · Cliff Clive, Ulrich Staudinger
An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-sig-finance/attachments/20111016/9f723fb9/attachment.pl>
Hey, this worked beautifully. Thanks! -- View this message in context: http://r.789695.n4.nabble.com/Filling-a-time-series-with-Last-Ask-Last-Bid-etc-tp3909390p3909449.html Sent from the Rmetrics mailing list archive at Nabble.com.