I have a data (let's call it mydata) with the following data frame.
datetime|side(0=Bid,1=Ask)| distance(1:best price, 2: 2nd best, etc.)| price
2008/01/28,09:11:28.000,0,1,1.6066
2008/01/28,09:11:28.000,0,2,1.6065
2008/01/28,09:11:28.000,0,3,1.6064
2008/01/28,09:11:28.000,0,4,1.6063
2008/01/28,09:11:28.000,0,5,1.6062
2008/01/28,09:11:28.000,1,1,1.6067
2008/01/28,09:11:28.000,1,2,1.6068
2008/01/28,09:11:28.000,1,3,1.6069
2008/01/28,09:11:28.000,1,4,1.6070
2008/01/28,09:11:28.000,1,5,1.6071
I want to calculate minAsk-maxBid, in this case=1.6067-1.6066. I want to do this for my whole data. I was thinking using "by" but even using this simple code:
by(mydata,mydata$datetime, min(mydata$price))
to find just the minimum price in each block I get the following error: Error in FUN(X[[1L]], ...) : could not find function "FUN"
Any idea how to implement that? Should I use a different function ddply
perhaps?
Order Book – UsesThe order is being bought or sold according to the current market price. Another example is when a trader employs limit order strategies. In such a case, traders can set a certain price level at which they want to buy and sell the security.
There are two sides of the Order Book. The green buy side (Bid) and the red sell side (Ask). Both display the prices, amounts, and totals. The larger the totals, the larger the green or red colored depth to that area of the order book.
Try
by(mydata,mydata$datetime, function(d)with(d, min(price[side==1])-max(price[side==0])))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With