Well, sorta. More precisely, money is the sum of coin$flip divided by the number of coin$flip. But we’ll get to that later. For now, let me introduce you to a new algorithm written in R. This one is another “quote” — simple few lines of code — whose theme you can expand to include something more interesting than what I’m presenting here.

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

*Related*

To

**leave a comment** for the author, please follow the link and comment on his blog:

** Milk Trader**.

R-bloggers.com offers

**daily e-mail updates** about

R news and

tutorials on topics such as: visualization (

ggplot2,

Boxplots,

maps,

animation), programming (

RStudio,

Sweave,

LaTeX,

SQL,

Eclipse,

git,

hadoop,

Web Scraping) statistics (

regression,

PCA,

time series,

trading) and more...

If you got this far, why not

__subscribe for updates__ from the site? Choose your flavor:

e-mail,

twitter,

RSS, or

facebook...

**Tags:** R