Skip to content

Functions that depend on wma don't work with Float32 arrays #40

@kpa28-git

Description

@kpa28-git

Indicators.hma(Float64.(.1:.1:10.0)) works, but Indicators.hma(Float32.(.1:.1:10.0)) throws a dispatch error when it calls wma.

I think this is because the wma is defined, both the input and weight array are of type T<:Real. By default wma's weight array will be a Float64 array, forcing the input array to also be Float64. With financial data we might sometimes want to work with Float32 or other real number types.

I think it is as simple as changing this:
function wma(x::AbstractArray{T}; n::Int64=10, wts::AbstractArray{T}=collect(1:n)/sum(1:n)) where {T<:Real}

to this:
function wma(x::AbstractArray{T}; n::Int64=10, wts::AbstractArray{W}=collect(1:n)/sum(1:n)) where {T<:Real, W<:Real}

which would allow x to be a type different from wts.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions