Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 19 additions & 7 deletions R/paramsets.R
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,20 @@ clone.portfolio <- function(portfolio.st, cloned.portfolio.st, strip.history=TRU
{
#must.have.args(match.call(), c('portfolio.st', 'cloned.portfolio.st'))

portfolio <- .getPortfolio(portfolio.st)
# must copy underlying environments IOT to actually clone
portfolio.list <- getPortfolio(portfolio.st)
if(is.environment(portfolio.list))
return() # should never happen
else
portfolio <- list2env(portfolio.list)
portfolio$symbols <- list2env(lapply(portfolio$symbols, list2env))
attributes(portfolio) <- attributes(portfolio.list)[-1] # names are no longer attributes

# sanity checks
# all.equal(.getPortfolio(portfolio.st), portfolio) # TRUE but now no longer pointer
# identical(data.table::address(portfolio), data.table::address(.getPortfolio(portfolio.st))) # FALSE, new address
# put.portfolio('test', .getPortfolio(portfolio.st)) # make test portfolio
# identical(data.table::address(.getPortfolio('test')), data.table::address(.getPortfolio(portfolio.st))) # TRUE, point to same address

if(strip.history==TRUE)
{
Expand All @@ -72,15 +85,14 @@ clone.orderbook <- function(portfolio.st, cloned.portfolio.st, strip.history=TRU
#must.have.args(match.call(), c('portfolio.st', 'cloned.portfolio.st'))

orderbook <- getOrderBook(portfolio.st)

i <- 1 # TODO: find index number by name
names(orderbook)[i] <- cloned.portfolio.st
names(orderbook) <- cloned.portfolio.st

if(strip.history == TRUE)
{
for(symbol in names(orderbook[[portfolio.st]]))
orderbook[[portfolio.st]][[symbol]] <- orderbook[[portfolio.st]][[symbol]][1,]
}
symbols <- names(orderbook[[cloned.portfolio.st]])
for(symbol in symbols)
orderbook[[cloned.portfolio.st]][symbol] <- list(NULL)
}

put.orderbook(cloned.portfolio.st, orderbook)
}
Expand Down