Skip to content

Commit 3764c17

Browse files
committed
🔨 Added lookback-function to templates
1 parent a2d960c commit 3764c17

6 files changed

Lines changed: 102 additions & 2 deletions

codegen/generate_indicator_core.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ done
144144
for i in "${!in_scalars_name[@]}"; do
145145
R_SIGNATURE+=$'\tSEXP '"${in_scalars_name[$i]}"$',\n'
146146
done
147-
R_SIGNATURE=${R_SIGNATURE%$'\n'}
147+
R_SIGNATURE=${R_SIGNATURE%,$'\n'}
148148

149149
## 6) PARAM_DOC
150150
##

codegen/templates/candlestick_template.c.in

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,21 @@
2424
#include "normalize.h"
2525
#include <ta_libc.h>
2626

27+
// the lookback function
28+
// is exported as a standalone
29+
// function for downstream wrappers
30+
// clang-format off
31+
SEXP impl_ta_${NAME}_lookback($R_SIGNATURE
32+
)
33+
// clang-format on
34+
{
35+
// calculate lookback
36+
const int lookback = {{LOOKBACK}};
37+
SEXP output = PROTECT(Rf_ScalarInteger(lookback));
38+
39+
return output;
40+
}
41+
2742
// clang-format off
2843
SEXP impl_ta_{{NAME}}(
2944
SEXP inOpen,

codegen/templates/indicator_template.R.in

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,3 +110,31 @@ ${FUN}.matrix <- function(
110110
...
111111
)
112112
}
113+
114+
#' @usage NULL
115+
${ALIAS}_lookback <- ${FUN}_lookback <- function(
116+
x,
117+
cols,${ARGS}
118+
...
119+
) {
120+
## validate 'cols'-argument
121+
## if explicitly passed
122+
if (!missing(cols)) {
123+
assert_formula(cols)
124+
}
125+
126+
## construct series
127+
## from input
128+
constructed_series <- series(
129+
x = cols,
130+
default_formula = ${FORMULA},
131+
data = x,
132+
...
133+
)
134+
135+
.Call(
136+
C_impl_ta_${TA_FUN}_lookback,
137+
## splice:lookback:start
138+
## splice:lookback:end
139+
)
140+
}

codegen/templates/indicator_template.c.in

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,24 @@
2020
#include <Rinternals.h>
2121
#include <ta_libc.h>
2222

23+
// the lookback function
24+
// is exported as a standalone
25+
// function for downstream wrappers
2326
// clang-format off
24-
SEXP impl_ta_${NAME}($R_SIGNATURE
27+
SEXP impl_ta_${NAME}_lookback($R_SIGNATURE
28+
)
29+
// clang-format on
30+
{
31+
// calculate lookback
32+
const int lookback = TA_${NAME}_Lookback($LOOKBACK_ARGS);
33+
34+
SEXP output = PROTECT(Rf_ScalarInteger(lookback));
35+
36+
return output;
37+
}
38+
39+
// clang-format off
40+
SEXP impl_ta_${NAME}($R_SIGNATURE,
2541
SEXP na_bridge
2642
)
2743
// clang-format on

codegen/templates/moving_average_template.R.in

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,34 @@ $FUN.numeric <- function(
163163

164164
}
165165

166+
#' @usage NULL
167+
${ALIAS}_lookback <- ${FUN}_lookback <- function(
168+
x,
169+
cols,${ARGS}
170+
...
171+
) {
172+
## validate 'cols'-argument
173+
## if explicitly passed
174+
if (!missing(cols)) {
175+
assert_formula(cols)
176+
}
177+
178+
## construct series
179+
## from input
180+
constructed_series <- series(
181+
x = cols,
182+
default_formula = ${FORMULA},
183+
data = x,
184+
...
185+
)
186+
187+
.Call(
188+
C_impl_ta_${TA_FUN}_lookback,
189+
## splice:lookback:start
190+
## splice:lookback:end
191+
)
192+
}
193+
166194
#' @usage NULL
167195
#' @aliases $FUN
168196
#'

codegen/templates/rolling_template.R.in

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,3 +70,16 @@ ${FUN}.numeric <- function(
7070
## return indicator
7171
as.double(x)
7272
}
73+
74+
#' @usage NULL
75+
${ALIAS}_lookback <- ${FUN}_lookback <- function(
76+
x,${ARGS}
77+
) {
78+
79+
.Call(
80+
C_impl_ta_${TA_FUN}_lookback,
81+
## splice:lookback:start
82+
## splice:lookback:end
83+
)
84+
85+
}

0 commit comments

Comments
 (0)