SCM

SCM Repository

[rmetrics] Diff of /pkg/fPortfolio/R/2A-PortfolioClass.R
ViewVC logotype

Diff of /pkg/fPortfolio/R/2A-PortfolioClass.R

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

pkg/fPortfolio/R/2D-PortfolioClass.R revision 1232, Tue Feb 27 16:25:37 2007 UTC pkg/fPortfolio/R/2A-PortfolioClass.R revision 1611, Thu Jun 14 09:43:05 2007 UTC
# Line 28  Line 28 
28    
29    
30  ################################################################################  ################################################################################
31  # FUNCTION                      PORTFOLIO CLASS:  # FUNCTION:                     PORTFOLIO CLASS:
32  #  'fPORTFOLIO'                  S4 Portfolio Class  #  'fPORTFOLIO'                  S4 Portfolio Class
33    #  portfolioFrontier             Returns the efficient frontier of a portfolio
34    #  show.fPORTFOLIO               S4 Print method for 'fPPORTFOLIO' objects
35  # FUNCTION:                     SINGLE PORTFOLIOS:  # FUNCTION:                     SINGLE PORTFOLIOS:
36  #  feasiblePortfolio             Returns a feasible portfolio  #  feasiblePortfolio             Returns a feasible portfolio
37    #  efficientPortfolio            Returns a frontier portfolio
38  #  cmlPortfolio                  Returns capital market line  #  cmlPortfolio                  Returns capital market line
39  #  tangencyPortfolio             Returns the tangency portfolio  #  tangencyPortfolio             Returns the tangency portfolio
40  #  minvariancePortfolio          Returns the minimum variance portfolio  #  minvariancePortfolio          Returns the minimum variance portfolio
 #  frontierPortfolio             Returns a frontier portfolio  
 # FUNCTION:                     PORTFOLIO FRONTIER:  
 #  portfolioFrontier             Returns the efficient frontier of a portfolio  
41  # FUNCTION:                     PRINT AND PLOT METHODS:  # FUNCTION:                     PRINT AND PLOT METHODS:
 #  show.fPORTFOLIO               S4 Print method for 'fPPORTFOLIO' objects  
