Skip to content

Instantly share code, notes, and snippets.

white_bull <- function(ticker) {
require("quantmod")
x <- getSymbols(ticker, auto.assign=FALSE)
c <- x[,4]
c50 <- SMA(c, n=50)
c200 <- SMA(c, n=200)
@milktrader
milktrader / white_bull.r
Created December 11, 2010 20:47
white bull algorithm
white_bull <- function(ticker) {
require("quantmod")
x <- getSymbols(ticker, auto.assign=FALSE)
c <- x[,4]
c50 <- SMA(c, n=50)
c200 <- SMA(c, n=200)
@milktrader
milktrader / crazy.r
Created March 22, 2011 18:36
Naive Bayesian Algorithm
crazy <- function(sym1, sym2) {
require ("quantmod")
# FIRST get the objects (price series returns) correctly formatted
x <- getSymbols(sym1, auto.assign=FALSE)
y <- getSymbols(sym2, auto.assign=FALSE)
x <- Delt(x[,4])
@milktrader
milktrader / delta_farce.r
Created March 24, 2011 03:21
compare close with close n days ago
delta_farce <- function(sym="SPY", expiry=22, pct=.03){
require("quantmod")
ticker <- getSymbols(sym, auto.assign=FALSE)
ticker <- ticker[,4]
win <- 0
@milktrader
milktrader / lemon_lime.r
Created March 24, 2011 14:44
weighted coin
lemon_lime <- function(sym="SLV", expiry=24, pct=.1){
require("quantmod")
ticker <- getSymbols(sym, auto.assign=FALSE)
ticker <- ticker[,4]
win <- 0
lose <- 0
@milktrader
milktrader / blueberry.r
Created March 25, 2011 02:18
Plot how much today's close is different from the close 24 days ago in % terms
blueberry <- function(sym="SLV", file="~/Desktop/24_days_ago.png"){
require("quantmod")
ticker <- getSymbols(sym, auto.assign=FALSE)
ticker <- merge(ticker[,4], lag(ticker[,4],24))
ticker <- na.locf(ticker, na.rm=TRUE)
require(quantmod)
require(vioplot)
getSymbols("GLD")
friend <- DonchianChannel( GLD[,c("GLD.High","GLD.Low")], n=20 )
buddy <- DonchianChannel( GLD[,c("GLD.High","GLD.Low")], n=10 )
pal <- DonchianChannel( GLD[,c("GLD.High","GLD.Low")], n=5 )
posse <- merge(friend$mid, buddy$mid, pal$mid)
@milktrader
milktrader / gnat.r
Created April 27, 2011 14:21
gnat trading algorithm based on a simple moving average crossover
gnat <- function(sym="GLD", fast=50, slow=200){
require("quantmod")
x <- getSymbols(sym, auto.assign=FALSE)
x$fast <- SMA(Cl(x), n=fast)
x$slow <- SMA(Cl(x), n=slow)
x$signal <- Lag(ifelse (x$fast > x$slow, 1, -1))
x <- na.omit(x)
@milktrader
milktrader / pulp.r
Created May 11, 2011 00:45
adds returns to xts object
pulp <- function(sym){
require("quantmod")
juice <- getSymbols(sym, auto.assign=FALSE)
juice$log_ret <- dailyReturn(Cl(juice), type="log")
assign(sym, juice, envir=.GlobalEnv)
}
@milktrader
milktrader / two_y_axis.r
Created May 28, 2011 20:10
Import two xts objects from Yahoo
# install.packages("quantmod")
require("quantmod")
getSymbols("^GSPC;^VIX")
plot(VIX)
par(new=TRUE)
plot(GSPC)
axis(4)