position(amount = c(1, 1, -1, 3, -4),
timestamp = 1:5, when = 4.9)
## using a journal
J <- journal(timestamp = 1:5, amount = c(1, 1, -1, 3, -4))
position(J, when = 4.9)
## 'declaring' a position, using named amounts
amount <- c(1, 1, 1)
instrument <- c("A", "A", "B")
position(amount = amount, instrument = instrument)
## .... or equivalently
amount <- c(A = 2, B = 1)
position(amount)
## ignore names of amount
position(amount, use.names = FALSE)
## adding/subtracting positions
p1 <- position(c(A = 0.2, B = 0.8))
p2 <- position(c( B = 0.7, C = 0.3))
p1 - p2
## A 0.2
## B 0.1
## C -0.3
Run the code above in your browser using DataLab