42  #  plot.fPORTFOLIO               S3 Plot method for 'fPORTFOLIO' objects  #  plot.fPORTFOLIO               S3 Plot method for 'fPORTFOLIO' objects
43    #  summary.fPORTFOLIO            S3 Summary method for 'fPORTFOLIO' objects
44  # FUNCTION:                     EDUCATIONAL PORTFOLIO SLIDERS:  # FUNCTION:                     EDUCATIONAL PORTFOLIO SLIDERS:
45  #  weightsSlider                 Weights Slider  #  weightsSlider                 Weights Slider
46  #  frontierSlider                Efficient Frontier Slider  #  frontierSlider                Efficient Frontier Slider
# Line 51  Line 51 
51      representation(      representation(
52          call = "call",          call = "call",
53          data = "list",          data = "list",
54          specification = "fPFOLIOSPEC",          spec = "list",
55          constraints = "character",          constraints = "character",
56          portfolio = "list",          portfolio = "list",
57          title = "character",          title = "character",
# Line 62  Line 62 
62  # ------------------------------------------------------------------------------  # ------------------------------------------------------------------------------
63    
64    
65  feasiblePortfolio =  portfolioFrontier =
66  function(data, spec = portfolioSpec(), constraintsStrings = NULL)  function(data, spec = portfolioSpec(), constraints = NULL,
67    title = NULL, description = NULL)
68  {   # A function implemented by Rmetrics  {   # A function implemented by Rmetrics
69    
70      # Description:      # Description:
71      #   Computes Risk and Return for a feasible portfolio      #   Computes the efficient frontier of a portfolio
72    
73      # Arguments:      # Arguments:
74      #   data - a rectangular object of assets      #   data - a rectangular object of assets
75      #   spec - an object of class 'fPFOLIOSPEC'      #   spec - an object of class 'fPFOLIOSPEC'
76        #   constraints - a character vector or NULL
77    
78      # FUNCTION:      # FUNCTION:
79    
80      # Check Data:      # Compose Portfolio Data:
81      if (is.list(data)) {      data = portfolioData(data, spec)
         series = NA  
         mu = data$mu  
         Sigma = data$Sigma  
         statistics = list(mu = mu, Sigma = Sigma)  
     } else {  
         series = data  
         statistics = portfolioStatistics(data, spec)  
         mu = statistics$mu  
         Sigma = statistics$Sigma  
     }  
     data = list(series = series, statistics = statistics)  
   
     # Compose Function:  
     if(is.null(constraintsStrings) | length(constraintsStrings) == 0)  
         Model = "Short" else Model = "Constrained"  
     Type = spec@model$type  
     fun = match.fun(paste(".feasible", Model, Type, "Portfolio", sep = ""))  
82    
83      # Compute Portfolio      # Compose Optimization Function:
84      ans = fun(data, spec, constraintsStrings)      if(is.null(constraints) | length(constraints) == 0) {
85            Model = c("Constrained", "LongOnly")
86            nAssets = getNumberOfAssets(data)
87            constraints = paste("minW[1:", nAssets, "]=0", sep = "")
88        } else if (constraints[1] == "Short") {
89            Model = "Short"
90        } else {
91            Model = "Constrained"
92        }
93        Type = getType(spec)
94        fun = match.fun(paste(".portfolio", Model[1], Type[1], "Frontier",
95            sep = ""))
96        attr(constraints, "model") = Model
97    
98        # Compute Portfolio:
99        ans = fun(data, spec, constraints)
100        attr(ans@constraints, "model") = Model
101    
102      # Reset Call:      # Reset Call:
103      ans@call = match.call()      ans@call = match.call()
# Line 105  Line 107 
107  }  }
108    
109    
110  # ------------------------------------------------------------------------------  ################################################################################
111    
112    
113  cmlPortfolio =  show.fPORTFOLIO =
114  function(data, spec = portfolioSpec(), constraintsStrings = NULL)  function(object)
115  {   # A function implemented by Rmetrics  {   # A function implemented by Rmetrics
116    
117      # Description:      # Description:
118      #   Computes Capital Market Line      #   S4 Print Method for an object of class "fPORTFOLIO"
119    
120      # Arguments:      # Arguments:
121      #   data - a rectangular object of assets      #   object - an object of class "fPORTFOLIO"
     #   spec - an object of class 'fPFOLIOSPEC'  
122    
123      # FUNCTION:      # FUNCTION:
124    
125      # Check Data:      # Title:
126      if (is.list(data)) {      cat("\nTitle:\n ")
127          series = NA      cat(getTitle(object), "\n")
         mu = data$mu  
         Sigma = data$Sigma  
         statistics = list(mu = mu, Sigma = Sigma)  
     } else {  
         series = data  
         statistics = portfolioStatistics(data, spec)  
         mu = statistics$mu  
         Sigma = statistics$Sigma  
     }  
     data = list(series = series, statistics = statistics)  
   
     # Compose Function:  
     if(is.null(constraintsStrings) | length(constraintsStrings) == 0)  
         Model = "Short" else Model = "Constrained"  
     Type = spec@model$type  
     fun = match.fun(paste(".cml", Model, Type, "Portfolio", sep = ""))  
128    
129      # Compute Portfolio      # Call:
130      ans = fun(data, spec, constraintsStrings)      cat("\nCall:\n ")
131        print.default(getCall(object))
132    
133      # Reset Call:      # Target Weights:
134      ans@call = match.call()      cat("\nPortfolio Weight(s):\n")
135        weights = round(getWeights(object), digits = 4)
136        if (length(weights) == 1) {
137            cat(" ", weights, "\n")
138        } else {
139            print.table(weights)
140        }
141    
142        # Covariance Risk Budgets:
143        cat("\nRiskBudget(s):\n")
144        riskBudgets = round(getRiskBudgets(object), digits = 4)
145        if (length(riskBudgets) == 1) {
146            cat(" ", riskBudgets, "\n")
147        } else {
148            print.table(riskBudgets)
149        }
150    
151        # Tail Risk Budgets:
152        if (FALSE) {
153            if (!is.na(getTailRiskBudgets(object))) {
154                 cat("\nRiskBudget(s):\n")
155                riskBudgets = round(getTailRiskBudgets(object), digits = 4)
156                if (length(riskBudgets) == 1) {
157                    cat(" ", riskBudgets, "\n")
158                } else {
159                    print.table(riskBudgets)
160                }
161            }
162        }
163    
164        # Target Returns:
165        # cat("\nTarget Return(s):\n")
166        targetReturn = object@portfolio$targetReturn # getTargetReturn(object)
167        # print(targetReturn)
168    
169        # Target Risk:
170        # cat("\nTarget Risk(s):\n")
171        targetRisk = object@portfolio$targetRisk # getTargetRisk(object)
172        # print(targetRisk)
173    
174        cat("\nTarget Risk(s) and Return(s):\n")
175        if (is.null(dim(targetReturn))) {
176            targetReturn = matrix(targetReturn, nrow = 1)
177            colnames(targetReturn) = getEstimator(spec)[1]
178        }
179        if (is.null(dim(targetRisk))) {
180            targetRisk = matrix(targetRisk, nrow = 1)
181            colnames(targetRisk) = getEstimator(spec)[2]
182        }
183        target = cbind(targetReturn, targetRisk)
184        colnames(target) = c(colnames(targetReturn), colnames(targetRisk))
185        if (nrow(target) == 1) {
186            print(target[1, ])
187        } else {
188            print(target)
189        }
190    
191        # Description:
192        cat("\nDescription:\n ")
193        cat(getDescription(object), "\n")
194    
195      # Return Value:      # Return Value:
196      ans      invisible(object)
197  }  }
198    
199    
200  # ------------------------------------------------------------------------------  # ------------------------------------------------------------------------------
201    
202    
203  tangencyPortfolio =  setMethod("show", "fPORTFOLIO", show.fPORTFOLIO)
204  function(data, spec = portfolioSpec(), constraintsStrings = NULL)  
 {   # A function implemented by Rmetrics  
205    
206    ################################################################################
207    
208    
209    feasiblePortfolio =
210    function(data, spec = portfolioSpec(), constraints = NULL)
211    {   # A function implemented by Rmetrics
212      # Description:      # Description:
213      #   Computes target risk and weights for the tangency portfolio      #   Computes Risk and Return for a feasible portfolio
214    
215      # Arguments:      # Arguments:
216      #   data - a rectangular object of assets      #   data - a rectangular object of assets
217      #   spec - an object of class 'fPFOLIOSPEC'      #   spec - an object of class 'fPFOLIOSPEC'
218        #   constraints - a character vector or NULL
219    
220      # FUNCTION:      # FUNCTION:
221    
222      # Check Data:      # Compose Portfolio Data:
223      if (is.list(data)) {      data = portfolioData(data, spec)
224          series = NA  
225          mu = data$mu      # Constraints:
226          Sigma = data$Sigma      # .checkPortfolioConstraints
227          statistics = list(mu = mu, Sigma = Sigma)  
228      } else {      # Compose Optimization Function:
229          series = data      if(is.null(constraints) | length(constraints) == 0) {
230          statistics = portfolioStatistics(data, spec)          Model = c("Constrained", "LongOnly")
231          mu = statistics$mu          nAssets = getNumberOfAssets(data)
232          Sigma = statistics$Sigma          constraints = paste("minW[1:", nAssets, "]=0", sep = "")
233      }      } else if (constraints[1] == "Short") {
234      data = list(series = series, statistics = statistics)          Model = "Short"
235        } else {
236      # Compose Function:          Model = "Constrained"
237      if(is.null(constraintsStrings) | length(constraintsStrings) == 0)      }
238          Model = "Short" else Model = "Constrained"      Type = getType(spec)
239      Type = spec@model$type      fun = match.fun(paste(".feasible", Model[1], Type[1], "Portfolio",
240      fun = match.fun(paste(".tangency", Model, Type, "Portfolio", sep = ""))          sep = ""))
241        attr(constraints, "model") = Model
242    
243      # Compute Portfolio:      # Compute Portfolio:
244      ans = fun(data, spec, constraintsStrings)      ans = fun(data, spec, constraints)
245        attr(ans@constraints, "model") = Model
246    
247      # Reset Call:      # Reset Call:
248      ans@call = match.call()      ans@call = match.call()
# Line 202  Line 255 
255  # ------------------------------------------------------------------------------  # ------------------------------------------------------------------------------
256    
257    
258  minvariancePortfolio =  cmlPortfolio =
259  function(data, spec = portfolioSpec(), constraintsStrings = NULL)  function(data, spec = portfolioSpec(), constraints = NULL)
260  {   # A function implemented by Rmetrics  {   # A function implemented by Rmetrics
261    
262      # Description:      # Description:
263      #   Computes minimum variance portfolio      #   Computes Capital Market Line
264    
265      # Arguments:      # Arguments:
266      #   data - a rectangular object of assets      #   data - a rectangular object of assets
267      #   spec - an object of class 'fPFOLIOSPEC'      #   spec - an object of class 'fPFOLIOSPEC'
268        #   constraints - a character vector or NULL
269    
270      # FUNCTION:      # FUNCTION:
271    
272      # Check Data:      # Compose Portfolio Data:
273      if (is.list(data)) {      data = portfolioData(data, spec)
         series = NA  
         mu = data$mu  
         Sigma = data$Sigma  
         statistics = list(mu = mu, Sigma = Sigma)  
     } else {  
         series = data  
         statistics = portfolioStatistics(data, spec)  
         mu = statistics$mu  
         Sigma = statistics$Sigma  
     }  
     data = list(series = series, statistics = statistics)  
   
     # Compose Function:  
     if(is.null(constraintsStrings) | length(constraintsStrings) == 0)  
         Model = "Short" else Model = "Constrained"  
     Type = spec@model$type  
     fun = match.fun(paste(".minvariance", Model, Type, "Portfolio", sep = ""))  
274    
275      # Compute Portfolio:      # Compose Optimization Function:
276      ans = fun(data, spec, constraintsStrings)      if(is.null(constraints) | length(constraints) == 0) {
277            Model = c("Constrained", "LongOnly")
278            nAssets = getNumberOfAssets(data)
279            constraints = paste("minW[1:", nAssets, "]=0", sep = "")
280        } else if (constraints[1] == "Short") {
281            Model = "Short"
282        } else {
283            Model = "Constrained"
284        }
285        Type = getType(spec)
286        fun = match.fun(paste(".cml", Model[1], Type[1], "Portfolio",
287            sep = ""))
288        attr(constraints, "model") = Model
289    
290        # Compute Portfolio
291        ans = fun(data, spec, constraints)
292        attr(ans@constraints, "model") = Model
293    
294      # Reset Call:      # Reset Call:
295      ans@call = match.call()      ans@call = match.call()
# Line 249  Line 302 
302  # ------------------------------------------------------------------------------  # ------------------------------------------------------------------------------
303    
304    
305  frontierPortfolio =  tangencyPortfolio =
306  function(data, spec = portfolioSpec(), constraintsStrings = NULL)  function(data, spec = portfolioSpec(), constraints = NULL)
307  {   # A function implemented by Rmetrics  {   # A function implemented by Rmetrics
308    
309      # Description:      # Description:
310      #   Computes target risk and weights for an efficient portfolio      #   Computes target risk and weights for the tangency portfolio
311    
312      # Arguments:      # Arguments:
313      #   data - a rectangular object of assets      #   data - a rectangular object of assets
314      #   spec - an object of class 'fPFOLIOSPEC'      #   spec - an object of class 'fPFOLIOSPEC'
315        #   constraints - a character vector or NULL
316    
317      # FUNCTION:      # FUNCTION:
318    
319      # Check Data:      # Compose Portfolio Data:
320      if (is.list(data)) {      data = portfolioData(data, spec)
321          series = NA  
322          mu = data$mu      # Compose Optimization Function:
323          Sigma = data$Sigma      if(is.null(constraints) | length(constraints) == 0) {
324          statistics = list(mu = mu, Sigma = Sigma)          Model = c("Constrained", "LongOnly")
325      } else {          nAssets = getNumberOfAssets(data)
326          series = data          constraints = paste("minW[1:", nAssets, "]=0", sep = "")
327          statistics = portfolioStatistics(data, spec)      } else if (constraints[1] == "Short") {
328          mu = statistics$mu          Model = "Short"
329          Sigma = statistics$Sigma      } else {
330      }          Model = "Constrained"
331      data = list(series = series, statistics = statistics)      }
332        Type = getType(spec)
333      # Compose Function:      fun = match.fun(paste(".tangency", Model[1], Type[1], "Portfolio",
334      if(is.null(constraintsStrings) | length(constraintsStrings) == 0)          sep = ""))
335          Model = "Short" else Model = "Constrained"      attr(constraints, "model") = Model
     Type = spec@model$type  
     fun = match.fun(paste(".frontier", Model, Type, "Portfolio", sep = ""))  
336    
337      # Compute Portfolio:      # Compute Portfolio:
338      ans = fun(data, spec, constraintsStrings)      ans = fun(data, spec, constraints)
339        attr(ans@constraints, "model") = Model
340    
341      # Reset Call:      # Reset Call:
342      ans@call = match.call()      ans@call = match.call()
# Line 296  Line 349 
349  # ------------------------------------------------------------------------------  # ------------------------------------------------------------------------------
350    
351    
352  portfolioFrontier =  minvariancePortfolio =
353  function(data, spec = portfolioSpec(), constraintsStrings = NULL,  function(data, spec = portfolioSpec(), constraints = NULL)
 title = NULL, description = NULL)  
354  {   # A function implemented by Rmetrics  {   # A function implemented by Rmetrics
355    
356      # Description:      # Description:
357      #   Computes the efficient frontier of a portfolio      #   Computes minimum variance portfolio
358    
359      # Arguments:      # Arguments:
360      #   data - a rectangular object of assets      #   data - a rectangular object of assets
361      #   spec - an object of class 'fPFOLIOSPEC'      #   spec - an object of class 'fPFOLIOSPEC'
362        #   constraints - a character vector or NULL
363    
364      # FUNCTION:      # FUNCTION:
365    
366      # Check Data:      # Compose Portfolio Data:
367      if (is.list(data)) {      data = portfolioData(data, spec)
368          series = NA  
369          mu = data$mu      # Compose Optimization Function:
370          Sigma = data$Sigma      if(is.null(constraints) | length(constraints) == 0) {
371          statistics = list(mu = mu, Sigma = Sigma)          Model = c("Constrained", "LongOnly")
372      } else {          nAssets = getNumberOfAssets(data)
373          series = data          constraints = paste("minW[1:", nAssets, "]=0", sep = "")
374          statistics = portfolioStatistics(data, spec)      } else if (constraints[1] == "Short") {
375          mu = statistics$mu          Model = "Short"
376          Sigma = statistics$Sigma      } else {
377      }          Model = "Constrained"
378      data = list(series = series, statistics = statistics)      }
379        Type = getType(spec)
380      # Compose Function:      fun = match.fun(paste(".minvariance", Model[1], Type[1], "Portfolio",
381      if(is.null(constraintsStrings) | length(constraintsStrings) == 0)          sep = ""))
382          Model = "Short" else Model = "Constrained"      attr(constraints, "model") = Model
     Type = spec@model$type  
     fun = match.fun(paste(".portfolio", Model, Type, "Frontier", sep = ""))  
383    
384      # Compute Portfolio:      # Compute Portfolio:
385      ans = fun(data, spec, constraintsStrings)      ans = fun(data, spec, constraints)
386        attr(ans@constraints, "model") = Model
387    
388      # Reset Call:      # Reset Call:
389      ans@call = match.call()      ans@call = match.call()
# Line 341  Line 393 
393  }  }
394    
395    
396  ################################################################################  # ------------------------------------------------------------------------------
397    
398    
399  show.fPORTFOLIO =  efficientPortfolio =
400  function(object)  function(data, spec = portfolioSpec(), constraints = NULL)
401  {   # A function implemented by Rmetrics  {   # A function implemented by Rmetrics
402    
403      # Description:      # Description:
404      #   S4 Print Method for an object of class "fPORTFOLIO"      #   Computes target risk and weights for an efficient portfolio
405    
406      # Arguments:      # Arguments:
407      #   object - an object of class "fPORTFOLIO"      #   data - a rectangular object of assets
408        #   spec - an object of class 'fPFOLIOSPEC'
409        #   constraints - a character vector or NULL
410    
411      # FUNCTION:      # FUNCTION:
412    
413      # Title:      # Compose Portfolio Data:
414      cat("\nTitle:\n ")      data = portfolioData(data, spec)
     cat(getTitle(object), "\n")  
   
     # Call:  
     cat("\nCall:\n ")  
     print.default(getCall(object))  
415    
416      # Target Weights:      # Compose Optimization Function:
417      cat("\nPortfolio Weight(s):\n")      if(is.null(constraints) | length(constraints) == 0) {
418      weights = getWeights(object)          Model = c("Constrained", "LongOnly")
419      if (length(weights) == 1) {          nAssets = getNumberOfAssets(data)
420          cat(" ", weights, "\n")          constraints = paste("minW[1:", nAssets, "]=0", sep = "")
421        } else if (constraints[1] == "Short") {
422            Model = "Short"
423      } else {      } else {
424          print(weights)          Model = "Constrained"
425      }      }
426        Type = getType(spec)
427        fun = match.fun(paste(".efficient", Model[1], Type[1], "Portfolio",
428            sep = ""))
429        attr(constraints, "model") = Model
430    
431      # Target Returns:      # Compute Portfolio:
432      cat("\nTarget Return(s):\n")      ans = fun(data, spec, constraints)
433      targetReturn = getTargetReturn(object)      attr(ans@constraints, "model") = Model
     if (length(targetReturn) == 1) {  
         cat(" ", targetReturn, "\n")  
     } else {  
         print(targetReturn)  
     }  
   
     # Target Risk:  
     cat("\nTarget Risk(s):\n")  
     targetRisk = getTargetRisk(object)  
     if (length(targetRisk) == 1) {  
         cat(" ", targetRisk, "\n")  
     } else {  
         print(targetRisk)  
     }  
   
     # Target Stdev:  
     cat("\nTarget Standard Deviation(s):\n")  
     targetStdev = getTargetStdev(object)  
     if (length(targetStdev) == 1) {  
         cat(" ", targetStdev, "\n")  
     } else {  
         print(targetStdev)  
     }  
434    
435      # Description:      # Reset Call:
436      cat("\nDescription:\n ")      ans@call = match.call()
     cat(getDescription(object), "\n")  
437    
438      # Return Value:      # Return Value:
439      invisible(object)      ans
440  }  }
441    
442    
443  # ------------------------------------------------------------------------------  # ------------------------------------------------------------------------------
444    
445    
 setMethod("show", "fPORTFOLIO", show.fPORTFOLIO)  
   
   
 # ------------------------------------------------------------------------------  
   
   
