Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
braverock
GitHub Repository: braverock/portfolioanalytics
Path: blob/master/R/constraintsFUN.R
1433 views
1
2
#' Function to compute diversification as a constraint
3
#'
4
#' Diversification is defined as 1 minus the sum of the squared weights
5
#' \deqn{diversification = 1 - sum(w^2)}
6
#'
7
#' @param weights vector of asset weights
8
#' @author Ross Bennett
9
#' @export
10
diversification <- function(weights){
11
div <- 1 - sum(weights^2)
12
return(div)
13
}
14
15
16
###############################################################################
17
# R (https://r-project.org/) Numeric Methods for Optimization of Portfolios
18
#
19
# Copyright (c) 2004-2021 Brian G. Peterson, Peter Carl, Ross Bennett, Kris Boudt
20
#
21
# This library is distributed under the terms of the GNU Public License (GPL)
22
# for full details see the file COPYING
23
#
24
# $Id$
25
#
26
###############################################################################
27
28