add-methods: Generic 'add' method

addR Documentation

Generic add method

Description

Implemented for various purposes.

Each element of the what parameter is expected to be an instance of RiskFactor class. All elements are added to the RiskFactorConnector object for later 'linking' to an ACTUS CT.

Add an instance of RiskFactor class to the RiskFactorConnector object for later 'linking' to an ACTUS CT.

Add additional contracts, i.e. ContractType-objects, to the portfolio.

Usage

add(object, what, ...)

## S4 method for signature 'RiskFactorConnector,list'
add(object, what, ...)

## S4 method for signature 'RiskFactorConnector,RiskFactor'
add(object, what, ...)

## S4 method for signature 'Portfolio,ContractType'
add(object, what, ...)

## S4 method for signature 'Portfolio,list'
add(object, what, ...)

Arguments

object

An object of class Portfolio or PortfolioFast

what

Either an object of class ContractType which is added or a list of ContractType-objects in which case all elements are added to the portfolio

...

See Also

remove

get

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

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)))
    
rf <- RFConn() # create a RiskFactorConnector object
add(rf,yc) # add the single RiskFactor to the RiskFactorConnector

# load contract demo data
data(BondPortfolio)

# create new portfolio
ptf <- Portfolio()

# define subset of ContractTerms to be used to create 
# new PrincipalAtMaturity contract
# (we use a subset just to make the case here)
attr.names=c("ContractID", 
             "Currency", 
             "ContractRole", 
             "StatusDate", 
             "ContractDealDate",
             "InitialExchangeDate",
             "MaturityDate",
             "NotionalPrincipal",
             "NominalInterestRate",
             "DayCountConvention")

# add first contract of the demo data
add(ptf, Pam(as.list(BondPortfolio[1,attr.names])))

# add second contract of the demo data
add(ptf, Pam(as.list(BondPortfolio[2,attr.names])))


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