[Returnanalytics-commits] r2507 - in pkg/PortfolioAnalytics: . R man

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Fri Jul 5 20:58:16 CEST 2013


Author: rossbennett34
Date: 2013-07-05 20:58:16 +0200 (Fri, 05 Jul 2013)
New Revision: 2507

Added:
   pkg/PortfolioAnalytics/man/summary.portfolio.Rd
Modified:
   pkg/PortfolioAnalytics/NAMESPACE
   pkg/PortfolioAnalytics/R/generics.R
Log:
Adding summary method for objects of class portfolio.

Modified: pkg/PortfolioAnalytics/NAMESPACE
===================================================================
--- pkg/PortfolioAnalytics/NAMESPACE	2013-07-05 16:59:01 UTC (rev 2506)
+++ pkg/PortfolioAnalytics/NAMESPACE	2013-07-05 18:58:16 UTC (rev 2507)
@@ -11,7 +11,6 @@
 export(charts.RP)
 export(constrained_group_tmp)
 export(constrained_objective)
-export(constraint_fn_map)
 export(constraint_ROI)
 export(constraint_v2)
 export(constraint)
@@ -51,6 +50,7 @@
 export(rp_transform)
 export(set.portfolio.moments)
 export(summary.optimize.portfolio.rebalancing)
+export(summary.portfolio)
 export(trailingFUN)
 export(turnover_constraint)
 export(turnover_objective)

Modified: pkg/PortfolioAnalytics/R/generics.R
===================================================================
--- pkg/PortfolioAnalytics/R/generics.R	2013-07-05 16:59:01 UTC (rev 2506)
+++ pkg/PortfolioAnalytics/R/generics.R	2013-07-05 18:58:16 UTC (rev 2507)
@@ -38,4 +38,69 @@
             print(object[[i]]$constrained_objective)
         }
     }    
+}
+
+#' Summary method for objects of class 'portfolio'
+#' 
+#' @param portfolio object of class portfolio
+#' @author Ross Bennett
+#' @export
+summary.portfolio <- function(portfolio){
+  if(!is.portfolio(portfolio)) stop("object passed in is not of class 'portfolio'")
+  
+  cat(rep("*", 50) ,"\n", sep="")
+  cat("PortfolioAnalytics Portfolio Specification", "\n")
+  cat(rep("*", 50) ,"\n", sep="")
+  
+  # Assets
+  cat("\nAssets\n")
+  nassets <- length(portfolio$assets)
+  cat("Number of assets:", nassets, "\n")
+  
+  # Constraints
+  cat("\nConstraints\n")
+  nconstraints <- length(portfolio$constraints)
+  # logical vector of enabled constraints
+  enabled.constraints <- sapply(pspec$constraints, function(x) x$enabled)
+  # character vector of constraint types
+  names.constraints <- sapply(pspec$constraints, function(x) x$type)
+  cat("Number of constraints:", nconstraints, "\n")
+  cat("Number of enabled constraints:", sum(enabled.constraints), "\n")
+  if(sum(enabled.constraints) > 0){
+    cat("Enabled constraint types\n")
+    for(type in names.constraints[enabled.constraints]) {
+      cat("\t\t-", type, "\n")
+    }
+  }
+  cat("Number of disabled constraints:", nconstraints - sum(enabled.constraints), "\n")
+  if((nconstraints - sum(enabled.constraints)) > 0){
+    cat("Disabled constraint types\n")
+    for(type in setdiff(names.constraints, names.constraints[enabled.constraints])) {
+      cat("\t\t-", type, "\n")
+    }
+  }
+  
+  # Objectives
+  cat("\nObjectives\n")
+  nobjectives <- length(portfolio$objectives)
+  # logical vector of enabled objectives
+  enabled.objectives <- sapply(pspec$objectives, function(x) x$enabled)
+  # character vector of objective names
+  names.objectives <- sapply(pspec$objectives, function(x) x$name)
+  cat("Number of objectives:", nobjectives, "\n")
+  cat("Number of enabled objectives:", sum(enabled.objectives), "\n")
+  if(sum(enabled.objectives) > 0){
+    cat("Enabled objective names\n")
+    for(name in names.objectives[enabled.objectives]) {
+      cat("\t\t-", name, "\n")
+    }
+  }
+  cat("Number of disabled objectives:", nobjectives - sum(enabled.objectives), "\n")
+  if((nobjectives - sum(enabled.objectives)) > 0){
+    cat("Disabled objective types\n")
+    for(name in setdiff(names.objectives, names.objectives[enabled.objectives])) {
+      cat("\t\t-", name, "\n")
+    }
+  }
+  cat("\n")
 }
\ No newline at end of file

Added: pkg/PortfolioAnalytics/man/summary.portfolio.Rd
===================================================================
--- pkg/PortfolioAnalytics/man/summary.portfolio.Rd	                        (rev 0)
+++ pkg/PortfolioAnalytics/man/summary.portfolio.Rd	2013-07-05 18:58:16 UTC (rev 2507)
@@ -0,0 +1,16 @@
+\name{summary.portfolio}
+\alias{summary.portfolio}
+\title{Summary method for objects of class 'portfolio'}
+\usage{
+  summary.portfolio(portfolio)
+}
+\arguments{
+  \item{portfolio}{object of class portfolio}
+}
+\description{
+  Summary method for objects of class 'portfolio'
+}
+\author{
+  Ross Bennett
+}
+



More information about the Returnanalytics-commits mailing list