0

I need to evaluate the post split stock performance with the quantmod package in R for NYSE,AMEX,NASDAQ. My problem is that I'm only able to look up specific symbols ( getSymbols()), but I need to separate my data into non splitting firms and splitting firms, to compare them. Does anyone have an idea how I can do this for the last 25 years ?

Thanks

G5W
  • 36,531
  • 10
  • 47
  • 80
Shuzo
  • 31
  • 1
  • 1
  • 5
  • I think you’re asking for a resource which is not on stackoverflow. The site is not intended to find people to help hunt for references. Maybe you could first find a data source with the splitting information that you need and then try to join the two. You could then posted my specific question after you get started. – Bobby Dec 02 '18 at 11:53

1 Answers1

1

Since you're using the quantmod package, you can use getSplits() function to determine which splits a stock has had within a certain timeframe. Since you're dealing with a large number of stocks, you can use a custom function to get what you want.

getSymbolSplit <- function(symbol,xts,date) {
  splitCheck <- getSplits(symbol,from = date)
  if(anyNA(splitCheck, recursive = FALSE)){
    xts$Split <- 0
  } else {
    xts$Split <- 1
  }
  return(xts)
}

Once you have that function, you can quickly add a split to the existing stocks data. Example:

getSymbols('GOOG')
GOOG <- getSymbolSplit('GOOG',GOOG,'1993-01-01')

The getSymbols() function creates the xts named GOOG, so our function checks if any splits have happened since 1993-01-01 (yes) and adds a column Split with the value of 1.

getSymbols('REGN')
REGN <- getSymbolSplit('REGN',REGN,'1993-01-01')

Same deal, but REGN has had no splits since 1993 and the column has a value of 0.

Now you have a clear binary variable for grouping between firms that have had a split in your given timeframe.

As a warning, I encountered a problem with BRK-A. R does not normally permit names that include a '-', and the function breaks when trying to pass an xts named BRK-A. If you have stocks that use a - in their symbol, I recommend you rename them before using them. This function is not the only place where the dash could cause problems.

Jared C
  • 362
  • 7
  • 19
  • This doesnt work .. i tried to use it with BHB getSymbols('BHB') BHB <- getSymbolSplit('BHB',BHB,'1993-01-01') But there isnt a Value 1 in the added column where a split original occured It begins at 2007-01-01 – Shuzo Dec 02 '18 at 13:48
  • I'm sorry, there was a typo. The line after `} else {` should say `xts$Split <- 1` – Jared C Dec 02 '18 at 13:55
  • Please show me your code, and the output from running it. For example, using pastebin.com – Jared C Dec 03 '18 at 22:28
  • Isn't this working as expected? Google had a split in 2014, so the result is that the split column shows 1. Now it is incredibly easy to distinguish stocks which split or didn't. – Jared C Dec 09 '18 at 18:10
  • yeah but i have a 1 for every single column, that means that google had a stock split on every single day , that cant be true – Shuzo Dec 10 '18 at 18:52
  • Ok you never asked for a distinction between which days have the stock splits. You said that you wanted to have a way to separate stocks with a split vs stocks without a split. If you need the days of splits, then you can just use the built in getSplits() function. – Jared C Dec 10 '18 at 20:55