diff --git a/README.md b/README.md index 6ea24b1..cd4990b 100644 --- a/README.md +++ b/README.md @@ -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/) diff --git a/src/cumulative_return.jl b/src/cumulative_return.jl index 1b56c24..da6881d 100644 --- a/src/cumulative_return.jl +++ b/src/cumulative_return.jl @@ -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 diff --git a/test/runtests.jl b/test/runtests.jl index a61137f..32dcb63 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -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, @@ -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