
First things first: getting data and getting it into R.
I like Yahoo! finance: http://finance.yahoo.com/
Choose a company you might be interested in, e.g., Questar gas (STR).
We'll want a lot of data so choose historical prices from the Quotes: summary options on the left.
Now, scroll to the bottom and choose Download to Spreadsheet. There you have your .csv file.
*See previous posts about getting .csv data into R*
Here is some sample R code to run a simple analysis and plot the data:
data<-read .csv=".csv" file.choose="file.choose" span="span">
data
summary(data)
attach(data)
Date_3=1:length(Close)
data=cbind(data,Date_3)
lin=lm(Close~Date_3)
pdf(file='moola.pdf')
par(bg="snow", family="serif", ps=10)
plot(Close~Date_3, data=data, type="l", xlab="Date", sub="Questar",axes=F, ylab="Closing $")
abline(h=mean(Close), col="blue", lty=2)
abline(h=max(Close), col="lightblue", lty=5)
abline(h=min(Close), col="lightblue", lty=5)
abline(lin, col="green", lty=2)
axis(1,at=c(1,1000,2000,3000,4000, 5232),
labels=c("12/30/87","12/11/91", "11/24/95", "11/10/99","11/12/03","Oct 6, 2008"))
axis(2, label=T)
axis(2, at=mean(Close), labels="[Mean]")
dev.off()-read>
