Skip to content

Instantly share code, notes, and snippets.

View dalamar66's full-sized avatar

Daniel dalamar66

View GitHub Profile
@dalamar66
dalamar66 / dvi.r
Last active August 29, 2015 14:10 — forked from ivannp/dvi.r
require(quantmod)
require(SIT)
dvi.indicator = function(prices) {
dvi = TTR:::DVI(prices)[,3]
indicator.long = ifelse(dvi <= 0.5, 1, 0)
indicator.short = ifelse(dvi > 0.5, -1, 0)
indicator = reclass(cbind(indicator.short + indicator.long), prices)
@dalamar66
dalamar66 / gys.r
Last active August 29, 2015 14:10 — forked from ivannp/gys.r
#' Saves symbols (from an environment) to a specified directory
#'
#' The files (one per symbol) are saved in \code{dir}. The file name
#' is the symbol itself, and the file extension is RData.
#'
#' @param symbols The symbols
#' @param dir The destination folder (file system directory). It must exist.
#' @param env The environment containing the symbols
#'
#' @examples
require(quantmod)
prepare.indicator = function(close, indicator, roc.n, normalize=FALSE, func=mean) {
rets = ROC(close, type="discrete", n=roc.n)
if(normalize) {
# Normalize the returns to daily
rets = ((1 + rets) ^ (1/roc.n)) - 1
}
@dalamar66
dalamar66 / garchAuto.R
Last active August 29, 2015 14:10 — forked from ivannp/garchAuto.R
garchAutoTryFit = function(
ll,
data,
trace=FALSE,
forecast.length=1,
with.forecast=TRUE,
ic="AIC",
garch.model="garch" )
{
formula = as.formula( paste( sep="",
@dalamar66
dalamar66 / e1071.R
Last active January 24, 2017 16:43 — forked from ivannp/e1071.R
svmComputeOneForecast = function(
id,
data,
response,
startPoints,
endPoints,
len,
history=500,
trace=FALSE,
kernel="radial",
@dalamar66
dalamar66 / armaSearch.R
Last active August 29, 2015 14:10 — forked from ivannp/armaSearch.R
armaSearch = function(
xx,
minOrder=c(0,0),
maxOrder=c(5,5),
trace=FALSE )
{
bestAic = 1e9
len = NROW( xx )
for( p in minOrder[1]:maxOrder[1] ) for( q in minOrder[2]:maxOrder[2] )
{
findBestArma = function(
xx,
minOrder=c(0,0),
maxOrder=c(5,5),
trace=FALSE )
{
bestAic = 1e9
len = NROW( xx )
for( p in minOrder[1]:maxOrder[1] ) for( q in minOrder[2]:maxOrder[2] )
{
@dalamar66
dalamar66 / svm_rsi_trend.R
Created January 24, 2017 16:05 — forked from Inpirical-Coder/svm_rsi_trend.R
Trains and tests SVM on two features (relative strength index and trend over x observations)
# Some code to asses an SVM with a two-dimensional feature space:
# trend (price - simple moving average) and relative strength index.
# The code is an adaptation of the code found in the following linkedin post:
# "Trading the RSI using a Support Vector Machine"
# "https://www.linkedin.com/pulse/article/20141103165037-172934333-trading-the-rsi-using-a-support-vector-machine"
# Settings
sma.window = 50 # Number of observations in simple moving average.
rsi.window = 3 # Number of observation in relative strength index (RSI)
@dalamar66
dalamar66 / sentiment_score_simple.R
Created January 24, 2017 16:06 — forked from Inpirical-Coder/sentiment_score_simple.R
R Sentiment Scoring HSBC w/ Harvard General Inquirer
# Code to fetch news streams from 5 live sources, process the streams and text
# and apply a simple sentiment scoring algorigthm.
#
# A writeup of the analysis can be found here:
# https://www.linkedin.com/pulse/article/20141109035942-34768479-r-sentiment-scoring-hsbc-w-harvard-general-inquirer
# Define the packages we want to load:
packs = c(
"tm", # Text mining
"tm.plugin.webmining", # Web-source plugin for text mining
@dalamar66
dalamar66 / twttr_sentiment_bench.R
Created January 24, 2017 16:06 — forked from Inpirical-Coder/twttr_sentiment_bench.R
Benchmarking sentiment scoring algorithms for twitter using precision, recall, F-measure
# Short scripts for testing three different sentiment classifiers on tweets,
# acquiring the tweets used for testing,
# calculating systems' precision, recall and F-measures.
require(RCurl) # For downloading file from a given URL.
require(twitteR) # Used for the 'twitter' class.
require(sentiment) # For bayes and voter classifiers.
source("sent140.R") # Used for the Sentiment 140 API. Can be downloaded from here:
# https://github.com/okugami79/sentiment140/blob/master/R/sentiment.r