Skip to content

Commit

Permalink
Fix cumulative return
Browse files Browse the repository at this point in the history
  • Loading branch information
femtotrader committed Apr 23, 2024
1 parent 70ffb0a commit 129e95b
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 9 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

[![Build Status](https://github.com/femtotrader/OnlinePortfolioAnalytics.jl/actions/workflows/CI.yml/badge.svg?branch=main)](https://github.com/femtotrader/OnlinePortfolioAnalytics.jl/actions/workflows/CI.yml?query=branch%3Amain)

This project implements aims to provide users with functionality for performing quantitative portfolio analytics via [online algorithms](https://en.wikipedia.org/wiki/Online_algorithm).
This project aims to provide users with functionality for performing quantitative portfolio analytics via [online algorithms](https://en.wikipedia.org/wiki/Online_algorithm).

It depends especially on [OnlineStatsBase.jl](https://joshday.github.io/OnlineStats.jl/)

Expand Down
10 changes: 5 additions & 5 deletions src/cumulative_return.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@ mutable struct CumulativeReturn{T} <: PortfolioAnalytics{T}
value::T
n::Int

sum::Sum
prod::Prod

function CumulativeReturn{T}() where {T}
val = zero(T)
s = Sum()
new{T}(val, 0, s)
p = Prod()
new{T}(val, 0, p)
end
end

function OnlineStatsBase._fit!(stat::CumulativeReturn, data)
fit!(stat.sum, data)
fit!(stat.prod, 1 + data)
stat.n += 1
stat.value = 1 + value(stat.sum)
stat.value = value(stat.prod)
end
4 changes: 1 addition & 3 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -214,8 +214,6 @@ const weights = [0.4, 0.4, 0.2]
push!(cum_returns, value)
end
subscribe!(mapped_source, observer)
#@test isapprox(values[1], 1.1245, atol = ATOL)
#@test isapprox(values[end], 1.51812, atol = ATOL)

expected_cum_returns = [
1.1245,
Expand All @@ -231,7 +229,7 @@ const weights = [0.4, 0.4, 0.2]
1.6222,
1.4976
]
#println(cum_returns)
@test all(isapprox.(cum_returns, expected_cum_returns, atol = ATOL))

end

Expand Down

0 comments on commit 129e95b

Please sign in to comment.