446  plot.fPORTFOLIO =  plot.fPORTFOLIO =
447  function(x, which = "ask", control = list(), ...)  function(x, which = "ask", control = list(), ...)
448  {   # A function implemented by Rmetrics  {   # A function implemented by Rmetrics
449    
450      # Description:      # Description:
451      #   Plot method for an object of class 'fGARCH'      #   Plot method for an object of class 'fPORTFOLIO'
452    
453      # Note:      # Note:
454      #   This method can also be used for plotting graphs fitted by      #   This method can also be used for plotting graphs fitted by
# Line 432  Line 457 
457      # FUNCTION:      # FUNCTION:
458    
459      # Control Parameters:      # Control Parameters:
460      N = length(x@data$statistics$mu)      Statistics = getStatistics(x)
461    
462      # Use default, if xlim and ylim is not specified ...      # Use default, if xlim and ylim is not specified ...
463      mu = x@data$statistics$mu      mu = Statistics$mu
464      Sigma = x@data$statistics$Sigma      Sigma = Statistics$Sigma
465        N = length(mu)
466      yLim = range(mu) + 0.25*c(-diff(range(mu)), diff(range(mu)))      yLim = range(mu) + 0.25*c(-diff(range(mu)), diff(range(mu)))
467    
468      # First, take care that all assets appear on the plot ...      # First, take care that all assets appear on the plot ...
469      sqrtSig = sqrt(diag(Sigma))      # sqrtSig = sqrt(diag(Sigma))
470      xLimAssets = c(min(sqrtSig), max(sqrtSig))+      # xLimAssets = c(
471           c(-0.4*diff(range(sqrtSig)), 0.1*diff(range(sqrtSig)))      #    min(sqrtSig),
472        #    max(sqrtSig))+ c(-0.4*diff(range(sqrtSig)), 0.1*diff(range(sqrtSig)))
473        xRange = range(getFrontier(x)[, 1])
474        xDiff = diff(xRange)
475        xLimAssets = c(xRange[1] - 2.5*xDiff/10, xRange[2] + xDiff/10)
476    
477      # ... second take care that the whole frontier appears on the plot:      # ... second take care that the whole frontier appears on the plot:
478      fullFrontier = getFrontier(x)      fullFrontier = getFrontier(x)
479      xLimFrontier = range(fullFrontier[, 1])      xLimFrontier = range(fullFrontier[, 1])
# Line 449  Line 481 
481    
482      # Control List:      # Control List:
483      con <<- list(      con <<- list(
484          sharpeRatio.col = "black",          sharpeRatio.col = "blue",
485          minvariance.col = "red",          minvariance.col = "red",
486          tangency.col = "steelblue",          tangency.col = "steelblue",
487          cml.col = "green",          cml.col = "green",
# Line 457  Line 489 
489          singleAsset.col = rainbow(N),          singleAsset.col = rainbow(N),
490          twoAssets.col = "grey",          twoAssets.col = "grey",
491          monteCarlo.col = "black",          monteCarlo.col = "black",
   
492          sharpeRatio.cex = 0.1,          sharpeRatio.cex = 0.1,
493          minvariance.cex = 1,          # Point Sizes:
494            minvariance.cex = 1.25,
495          tangency.cex = 1.25,          tangency.cex = 1.25,
496          cml.cex = 1.25,          cml.cex = 1.25,
497          equalWeights.cex = 0.8,          equalWeights.cex = 1.25,
498          singleAsset.cex = 1,          singleAsset.cex = 1,
499          twoAssets.cex = 0.01,          twoAssets.cex = 0.01,
500          monteCarlo.cex = 0.01,          monteCarlo.cex = 0.01,
501            # Frontier Limits:
502          xlim.frontier = xLim,          xlim = xLim,
503          ylim.frontier = yLim,          ylim = yLim,
504            # Monte Carlo Steps:
505          mcSteps = 5000,          mcSteps = 5000,
506            # Pie Settings:
507          pieR = NULL,          pieR = NULL,
508          piePos = NULL,          piePos = NULL,
509          pieOffset = NULL          pieOffset = NULL
# Line 480  Line 512 
512    
513      par(mar = c(5, 4, 4, 3) + 0.1)      par(mar = c(5, 4, 4, 3) + 0.1)
514    
   
515      # Plot Function and Addons:      # Plot Function and Addons:
516      plot.1 <<- function(x, ...) {      plot.1 <<- function(x, ...) {
517          frontierPlot(object = x, xlim = con$xlim.frontier,          Type = getType(x)
518              ylim = con$ylim.frontier)          if (Type == "MV") {
519                xLab = "Mean-Var Target Risk"
520            } else if (Type == "CVaR") {
521                xLab = "-CVaR Target Risk"
522            }
523            frontierPlot(object = x, xlim = con$xlim,
524                ylim = con$ylim, main = "Efficient Frontier",
525                xlab = xLab, ylab = "Target Return",
526                pch = 19, cex = 0.75)
527      }      }
528      plot.2 <<- function(x, ...) {      plot.2 <<- function(x, ...) {
         .sharpeRatioPlot(object = x, type = "l",  
             col = con$sharpeRatio.col, cex = con$sharpeRatio.cex,  
             lty = 3)  
     }  
     plot.3 <<- function(x, ...) {  
529          .minvariancePlot(object = x,          .minvariancePlot(object = x,
530              col = con$minvariance.col, cex = con$minvariance.cex,              col = con$minvariance.col, cex = con$minvariance.cex,
531              pch = 19)              pch = 19)
532      }      }
533      plot.4 <<- function(x, ...) {      plot.3 <<- function(x, ...) {
534          .tangencyPlot(object = x,          .tangencyPlot(object = x,
535              col = con$tangency.col, cex = con$tangency.cex,              col = con$tangency.col, cex = con$tangency.cex,
536              pch = 17)              pch = 17)
537      }      }
538      plot.5 <<- function(x, ...) {      plot.4 <<- function(x, ...) {
539          .singleAssetPlot(object =x ,          .singleAssetPlot(object =x ,
540              col = con$singleAsset.col, cex = con$singleAsset.cex,              col = con$singleAsset.col, cex = con$singleAsset.cex,
541              pch = 18)              pch = 18)
542      }      }
543      plot.6 <<- function(x, ...) {      plot.5 <<- function(x, ...) {
544          .equalWeightsPlot(object = x,          .equalWeightsPlot(object = x,
545              col = con$equalWeights.col, cex = con$equalWeights.cex,              col = con$equalWeights.col, cex = con$equalWeights.cex,
546              pch = 15)              pch = 15)
547      }      }
548      plot.7 <<- function(x, ...) {      plot.6 <<- function(x, ...) {
549            .singleAssetPlot(object = x ,
550                col = con$singleAsset.col, cex = con$singleAsset.cex,
551                pch = 18)
552            lines(getFrontier(object = x), col = "grey")
553          .twoAssetsPlot(object = x, col = con$twoAssets.col)          .twoAssetsPlot(object = x, col = con$twoAssets.col)
554      }      }
555      plot.8 <<- function(x, ...) {      plot.7 <<- function(x, ...) {
556          .wheelPiePlot(object = x,          .weightsWheel(object = x,
557              piePos = con$PiePos, pieR = con$pieR, pieOffset = con$pieOffset)              piePos = con$PiePos, pieR = con$pieR, pieOffset = con$pieOffset)
558      }      }
559      plot.9 <<- function(x, ...) {      plot.8 <<- function(x, ...) {
560          .monteCarloPlot(object = x,          .monteCarloPlot(object = x,
561              col = con$monteCarlo.col, cex = con$monteCarlo.cex,              col = con$monteCarlo.col, cex = con$monteCarlo.cex,
562              mcSteps = con$mcSteps)              mcSteps = con$mcSteps)
563      }      }
564        plot.9 <<- function(x, ...) {
565            .sharpeRatioPlot(object = x, type = "l",
566                col = con$sharpeRatio.col, cex = con$sharpeRatio.cex,
567                lty = 3)
568        }
569    
570      # Plot:      # Plot:
571      interactivePlot(      interactivePlot(
572          x,          x,
573          choices = c(          choices = c(
574              "Plot Efficient Frontier",              "Plot Efficient Frontier",
575              "Add Sharpe Ratio",              "Add Minimum Risk Portfolio",
             "Add minvariance Portfolio",  
576              "Add Tangency Portfolio",              "Add Tangency Portfolio",
577              "Add Single Assets",              "Add Risk/Return of Single Assets",
578              "Add Equal Weights Portfolio",              "Add Equal Weights Portfolio",
579              "Add Two Asset Frontiers",              "Add Two Asset Frontiers [0-1 PF Only]",
580              "Add Wheel Pie",              "Add Wheel Pie of Weights",
581              "Add Monte Carlo Portfolios"),              "Add Monte Carlo Portfolios",
582                "Add Sharpe Ratio [MV PF Only]"),
583          plotFUN = c(          plotFUN = c(
584              "plot.1", "plot.2", "plot.3", "plot.4", "plot.5",              "plot.1", "plot.2", "plot.3", "plot.4", "plot.5",
585              "plot.6", "plot.7", "plot.8", "plot.9"),              "plot.6", "plot.7", "plot.8", "plot.9"),
# Line 547  Line 590 
590  }  }
591    
592    
593    # ------------------------------------------------------------------------------
594    
595    
596    summary.fPORTFOLIO =
597    function(object, ...)
598    {   # A function implemented by Rmetrics
599    
600        # Description:
601        #   Plot method for an object of class 'fPORTFOLIO'
602    
603        # Note:
604        #   This method can also be used for plotting graphs fitted by
605        #   the function 'garch' from the contributed R package 'tseries'.
606    
607        # FUNCTION:
608    
609        # Summary:
610        print(object)
611        funCalled = as.character(object@call[1])
612        if (funCalled == "portfolioFrontier") {
613            weightsPlot(object)
614            attributesPlot(object)
615            riskBudgetsPlot(object)
616            # Plot Frontier:
617            plot(object, which = 1)
618        } else {
619            weightsPie(object)
620            attributesPie(object)
621            riskBudgetsPie(object)
622        }
623    
624        # Return Value:
625        invisible(object)
626    }
627    
628    
629    
630  ################################################################################  ################################################################################
631    
632    
# Line 555  Line 635 
635  {   # A function implemented by Rmetrics  {   # A function implemented by Rmetrics
636    
637      # Description:      # Description:
638        #    Interactive view of Portfolio Weights
639    
640      # FUNCTION:      # FUNCTION:
641    
642      # Global Variables:      # Global Variables:
643      object <<- object      object <<- object
644      nFrontierPoints <<- length(getTargetRisk(object))      nFrontierPoints <<- length(getTargetRisk(object)[ ,1])
645      dim = dim(getWeights(object))[2]      dim = dim(getWeights(object))[2]
646    
647      # Use default, if xlim and ylim is not specified ...      # Use default, if xlim and ylim is not specified ...
648      mu = object@data$statistics$mu      mu = getStatistics(object)$mu
649      Sigma = object@data$statistics$Sigma      Sigma = getStatistics(object)$Sigma
650      yLim = range(mu) + 0.25*c(-diff(range(mu)), diff(range(mu)))      yLim = range(mu) + 0.25*c(-diff(range(mu)), diff(range(mu)))
651    
652      # First, take care that all assets appear on the plot ...      # First, take care that all assets appear on the plot ...
653      sqrtSig = sqrt(diag(Sigma))      sqrtSig = sqrt(diag(Sigma))
654      xLimAssets = c(min(sqrtSig), max(sqrtSig))+      xLimAssets = c(min(sqrtSig), max(sqrtSig))+
655           c(-0.4*diff(range(sqrtSig)), 0.1*diff(range(sqrtSig)))           c(-0.4*diff(range(sqrtSig)), 0.1*diff(range(sqrtSig)))
656    
657      # ... second take care that the whole frontier appears on the plot:      # ... second take care that the whole frontier appears on the plot:
658      fullFrontier = getFrontier(object)      fullFrontier = getFrontier(object)
659      xLimFrontier = range(fullFrontier[, 1])      xLimFrontier = range(fullFrontier[, 1])
660      xLim = range(c(xLimAssets, xLimFrontier))      xLim = range(c(xLimAssets, xLimFrontier))
661        xLim[1] = xLim[1]-diff(xLim)/5
662    
663      # Control Parameters:      # Control Parameters:
664      con <<- list(      con <<- list(
665          sliderResolution = ceiling(nFrontierPoints/10),          sliderResolution = 1,
   
666          sliderFlag = "weights",          sliderFlag = "weights",
   
667          runningPoint.col  = "red",          runningPoint.col  = "red",
668          minvariance.col = "red",          minvariance.col = "red",
669          tangency.col = "steelblue",          tangency.col = "steelblue",
670          singleAsset.col = rainbow(dim),          singleAsset.col = rainbow(dim),
   
671          minvariance.pch = 19,          minvariance.pch = 19,
672          singleAsset.pch = 19,          singleAsset.pch = 19,
673            tangency.pch = 17,
674          runningPoint.cex = 1.5,          runningPoint.cex = 1.5,
675          minvariance.cex = 1,          minvariance.cex = 1,
676          tangency.cex = 1.25,          tangency.cex = 1.25,
677          singleAsset.cex = 1,          singleAsset.cex = 1,
678            xlim = xLim,
679          xlim.frontier = xLim,          ylim = yLim
         ylim.frontier = yLim  
   
680          )          )
681      con[(Names <- names(control))] <- control      con[(Names <- names(control))] <- control
682    
683      # Internal Function:      # Internal Function:
684      refresh.code = function(...)      refresh.code = function(...)
685      {      {
686            # Startup Counter:
687            .counter <<- .counter + 1
688            if (.counter < 1) return ()
689    
690          # Sliders:          # Sliders:
691          N = .sliderMenu(no = 1)          N = .sliderMenu(no = 1)
692    
# Line 612  Line 695 
695    
696          # Plot 1 - Weights Plot:          # Plot 1 - Weights Plot:
697          weightsPlot(object)          weightsPlot(object)
         title(main = "Weights", line = 3)  
         # Weights Plot Pointer:  
698          abline(v = N, col = "black")          abline(v = N, col = "black")
699    
700          # Plot 2 - Single Weights Plot:          # Plot 2 - Single Weights Plot:
701          .notStackedWeightsPlot(object)          .notStackedWeightsPlot(object)
         # Weights Plot Pointer for not stacked:  
702          abline(v = N, col = "black")          abline(v = N, col = "black")
         title(main = "Not Stacked Weights", line = 3)  
703    
704          # Plot 3 - Frontier Plot:          # Plot 3 - Frontier Plot:
705          frontier = getFrontier(object)          frontier = getFrontier(object)
706          fPoint = frontier[N, ]          fPoint = frontier[N, ]
707          frontierPlot(object, xlim = con$xlim.frontier, ylim = con$ylim.frontier,          frontierPlot(object, xlim = con$xlim, ylim = con$ylim,
708              xlab = "", ylab = "")              xlab = "", ylab = "")
709          mtext("Risk", side = 1, line = 2, cex = .7)          mtext("Target Risk", side = 1, line = 2, cex = 0.7)
710          mtext("Weight", side = 2, line = 2, cex = .7)          mtext("Target Return", side = 2, line = 2, cex = 0.7)
711          points(fPoint[1], fPoint[2], col = con$runningPoint.col, pch = 19,          points(fPoint[1], fPoint[2], col = con$runningPoint.col, pch = 19,
712              cex = con$runningPoint.cex)              cex = con$runningPoint.cex)
713          .tangencyPlot(object, col = con$tangency.col)          .tangencyPlot(object, col = con$tangency.col, pch = con$tangency.pch)
714          .singleAssetPlot(object, col = con$singleAsset.col,          .singleAssetPlot(object, col = con$singleAsset.col,
715              cex = con$singleAsset.cex, pch = con$singleAsset.pch)              cex = con$singleAsset.cex, pch = con$singleAsset.pch)
716          .minvariancePlot(object, col = con$minvariance.col,          .minvariancePlot(object, col = con$minvariance.col,
717              cex = con$minvariancePlot.cex, pch = con$minvariance.pch)              cex = con$minvariancePlot.cex, pch = con$minvariance.pch)
718          Title = paste(          Title = paste(
719              "Return =", signif(fPoint[1], 2), "|",              "Return =", signif(fPoint[2], 2), "|",
720              "Risk = ", signif(fPoint[2], 2))              "Risk = ", signif(fPoint[1], 2))
721          .addlegend(object = object, control = con)          .addlegend(object = object, control = con)
722          title(main = Title)          title(main = Title)
723          grid()          grid()
724    
725          # Weights Pie:          # Plot 4 - Weights Pie:
726          Object = object          Object = object
727          Object@portfolio$weights = getWeights(object)[N, ]          Object@portfolio$weights = getWeights(object)[N, ]
728          weightsPie(Object)          weightsPie(Object)
729          title(main = "Portfolio Pie")          targetReturn = signif(getTargetReturn(object)[N], 3)
730            targetRisk = signif(getTargetRisk(object)[N], 3)
731            Text = paste(
732                "Target Return =", targetReturn, " | ",
733                "Target Risk =", targetRisk)
734            mtext(Text, side = 1, line = 0, adj = 0, cex = 0.7)
735    
736      }      }
737    
738      # Open Slider Menu:      # Open Slider Menu:
739      .sliderMenu(refresh.code,      .counter <<- 0
740        Start <<- which.min(getTargetRisk(object)[ , 1])
741        .sliderMenu(refresh.code, title = "Weights Slider",
742         names =       c(                 "N"),         names =       c(                 "N"),
743         minima =      c(                   1),         minima =      c(                   1),
744         maxima =      c(     nFrontierPoints),         maxima =      c(     nFrontierPoints),
745         resolutions = c(con$sliderResolution),         resolutions = c(con$sliderResolution),
746         starts =      c(                   1))         starts =      c(               Start))
747    
748      # Return Value:      # Return Value:
749      invisible()      invisible()
# Line 671  Line 758 
758  {   # A function implemented by Rmetrics  {   # A function implemented by Rmetrics
759    
760      # Description:      # Description:
761        #   Views interactively frontier and related plots
762    
763      # FUNCTION:      # FUNCTION:
764    
# Line 680  Line 768 
768      dim = dim(getWeights(object))[2]      dim = dim(getWeights(object))[2]
769    
770      # Use default, if xlim and ylim is not specified ...      # Use default, if xlim and ylim is not specified ...
771      mu = object@data$statistics$mu      mu = getStatistics(object)$mu
772      Sigma = object@data$statistics$Sigma      Sigma = getStatistics(object)$Sigma
773      yLim = range(mu) + 0.25*c(-diff(range(mu)), diff(range(mu)))      yLim = range(mu) + 0.25*c(-diff(range(mu)), diff(range(mu)))
774    
775      # First, take care that all assets appear on the plot ...      # First, take care that all assets appear on the plot ...
776      sqrtSig = sqrt(diag(Sigma))      sqrtSig = sqrt(diag(Sigma))
777      xLimAssets = c(min(sqrtSig), max(sqrtSig))+      xLimAssets = c(min(sqrtSig), max(sqrtSig))+
778           c(-0.4*diff(range(sqrtSig)), 0.1*diff(range(sqrtSig)))           c(-0.4*diff(range(sqrtSig)), 0.1*diff(range(sqrtSig)))
779    
780      # ... second take care that the whole frontier appears on the plot:      # ... second take care that the whole frontier appears on the plot:
781      fullFrontier = getFrontier(object)      fullFrontier = getFrontier(object)
782      xLimFrontier = range(fullFrontier[, 1])      xLimFrontier = range(fullFrontier[, 1])
783      xLim = range(c(xLimAssets, xLimFrontier))      xLim = range(c(xLimAssets, xLimFrontier))
784        xLim[1] = xLim[1]-diff(xLim)/5
785    
786        # Initial setting of the pies:
787        Data = getSeries(object)
788        Spec = getSpec(object)
789        Constraints = getConstraints(object)
790        tg = getTargetReturn(tangencyPortfolio(Data, Spec, Constraints))
791        ef = getTargetReturn(object)
792        piePos = which(diff(sign(as.vector(ef)-as.vector(tg))) > 0)
793    
794      # Control list:      # Control list:
795      con <<- list(      con <<- list(
796          sliderFlag = "frontier",          sliderFlag = "frontier",
   
797          sharpeRatio.col = "black",          sharpeRatio.col = "black",
798          minvariance.col = "red",          minvariance.col = "red",
799          tangency.col = "steelblue",          tangency.col = "steelblue",
# Line 704  Line 802 
802          singleAsset.col = rainbow(dim),          singleAsset.col = rainbow(dim),
803          twoAssets.col = "grey",          twoAssets.col = "grey",
804          monteCarlo.col = "black",          monteCarlo.col = "black",
   
805          minvariance.pch = 17,          minvariance.pch = 17,
806          tangency.pch = 17,          tangency.pch = 17,
807          cml.pch = 17,          cml.pch = 17,
808          equalWeights.pch = 15,          equalWeights.pch = 15,
809          singleAsset.pch = 18,          singleAsset.pch = 18,
   
810          sharpeRatio.cex = 0.1,          sharpeRatio.cex = 0.1,
811          minvariance.cex = 1,          minvariance.cex = 1,
812          tangency.cex = 1.25,          tangency.cex = 1.25,
# Line 719  Line 815 
815          singleAsset.cex = 1,          singleAsset.cex = 1,
816          twoAssets.cex = 0.01,          twoAssets.cex = 0.01,
817          monteCarlo.cex = 0.01,          monteCarlo.cex = 0.01,
   
818          mcSteps = 5000,          mcSteps = 5000,
819            weightsPieR = NULL,
820          pieR = NULL,          weightsPieOffset = NULL,
821          piePos = NULL,          attributesPieR = NULL,
822          pieOffset = NULL,          attributesPieOffset = NULL,
823            xlim = xLim,
824          xlim.frontier = xLim,          ylim = yLim
         ylim.frontier = yLim  
825          )          )
826      con[(Names <- names(control))] <- control      con[(Names <- names(control))] <- control
827    
# Line 739  Line 833 
833      # Internal Function:      # Internal Function:
834      refresh.code = function(...)      refresh.code = function(...)
835      {      {
836            # Startup Counter:
837            .counter <<- .counter + 1
838            if (.counter < 14) return ()
839    
840          # Sliders:          # Sliders:
841          N                = .sliderMenu(no =  1)          N                = .sliderMenu(no =  1)
842          pieFlag          = .sliderMenu(no =  2)          weightsWheel     = .sliderMenu(no =  2)
843          attributePieFlag = .sliderMenu(no =  3)          attributesWheel  = .sliderMenu(no =  3)
844          legendFlag       = .sliderMenu(no =  4)          legendFlag       = .sliderMenu(no =  4)
845          minvarianceFlag  = .sliderMenu(no =  5)          minvarianceFlag  = .sliderMenu(no =  5)
846          tangencyFlag     = .sliderMenu(no =  6)          tangencyFlag     = .sliderMenu(no =  6)
# Line 759  Line 857 
857          par(mfrow = c(1, 1))          par(mfrow = c(1, 1))
858    
859          # Plots and Addons:          # Plots and Addons:
860          frontierPlot(object = object, pch = 19, ylim = con$ylim.frontier,          frontierPlot(object = object, pch = 19,
861              xlim = con$xlim.frontier)              xlim = con$xlim, ylim = con$ylim)
862          ef = getFrontier(object)          ef = getFrontier(object)
863          points(ef[N, 1], ef[N, 2], col = "red", pch = 19, cex = 1.5)          points(ef[N, 1], ef[N, 2], col = "red", pch = 19, cex = 1.5)
864          if (sharpeRatioFlag) {          if (sharpeRatioFlag) {
865              .sharpeRatioPlot(object = object, type = "l",              .sharpeRatioPlot(object = object,
866                  col = con$sharpeRatio.col, cex = con$sharpeRatio.cex,                  type = "l",
867                    col = con$sharpeRatio.col,
868                    cex = con$sharpeRatio.cex,
869                  lty = 3)                  lty = 3)
870          }          }
871          if (minvarianceFlag) {          if (minvarianceFlag) {
872              .minvariancePlot(object = object,              .minvariancePlot(object = object,
873                  col = con$minvariance.col, cex = con$minvariance.cex,                  col = con$minvariance.col,
874                    cex = con$minvariance.cex,
875                  pch = con$minvariance.pch)                  pch = con$minvariance.pch)
876          }          }
877          if (cmlFlag) {          if (cmlFlag) {
878              object@specification@portfolio$riskFreeRate = riskFreeRate              object@spec$spec@portfolio$riskFreeRate = riskFreeRate
879              data = object@data$statistics              .cmlPlot(object,
880              spec = object@specification                  col = con$cml.col,
881              constraintsString = object@constraints                  cex = con$cml.cex,
882              setRiskFreeRate(spec = object@specification,                  pch = con$cml.pch)
                 riskFreeRate = riskFreeRate)  
             cml = cmlPortfolio(data = data, spec = spec,  
                constraintsString = constraintsString)  
             .cmlPlot(object = cml,  
                 col = con$cml.col, cex = con$cml.cex, pch = con$cml.pch)  
883          }          }
   
884          if (tangencyFlag) {          if (tangencyFlag) {
885              .tangencyPlot(object = object,              .tangencyPlot(object = object,
886                  col = con$tangency.col, cex = con$tangency.cex,                  col = con$tangency.col,
887                    cex = con$tangency.cex,
888                  pch = con$tangency.pch)                  pch = con$tangency.pch)
889          }          }
890          if (singleAssetFlag) {          if (singleAssetFlag) {
891              .singleAssetPlot(object = object,              .singleAssetPlot(object = object,
892                  col = con$singleAsset.col, cex = con$singleAsset.cex,                  col = con$singleAsset.col,
893                    cex = con$singleAsset.cex,
894                  pch = con$singleAsset.pch)                  pch = con$singleAsset.pch)
895          }          }
896          if (equalWeightsFlag) {          if (equalWeightsFlag) {
897              .equalWeightsPlot(object = object,              .equalWeightsPlot(object = object,
898                  col = con$equalWeights.col, cex = con$equalWeights.cex,                  col = con$equalWeights.col,
899                    cex = con$equalWeights.cex,
900                  pch = con$equalWeights.pch)                  pch = con$equalWeights.pch)
901          }          }
902          if (twoAssetsFlag) {          if (twoAssetsFlag) {
903              .twoAssetsPlot(object = object, col = con$twoAssets.col)              .twoAssetsPlot(object = object,
904                    col = con$twoAssets.col)
905          }          }
906          if (pieFlag) {          if (weightsWheel) {
907              .wheelPiePlot(object = object,              .weightsWheel(object = object,
908                  piePos = N, pieR = con$PieR, pieOffset = con$pieOffset)                  piePos = N, pieR = con$weightsPieR,
909                    pieOffset = con$weightsPieOffset)
910            }
911            if (attributesWheel) {
912                .attributesWheel(object = object,
913                    piePos = N,
914                    pieR = con$attributesPieR,
915                    pieOffset = con$attributesPieOffset)
916          }          }
917          if (mcFlag) {          if (mcFlag) {
918              .monteCarloPlot(object = object,              .monteCarloPlot(object = object,
919                  col = con$monteCarlo.col, cex = con$monteCarlo.cex,                  col = con$monteCarlo.col,
920                    cex = con$monteCarlo.cex,
921                  mcSteps = mcSteps)                  mcSteps = mcSteps)
922          }          }
923          if (legendFlag) {          if (legendFlag) {
924              .addlegend(object = object, control = con)              .addlegend(object = object,
925          }                  control = con)
         if (attributePieFlag) {  
             .attPiePlot(object = object,  
                 piePos = N, pieR = con$PieR, pieOffset = con$pieOffset)  
926              }              }
927          fPoint = ef[N, ]          fPoint = ef[N, ]
928          Title = paste(          Title = paste(
929              "Return =", signif(fPoint[1], 2), "|",              "Return =", signif(fPoint[2], 2), "|",
930              "Risk = ", signif(fPoint[2], 2))              "Risk = ", signif(fPoint[1], 2))
931          title(main = Title)          title(main = Title)
932    
933            grid()
934      }      }
935    
936      # Open Slider Menu:      # Open Slider Menu:
937        .counter <<-0
938      nFP = nFrontierPoints      nFP = nFrontierPoints
939      .sliderMenu(refresh.code,      maxRF = max(getTargetReturn(object))
940        resRF = maxRF/100
941        .sliderMenu(refresh.code, title = "Frontier Slider",
942          names =       c(  "Select Frontier Point  ",          names =       c(  "Select Frontier Point  ",
943                            "Add Weights Pie        ",                        "Add|Remove Weights Pie        ",
944                            "Add Attribute Pie      ",                        "Add|Remove Attribute Pie      ",
945                            "Add Legend             ",                        "Add|Remove Legend             ",
946                            "Add Min Variance PF    ",                        "Add|Remove Min Variance PF    ",
947                            "Add Tangency PF        ",                        "Add|Remove Tangency PF        ",
948                            "Add Capital Market Line",                        "Add|Remove Capital Market Line",
949                            "Risk Free Rate         ",                        "-> Risk Free Rate             ",
950                            "Add Sharpe Ratio       ",                        "Add|Remove Sharpe Ratio       ",
951                            "Add Equal Weights PF   ",                        "Add|Remove Equal Weights PF   ",
952                            "Add Single Assets      ",                        "Add|Remove Single Assets      ",
953                            "Add Two Assets EFs     ",                        "Add|Remove Two Assets EFs     ",
954                            "Add Monte Carlo PFs    ",                        "Add|Remove Monte Carlo PFs    ",
955                            "# of MC Steps          "),                        "-> # of MC Steps              "),
956    
957                #  frontierPoints Pie Pie L mv tg cml   #RF SR EW SA TA MC   #MC                #  frontierPoints Pie Pie L mv tg cml   #RF SR EW SA TA MC   #MC
958                        #       1   2   2 3  4  5   7     8  6  9 10 11 12    13                        #       1   2   2 3  4  5   7     8  6  9 10 11 12    13
959          minima =      c(      1,  0,  0,0, 0, 0,  0,    0, 0, 0, 0, 0, 0,    0),          minima =      c(      1,  0,  0,0, 0, 0,  0,    0, 0, 0, 0, 0, 0,    0),
960          maxima =      c(    nFP,  1,  1,1, 1, 1,  1,   20, 1, 1, 1, 1, 1,25000),          maxima =      c(   nFP,  1,  1, 1, 1, 1, 1, maxRF, 1, 1, 1, 1, 1,25000),
961          resolutions = c(      1,  1,  1,1, 1, 1,  1,.0001, 1, 1, 1, 1, 1, 1000),          resolutions = c(     1,  1,  1, 1, 1, 1, 1, resRF, 1, 1, 1, 1, 1, 1000),
962          starts =      c(      1,  1,  0,1, 1, 1,  1,    0, 0, 0, 1, 0, 0, 1000))          starts =      c(piePos,  1,  0, 1, 1, 1, 1,     0, 0, 0, 1, 0, 0, 1000))
963    
964      # Return Value:      # Return Value:
965      invisible()      invisible()

Legend:
Removed from v.1232  
changed lines
  Added in v.1611

R-Forge@R-project.org
ViewVC Help
Powered by ViewVC 1.0.0  
Thanks to:
Vienna University of Economics and Business University of Wisconsin - Madison Powered By FusionForge