I'm admittedly a beginner in R and financial analysis as a whole. To better myself I've been working on a side project to automate a "Trending Value" screener. Essentially you pull 6 financial metrics - P/E, P/B, P/FCF, P/S, EV/EBITDA, and Shareholder Yield, which is dividend yield + stock buyback yield (i.e. equity returned to the shareholder in some way). There's more to it here if you'd like to know more but pulling metrics is the first part.
The code I've put together based on other posts has pulled the tickers P/E, P/B, & P/S. So I'm missing Market Cap, P/FCF, EV/EBITDA, and Shareholder Yield. Here's what I have thus far:
library(quantmod) # also loads xts and TTR
require(plyr)
# Fetch all Symbols & store only the tickers to retrieve the data
symbols <- stockSymbols()
# Convert to just tickers.
tickers <- symbols[,1]
# Pull P/E, P/B, P/S
what_metrics <- yahooQF(c( "P/E Ratio",
"Price/Book",
"Price/Sales"))
# Not all the metrics are returned by Yahoo.
metrics <- getQuote(paste(tickers, sep="", collapse=";"), what=what_metrics)
#Add tickers as the first column and remove the first column which had date stamps
metrics <- data.frame(Symbol=tickers, metrics[,2:length(metrics)])
#Change colnames
colnames(metrics) <- c("Symbol","P/E","P/B","Price/Sales")
#Persist this to the csv file
write.csv(metrics, "FinancialMetrics.csv", row.names=FALSE)
Any help would be appreciated!