MarketTechnicals.jl icon indicating copy to clipboard operation
MarketTechnicals.jl copied to clipboard

Update utilities.jl

Open millerjoey opened this issue 3 years ago • 3 comments

Fix to lagfill to address issue #133

millerjoey avatar Nov 05 '21 01:11 millerjoey

Codecov Report

Merging #134 (d5b9bc6) into master (f0b6e22) will increase coverage by 0.28%. The diff coverage is 0.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #134      +/-   ##
==========================================
+ Coverage   62.81%   63.10%   +0.28%     
==========================================
  Files           8        8              
  Lines         433      458      +25     
==========================================
+ Hits          272      289      +17     
- Misses        161      169       +8     
Impacted Files Coverage Δ
src/utilities.jl 81.69% <0.00%> (-10.12%) :arrow_down:
src/movingaverages.jl 100.00% <0.00%> (ø)
src/momentum.jl 36.19% <0.00%> (+0.79%) :arrow_up:
src/volume.jl 51.51% <0.00%> (+1.51%) :arrow_up:

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update f0b6e22...d5b9bc6. Read the comment docs.

codecov[bot] avatar Nov 09 '21 02:11 codecov[bot]

diff --git a/src/utilities.jl b/src/utilities.jl
index 844d746..edc2fc0 100644
--- a/src/utilities.jl
+++ b/src/utilities.jl
@@ -92,19 +92,16 @@ function lagfill(ta::TimeArray, r1::Integer, fill::AbstractFloat)
   _lta_values = values(_lta)
   _lta_values[1:r1] .= fill
 
-  TimeArray(timestamp(ta), _lta_values, colnames(ta))
+  TimeArray(timestamp(ta), _lta_values, colnames(ta), unchecked = true)
 end
 
-function lagfill(ta::TimeArray, r1::Integer, fill::AbstractMatrix{T}) where T<:AbstractFloat
+function lagfill(ta::TimeArray, r1::Integer, fill::AbstractMatrix{<:AbstractFloat})
   @assert size(fill, 2) == size(ta, 2)
   _lta = lag(ta, r1, padding = true)
   _lta_values = values(_lta)
+  _lta_values[1:r1, :] .= fill
 
-  for i in 1:r1
-    _lta_values[i, :] = fill
-  end
-
-  TimeArray(timestamp(ta), _lta_values, colnames(ta))
+  TimeArray(timestamp(ta), _lta_values, colnames(ta), unchecked = true)
 end
 
 _nanmean(x) = mean(filter(!isnan, x))

iblislin avatar Nov 09 '21 02:11 iblislin

And maybe we need to fix the colname of dpo

diff --git a/src/momentum.jl b/src/momentum.jl
index d73f151..a42f931 100644
--- a/src/momentum.jl
+++ b/src/momentum.jl
@@ -349,7 +349,7 @@ function dpo(ta::TimeArray, n::Integer = 14)
   lagPeriod = Int(floor(0.5*n) + 1)
   _lagc = lagfill(ta, lagPeriod, nanmean(values(ta)))
 
-  dpo = rename(_lagc .- moving(nanmean, ta, n), [:dpo])
+  dpo = rename!(_lagc .- moving(nanmean, ta, n), gen_colnames(colnames(ta), [:dpo]))
 end
 
 """

iblislin avatar Nov 09 '21 03:11 iblislin