Skip to content

Commit f943b94

Browse files
committed
output types to float. input types within the reals.
1 parent f1c1242 commit f943b94

File tree

6 files changed

+121
-121
lines changed

6 files changed

+121
-121
lines changed

src/ma.jl

+16-16
Original file line numberDiff line numberDiff line change
@@ -5,25 +5,25 @@ sma(x::Array{T}; n::Int64=10)::Array{T}
55
66
Simple moving average (SMA)
77
"""
8-
function sma(x::Array{T}; n::Int64=10)::Array{T} where {T<:Real}
8+
function sma(x::Array{T}; n::Int64=10)::Array{Float64} where {T<:Real}
99
return runmean(x, n=n, cumulative=false)
1010
end
1111

1212
"""
1313
```
14-
trima(x::Array{T}; n::Int64=10, ma::Function=sma, args...)::Array{T}
14+
trima(x::Array{T}; n::Int64=10, ma::Function=sma, args...)::Array{Float64}
1515
```
1616
1717
1818
Triangular moving average (TRIMA)
1919
"""
20-
function trima(x::Array{T}; n::Int64=10, ma::Function=sma)::Array{T} where {T<:Real}
20+
function trima(x::Array{T}; n::Int64=10, ma::Function=sma)::Array{Float64} where {T<:Real}
2121
return ma(ma(x, n=n), n=n)
2222
end
2323

2424
"""
2525
```
26-
wma(x::Array{T}; n::Int64=10, wts::Array{T}=collect(1:n)/sum(1:n))::Array{T}
26+
wma(x::Array{T}; n::Int64=10, wts::Array{T}=collect(1:n)/sum(1:n))::Array{Float64}
2727
```
2828
2929
Weighted moving average (WMA)
@@ -52,7 +52,7 @@ end
5252

5353
"""
5454
```
55-
ema(x::Array{T}; n::Int64=10, alpha::T=2.0/(n+1.0), wilder::Bool=false)::Array{T}
55+
ema(x::Array{T}; n::Int64=10, alpha::T=2.0/(n+1.0), wilder::Bool=false)::Array{Float64}
5656
```
5757
5858
Exponential moving average (EMA)
@@ -74,7 +74,7 @@ end
7474

7575
"""
7676
```
77-
mma(x::Array{T}; n::Int64=10)::Array{T}
77+
mma(x::Array{T}; n::Int64=10)::Array{Float64}
7878
```
7979
8080
Modified moving average (MMA)
@@ -85,7 +85,7 @@ end
8585

8686
"""
8787
```
88-
dema(x::Array{T}; n::Int64=10, alpha=2.0/(n+1), wilder::Bool=false)::Array{T}
88+
dema(x::Array{T}; n::Int64=10, alpha=2.0/(n+1), wilder::Bool=false)::Array{Float64}
8989
```
9090
9191
Double exponential moving average (DEMA)
@@ -98,7 +98,7 @@ end
9898

9999
"""
100100
```
101-
tema(x::Array{T}; n::Int64=10, alpha=2.0/(n+1), wilder::Bool=false)::Array{T}
101+
tema(x::Array{T}; n::Int64=10, alpha=2.0/(n+1), wilder::Bool=false)::Array{Float64}
102102
```
103103
104104
Triple exponential moving average (TEMA)
@@ -114,12 +114,12 @@ end
114114

115115
"""
116116
```
117-
mama(x::Array{T}; fastlimit::T=0.5, slowlimit::T=0.05)::Matrix{T}
117+
mama(x::Array{T}; fastlimit::T=0.5, slowlimit::T=0.05)::Matrix{Float64}
118118
```
119119
120120
MESA adaptive moving average (MAMA)
121121
"""
122-
function mama(x::Array{T}; fastlimit::T=0.5, slowlimit::T=0.05)::Matrix{T} where {T<:Real}
122+
function mama(x::Array{T}; fastlimit::T=0.5, slowlimit::T=0.05)::Matrix{Float64} where {T<:Real}
123123
n = size(x,1)
124124
out = zeros(T, n, 2)
125125
#smooth = [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0]
@@ -281,7 +281,7 @@ end
281281

