This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ############################################ | |
| # Load all necessary R packages | |
| # library(devtools) | |
| # install_github("hrbrmstr/Rforecastio") | |
| library(Rforecastio) | |
| library(ggplot2) | |
| library(plyr) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ############################################################################### | |
| # Load Systematic Investor Toolbox (SIT) | |
| # http://systematicinvestor.wordpress.com/systematic-investor-toolbox/ | |
| ############################################################################### | |
| setInternet2(TRUE) | |
| con = gzcon(url('http://www.systematicportfolio.com/sit.gz', 'rb')) | |
| source(con) | |
| close(con) | |
| #library(griffun) | |
| load.packages('forecast,quantmod,lmtest,TTR') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Sample dates | |
| dates <- c("09/27/99", "03/15/08") | |
| newDates <- as.Date(dates, format = "%m/%d/%y") # <-- Must change the format based on the format of what's being referenced | |
| newDates # R output will be ISO standard dates in the format "%Y-%m-%d" | |
| # Similar example to the last, but must be handled differently | |
| dates <- c("09/27/1999", "03/15/2008") | |
| newDates <- as.Date(dates, format = "%m/%d/%Y") # <-- the only difference here is the "Y" is capitalized | |
| newDates # R output will be ISO standard dates in the format "%Y-%m-%d" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| USE AdventureWorks2012 | |
| DECLARE @DefaultSort VARCHAR(max) = 'SalesPerson' -- SSRS parameter | |
| DECLARE @tblSales AS TABLE ( | |
| SalesPersonID INT, | |
| SalesOrderID INT, | |
| SalesYear VARCHAR(4) | |
| ); | |
| BEGIN |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| reverse_name <- function(x, p="TRUE"){ | |
| require(stringr); require(Hmisc) | |
| if (p == "TRUE"){ | |
| #x = str_replace_all(x, "[^[:print:]]", " ") | |
| x = str_replace_all(x, "[^a-zA-Z.-]", " ") #keep periods and hyphens | |
| la = capitalize(substr(str_trim(x, side = "both"),1, | |
| str_locate(x, " ")-1)) | |
| fi = capitalize(substr(str_trim(x, side = "both"), | |
| str_locate(x, " ")+1,str_length(x))) | |
| out = str_trim(paste(fi,la), side = "both") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # ANALYSIS OF FIP vs ERA FOR 2013 (AS OF 20130604) | |
| require(toolbox) | |
| load.packages('stringr,sqldf') | |
| setwd("~") #;getwd() | |
| # SP - Standard Pitching | |
| SP = read.csv("SP2013.CSV", strip.white = TRUE) | |
| head(SP) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Used for 2013 Draft Strategy | |
| require(toolbox) | |
| load.packages('stringr,sqldf') | |
| setwd("~") #;getwd() | |
| # SP - Standard Pitching | |
| # 2011-2012 filtered by innings pitched | |
| # Data compiled from http://www.baseball-reference.com/ | |
| SP = read.csv("SP.csv", strip.white = TRUE) | |
| head(SP) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Used for 2013 Draft Strategy | |
| require(toolbox) | |
| load.packages('stringr,sqldf,toolbox') | |
| setwd("~") #;getwd() | |
| # SB - Standard Batting | |
| # 2011-2012 filtered by qualifying plate appearances | |
| SB = read.csv("SB.csv", strip.white = TRUE) | |
| head(SB) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #' Adding future dates to a forecast | |
| #' | |
| #' @param dates the dates of the historical values | |
| #' @param forecast a vector of forecasted values | |
| #' | |
| #' @keywords forecast, dates | |
| #' @export | |
| #' @examples | |
| #' ##NULL | |
| extendForecast <- function(dates, forecast) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ############### DREWGRIFFITH15############### remove objects | |
| rm(list = ls()) | |
| # load toolbox | |
| install_github("toolbox", "drewgriffith15") | |
| require(toolbox) | |
| # load packages | |
| load.packages("tm,wordcloud,RColorBrewer") |
NewerOlder