Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Quantmod: extracting split dates from yahoo EOD price data

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

like image 738
R.S. Avatar asked May 25 '26 08:05

R.S.


1 Answers

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)
like image 165
Joshua Ulrich Avatar answered May 27 '26 22:05

Joshua Ulrich



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!