R/Methods-SecurityAttribution.R

#'Method for Security Attribution
#'

setGeneric(name = "SecurityperformanceAttribution",
           def = function(object){
             standardGeneric("SecurityperformanceAttribution")
           })
setMethod(f="SecurityperformanceAttribution",
          signature = "SecurityAttribution",
          definition = function(object){
            #Calculate Active Return
            AssetClass<-object@AssetClass
            AssetCategory<-object@AssetCategory
            Asset<-object@Asset
            PortfolioReturn<-object@PortfolioReturns
            Benchmark<-object@BenchmarkReturns

            ActiveReturn<-PortfolioReturn-Benchmark #Active Returns

            PortfolioWeight<-object@PortfolioWeights
            BenchmarkWeight<-object@BenchmarkWeights

            ExcessWeight<-PortfolioWeight-BenchmarkWeight #Active Weights

            #Attribute
            Allocationeffect <- (object@PortfolioWeights - object@BenchmarkWeights) * (object@BenchmarkReturns
                                                                                       - sum(object@BenchmarkWeights * object@BenchmarkReturns))

            SelectionEffect <- (object@PortfolioReturns - object@BenchmarkReturns) * object@BenchmarkWeights


            InteractionEffect <- (object@PortfolioWeights - object@BenchmarkWeights) *(object@PortfolioReturns
                                                                                       - object@BenchmarkReturns)
            # Form data frame for overal performance reports
            Performance <- data.frame(
              AssetClass = AssetClass,
              AssetCategory = AssetCategory,
              Asset= Asset,
              PortfolioReturn = PortfolioReturn,
              Benchmark = Benchmark,
              ActiveReturn = ActiveReturn,
              PortfolioWeight = PortfolioWeight,
              BenchmarkWeight = BenchmarkWeight,
              ExcessWeight = ExcessWeight,
              AllocationEffect = Allocationeffect,
              SellectionEffect = SelectionEffect,
              InteractionEffect = InteractionEffect)
            Performance
          }
)
CarlvinJerry/InnovaPerformanceAttribution documentation built on May 16, 2019, 7:26 a.m.