Skip to content

Commit

Permalink
feat: Indexing reward
Browse files Browse the repository at this point in the history
Signed-off-by: Anirudh <[email protected]>
  • Loading branch information
anirudh2 committed Mar 14, 2023
1 parent 3b8ead8 commit 1ac9da2
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/domain.jl
Original file line number Diff line number Diff line change
Expand Up @@ -375,3 +375,23 @@ function newtokenissuance(n::FlexTable, config::Dict)
newtokens = p*(r^t - 1.0)
return newtokens
end

"""
indexingreward(x, Ω, ψ, Φ, Ψ)
The indexing rewards for the allocation vector `x` given signals `ψ`, the existing
allocations on subgraphs `Ω`, token issuance `Φ`, and total signal `Ψ`.
```julia
julia> ψ = [0.0, 1.0]
julia> Ω = [0.0, 0.0]
julia> Φ = 1.0
julia> Ψ = 2.0
julia> x = [0.0, 1.0]
julia> AllocationOpt.indexingreward(x, Ω, ψ, Φ, Ψ)
```
"""
function indexingreward(x, Ω, ψ, Φ, Ψ)
sr = Φ * ψ / Ψ
return sum(sr .* x ./ (x .+ Ω))
end
23 changes: 23 additions & 0 deletions test/domain.jl
Original file line number Diff line number Diff line change
Expand Up @@ -154,4 +154,27 @@
@test AllocationOpt.newtokenissuance(n, config) == 1
end

@testset "indexingreward" begin
ψ = [0.0, 1.0]
Ω = [1.0, 1.0]
Φ = 1.0
Ψ = 2.0
x = [1.0, 0.0]
@test AllocationOpt.indexingreward(x, Ω, ψ, Φ, Ψ) == 0.0

ψ = [0.0, 1.0]
Ω = [1.0, 1.0]
Φ = 1.0
Ψ = 2.0
x = [0.0, 1.0]
@test AllocationOpt.indexingreward(x, Ω, ψ, Φ, Ψ) == 0.25

ψ = [1.0, 1.0]
Ω = [1.0, 1.0]
Φ = 1.0
Ψ = 2.0
x = [1.0, 1.0]
@test AllocationOpt.indexingreward(x, Ω, ψ, Φ, Ψ) == 0.5
end

end

0 comments on commit 1ac9da2

Please sign in to comment.