Learn R Programming

maRketSim (version 0.9.2)

VFITX_prices: Vanguard Intermediate Treasury Data, as downloaded from Yahoo

Description

VFITX prices

Usage

data(VFITX_prices)

Arguments

Format

A data frame with 3626 observations on the following 7 variables.
Date
date, as a factor
Open
a numeric vector
High
a numeric vector
Low
a numeric vector
Close
a numeric vector
Volume
a numeric vector
Adj.Close
a numeric vector

Source

Yahoo

Details

Price history only. See demo file for details.

Examples

Run this code
data(VFITX_prices)
pr.df <- VFITX_prices
pr.df$Date <- as.Date(pr.df$Date)
pr.df$month <- format(pr.df$Date,format="%m")
pr.df <- subset(pr.df,month=="06"|month=="12",select=c("Date","Close","month"))
pr.df$month <- as.numeric(pr.df$month)
pr.df$year <- as.numeric(format(pr.df$Date,format="%Y"))
pr.df$day <- as.numeric(format(pr.df$Date,format="%d"))
# Select last available day of each month
by.res <- by(pr.df,list(pr.df$month,pr.df$year),function(x) x[x$day==max(x$day),] )
pr.df <- by.res[[1]]
for(i in seq(2,length(by.res))) {
	if(!is.null(by.res[[i]])) {
		pr.df <- rbind(pr.df,by.res[[i]])
	}
}
pr.df <- subset(pr.df,select=c("Close","month","year"))
names(pr.df)[names(pr.df)=="Close"] <- "p"

Run the code above in your browser using DataLab