This is in relation to stock data obtained from Yahoo Finance.
I'm looking for a method for determining dates when a stock was split (or bonus shares were issued, the distinction is immaterial to current task).
I could not find any specific answer to this problem. Here's the best I could think of:
require(quantmod)
AAPL<- getSymbols("AAPL", from="1987-01-01",to="2016-08-01", auto.assign = F)
# head(AAPL)
# tail(AAPL)
# assuming a minimum split of 10:11
probableSplits<- which( Delt(Cl(AAPL)/Ad(AAPL)) <= -0.1)
probableSplitDates<- index(AAPL)[probableSplits]
x<- AAPL[c(probableSplits, ((probableSplits)-1))]
x$tmpratio<- Cl(x)/Ad(x)
x$splitRatio<- round(1/(1+Delt(x$tmpratio)))
#Added Following 1 line for very old stocks with adjusted price in low decimals
probableSplitDates<- index(x[x$splitRatio>1,])
x$splitRatio[probableSplitDates]
chartSeries(AAPL["2014-06"],theme = chartTheme('white'))
I would like to know what issues this solution might run into.
Even though I'm using Apple here, I am looking for data from Indian exchanges (for example, RELIANCE.NS) so some of the US specific sources for cross-referencing will not work for me.
EDIT: Added one line to code for old adjusted price in very low decimal values
You could use the split/dividend data that Yahoo Finance provides.
require(quantmod)
getSplits("RELIANCE.NS")
# RELIANCE.NS.spl
# 1997-10-27 0.5
# 2009-11-26 0.5
You could also use adjustOHLC
to do the adjustment for you.
getSymbols("RELIANCE.NS")
RELIANCE.NS.ADJ <- adjustOHLC(RELIANCE.NS)