Skip to content

Commit b8549d5

Browse files
authored
Clean up code.
Removed commented-out code and unused variables to clean up the function logic.
1 parent d529f3e commit b8549d5

File tree

1 file changed

+1
-34
lines changed

1 file changed

+1
-34
lines changed

src/20_Optimisation/02_CrossValidation/02_WalkForward.jl

Lines changed: 1 addition & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -91,26 +91,15 @@ function split_from_period(wf::WalkForward{<:Integer}, rd::ReturnsResult)
9191
date_range = date_range + period_offset
9292
end
9393
idx = Int[]
94-
j = 1
9594
for date in date_range
96-
# if date < ti
97-
# continue
98-
# end
99-
# if date > tf
100-
# break
101-
# end
10295
i = searchsortedlast(ts, date)
10396
if !previous && ts[i] != date
10497
i += 1
10598
end
10699
if i > length(ts)
107100
break
108101
end
109-
# if j != 1 && idx[j - 1] == i
110-
# continue
111-
# end
112102
push!(idx, i)
113-
j += 1
114103
end
115104
N = length(idx)
116105
i = 1
@@ -124,7 +113,7 @@ function split_from_period(wf::WalkForward{<:Integer}, rd::ReturnsResult)
124113
if !reduce_test
125114
break
126115
end
127-
push!(test_indices, idx[(i + train_size)]:T)
116+
push!(test_indices, idx[i + train_size]:T)
128117
else
129118
push!(test_indices, idx[i + train_size]:idx[i + train_size + test_size])
130119
end
@@ -151,47 +140,25 @@ function split_from_period(wf::WalkForward{<:Any, <:Any, <:Any}, rd::ReturnsResu
151140
date_range = date_range + period_offset
152141
end
153142
idx = Int[]
154-
j = 1
155143
for date in date_range
156-
# if date < ti
157-
# continue
158-
# end
159-
# if date > tf
160-
# break
161-
# end
162144
i = searchsortedlast(ts, date)
163145
if !previous && ts[i] != date
164146
i += 1
165147
end
166148
if i > length(ts)
167149
break
168150
end
169-
if j != 1 && idx[j - 1] == i
170-
continue
171-
end
172151
push!(idx, i)
173-
j += 1
174152
end
175153

176154
train_idx = Int[]
177-
j = 1
178155
for date in date_range
179156
date = date - train_size
180-
# if date < ti
181-
# continue
182-
# end
183-
# if date > tf
184-
# break
185-
# end
186157
i = searchsortedlast(ts, date)
187158
if i > length(ts)
188159
break
189160
end
190-
if j != 1 && train_idx[j - 1] == i
191-
continue
192-
end
193161
push!(train_idx, i)
194-
j += 1
195162
end
196163
N = length(idx)
197164
i = searchsortedlast(train_idx, 0) + 1

0 commit comments

Comments
 (0)