[Blotter-commits] r53 - pkg/R

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Wed Jan 21 16:13:01 CET 2009


Author: peter_carl
Date: 2009-01-21 16:13:00 +0100 (Wed, 21 Jan 2009)
New Revision: 53

Added:
   pkg/R/calcPortfWgt.R
Log:
- initial commit of code


Added: pkg/R/calcPortfWgt.R
===================================================================
--- pkg/R/calcPortfWgt.R	                        (rev 0)
+++ pkg/R/calcPortfWgt.R	2009-01-21 15:13:00 UTC (rev 53)
@@ -0,0 +1,24 @@
+calcPortfWgt <- function(Portfolio, Symbols = NULL, Dates = NULL, denominator = c('Gross.Value', 'Net.Value', 'Long.Value', 'Short.Value'), Account = NULL)
+{ # @author Peter Carl
+
+    # DESCRIPTION
+    # Calculates the portfolio weights for positions within a given portfolio.
+    # Portfolio weights may be calculated differently depending on their use.
+
+    # Inputs
+    # Portfolio: a portfolio object structured with initPortf()
+    # Symbol: an instrument identifier for a symbol included in the portfolio,
+    #   e.g., IBM
+    # Dates: dates to return the calculation over formatted as xts range
+
+    # Outputs
+    # Timeseries object with weights by date in rows and symbolname in columns
+
+    # FUNCTION
+
+    pos.value = getBySymbol(Portfolio = Portfolio, Date = Dates, Attribute = "Pos.Value", Symbols = Symbols)
+    portf.value = calcPortfAttr(Portfolio = Portfolio, Date = Dates, Attribute = denominator[1])
+    weights = apply(pos.value, MARGIN = 2, FUN = function(x,y){return(x/y)}, y=portf.value) 
+
+    return(weights)
+}
\ No newline at end of file



More information about the Blotter-commits mailing list