File: RollingAnalysis.Rd

package info (click to toggle)
ftrading 3042.79-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, forky, sid, trixie
  • size: 200 kB
  • sloc: makefile: 14
file content (126 lines) | stat: -rw-r--r-- 3,089 bytes parent folder | download | duplicates (4)
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
\name{RollingAnalysis}

\alias{RollingAnalysis}

\alias{rollFun}
% \alias{rollMin}
% \alias{rollMax}
% \alias{rollMean}
\alias{rollVar}

\title{Rolling Analysis}


\description{

    A collection and description of functions
    to perform a rolling analysis. A rolling
    analysis is often required in building
    trading models.
    \cr

    The functions are:

    \tabular{ll}{
    \code{rollFun} \tab Rolling or moving sample statistics, \cr
%    \code{rollMin} \tab Rolling or moving sample minimum, \cr
%    \code{rollMax} \tab Rolling or moving sample maximum, \cr
%    \code{rollMean} \tab Rolling or moving sample mean, \cr
    \code{rollVar} \tab Rolling or moving sample variance. }

}


\usage{
rollFun(x, n, trim = TRUE, na.rm = FALSE, FUN, ...)
% rollMin(x, n = 9, trim = TRUE, na.rm = FALSE)
% rollMax(x, n = 9, trim = TRUE, na.rm = FALSE)
% rollMean(x, n = 9, trim = TRUE, na.rm = FALSE)
rollVar(x, n = 9, trim = TRUE, unbiased = TRUE, na.rm = FALSE)
}


\arguments{

    \item{FUN}{
        the rolling function, arguments to this function can be
        passed through the \code{\dots} argument.
        }
    \item{n}{
        an integer specifying the number of periods or
        terms to use in each rolling/moving sample.
        }
    \item{na.rm}{
        a logical flag: if TRUE, missing values in x will be removed
        before computation. The default is FALSE.
        }
    \item{trim}{
        a logical flag: if TRUE, the first n-1 missing values in
        the returned object will be removed; if FALSE, they will
        be saved in the returned object. The default is TRUE.
        }
    \item{unbiased}{
        a logical flag. If TRUE, the unbiased sample variance
        will be returned. The default is TRUE.
        }
    \item{x}{
        an univariate \code{timeSeries} object or a numeric vector.
        }
    \item{\dots}{
        additional arguments to be passed.
        }

}


\value{

    The functions return a \code{timeSeries} object or a numeric
    vector, depending on the argument \code{x}.

    \code{rollMax} returns the rolling sample maximum, \cr
    \code{rollMin} returns the rolling sample minimum, \cr
    \code{rollMean} returns the rolling sample mean, and \cr
    \code{rollVar} returns the biased/unbiased rolling sample variance.

    Note, that the function \code{rollFun} always returns a numeric
    vector, independent of the argument \code{x}.

    If you like to operate for \code{x} with rectangular objects,
    you have to call the functions columnwise within a loop.

}


\seealso{

    \code{\link{var}}.

}


\author{

    Diethelm Wuertz for the Rmetrics \R-port.

}


\examples{
## Rolling Analysis:
   x = (1:10)^2
   x
   trim =  c(TRUE, TRUE, FALSE, FALSE)
   na.rm = c(TRUE, FALSE, TRUE, FALSE)
   for (i in 1:4)
     rollFun(x, 5, trim[i], na.rm[i], FUN = min)
   for (i in 1:4)
     rollFun(x, 5, trim[i], na.rm[i], FUN = max)
   for (i in 1:4)
     rollVar(x, 5, trim[i], unbiased = TRUE, na.rm[i])
   for (i in 1:4)
     rollVar(x, 5, trim[i], unbiased = FALSE, na.rm[i])
}


\keyword{math}