getReturns (stockPortfolio package)

getReturns(ticker, freq=”month”, get=”overlapOnly”, start=”1970-01-01″, end=NULL)
Retrieve stock performance data from Yahoo! Finance. Use the returned object to fit a stock model (via stockModel) and then estimate the optimal portfolio based on that model (via optimalPort).
  • ticker – A character vector of stock tickers.
  • freq – Indicate what resolution should be retrieved: "month" (the default), "week", or "day".
  • get – Indicate whether the processed returns should include only overlapping dates for the stocks (the default) or whether all processed returns data should be provided ("all").
  • start – The earliest date to begin retrieving stock data, input as "YYYY-MM-DD".
  • end – The end date as "YYYY-MM-DD" (default is the most recent trading day).

Continue reading

sub, gsub

sub(pattern, replacement, x)
gsub(pattern, replacement, x)
Replace the first occurrence of a pattern with sub or replace all occurrences with gsub.
  • pattern – A pattern to search for, which is assumed to be a regular expression. Use an additional argument fixed=TRUE to look for a pattern without using regular expressions.
  • replacement – A character string to replace the occurrence (or occurrences for gsub) of pattern.
  • x – A character vector to search for pattern. Each element will be searched separately.

Continue reading

by

by(data, INDICES, FUN, …)
Apply a function across subsets of data, where the subsets are defined by the INDICES argument. The by function returns a list, where each list item represents the results for a particular subset of the data.
  • data – The full set of data, e.g. a vector or data.frame.
  • INDICES – A vector describing how the data subsets are to be constructed (e.g. a factor vector). Multiple columns in a data frame may also be given, where each combination of the variables defines a new subset of data.
  • FUN – A function to apply to each subset of data.
  • – Any additional arguments to pass to FUN.

Continue reading

append

append(x, values, after=length(x))
Append values to x, possibly inserted into the middle of x. This function is important since it tends to perform a little faster than using the concatenation (c) function.
  • x – A vector.
  • y – Another vector to place at the end of or within x.
  • after – Where values should go in x, by default at the end.

Continue reading