mercredi 25 juillet 2018

Tick test for trade classification

Writing my master thesis, I have downloaded trading data:

  >head(Data1)
  PRICE PREVIOUS
1 100   99
2 98    100
3 100   98
4 100   100
5 100   100
6 101   100      

The goal is to add a column that indicates if a trade was buyer ("buy") or seller ("sell") initiated. The rules are as follows:

  • PRICE < PREVIOUS => Sell
  • PRICE > PREVIOUS => Buy
  • PRICE == PREVIOUS => Prior classification

This is how it should look like

      >head(Data1)
     PRICE PREVIOUS TICK
    1 100   99       Buy
    2 98    100      Sell
    3 100   98       Buy
    4 100   100      Buy
    5 100   100      Buy
    6 101   100      Buy

I have written the following code:

Data1$TICK <- ifelse(Data1$PRICE == Data1$PREVIOUS, yes = shift(Data1[ ,3]), no = ifelse(Data1$PRICE>Data1$PREVIOUS, yes= "Buy", no = "Sell"))

However, when I try to execute the code I get the warning:

Error in [.data.frame(Data1, , 3)` : undefined columns selected

Therefore I have two questions:

  1. Is this code capable of delivering the result I would like to get?
  2. What is the error message referring to?

Aucun commentaire:

Enregistrer un commentaire