-
Notifications
You must be signed in to change notification settings - Fork 9
/
payoffs.R
51 lines (40 loc) · 1.29 KB
/
payoffs.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
Payoffs <- function ( g,
ct # current time
){
require(igraph)
######
## Useful variables
######
n.secu <- length((V(g)$secu)[[1]])
n.traders <- length(V(g))
n.approx <- length(unique(V(g)$approx))
######
## Actual temperature
######
time <- g$burn.in + g$horizon
anom.star <- g$t.anom[ct]
min.trad <- min(g$secu.inter)
max.trad <- max(g$secu.inter)
#### Pay securities
#
# TODO: Check that indexing is correct. Check for edge conditions and off-by-one.
#
which.payoff <- findInterval(anom.star, g$secu.inter) + 1
if(length(g$secu.inter) != n.secu - 1) warning("Mismatch between n.secu and length of secu.inter")
if (! which.payoff %in% 1:n.secu) warning("Index out of range in Payoffs")
message("Payoff for ", ct, " = ", which.payoff, ": temperature = ", anom.star)
## Check for accuracy
for (i in 1:n.secu) {
if ((i == 1 || g$secu.inter[i-1] <= anom.star) && (i == n.secu || anom.star < g$secu.inter[i])) {
if (which.payoff != i) warning("Internal inconsistency in Payoffs")
}
}
# Make payoffs
for (i in 1:n.traders) {
V(g)$money[i] <- V(g)$money[i] + V(g)$secu[[i]][which.payoff]
}
#######
## Return the network
#######
g
}