Skip to content

Commit 4e9f902

Browse files
committed
Update TestPortSelect.R
now it matches the sample periods
1 parent 1539cbb commit 4e9f902

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

Signals/pyCode/utils/TestPortSelect.R

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ suppressPackageStartupMessages({
1414
library(readr)
1515
library(tidyr)
1616
library(stringr)
17+
library(lubridate)
1718
})
1819

1920
args_trailing <- commandArgs(trailingOnly = TRUE)
@@ -121,6 +122,27 @@ if (nrow(ls_df) == 0) {
121122
stop("No LS portfolio rows found for the requested predictors. Ensure upstream portfolios have been generated.")
122123
}
123124

125+
sample_info <- signal_doc %>%
126+
select(signalname, SampleStartYear, SampleEndYear, Year)
127+
128+
ls_df <- ls_df %>%
129+
mutate(date = as.Date(date)) %>%
130+
left_join(sample_info, by = "signalname") %>%
131+
mutate(
132+
sample_year = year(date),
133+
samptype = case_when(
134+
!is.na(SampleStartYear) & !is.na(SampleEndYear) &
135+
sample_year >= SampleStartYear & sample_year <= SampleEndYear ~ "insamp",
136+
!is.na(Year) & sample_year > Year ~ "postpub",
137+
TRUE ~ NA_character_
138+
)
139+
) %>%
140+
filter(samptype == "insamp")
141+
142+
if (nrow(ls_df) == 0) {
143+
stop("No in-sample LS portfolio rows matched the documentation-defined sample period for the requested predictors.")
144+
}
145+
124146
summary_df <- ls_df %>%
125147
mutate(
126148
Ncheck = pmin(Nlong, Nshort, na.rm = TRUE)

0 commit comments

Comments
 (0)