Download Stock Price Online with R
This article is originally published at https://statcompute.wordpress.com
library(chron) library(zoo) # STOCK TICKER OF Fifth Third Bancorp stock <- 'FITB' # DEFINE STARTING DATE start.date <- 1 start.month <- 1 start.year <- 2012 # DEFINE ENDING DATE end.date <- 11 end.month <- 10 end.year <- 2012 # DEFINE URL LINK link <- paste("http://ichart.finance.yahoo.com/table.csv?s=", stock, "&a=", as.character(start.month - 1), "&b=", as.character(start.date), "&c=", as.character(start.year), "&d=", as.character(end.month - 1), "&e=", as.character(end.date), "&f=", as.character(end.year), "&g=d&ignore=.csv", sep = '') # DOWNLOAD STOCK PRICE AS CSV FILE download.file(link, "c:/projects/data.csv") # READ THE CSV FILE INTO R data <- read.csv("c:/projects/data.csv") # CONVERT CHARACTER INTO DATE dt <- dates(as.character(data[, 1]), format = "y-m-d") # CONVERT DATA FRAME INTO TS OBJECT ts <- zoo(data[, 2:5], dt) # CREATE A PLOT FOR OPEN/CLOSE/HIGH/LOW PRICES plot(ts, main = stock)
Thanks for visiting r-craft.org
This article is originally published at https://statcompute.wordpress.com
Please visit source website for post related comments.