rmv-methods: Generic 'remove' method

removeR Documentation

Generic remove method

Description

Implemented for various purposes.

Each element of the what parameter is expected to point to an element in the RiskFactorConnector by their 'keys'. All elements that can be found in RiskFactorConnector are removed.

Remove contracts from a portfolio by their respective ContractIDs.

Usage

remove(object, what, ...)

## S4 method for signature 'RiskFactorConnector,character'
remove(object, what, ...)

## S4 method for signature 'Portfolio,character'
remove(object, what, ...)

Arguments

object

An object of class Portfolio or PortfolioFast

what

A single or vector of characters representing the ContractIDs of the contracts to be removed

...

See Also

add

add

Examples

yc <- YieldCurve() # create a YieldCurve object
tenors <- c("1W", "1M", "6M", "1Y", "2Y", "5Y")
rates <- c(0.001, 0.0015, 0.002, 0.01, 0.02, 0.03)
set(yc, what = list(MarketObjectCode = "YC_Prim",
    Nodes = list(ReferenceDate = "2015-01-01", 
    Tenors = tenors, Rates = rates)))

ind <- Index() # create a ReferenceIndex object
times <- c("2015-01-01", "2016-01-01", "2017-01-01", "2018-01-01",
           "2019-01-01")
values <- c(100, 110, 120, 130, 140)
set(ind, what=list(MarketObjectCode = "CHF_SMI",
    Data=list(Dates=times,Values=values)))
    
fx <- FxRate() # create an FX-Rate object
times <- c("2015-01-01", "2016-01-01", "2017-01-01", 
           "2018-01-01", "2019-01-01")
values <- c(1.04, 1.05, 1.2, 1.0, 0.9)
set(fx, what=list(MarketObjectCode = "CHF/USD",
    Data=list(Dates=times,Values=values)))   
    
rf <- RFConn() # create a RiskFactorConnector object
add(rf,list(yc,ind,fx)) # add all risk factors to the RiskFactorConnector
containsID(rf, c("YC_Prim", "CHF_SMI", "YC_2"))
remove(rf, "YC_Prim")
containsID(rf, c("YC_Prim", "CHF_SMI", "YC_2"))

# load contract demo data
data(BondPortfolio)

# create new portfolio
ptf <- Portfolio()

# import the portfolio
import(ptf, BondPortfolio)

# get ContractIDs of the contracts in the
get(ptf, "ids")

# remove the first contract from the portfolio
remove(ptf, get(ptf, "ids")[1])


wbreymann/FEMS documentation built on Dec. 8, 2022, 9:43 a.m.