282282
"""
283283
```
284-
hma(x::Array{T}; n::Int64=20)::Array{T}
284+
hma(x::Array{T}; n::Int64=20)::Array{Float64}
285285
```
286286
287287
Hull moving average (HMA)
@@ -330,12 +330,12 @@ end
330330

331331
"""
332332
```
333-
alma{T}(x::Array{T}; n::Int64=9, offset::T=0.85, sigma::T=6.0)::Array{T}
333+
alma{T}(x::Array{T}; n::Int64=9, offset::T=0.85, sigma::T=6.0)::Array{Float64}
334334
```
335335
336336
Arnaud-Legoux moving average (ALMA)
337337
"""
338-
function alma(x::Array{T}; n::Int64=9, offset::T=0.85, sigma::T=6.0)::Array{T} where {T<:Real}
338+
function alma(x::Array{T}; n::Int64=9, offset::T=0.85, sigma::T=6.0)::Array{Float64} where {T<:Real}
339339
@assert n<size(x,1) && n>0 "Argument n out of bounds."
340340
@assert sigma>0.0 "Argument sigma must be greater than 0."
341341
@assert offset>=0.0 && offset<=1 "Argument offset must be in (0,1)."
@@ -354,7 +354,7 @@ function alma(x::Array{T}; n::Int64=9, offset::T=0.85, sigma::T=6.0)::Array{T} w
354354
return out
355355
end
356356

357-
function lagged(x::Array{T}, n::Int=1)::Array{T} where {T<:Real}
357+
function lagged(x::Array{T}, n::Int=1)::Array{Float64} where {T<:Real}
358358
if n > 0
359359
return [fill(NaN,n); x[1:end-n]]
360360
elseif n < 0
@@ -366,11 +366,11 @@ end
366366

367367
"""
368368
```
369-
zlema(x::Array{T}; n::Int=10, ema_args...)::Array{T}
369+
zlema(x::Array{T}; n::Int=10, ema_args...)::Array{Float64}
370370
```
371371
372372
Zero-lag exponential moving average (ZLEMA)
373373
"""
374-
function zlema(x::Array{T}; n::Int=10, ema_args...)::Array{T} where {T<:Real}
374+
function zlema(x::Array{T}; n::Int=10, ema_args...)::Array{Float64} where {T<:Real}
375375
return ema(x+(x-lagged(x,round(Int, (n-1)/2.0))), n=n; ema_args...)
376376
end

src/mom.jl

+26-26
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
"""
44
```
5-
aroon(hl::Matrix{T}; n::Int64=25)::Array{T}
5+
aroon(hl::Matrix{T}; n::Int64=25)::Array{Float64}
66
```
77
88
Aroon up/down/oscillator
@@ -13,7 +13,7 @@ Aroon up/down/oscillator
1313
- Column 2: Aroon Down
1414
- Column 3: Aroon Oscillator
1515
"""
16-
function aroon(hl::Matrix{T}; n::Int64=25)::Matrix{T} where {T<:Real}
16+
function aroon(hl::Matrix{T}; n::Int64=25)::Matrix{Float64} where {T<:Real}
1717
@assert size(hl,2) == 2 "Argument `hl` must have exactly 2 columns."
1818
@assert n < size(hl,1) "Argument `n` must be less than the number of rows in argument `hl`."
1919
out = zeros(T, (size(hl,1),3))
@@ -30,7 +30,7 @@ end
3030

3131
"""
3232
```
33-
donch(hl::Matrix{T}; n::Int64=10, inclusive::Bool=true)::Array{T}
33+
donch(hl::Matrix{T}; n::Int64=10, inclusive::Bool=true)::Array{Float64}
3434
```
3535
3636
Donchian channel (if inclusive is set to true, will include current bar in calculations.)
@@ -41,7 +41,7 @@ Donchian channel (if inclusive is set to true, will include current bar in calcu
4141
- Column 2: Average of highest high and lowest low of last `n` periods
4242
- Column 3: Highest high of last `n` periods
4343
"""
44-
function donch(hl::Matrix{T}; n::Int64=10, inclusive::Bool=true)::Matrix{T} where {T<:Real}
44+
function donch(hl::Matrix{T}; n::Int64=10, inclusive::Bool=true)::Matrix{Float64} where {T<:Real}
4545
@assert size(hl,2) == 2 "Argument `hl` must have exactly 2 columns."
4646
local lower::Array{T} = runmin(hl[:,2], n=n, cumulative=false, inclusive=inclusive)
4747
local upper::Array{T} = runmax(hl[:,1], n=n, cumulative=false, inclusive=inclusive)
@@ -51,24 +51,24 @@ end
5151

5252
"""
5353
```
54-
momentum(x::Array{T}; n::Int64=1)::Array{T}
54+
momentum(x::Array{T}; n::Int64=1)::Array{Float64}
5555
```
5656
5757
Momentum indicator (price now vs price `n` periods back)
5858
"""
59-
function momentum(x::Array{T}; n::Int64=1)::Array{T} where {T<:Real}
59+
function momentum(x::Array{T}; n::Int64=1)::Array{Float64} where {T<:Real}
6060
@assert n>0 "Argument n must be positive."
6161
return diffn(x, n=n)
6262
end
6363

6464
"""
6565
```
66-
roc(x::Array{T}; n::Int64=1)::Array{T}
66+
roc(x::Array{T}; n::Int64=1)::Array{Float64}
6767
```
6868
6969
Rate of change indicator (percent change between i'th observation and (i-n)'th observation)
7070
"""
71-
function roc(x::Array{T}; n::Int64=1)::Array{T} where {T<:Real}
71+
function roc(x::Array{T}; n::Int64=1)::Array{Float64} where {T<:Real}
7272
@assert n<size(x,1) && n>0 "Argument n out of bounds."
7373
out = zeros(size(x)) .* NaN
7474
@inbounds for i = (n+1):size(x,1)
@@ -79,7 +79,7 @@ end
7979

8080
"""
8181
```
82-
macd(x::Array{T}; nfast::Int64=12, nslow::Int64=26, nsig::Int64=9)::Array{T}
82+
macd(x::Array{T}; nfast::Int64=12, nslow::Int64=26, nsig::Int64=9)::Array{Float64}
8383
```
8484
8585
Moving average convergence-divergence
@@ -91,7 +91,7 @@ Moving average convergence-divergence
9191
- Column 3: MACD Histogram
9292
"""
9393
function macd(x::Array{T}; nfast::Int64=12, nslow::Int64=26, nsig::Int64=9,
94-
fastMA::Function=ema, slowMA::Function=ema, signalMA::Function=sma)::Matrix{T} where {T<:Real}
94+
fastMA::Function=ema, slowMA::Function=ema, signalMA::Function=sma)::Matrix{Float64} where {T<:Real}
9595
out = zeros(T, (length(x),3))
9696
out[:,1] = fastMA(x, n=nfast) - slowMA(x, n=nslow)
9797
out[:,2] = signalMA(out[:,1], n=nsig)
@@ -101,12 +101,12 @@ end
101101

102102
"""
103103
```
104-
rsi(x::Array{T}; n::Int64=14, ma::Function=ema, args...)::Array{T}
104+
rsi(x::Array{T}; n::Int64=14, ma::Function=ema, args...)::Array{Float64}
105105
```
106106
107107
Relative strength index
108108
"""
109-
function rsi(x::Array{T}; n::Int64=14, ma::Function=ema, args...)::Array{T} where {T<:Real}
109+
function rsi(x::Array{T}; n::Int64=14, ma::Function=ema, args...)::Array{Float64} where {T<:Real}
110110
@assert n<size(x,1) && n>0 "Argument n is out of bounds."
111111
N = size(x,1)
112112
ups = zeros(N)
@@ -126,7 +126,7 @@ end
126126

127127
"""
128128
```
129-
adx(hlc::Array{T}; n::Int64=14, wilder=true)::Array{T}
129+
adx(hlc::Array{T}; n::Int64=14, wilder=true)::Array{Float64}
130130
```
131131
132132
Average directional index
@@ -137,7 +137,7 @@ Average directional index
137137
- Column 2: DI-
138138
- Column 3: ADX
139139
"""
140-
function adx(hlc::Array{T}; n::Int64=14, ma::Function=ema, args...)::Matrix{T} where {T<:Real}
140+
function adx(hlc::Array{T}; n::Int64=14, ma::Function=ema, args...)::Matrix{Float64} where {T<:Real}
141141
@assert n<size(hlc,1) && n>0 "Argument n is out of bounds."
142142
if size(hlc,2) != 3
143143
error("HLC array must have three columns")
@@ -164,7 +164,7 @@ end
164164

165165
"""
166166
```
167-
psar(hl::Array{T}; af_min::T=0.02, af_max::T=0.2, af_inc::T=af_min)::Array{T}
167+
psar(hl::Array{T}; af_min::T=0.02, af_max::T=0.2, af_inc::T=af_min)::Array{Float64}
168168
```
169169
170170
Parabolic stop and reverse (SAR)
@@ -175,7 +175,7 @@ Parabolic stop and reverse (SAR)
175175
- `af_max`: maximum acceleration factor (accel factor capped at this value)
176176
- `af_inc`: increment to the acceleration factor (speed of increase in accel factor)
177177
"""
178-
function psar(hl::Array{T}; af_min::T=0.02, af_max::T=0.2, af_inc::T=af_min)::Array{T} where {T<:Real}
178+
function psar(hl::Array{T}; af_min::T=0.02, af_max::T=0.2, af_inc::T=af_min)::Array{Float64} where {T<:Real}
179179
@assert af_min<1.0 && af_min>0.0 "Argument af_min must be in [0,1]."
180180
@assert af_max<1.0 && af_max>0.0 "Argument af_max must be in [0,1]."
181181
@assert af_inc<1.0 && af_inc>0.0 "Argument af_inc must be in [0,1]."
@@ -227,14 +227,14 @@ end
227227
```
228228
kst(x::Array{T};
229229
nroc::Array{Int64}=[10,15,20,30], navg::Array{Int64}=[10,10,10,15],
230-
wgts::Array{Int64}=collect(1:length(nroc)), ma::Function=sma)::Array{T}
230+
wgts::Array{Int64}=collect(1:length(nroc)), ma::Function=sma)::Array{Float64}
231231
232232
```
233233
234234
KST (Know Sure Thing) -- smoothed and summed rates of change
235235
"""
236236
function kst(x::Array{T}; nroc::Array{Int64}=[10,15,20,30], navg::Array{Int64}=[10,10,10,15],
237-
wgts::Array{Int64}=collect(1:length(nroc)), ma::Function=sma)::Array{T} where {T<:Real}
237+
wgts::Array{Int64}=collect(1:length(nroc)), ma::Function=sma)::Array{Float64} where {T<:Real}
238238
@assert length(nroc) == length(navg)
239239
@assert all(nroc.>0) && all(nroc.<size(x,1))
240240
@assert all(navg.>0) && all(navg.<size(x,1))
@@ -249,25 +249,25 @@ end
249249

