Skip to content

Instantly share code, notes, and snippets.

@kevin3
Created March 4, 2013 16:36
Show Gist options
  • Save kevin3/5083555 to your computer and use it in GitHub Desktop.
Save kevin3/5083555 to your computer and use it in GitHub Desktop.
R code to retrieve the trading range for a stock on a historical date using quantmod library
library('quantmod')
#loadSymbols of the stock codes you are interested in
loadSymbols(c('K17.SI','BN4.SI'))
#retrieves the values for a single date
BN4.SI['2013-01-25']
#K17.SI['2013-03-04']
#Convert the matrix retrieved as a data.frame for easier data usage
=kep=as.data.frame(BN4.SI['2013-01-25'])
#Calculates the Trading Range for the specified date
TradingRange=kep['BN4.SI.High']-kep['BN4.SI.Low']
TradingRange
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment