main content

diversify esg portfolios -凯发k8网页登录

this example shows how to include qualitative factors for environmental, social, and corporate governance (esg) in the portfolio selection process. the example extends the traditional mean-variance portfolio using a object to include the esg metric. first, the function computes the mean-variance efficient frontier for different esg levels. then, the example illustrates how to combine the esg performance measure with portfolio diversification techniques. specifically, it introduces hybrid models that use the herfindahl-hirshman (hh) index and the most diversified portfolio (mdp) approach using the function. finally, the framework compares the returns and behavior of the different esg strategies.

define mean-variance portfolio

load the table with the asset returns and a vector with esg scores for the assets. both the asset returns and their esg scores are simulated values and do not represent the performance of any real securities. hower, you can apply the code and workflow in this example to any data set with prices and returns and esg information.

% load data
load('asset_return_100_simulated.mat') % returns table
load('esg_s26.mat')                    % esg scores

transform the returns table into a prices .

% transform returns to prices
assetprices = ret2tick(stockreturns);
% transform prices table to timetable
nrows = size(stockreturns,1);
day = datetime("today");
time = (day-nrows):day;
assetprices = table2timetable(assetprices,"rowtimes",time);

define a object with default constraints where the weights must be nonnegative and sum to 1.

% create a mean-variance portfolio object with default constraints
p = portfolio;
p = estimateassetmoments(p,stockreturns);
p = setdefaultconstraints(p);

compute the mean-variance efficient frontier for different esg levels

obtain contour plots of the esg-mean-variance efficient surface. you obtain the efficient surface from the pareto optima of the multiobjective problem that includes all the performance metrics: average esg score, average return, and return variance.

first, obtain feasible values of the esg metric by finding the minimum and maximum esg levels. to do this step, use the function assigning the average esg score as the objective function. the average esg score of a portfolio is the weighted sum of the individual asset esg scores, where the weights are given by the amount invested in each asset.

% define objective function: average esg score
esgscore = @(x) esgnumeric'*x;
% find the minimum esg score
solmin = estimatecustomobjectiveportfolio(p,esgscore);
minesg = esgscore(solmin)
minesg = 0.0187
% find the maximum esg score
solmax = estimatecustomobjectiveportfolio(p,esgscore, ...
    objectivesense="maximize");
maxesg = esgscore(solmax)
maxesg = 0.9735

to compute the contours of the efficient surface, you add the average esg score as a constraint using the function. the coefficients of the linear constraint are the esg scores associated with each asset and the right-hand side is the target esg score for the desired contour. notice that the convention of the inequalities in the object is . because the goal is to maximize the average esg score, the target esg value for the contour should be a lower bound. therefore, you need to flip the signs of the coefficients and the right-hand side of the added inequality. the function that computes and plots the contours is in the local functions section.

n = 20; % number of efficient portfolios per esg value
% add esg score as a constraint to the portfolio object
ain = -esgnumeric';
bin = -minesg; % start with the smallest esg score
p = setinequality(p,ain,bin);
% esimate lower value for contour plots
pwgt = estimatefrontier(p,n);
pesg = pwgt'*esgnumeric;
mincontour = max(pesg); % all esg scores lower than this have
                        % overlapped contours.
% plot contours
nc = 5; % number of contour plots
plotesgcontours(p,esgnumeric,mincontour,maxesg,nc,n);

figure contains an axes object. the axes object with title efficient frontiers, xlabel standard deviation of portfolio returns, ylabel mean of portfolio returns contains 6 objects of type line. these objects represent 72.67 esg, 77.61 esg, 82.54 esg, 87.48 esg, 92.42 esg, no esg restriction.

diversification techniques

in this example, the two diversification measures are the equally weighted (ew) portfolio and the most diversified portfolio (mdp).

you obtain the ew portfolio using the herfindahl-hirschman (hh) index as the diversification measure

hh(x)=i=1nxi2

an equally weighted portfolio minimizes this index. therefore, the portfolios that you obtain from using this index as a penalty have weights that satisfy the portfolio constraints and are more evenly weighted.

the diversification measure for the most diversified portfolio (mdp) is

mdp(x)=-i=1nσixi

where σi represents the standard deviation of asset i. using this measure as a penalty function maximizes the diversification ratio [1].

φ(x)=xtσxtσx

if the portfolio is fully invested in one asset, or if all assets are perfectly correlated, the diversification ratio φ(x) is equal to 1. for all other cases, φ(x)>1. therefore, if φ(x)1, there is no diversification, so the goal is to maximize φ(x). unlike the hh index, the goal of mdp is not to obtain a portfolio whose weights are evenly distributed among all assets, but to obtain a portfolio whose selected (nonzero) assets have the same correlation to the portfolio as a whole.

diversification for fixed esg level

you can extend the traditional minimum variance portfolio problem subject to an expected return to inlcude the esg metric by setting an esg constraint for the problem. the purpose of the esg constraint is to force the portfolio to achieve an esg score greater than a certain target. then, add a penalty term to the objective function to guide the problem toward more or less diversified portfolios. how diversified a portfolio is depends on your choice of the penalty parameter.

choose an esg level of 0.85 and an expected return of 0.001.

% minimum esg and return levels
esg0 = 0.85;
ret0 = 1e-3;

currently, the portfolio problem assumes that the weights must be nonnegative and sum to 1. add the requirement that the return of the portfolio is at least ret0 and the esg score is at least esg0. the feasible set is represented as x, which is

x={x|x0,i=1nxi=1,μtxret0,esg(x)esg0}

add the esg constraint using the function.

% add esg constraint
ain = -esgnumeric';
bin = -esg0; % set target esg score
p = setinequality(p,ain,bin);

to add the return constraint, pass the name-value argument targetreturn=ret0 to the function for each of the different custom objective portfolios of interest.

the portfolio that minimizes the variance with the hh penalty is

minxx   xtσx λhhxtx

% hh penalty parameter
lambdahh =0.001;
% variance   herfindahl-hirschman (hh) index
var_hh = @(x) x'*p.assetcovar*x   lambdahh*(x'*x);
% solution that accounts for risk and hh diversification
whhmix = estimatecustomobjectiveportfolio(p,var_hh,targetreturn=ret0);

the portfolio that minimizes the variance with the mdp penalty is

minxx   xtσx-λmdpσtx

% mdp penalty parameter
lambdamdp =0.01;
% variance   most diversified portfolio (mdp)
sigma = sqrt(diag(p.assetcovar));
var_mdp = @(x) x'*p.assetcovar*x - lambdamdp*(sigma'*x);
% solution that accounts for risk and mdp diversification
wmdpmix = estimatecustomobjectiveportfolio(p,var_mdp,targetreturn=ret0);

plot the asset allocation from the penalized strategies.

% plot asset allocation
figure
t = tiledlayout(1,2);
% hh penalized method
nexttile    
bar(whhmix');
title('variance   hh')
% mdp penalized method
nexttile
bar(wmdpmix')
title('variance   mdp')
% general labels
ylabel(t,'asset weight')
xlabel(t,'asset number')

figure contains 2 axes objects. axes object 1 with title variance   hh contains an object of type bar. axes object 2 with title variance   mdp contains an object of type bar.

the strategies that include the penalty function in the objective give weights that are between the minimum variance portfolio weights and the weights from the respective maximum diversification technique. in fact, for the problem with the hh penalty, choosing λhh=0 returns the minimum variance solution, and as λhh, the solution approaches the one that maximizes hh diversification. for the problem with the mdp penalty, choosing λmdp=0 also returns the minimum variance solution, and there exists a value λˆmdp such that the mdp problem and the penalized version are equivalent. consequently, values of λmdp[0,λˆmdp] return asset weights that range from the minimum variance behavior to the mdp behavior.

diversification by "tilting"

the strategies in diversification for fixed esg level explicitly set a target esg average score. however, a different set of strategies controls the esg score in a less direct way. the method in these strategies uses esg tilting. with tilting, you discretize the esg score into 'high' and 'low' levels and the objective function penalizes each level differently. in other words, you use the diversification measure to tilt the portfolio toward higher or lower esg values. therefore, instead of explicitly requiring that the portfolios maintain a target esg average score, you select assets, with respect to their esg score, implicitly through the choice of penalty parameters.

start by labeling the assets with an esg score less than or equal to 0.5 as 'low' and assets with an esg score greater than 0.5 as 'high', and then remove the esg constraint.

% label esg data
esglabel = discretize(esgnumeric,[0 0.5 1], ...
    "categorical",{'low','high'});
% create table with esg scores and labels
esg = table(esgnumeric,esglabel);
% remove esg constraint
p = setinequality(p,[],[]);

the tilted version of the portfolio with the hh index is

min   xtσx λhhhighihxi2 λhhlowilxi2s.t.  i=1nxi=1,μtxret0,x0

the feasible region does not bound the average esg level of the portfolio. instead, you implicitly control the esg score by applying different penalization terms to assets with a 'high' esg score (ih) and assets with a 'low' esg score (il). to achieve a portfolio with a high average esg score, the penalty terms must satisfy that 0λhhhighλhhlow.

% hh penalty parameters
% penalty parameter for assets with 'low' esg score
lambdalowhh =0.01;
% penalty parameter for assets with 'high' esg score
lambdahighhh =0.001;
% lambda for hh 'tilted' penalty
lambdatilthh = (esg.esglabel=='low').*lambdalowhh   (esg.esglabel=='high').*lambdahighhh;
% variance   herfindahl-hirschman (hh) index
tilt_hh = @(x) x'*p.assetcovar*x   lambdatilthh'*(x.^2);
% solution that minimizes variance   hh term
wtilthh = estimatecustomobjectiveportfolio(p,tilt_hh,targetreturn=ret0);

similarly, the tilted version of the portfolio with the mdp penalty term is given by

min   xtσx-λmdphighihσixi-λmdplowilσixis.t.  i=1nxi=1,μtxret0,x0

in this case, to achieve a portfolio with a high average esg score, the penalty terms must satisfy that 0λmdplowλmdphigh.

% mdp penalty parameters
% penalty parameter for assets with 'low' esg score
lambdalowmdp =0.001;
% penalty parameter for assets with 'high' esg score
lambdahighmdp =0.01;
% lambda for mdp 'tilted' penalty
lambdatiltmdp = (esg.esglabel=='low').*lambdalowmdp   (esg.esglabel=='high').*lambdahighmdp;
% variance   mdp index
tilt_mdp = @(x) x'*p.assetcovar*x - lambdatiltmdp'*(sigma.*x);
% solution that minimizes variance   hh term
wtiltmdp = estimatecustomobjectiveportfolio(p,tilt_mdp,targetreturn=ret0);

compare esg scores

compare the esg scores using tilting and a target esg constraint. for the comparison to be more meaningful, compute the minimum variance portfolio without esg constraints or penalty terms, and use the esg score of the minimum variance portfolio as benchmark.

% compute the minimum variance portfolio without esg constraints
p = setinequality(p,[],[]);
wbmk = estimatefrontierbyreturn(p,ret0);
% compute esg scores for the different strategies
benchmark = esgnumeric'*wbmk;
constrainedhh = esgnumeric'*whhmix;
constrainedmd = esgnumeric'*wmdpmix;
tiltedhh = esgnumeric'*wtilthh;
tiltedmdp = esgnumeric'*wtiltmdp;
% create table
strategiesesg = table(benchmark,constrainedhh,constrainedmd,tiltedhh,tiltedmdp);
figure;
bar(categorical(strategiesesg.properties.variablenames),strategiesesg.variables)
title('esg scores')

figure contains an axes object. the axes object with title esg scores contains an object of type bar.

as expected, the esg scores of the penalized strategies are better than the esg scores of the minimum variance portfolio without constraint and penalty terms. however, the tilted strategies achieve lower esg scores than the ones that include the target esg score as a constraint. this comparison shows the flexibility of the tilted strategy. if the esg target score is not an essential requirement, then you can consider a tilting strategy.

backtest using strategies

to show the performance through time for the two strategies (diversification for fixed esg level and diversification by "tilting"), use the framework. use to compare the strategies with a prespecified target esg score with the strategies that use esg tilting.

% store info to pass to esg constrained strategies
ain = -esgnumeric';
bin = -esg0; % set target esg score
construct.p = setinequality(p,-esgnumeric',-esg0);
construct.ret0 = ret0;
construct.lambdahh =0.01;
construct.lambdamdp =0.05;
% store info to pass to esg tilting strategies
tiltstruct.p = setinequality(p,[],[]);
tiltstruct.ret0 = ret0;
% hh tilting penalty parameters
% penalty parameter for assets with 'low' esg score
hhlambdalow =0.1;
% penalty parameter for assets with 'high' esg score
hhlambdahigh =0.01;
% combined penalty terms for hh
tiltstruct.lambdahh = (esg.esglabel=='low').*hhlambdalow   ...
    (esg.esglabel=='high').*hhlambdahigh;
% mdp tilting penalty parameters
% penalty parameter for assets with 'low' esg score
mdplambdalow =0.005;
% penalty parameter for assets with 'high' esg score
mdplambdahigh =0.05;
% combined penalty terms for mdp
tiltstruct.lambdamdp = (esg.esglabel=='low').*mdplambdalow   ...
    (esg.esglabel=='high').*mdplambdahigh;

define the investment strategies that you want to use to make the asset allocation decisions at each investment period. for this example, four investment strategies are defined as input to . the first two strategies require a minimum esg score and the last two use the esg tilting method.

% define backtesting parameters
warmupperiod = 84;       % warmup period
rebalfreq = 42;          % rebalance frequency
lookback  = [42 126];     % lookback window
transactioncost = 0.001; % transaction cost for trade
% constrained variance   hh strategy
strat1 = backteststrategy('mixedhh', @(w,p) mixhh(w,p,construct), ...
    'rebalancefrequency', rebalfreq, ...
    'lookbackwindow', lookback, ...
    'transactioncosts', transactioncost, ...
    'initialweights', whhmix);
% constrained variance   mdp
strat2 = backteststrategy('mixedmdp', @(w,p) mixmdp(w,p,construct), ...
    'rebalancefrequency', rebalfreq, ...
    'lookbackwindow', lookback, ...
    'transactioncosts', transactioncost, ...
    'initialweights', wmdpmix);
% hh tilted strategy
strat3 = backteststrategy('tiltedhh', @(w,p) tiltedhh(w,p,tiltstruct), ...
    'rebalancefrequency', rebalfreq, ...
    'lookbackwindow', lookback, ...
    'transactioncosts', transactioncost, ...
    'initialweights', wtilthh);
% mdp tilted strategy
strat4 = backteststrategy('tiltedmdp', @(w,p) tiltedmdp(w,p,tiltstruct), ...
    'rebalancefrequency', rebalfreq, ...
    'lookbackwindow', lookback, ...
    'transactioncosts', transactioncost, ...
    'initialweights', wtiltmdp);
% all strategies
strategies = [strat1,strat2,strat3,strat4];

run the backtest using and generate a for each strategy's performance results.

% create the backtesting engine object
backtester = backtestengine(strategies);
% run backtest
backtester = runbacktest(backtester,assetprices,...
    'start',warmupperiod);
% summary
summary(backtester)
ans=9×4 table
                        mixedhh       mixedmdp      tiltedhh     tiltedmdp 
                       __________    __________    __________    __________
    totalreturn            0.7077        1.1927       0.79527        1.3295
    sharperatio          0.029317       0.03188      0.031911      0.034608
    volatility           0.011965      0.017845      0.011719      0.016851
    averageturnover     0.0054528     0.0065605     0.0053991     0.0070898
    maxturnover           0.80059       0.72624       0.80099       0.76676
    averagereturn      0.00035068    0.00056875    0.00037387    0.00058304
    maxdrawdown           0.23083       0.34334       0.22526       0.34688
    averagebuycost       0.068778      0.097277      0.070048       0.12019
    averagesellcost      0.068778      0.097277      0.070048       0.12019

to visualize their performance over the entire investment period, plot the daily results of the strategies using .

% plot daily stocks and esg strategy behavior
figure
t = tiledlayout(2,1,'padding','none');
% equity curves
nexttile(t)
equitycurve(backtester);
% table and plot of the average esg score for the mixed and tilted
% strategies throughout the investment period
nexttile(t)
tavgesg = averageesgtimetable(backtester,esgnumeric,esg0);

figure contains 2 axes objects. axes object 1 with title equity curve, xlabel time, ylabel portfolio value contains 4 objects of type line. these objects represent mixedhh, mixedmdp, tiltedhh, tiltedmdp. axes object 2 with title esg curves, ylabel averagde esg score contains 5 objects of type line. these objects represent mixedhh, mixedmdp, tiltedhh, tiltedmdp, targetesg.

in the equity curve plot, the tilted mdp strategy is the one that performs the best by the end of the investment period, followed by the mixed mdp strategy with the esg constraint. the performance of the mixed and tilted strategies depend on the choice of the penalty parameters. both esg methods, the constrained and the tilted methods, require defining two parameters for each strategy. the esg constrained method requires you to provide a target esg score and a penalty parameter for the diversification term. the esg tilting requires one penalty parameter value for the assets with 'high' esg scores and a different one for 'low' esg scores. in addition, the esg tilting requires a third parameter to determine the cutoff point between 'high' and 'low' esg assets. given the dependency of the penalized strategies on the value of their parameters, the performance of those strategies vary widely. however, this example shows that it is possible to find values of the parameters so that the resulting strategies obtain good returns while improving on the average esg score.

the esg curves plot shows the average esg evolution computed throughout the investment period for the penalized investment strategies, both for the esg constrained method and the esg tilting method. you can see that, unlike the choice of the esg target for the esg constraint, the selection of the tilting penalty parameters has an effect on the esg score of the optimal portfolios that is less explicit. therefore, the average esg score varies more with the tilting strategies than with the constrained strategies, as expected.

although not shown in this example, the traditional minimum variance portfolio strategy, subject to the same expected return and esg levels, results in higher average turnover and transaction costs than any of the strategies covered in the example. another advanvange of adding a diversification measure to the formulation of the problem is to reduce the average turnover and transaction costs.

references

[1] richard, j. c., and t. roncalli. smart beta: managing diversification of minimum variance portfolios. risk-based and factor investing. elsevier, pp. 31-63, 2015.

local functions

function [] = plotesgcontours(p,esgscores,minesg,maxesg,ncont,...
    nport)
% plot mean-variance frontier for different esg levels
% add esg constraint
p.ainequality = -esgscores';
% compute mean-variance risks and returns for different esg levels
contouresg = linspace(minesg,maxesg,ncont 1);
figure
hold on
labels = strings(ncont 1,1);
for i = 1:ncont
    p.binequality = -contouresg(i); % change target esg score
    plotfrontier(p,nport);
    labels(i) = sprintf("%6.2f esg",contouresg(i)*100);
end
% plot the original mean-variance frontier
p.ainequality = []; p.binequality = [];
plotfrontier(p,nport);
labels(i 1) = "no esg restriction";
title('efficient frontiers')
legend(labels,'location','southeast')
hold off
end
function [esgtimetable] = averageesgtimetable(backtester,...
    esgscores,targetesg)
% create a table of the average esg score for the mix and tilted
% strategies throughout the investment period and plot it
% normalize weights
wmixedhh = backtester.positions.mixedhh{:,2:end}./...
    sum(backtester.positions.mixedhh.variables,2);
wmixedmdp = backtester.positions.mixedmdp{:,2:end}./...
    sum(backtester.positions.mixedmdp.variables,2);
wtiltedhh = backtester.positions.tiltedhh{:,2:end}./...
    sum(backtester.positions.tiltedhh.variables,2);
wtiltedmdp = backtester.positions.tiltedmdp{:,2:end}./...
    sum(backtester.positions.tiltedmdp.variables,2);
% compute esg scores for the different strategies
conshh_esg = wmixedhh*esgscores;
consmdp_esg = wmixedmdp*esgscores;
tiltedhh_esg = wtiltedhh*esgscores;
tiltedmdp_esg = wtiltedmdp*esgscores;
% create timetable
esgtimetable = timetable(backtester.positions.tiltedhh.time,...
    conshh_esg,consmdp_esg,tiltedhh_esg,tiltedmdp_esg);
% plot esg curves
plot(esgtimetable.time, esgtimetable.variables);
hold on
plot(esgtimetable.time, targetesg*ones(size(esgtimetable.time)),...
    'k--','linewidth',1); % plots target esg scores
title('esg curves');
ylabel('averagde esg score');
legend('mixedhh','mixedmdp','tiltedhh','tiltedmdp', 'targetesg',...
    'location','southwest');
end
function new_weights = mixhh(~, assetprices, struct)
% min variance   max hh diversification strategy
% retrieve portfolio information
p = struct.p;
ret0 = struct.ret0;
% define returns and covariance matrix
assetreturns = tick2ret(assetprices);
p = estimateassetmoments(p,assetreturns{:,:});
% objective function: variance   herfindahl-hirschman
% diversification term
%   min x'*sigma*x   lambda*x'*x
objfun = @(x) x'*p.assetcovar*x   struct.lambdahh*(x'*x);
% solve problem
% solution that minimizes the variance   hh index
new_weights = estimatecustomobjectiveportfolio(p,objfun,...
    targetreturn=ret0);
end
function new_weights = mixmdp(~, assetprices, struct)
% min variance   mdp diversification strategy
% retrieve portfolio information
p = struct.p;
ret0 = struct.ret0;
% define returns and covariance matrix
assetreturns = tick2ret(assetprices);
p = estimateassetmoments(p,assetreturns{:,:});
sigma = sqrt(diag(p.assetcovar));
% objective function: variance   mdp diversification term
%   min x'*sigma*x - lambda*sigma'*x
objfun = @(x) x'*p.assetcovar*x - struct.lambdamdp*(sigma'*x);
% solve problem
% solution that minimizes variance   mdp term
new_weights = estimatecustomobjectiveportfolio(p,objfun,...
    targetreturn=ret0);
end
function new_weights = tiltedhh(~,assetprices,struct)
% tilted hh approach
% retrieve portfolio information
p = struct.p;
ret0 = struct.ret0;
lambda = struct.lambdahh;
% define returns and covariance matrix
assetreturns = tick2ret(assetprices);
p = estimateassetmoments(p,assetreturns{:,:});
% objective function: variance   herfindahl-hirschman
% diversification term
%   min x'*sigma*x   lambda*x'*x
objfun = @(x) x'*p.assetcovar*x   lambda'*(x.^2);
% solve problem
% solution that minimizes variance   hh term
new_weights = estimatecustomobjectiveportfolio(p,objfun,...
    targetreturn=ret0);
end
function new_weights = tiltedmdp(~,assetprices,struct)
% tilted mdp approach
% retrieve portfolio information
p = struct.p;
ret0 = struct.ret0;
lambda = struct.lambdamdp;
% define returns and covariance matrix
assetreturns = tick2ret(assetprices);
p = estimateassetmoments(p,assetreturns{:,:});
sigma = sqrt(diag(p.assetcovar));
% objective function: variance   mdp
%   min x'*sigma*x - lambda*sigma'*x
objfun = @(x) x'*p.assetcovar*x - lambda'*(sigma.*x);
% solve problem
% solution that minimizes variance   mdp term
new_weights = estimatecustomobjectiveportfolio(p,objfun,...
    targetreturn=ret0);
end
% the api of the rebalance functions (mixhh, mixmdp, tiltedhh, and
% tiltedmdp) require a first input with the current weights. they
% are redundant for these strategies and can be ignored.

see also

| | | | | | | | |

related examples

more about

    external websites

      网站地图