-
Notifications
You must be signed in to change notification settings - Fork 382
/
make.sit.pkg.r
143 lines (127 loc) · 4.69 KB
/
make.sit.pkg.r
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
###############################################################################
# Setup
###############################################################################
package.name = 'SIT'
os = Sys.info()[["sysname"]]
###############################################################################
# Create folders, copy files
###############################################################################
unlink('pkg', recursive = T, force = T)
dir.create('pkg')
#file.copy('Readme.txt', 'pkg/.')
#file.copy('Readme.pkg.txt', 'pkg/.')
dir.create('pkg/R', recursive = T)
if (os == "Windows") {
#shell('rmdir /S /Q pkg', wait = TRUE)
#shell('mkdir pkg', wait = TRUE)
#shell('copy Readme.txt pkg\\*.*', wait = TRUE)
#shell('copy Readme.pkg.txt pkg\\*.*', wait = TRUE)
#shell('mkdir pkg\\R', wait = TRUE)
shell('copy R\\*.* pkg\\R\\*.*', wait = TRUE)
} else {
system('cp R/* pkg/R/.', wait = T)
}
###############################################################################
# Create DESCRIPTION files
###############################################################################
write.dcf(list(
Package = toupper(package.name),
Type = 'Package',
Title = 'Systematic Investor Toolbox',
Description = 'Systematic Investor Toolbox is a collection of tools that\n I use in my investment research.',
Version = format(Sys.Date(),'%Y.%m.%d'),
Date = Sys.Date(),
License = 'Zlib',
LazyLoad = 'yes',
Author = 'Michael Kapler <[email protected]>',
Maintainer = 'Michael Kapler <[email protected]>',
Depends = 'SIT.date,quantmod,xts'
),
file = file.path('pkg', "DESCRIPTION")
)
cat("
#' Systematic Investor Toolbox.
#'
#' Systematic Investor Toolbox is a collection of tools that
#' I use in my investment research.
#'
#'
#'
#' @name SIT
#' @aliases SIT SIT-package
#' @docType package
#' @title Systematic Investor Toolbox.
#' @author Michael Kapler \\email{TheSystematicInvestor@@gmail.com}
#' @keywords package Asset Allocation Backtesting Trading
#' @examples
#' \\dontrun{
#' ##*****************************************************************
#' ## Permanent Portfolio Example
#' ##*****************************************************************
#' ## Load historical data
#' ##*****************************************************************
#' load.packages('quantmod')
#' tickers = spl('SPY,TLT,GLD,SHY')
#'
#' data = new.env()
#' getSymbols(tickers, src = 'yahoo', from = '1980-01-01', env = data, auto.assign = T)
#' # adjust for dividends
#' for(i in ls(data)) data[[i]] = adjustOHLC(data[[i]], use.Adjusted=T)
#' bt.prep(data, align='remove.na')
#'
#' ##*****************************************************************
#' ## Setup
#' ##******************************************************************
#' prices = data$prices
#' n = ncol(prices)
#'
#' ## rebalance quarterly
#' period.ends = endpoints(prices, 'quarters')
#' period.ends = period.ends[period.ends > 0]
#' period.ends = c(1, period.ends)
#'
#' models = list()
#'
#' ##*****************************************************************
#' ## Code Strategies
#' ##******************************************************************
#' target.allocation = matrix(rep(1/n,n), nrow=1)
#'
#' ## Buy & Hold
#' data$weight[] = NA
#' data$weight[1,] = target.allocation
#' models$buy.hold = bt.run.share(data, clean.signal=F)
#'
#' ## Equal Weight
#' data$weight[] = NA
#' data$weight[period.ends,] = ntop(prices[period.ends,], n)
#' models$equal.weight = bt.run.share(data, clean.signal=F)
#'
#' ##*****************************************************************
#' ## Create Report
#' ##******************************************************************
#' strategy.performance.snapshoot(models,T)
#'
#' plotbt.custom.report.part2(models$buy.hold)
#'
#' plotbt.custom.report.part2(models$equal.weight)
#' }
NULL
", file = file.path('pkg', 'R', paste(package.name,'package.R',sep='-')))
###############################################################################
# Create documentaion and build package
###############################################################################
pkg = 'pkg'
devtools::document(pkg);
devtools::spell_check(pkg);
name = devtools::build(pkg)
file.rename(name, paste(package.name, '.tar.gz', sep=''))
#file.remove(name)
# devtools::install(pkg, quick = TRUE, dependencies = FALSE);
devtools::install(pkg, quick = TRUE, dependencies = FALSE);
###############################################################################
# Usage
###############################################################################
# install.packages('SIT.tar.gz', repos = NULL, type='source')
# library(SIT)
# ?spl