Tom Clayton
Tom Clayton

Reputation: 31

Merge getSymbols data by ticker and date

I'm currently learning R and I'm just trying to pull in some price data using getSymbols in the quantmod package.

I have a dataframe that has tickers and dates of annual results releases for a sector on the Australian Stock Exchange. What I'd like to do is merge in an adjusted price for the day of the release as well as the price 5 days before and 5 days after.

Ticker  Ann_Rep_Date  Ad.Price  +5d.Ad.Price  -5d.Ad.Price
AGI.AX  14/10/16
ALL.AX  22/12/16
CWN.AX  19/09/16
TAH.AX  4/08/16
TAH.AX  4/08/17
TTS.AX  17/08/17

Note that there can be multiple prices required for a single ticker as there are multiple annual results releases.

Upvotes: 1

Views: 320

Answers (1)

Tom Clayton
Tom Clayton

Reputation: 31

I managed to do this using tqget from tidyquant. It can store all my prices in one big happy data frame which makes it easy to merge with the above.

library(tidyquant)

prices <- c('TBH.AX','CWN.AX','SGR.AX','AQS.AX','ALL.AX',
        'TAH.AX','JIN.AX','TTS.AX','AGI.AX') %>%
         tq_get(get = 'stock.prices')

Ann_Reps <- merge(prices, Ann_Reps, by.x=c('symbol','date'), 
by.y=c('ticker','Ann_Rep_Date'))

Upvotes: 1

Related Questions