Let's say you're having a really bad spell trading and basically have no money left. You have a computer, but you don't have any spare change to spend on software or data. Well, you're in luck. R is free, open source software and Yahoo Finance offers free data. Yes the free-ness means that you get delayed quotes, but let's not quibble about a few minutes. It's free!
The following lines of code enable you to create a list of stocks that may be of interest to you. I've included the venerable Dow 30. You can include the entire S&P 500 or just some select sector ETFs that give you a broad-stroke view of the current day's market action. In any case, it returns a value that I've named 'money'. This value is a percentage of our list that is trading above yesterday's close. Yeah, kinda boring, but as I mentioned, it's a theme for you to play with.
require("quantmod")
bank <- c("AA","AXP","BA","BAC","CAT","CSCO",
"CVX","DD","DIS","GE","HD","HPQ",
"IBM","INTC","JNJ","JPM","KFT",
"KO","MCD","MMM","MRK","MSFT","PFE",
"PG","T","TRV","UTX","VZ","WMT","XOM")
coin <- getQuote(bank, what=yahooQF(c("Last Trade (Price Only)", "Change")))
random <- function(change)
{
if ( change > 0 )
return (1)
else
return (0)
}
coin$flip <- mapply(random, coin[,3])
money <- sum(coin$flip)/length(coin$flip)*100
money
0 comments:
Post a Comment