250250
"""
251251
```
252-
wpr(hlc::Matrix{T}, n::Int64=14)::Array{T}
252+
wpr(hlc::Matrix{T}, n::Int64=14)::Array{Float64}
253253
```
254254
255255
Williams %R
256256
"""
257-
function wpr(hlc::Matrix{T}; n::Int64=14)::Array{T} where {T<:Real}
257+
function wpr(hlc::Matrix{T}; n::Int64=14)::Array{Float64} where {T<:Real}
258258
hihi = runmax(hlc[:,1], n=n, cumulative=false)
259259
lolo = runmin(hlc[:,2], n=n, cumulative=false)
260260
return -100 * (hihi - hlc[:,3]) ./ (hihi - lolo)
261261
end
262262

263263
"""
264264
```
265-
cci(hlc::Matrix{T}; n::Int64=20, c::T=0.015, ma::Function=sma)::Array{T}
265+
cci(hlc::Matrix{T}; n::Int64=20, c::T=0.015, ma::Function=sma)::Array{Float64}
266266
```
267267
268268
Commodity channel index
269269
"""
270-
function cci(hlc::Matrix{T}; n::Int64=20, c::T=0.015, ma::Function=sma, args...)::Array{T} where {T<:Real}
270+
function cci(hlc::Matrix{T}; n::Int64=20, c::T=0.015, ma::Function=sma, args...)::Array{Float64} where {T<:Real}
271271
tp = (hlc[:,1] + hlc[:,2] + hlc[:,3]) ./ 3.0
272272
dev = runmad(tp, n=n, cumulative=false, fun=mean)
273273
avg = ma(tp, n=n; args...)
@@ -276,13 +276,13 @@ end
276276

