@@ -188,7 +188,7 @@ skewness parameter, scale parameter (dispersion^1/α) and location parameter res
188188
189189α, β, c and δ are computed based on McCulloch (1986) fractile.
190190"""
191- function Distributions. fit (:: Type{<:AlphaStable} , x, alg= QuickSort)
191+ function Distributions. fit (:: Type{<:AlphaStable} , x:: AbstractArray{T} , alg= QuickSort) where {T}
192192 sx = sort (x, alg= alg)
193193 p = quantile .(Ref (sx), (0.05 , 0.25 , 0.28 , 0.5 , 0.72 , 0.75 , 0.95 ), sorted= true )
194194 να = (p[7 ]- p[1 ]) / (p[6 ]- p[2 ])
@@ -212,7 +212,7 @@ function Distributions.fit(::Type{<:AlphaStable}, x, alg=QuickSort)
212212 else
213213 δ = ζ - β * c * tan (π* α/ 2 )
214214 end
215- return AlphaStable (α= α , β= β , scale= c , location= oftype (α, δ))
215+ return AlphaStable (α= T (α) , β= T (β) , scale= T (c) , location= T ( δ))
216216end
217217
218218Base. @kwdef struct SymmetricAlphaStable{T} <: Distributions.ContinuousUnivariateDistribution
@@ -235,12 +235,12 @@ returns `SymmetricAlphaStable`
235235scale is computed based on Fama & Roll (1971) fractile.
236236location is the 50% trimmed mean of the sample.
237237"""
238- function Distributions. fit (:: Type{<:SymmetricAlphaStable} , x, alg= QuickSort)
238+ function Distributions. fit (:: Type{<:SymmetricAlphaStable} , x:: AbstractArray{T} , alg= QuickSort) where {T}
239239 sx = sort (x, alg= alg)
240240 δ = mean (@view (sx[end ÷ 4 : (3 * end )÷ 4 ]))
241241 p = quantile .(Ref (sx), (0.05 , 0.25 , 0.28 , 0.72 , 0.75 , 0.95 ), sorted= true )
242- c = (p[4 ]- p[3 ])/ 1.654
243- an = (p[6 ]- p[1 ])/ (p[5 ]- p[2 ])
242+ c = (p[4 ]- p[3 ]) / 1.654
243+ an = (p[6 ]- p[1 ]) / (p[5 ]- p[2 ])
244244 if an < 2.4388
245245 α = 2.
246246 else
@@ -253,7 +253,7 @@ function Distributions.fit(::Type{<:SymmetricAlphaStable}, x, alg=QuickSort)
253253 if α < 0.5
254254 α = 0.5
255255 end
256- return SymmetricAlphaStable (α= α , scale= c , location= oftype (α, δ))
256+ return SymmetricAlphaStable (α= T (α) , scale= T (c) , location= T ( δ))
257257end
258258
259259"""
@@ -322,16 +322,12 @@ The maximum acceptable size of `R` is `10x10`
322322julia> x = rand(AlphaSubGaussian(n=1000))
323323```
324324"""
325- Base. @kwdef struct AlphaSubGaussian{T<: AbstractFloat } <: Distributions.ContinuousUnivariateDistribution
325+ Base. @kwdef struct AlphaSubGaussian{T<: AbstractFloat ,M <: AbstractMatrix } <: Distributions.ContinuousUnivariateDistribution
326326 α:: T = 1.50
327- R:: AbstractMatrix{T} = SMatrix {5,5} (collect (SymmetricToeplitz ([1.0000 , 0.5804 , 0.2140 , 0.1444 , - 0.0135 ])))
327+ R:: M = SMatrix {5,5} (collect (SymmetricToeplitz ([1.0000 , 0.5804 , 0.2140 , 0.1444 , - 0.0135 ])))
328328 n:: Int
329329end
330330
331- AlphaSubGaussian (α:: T , n:: Int ) where {T<: AbstractFloat } = AlphaSubGaussian (α= α,
332- R= SMatrix {5,5} (T .(collect (SymmetricToeplitz ([1.0000 , 0.5804 , 0.2140 , 0.1444 , - 0.0135 ])))),
333- n= n)
334-
335331"""
336332Generates the conditional probability f(X2|X1) if [X1, X2] is a sub-Gaussian
337333stable random vector such that X1(i)~X2~S(alpha,delta) and rho is the correlation
377373function Random. rand! (rng:: AbstractRNG , d:: AlphaSubGaussian{T} , x:: AbstractArray{T} ) where {T<: Real }
378374 α= d. α; R= d. R; n= d. n
379375 length (x) >= n || throw (ArgumentError (" length of x must be at least n" ))
380- α ∈ T .( 1.10 : 0.01 : 1.98 ) || throw (DomainError (α, " α must lie within `1.10:0.01:1.98`" ))
376+ α ∈ 1.10 : 0.01 : 1.98 || throw (DomainError (α, " α must lie within `1.10:0.01:1.98`" ))
381377 m = size (R, 1 )- 1
382378 funk1 = x -> (2 ^ α)* sin (π* α/ 2 )* gamma ((α+ 2 )/ 2 )* gamma ((α+ x)/ 2 )/ (gamma (x/ 2 )* π* α/ 2 )
383379 funk2 = x -> 4 * gamma (x/ α)/ ((α* 2 ^ 2 )* gamma (x/ 2 )^ 2 )
430426
431427
432428Base. rand (rng:: AbstractRNG , d:: AlphaSubGaussian ) = rand! (rng, d, zeros (eltype (d), d. n))
433- Base. eltype (:: Type{<:AlphaSubGaussian{T}} ) where {T} = T
429+ Base. eltype (:: Type{<:AlphaSubGaussian} ) = Float64
434430
435431"""
436432 fit(d::Type{<:AlphaSubGaussian}, x, m; p=1.0)
0 commit comments