Description Usage Arguments Details Value Author(s) Examples
signalmap
returns a vector of states given four signal vectors.
statemap
returns a vector of states given a vector of phases.
phasemap
returns a vector of phases given a vector of states.
changemap
returns a vector of changes given a vector of states.
1 2 3 4 5 6 7 8 |
el |
logical. enter long signals. |
es |
logical. enter short signals. |
xl |
logical. exit long signals. |
xs |
logical. exit short signals. |
entrywins |
logical. see below. |
retval |
character. see below. |
states |
numeric vector of states. |
phases |
character vector of phases. |
signalmap
converts entry and exit signals into a numeric vector
of states. A signal is a logical vector and is one of four types:
enter long, enter short, exit long, and
exit short. All four signals taken together make up a 4-bit
binary number between 0 and 15 (e.g., el=TRUE
with the other
three signals FALSE
is 8). Six of these are called
phases and are special:
Signals | Phase | English |
0000 | 0 | Unchanged |
0001 | 1 | Exit Short |
0010 | 2 | Exit Long |
0011 | 3 | Exit All |
0100 | 4 | Enter Short |
1000 | 8 | Enter Long |
A phase specifies the transition from one state to the
next. statemap
recursively calculates a vector of states given a
vector of phases using the following rules:
s(i) = s(i-1) | if | h(i) = 0 |
s(i) = max[0, s(i-1)] | if | h(i) = 1 |
s(i) = min[0, s(i-1)] | if | h(i) = 2 |
s(i) = 0 | if | h(i) = 3 |
s(i) = -1 | if | h(i) = 4 |
s(i) = 1 | if | h(i) = 8 |
signalmap
calls statemap
in calculating the state
vector, but it first reduces the ten non-phase combinations to a phase
using the following mapping:
0101 [05] --> 0001 [1] |
0110 [06] --> 0100 [4] |
0111 [07] --> 0011 [3] |
1001 [09] --> 1000 [8] |
1010 [10] --> 0010 [2] |
1011 [11] --> 0011 [3] |
1100 [12] --> 0000 [0] |
1101 [13] --> 0001 [1] |
1110 [14] --> 0010 [2] |
1111 [15] --> 0011 [3]
|
If entrywins=TRUE
the mapping is altered so that conflicts
between an entry and an exit resolve into the entry, instead of the
exit (which is the default behavior above):
0101 [05] --> 0100 [4] |
0110 [06] --> 0100 [4] |
0111 [07] --> 0100 [4] |
1001 [09] --> 1000 [8] |
1010 [10] --> 1000 [8] |
1011 [11] --> 1000 [8] |
1100 [12] --> 0000 [0] |
1101 [13] --> 0001 [1] |
1110 [14] --> 0010 [2] |
1111 [15] --> 0011 [3]
|
phasemap
does the opposite of statemap
, taking a vector of
states and returning a vector of phases. If retval="phases"
,
signalmap
will skip the state calculation and return a vector
of phases instead. If retval="binary"
, the signals are simply
converted into their 4-bit integer representation and returned.
changemap
returns a vector containing 1 where there is a long
entry or short exit, -1 where there is a short entry or long exit, and
0 otherwise.
A state vector of the same length as the signal vectors.
Robert Sams robert@sanctumfi.com
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | ## statemap is invertable
statemap(p <- phasemap(s <- c(0,0,1,1,1,1,-1,-1,-1,0,0))) == s
## phasemap is not always invertable.. for example
q <- p
q[4] <- 8
phasemap(statemap(q)) == q
el <- c(TRUE,FALSE)
es <- c(FALSE,FALSE)
signalmap(el, es)
el[2] <- TRUE
xl <- c(FALSE,TRUE)
signalmap(el, es, xl)
signalmap(el, es, xl, entrywins=TRUE)
el <- c(TRUE,FALSE,TRUE)
es <- c(FALSE,FALSE,FALSE)
xl <- c(FALSE,TRUE,FALSE)
signalmap(el, es, xl)
signalmap(es, el, FALSE, xl)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.