277277
"""
278278
```
279-
stoch(hlc::Matrix{T}; nK::Int64=14, nD::Int64=3, kind::Symbol=:fast, ma::Function=sma, args...)::Matrix{T}
279+
stoch(hlc::Matrix{T}; nK::Int64=14, nD::Int64=3, kind::Symbol=:fast, ma::Function=sma, args...)::Matrix{Float64}
280280
```
281281
282282
Stochastic oscillator (fast or slow)
283283
"""
284284
function stoch(hlc::Matrix{T}; nK::Int64=14, nD::Int64=3,
285-
kind::Symbol=:fast, ma::Function=sma, args...)::Matrix{T} where {T<:Real}
285+
kind::Symbol=:fast, ma::Function=sma, args...)::Matrix{Float64} where {T<:Real}
286286
@assert kind == :fast || kind == :slow "Argument `kind` must be either :fast or :slow"
287287
@assert nK<size(hlc,1) && nK>0 "Argument `nK` out of bounds."
288288
@assert nD<size(hlc,1) && nD>0 "Argument `nD` out of bounds."
@@ -301,13 +301,13 @@ end
301301
"""
302302
```
303303
smi(hlc::Matrix{T}; n::Int64=13, nFast::Int64=2, nSlow::Int64=25, nSig::Int64=9,
304-
maFast::Function=ema, maSlow::Function=ema, maSig::Function=sma)::Matrix{T}
304+
maFast::Function=ema, maSlow::Function=ema, maSig::Function=sma)::Matrix{Float64}
305305
```
306306
307307
SMI (stochastic momentum oscillator)
308308
"""
309309
function smi(hlc::Matrix{T}; n::Int64=13, nFast::Int64=2, nSlow::Int64=25, nSig::Int64=9,
310-
maFast::Function=ema, maSlow::Function=ema, maSig::Function=sma)::Matrix{T} where {T<:Real}
310+
maFast::Function=ema, maSlow::Function=ema, maSig::Function=sma)::Matrix{Float64} where {T<:Real}
311311
hihi = runmax(hlc[:,1], n=n, cumulative=false)
312312
lolo = runmin(hlc[:,2], n=n, cumulative=false)
313313
hldif = hihi-lolo

0 commit comments

Comments
 (0)