Skip to content

Commit

Permalink
added volume weighted average price
Browse files Browse the repository at this point in the history
  • Loading branch information
Bapireddy Karri authored and Bapireddy Karri committed Sep 17, 2020
1 parent 37c65a3 commit bc3d57a
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/ma.jl
Original file line number Diff line number Diff line change
Expand Up @@ -395,3 +395,20 @@ function vwma(cv::Matrix{T}, n::Int64=10)::Array{Float64} where {T<:Real}
end
return out
end


"""
```
vwap(cv::Matrix{T})::Array{T}
```
volume weighted average price (VWAP)
"""
function vwap(cv::Matrix{T})::Array{Float64} where {T<:Real}
out = zeros(size(cv))[1]
close_price = cv[:,1]
volume = cv[:,2]
out = cumsum(close_price .* volume) ./ cumsum(volume)
end
return out
end
3 changes: 3 additions & 0 deletions test/ma.jl
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,9 @@
@test size(tmp, 2) == 1
tmp = vwma(X)
@test size(tmp, 1) == N
@test size(tmp, 2) == 1
tmp = vwap(X)
@test size(tmp, 1) == N
@test size(tmp, 2) == 1
end
end

0 comments on commit bc3d57a

Please sign in to comment.