250 assignment 2 optimisation 71726

Upload: nipun-arora

Post on 08-Jul-2018

215 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/19/2019 250 Assignment 2 Optimisation 71726

    1/17

    ECE3093 Semester 1, 2014

    Assignment 2, (worth 10%)

    ANSWER TEMPLATE

    Name: Hashan Wickramasuriya Student ID: 23417250 

    Please complete the following table, after solving Task 1 and Task 2:

    LP QP

    Optimal x vector ($ allocations to 10 indices) [0, 290.82, 500, 0, 0, 0, 0, 0,

    0, 0]

    !0, 36.133, 331.866, 0,

    0, 0, 500, 0, 0,

    132.001]

    Maximum R (for optimal & feasible solution) -0.05 (-5%) -0.05 (-5%)

    meanTrainreturn  4.17653061014567 -0.0120133444227590minTrainreturn  -49.9999999951506 -65.8214203733677

    maxTrainreturn  81.9030612100866 40.8724189006152

    meanTestreturn  -5.95748299573666 9.32363502669894

    minTestreturn  -93.5816326443381 -73.82869568812463

    maxTestreturn  57.4846938759323 48.6435043818340

    meanTrainvariance  739.031147816565 489.093204909667

    meanTestvariance  1305.54842096684 624.856921270185

    Please provide responses to Task 3 questions below:

    a)  Plot the monthly returns for each optimal strategy (LP and QP) during the training period and then

    what happens during the testing period. What do you observe?

    Linear Programming

    !"#$%& ()(

    P

    Returns on $1000 do not need to be quoted to 14 decimal places.

    $4.18

    -$5.96

    P

    P

    P   O

    P

    P

    P

    P

    -0.001

  • 8/19/2019 250 Assignment 2 Optimisation 71726

    2/17

     

    !"#$%& ()*

    !"#$%& ()+

    P

    NB scale

    -50;+100]

    NB scale-100;+100]

    The overlay plot, Figure 1.2, is a better plot, as the data is displayed on a common scale.

  • 8/19/2019 250 Assignment 2 Optimisation 71726

    3/17

  • 8/19/2019 250 Assignment 2 Optimisation 71726

    4/17

     

    !"#$%& *)*

    !"#$%& *)+

    P

  • 8/19/2019 250 Assignment 2 Optimisation 71726

    5/17

    For the quadratic programming, looking at the figure 2.1, it is observable that training period and testing

     period show considerable amount of resemblance to each other. Peaks and troughs of the training and testing

     period are almost synchronized to some extent. This could well be due to seasonality of the indices involved

    with the indices making up the portfolio. This observation is backed up by analytical results where mean train

    variance of 489.09 and mean test variance of 624.86. The differences between mean test variance and meantraining variance of the quadratic programming is significantly less than what we obtained previously in linear

     programming. Consequently by looking at these graphs and mean variances we can conclude that, modeling

    training period with testing period using quadratic programming is more useful for finding optimal portfolio

    allocation for given constraints.

    QP

    meanTrainvariance  489.093204909667

    meanTestvariance  624.856921270185

    LP QP

    Optimal x vector ($ allocations to 10 indices) [0, 290.82, 500, 0, 0, 0, 0, 0,

    0, 0]

    !0, 36.133, 331.866, 0,

    0, 0, 500, 0, 0,

    132.001] 

    Maximum R (for optimal & feasible solution)

    meanTrainreturn  4.17653061014567 -0.0120133444227590

    minTrainreturn  -49.9999999951506 -65.8214203733677

    maxTrainreturn  81.9030612100866 40.8724189006152

    meanTestreturn  -5.95748299573666 9.32363502669894minTestreturn  -93.5816326443381 -73.82869568812463

    maxTestreturn  57.4846938759323 48.6435043818340

    meanTrainvariance  739.031147816565 489.093204909667

    meanTestvariance  1305.54842096684 624.856921270185

    b)  Discuss whether the models built on the training data were useful for the testing period, and

    how they could be made more accurate.

    In the linear programming we tried to maximize expected returns for the training period. We can see that the

    mean train return that we obtained is 4.177, which is greater than zero and aligned with our expected

    return-maximizing objective. However, when we used those optimal allocations from training period to

    evaluate our testing period, the mean testing return is -5.957, which is less than zero, meaning that we are

    expecting a loss on the investment on average with those allocations. Therefore, problem here is that we

    modeled our initial linear program solely to maximize expected return using training period data. However,

    we did not consider how indices behave with each other over time and didn’t take into account that testing

     period may have completely different set of return on investment in index i over the period. Therefore, using

    allocations from training period to maximize expected return on the testing period in this scenario is

    unsuitable and naive, as we obtain a negative expected return on the testing period. This is also supported by

    looking at the mean train variance of 739.03 and mean test variance of 1305.55, discrepancy between thevariance is significant, indicating that model built on training period is not useful for testing period.

    Should they resemble each other?Overlaying LP and QP in the same time period is the valid way to identify synchrony.True, seasonality probably plays a part.

    The ratio between the variances is more valid.

    seems to be

    Summary, mean return LP training $4.18, test -$5.96, QP training -$0.01, test $9.32.

    489

    625

    LP variance, train 739, test 1306; nearly doubles.

    QP variance, train 489, test 625, increase by about one-third.

    we have

    $

    P

    P

    unrealistic

    The LP method tends to choose stock indices that move strongly with the stock markets's ups

    and downs. The LP method chooses those indices that give a maximum return in the training

    period.

  • 8/19/2019 250 Assignment 2 Optimisation 71726

    6/17

    In the quadratic programming we tried to minimize portfolio variance. We used covariance to measures the

    degree of linear dependence between indices of the training period. We chose our allocations such that it

    would minimize portfolio variance. Therefore, in quadratic programming we do not give priority to maximize

    expected return for the training set, this can be seen by looking at the mean training return of -0.012, which

    is an expected loss of return on average. Instead, by looking at the covariance of the training setwhich is the degree of linear dependence between indices, in essence we are getting a relationship between

    indices over time (behavioral analysis) to minimize variance, which then can be carried over when we are

    evaluating the testing period. In other words, if the returns on an index (asset) are relatively constant or

    stationary over some time and if we perform quadratic programming on training period and then perform

    quadratic programming on testing period, the way in which allocations are done would pretty much be the

    same for both cases. In our analysis we obtained mean train variance to be 489.09 and mean test variance of

    624.86. These mean variances are considerably lower than what we obtained in linear programming, which

    satisfy the objective to minimize the variance of the portfolio.

    Consequently, quadratic programming model on training data is more useful for testing period compared to

    linear programming where we only gave priority to maximum expected values. One way to improve quadratic

    model is by having a larger pool of dataset therefore more information for the training period, i.e. training

     period to be more than 24 months. This would consequently result in a much more intelligent allocation of the

     portfolio and investment strategy as we are analyzing the behavior of indices over longer time range. On the

    other hand it is difficult to improve the linear programming model where the objective is to maximize

    expected return. We could increase number of months as before, but it would have very less effect on how

    testing would be modeled, unless there are seasonality relationship between indices over time.

    c)  Discuss whether minimizing variance or maximizing expected returns was a more profitable

    strategy, and the pros and cons of each approach.

    Portfolio allocation requires a trade off between expected return and minimize variance (risk). In general

    riskier assets (high variance) have higher expected return. This is because investors who invest in a higher risk

    asset demand a reward for bearing risk called risk premium. Variance is one measure of the risk of an asset

    allocation. Minimizing variance means negative correlation, where correlation e! ects only the risk, not the

    expected return. With negative correlation, the two assets tend to move in opposite direction, which decreases

    the volatility of the portfolio. Therefore negative correlation is good. If we minimize variance by investing in

    two indices such that their correlation is 0 (uncorrelated), then a negative return of one tends to occur with a

     positive return of the other, which also explains the purpose of diversification.

    Generally, we cannot say minimizing variance or maximizing expected returns was a more profitable strategy.

    It is more about finding the right balance, as there are pros and cons for each approach. For example, pros of

    maximizing expected returns is, if we invest our entire portfolio in high-risk assets, it may be that we get

    really lucky and expected return is extremely high (High profitability). However con of this approach is that,

    if we continue to invest in the same high risk asset in a market for sometime, expected return will reduce and

    we would eventually make a loss. This is similar to what we did when we considered linear programming to

    maximize expected return on the indices for the training period. Then we used the allocations x corresponding

    to maximum expected return from training period to model testing period. These allocations are of high risk or

    high variance and generally not useful in modeling testing period and therefore would not be competent

    P

    P

    P

    maximising the return on investement is a constraint, but not an objective.

    we hope may

    PP

    P

    little

    Overlays of LP and QP in the same time period show there is a background of other movements.

    minimising

    O

    P

    P

    The given QP method minimises variance subject to a minimum return.

    What evidence of diversification is there in your data?

    The cumulative returns plots evidence that QP can deliver a steady profit, while LP may deliver

    short-term gains, the evidence is that LP can deliver a net loss over any other time period.

  • 8/19/2019 250 Assignment 2 Optimisation 71726

    7/17

     profitable strategy. Whereas quadratic programming determines the minimum variance for set of period which

    then can be used to forecast future expected return. Optimal portfolio is where it is not possible to increase the

    expected return without increasing the variance, or if it is possible to decrease the variance without decreasing

    the expected return.

    Another problem or con of using minimizing variance is, an investor using variance minimizing method need

    estimates of what yi (return) is. In our analysis we used training set returns to find optimal portfolio allocation

    x under constraints. However, those values in training maybe completely different to the testing set or an

    unexpected event shocked the market changing all the return rates. Therefore, allocation strategy used in

    training set may be irrelevant and can be dangerous to use to find expected return of the testing set. Another,

    disadvantage of minimizing variance is that it neglects any nonlinear dependence that might be present. In real

    life, investment returns are nonlinear.

    In our example, optimizing using linear programming to maximize expected return the mean test return is

    -5.957 (expected loss) whereas in quadratic programming to minimize variance the mean test returnis 9.323 (expected gain). Therefore, we can see that minimizing variance here is more powerful than

    maximizing expected return approach. Therefore quadratic programming to minimize variance

    would be a more useful profitable strategy.

    One of the pros of maximizing expected return via linear programming is that we allocate budget to indices to

    maximize mean monthly return for the training set therefore maximize profit.

    meanTestreturn  -5.95748299573666 9.32363502669894

    d)  How did your demands for a certain return R affect the optimal portfolio?

    !"#$%& ,)(

    P

    Plateau at R = -0.071

    we hope will forecastIt optimises expected return subject to the variance being minimum.

    The overlays of LP and QP show these market movements.

    Your reference?

    profitable

    P

  • 8/19/2019 250 Assignment 2 Optimisation 71726

    8/17

     

    Figure d.1 shows a plot of expected return against demand for certain return R-values. Negative Rvalues means that we tolerate minimal loss each month in order to maximize returns over time.

    Consequently, negative R returns would result in optimal portfolio in our case. First figure shows

    that maximum expected return of 4.177 is when minimum return R is -0.05, which is the verge of our

    negative threshold for R. As the R-value decreases to zero from -0.05 expected returns reduces

    linearly and goes to zero. As the demand for certain return on the investment (R) increases beyond

    zero the expected return is negative (expected loss). However, these R values greater than 0 are non

    feasible solutions. Optimal portfolio is when the expected return is maximum this is when R is -0.05

    or -5%.

    Variance is mean variance of monthly-expected return. Figure d.2 shows a plot of variance againstrange of R values. Figure indicates that for all the R values less than zero, variance is a relatively

    constant line about 489. For R values greater than zero, the variance corresponding to those values

    increase exponentially as depicted in the above figure. However, when R-values go beyond 0.01,

    mean variance of the monthly return are non-feasible solutions therefore set to zero. Optimal

     portfolio is when the variance is minimum this is when R is -0.05 or -5%.

    !"#$%& ,)*

    P

    P

    P

    P P

    for the LQ strategy.

    P

    P

    P

    You have not answered the question. How does the portfolio change as R is changed?

    Why does Figure d.1 have the characteristic shape it does?

    P

    R = -0.05 is NOT the largest R for which the variance is 489; for your data Rmax = -0.001.How does the portfolio change as R is changed? Why does Figure d.2 have the characteristic

    shape it does? Have a look at the portfolio plots I have returned to you with your assignment.

  • 8/19/2019 250 Assignment 2 Optimisation 71726

    9/17

     Please copy and paste your MATLAB code for LP.m

    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  

    %%%% LP Hashan Wickramasuriya %%%%%%%% %%%% 23417250 %%%%%%%% 

    clc 

    clear all 

    close all 

    % This script is to solve the portfolio optimisation problem using linear 

    % programming for a given subset of 10 stock indices 

    data = csvread('returns.dat',1,1); % reads in the monthly returns data file for all

    19 stock indices 

    % please change the next line to select the ten stocks you have been 

    % allocated (see ECE3093ID-Indices.xls for your allocated list) 

    indices = [19, 18, 5, 13, 14, 17, 11, 12, 15, 8]; % select the indices in your subset

    of 10 from 19 available indices 

    subset=[data(:,indices(1)),data(:,indices(2)),data(:,indices(3)),data(:,indices(4

    )),data(:,indices(5)),data(:,indices(6)),data(:,indices(7)),data(:,indices(8)),da

    ta(:,indices(9)),data(:,indices(10))];  

    training=subset(1:25,:); % take first 25 months as training data to optimise portfolio

     weights 

    testing=subset(26:49,:); % take last 24 months as testing data to evaluate

    performance 

    N=10; % number of stock indices considered in portfolio 

    T=25; % months in training data 

    Ttest=24; % months in testing data 

    C=1000; % dollar budget constraint 

    R=-0.05:0.001:0.05; % return threshold, to be varied  mu=0.5; 

    %No inequalities exist 

     Aeq=[];

    beq=[]; 

    %Defines vector for lower and upper bounds on the design variables x 

    LB=zeros(length(indices),1); 

    UB(1:length(indices),1)=mu*C; 

    % Define the linear coefficients in the constraints A*x ? b. 

    P

    P

    P

  • 8/19/2019 250 Assignment 2 Optimisation 71726

    10/17

  • 8/19/2019 250 Assignment 2 Optimisation 71726

    11/17

    %ExpectedReturn=-1*round(FVAL/0.01)*0.01; %report to two decimal places 

    optimalexpectedreturn = -1*round(optimal_FVAL/0.01)*0.01; 

    % Sort Optimal expected return from highest to lowest and returns 

    % corresponding array of indices IX(ER_index) 

    [sorted_Max_ER ER_index] = sort(optimalexpectedreturn,'descend'); %Max Expected return 

    Max_Expected_return = sorted_Max_ER(1); 

    % Gives the optimal allocation configuration 

    x = optimal_x(ER_index(1),:)'; 

    % calculate returns (min, max and mean) each month on training and test data using

    your best x 

    % % (designed to maximise expected return on training data) 

     meanTrainreturn=mean(training*x);  minTrainreturn=min(training*x); 

     maxTrainreturn=max(training*x); 

     meanTestreturn=mean(testing*x); 

     minTestreturn=min(testing*x); 

     maxTestreturn=max(testing*x); 

    % calculate variance each month on training and test data using your best x 

    % (designed to maximise expected return on training data) 

     meanTrainvariance=mean(x'*cov(training)*x); 

     meanTestvariance=mean(x'*cov(testing)*x); 

    figure(1) 

    %Subplot for expected return for training and testing set 

    subplot(2,1,1);

    Expected_return=training*x; 

     month=1:25; plot(month,Expected_return,'*-b') 

    xlabel('Month') 

    ylabel('Expected Monthly Return ($)') 

    title('Training set Expected Monthly Return LP') 

    grid 

    subplot(2,1,2); 

    Expected_return=testing*x; 

     month=26:49; 

    plot(month,Expected_return,'*-r') 

  • 8/19/2019 250 Assignment 2 Optimisation 71726

    12/17

    xlabel('Month') 

    ylabel('Expected Monthly Return ($)') 

    title('Testing set Expected Monthly Return LP') 

    grid 

    % Mapping Expected Monthly Return for both Training and testing 

    figure(2) 

    Expected_return=training*x; 

     month=1:25; 

    plot(month,Expected_return,'*-b') 

    grid 

    hold on 

    Expected_return=testing*x; 

     month=1:24; 

    plot(month,Expected_return,'*-r') xlabel('Month number') 

    ylabel('Expected Monthly Return ($)') 

    title('Mapping Expected Monthly Return for both Training and testing LP') 

    legend('Training set','Testing set') 

    grid on 

    hold off 

    % Combined Plot of training and testing data for expected monthly return 

    % Training part 

    figure(3) 

    subplot(2,1,[1 2]);

    Expected_return=training*x; 

     month=1:25; 

    plot(month,Expected_return,'*-b') 

    hold on 

    % Testing part 

    Expected_return=testing*x; 

     month=26:49; plot(month,Expected_return,'*-r') 

    xlabel('Month') 

    ylabel('Expected Monthly Return ($)') 

    title('Combined Plot of training and testing data for Expected Monthly Return LP') 

    legend('Training set','Testing set') 

    grid

    % plot of Expected returns with the R range 

    figure (4) 

     All_expected_return=-1*round(FVAL/0.01)*0.01; 

    plot(R,All_expected_return) 

  • 8/19/2019 250 Assignment 2 Optimisation 71726

    13/17

    xlabel('R value') 

    ylabel('Expected Return') 

    title('Expected Return Vs R value') 

    grid

     Please copy and paste your MATLAB code for QP.m

    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  

    %%%% QP Hashan Wickramasuriya %%%%%%%% 

    %%%% 23417250 %%%%%%%% 

    clc clear all 

    close all 

    % This script is to solve the portfolio optimisation problem using quadratic

    programming on 

    % Markowitz' model (minimising variance) for a given subset of 10 stock indices 

    data = csvread('returns.dat',1,1); % reads in the monthly returns data file for all

    19 stock indices 

    % please change the next line to select the ten stocks you have been 

    % allocated (see ECE3093ID-Indices.xls for your allocated list) 

    indices = [19, 18, 5, 13, 14, 17, 11, 12, 15, 8]; % select the indices in your subset

    of 10 from 19 available indices 

    subset=[data(:,indices(1)),data(:,indices(2)),data(:,indices(3)),data(:,indices(4

    )),data(:,indices(5)),data(:,indices(6)),data(:,indices(7)),data(:,indices(8)),da

    ta(:,indices(9)),data(:,indices(10))];  

    training=subset(1:25,:); % take first 25 months as training data to optimise portfolio

     weights 

    testing=subset(26:49,:); % take last 24 months as testing data to evaluate

    performance 

    N=10; % number of stock indices considered in portfolio 

    T=25; % months in training data 

    Ttest=24; % months in testing data 

    C=1000; % dollar budget constraint 

    R=-0.05:0.001:0.05; % return threshold, to be varied 

     mu=0.5; 

    P

  • 8/19/2019 250 Assignment 2 Optimisation 71726

    14/17

     

    % Now write some code that defines the matrices and vectors needed to solve 

    % the quadratic programming problem to minimise variance. You need to 

    % define H, f, A, b, Aeq, beq, LB, UB in the quadprog function 

    %define objective function 

    H=2*cov(training); % H is defined to be the covarience between yi & yj 

    % Define the linear coefficients in the constraints A*x ? b. 

     A=-(1/T)*sum(training); % YBAR is the mean yi for each index ( average of each individual

    column) 

    % Define the lower bound(LB) and upper bound (UB) elementwise in lb ? x ? ub. 

    LB=zeros(N,1); 

    UB(1:N,1)=mu*C; 

    % Define linear coefficients in the constraints Aeq*x = beq. 

     Aeq(1,1:N)=1;

    beq=C; 

    f=zeros(N,1); 

    % Options structure created using optimset

    options = optimset( 'Algorithm', 'interior-point-convex','Display','off'); 

    % Create zero matrix to predefine variables 

    EXITFLAG=zeros(length(R),1); 

    optimal_Va=[]; 

    optimal_x=[]; 

    %Keeps track of the corresponing R value which satisfy below if statement 

    track_R=[]; count=1; 

    %For loop to see the effects of the range of R values

    for steps=1:length(R) 

    b=-R(steps)*C; %Define the constant vector in the constraints A*x ? b. % Define Quadratic programming 

    [x,FVAL,EXITFLAG(steps,1)]=quadprog(H,f,A,b,Aeq,beq,LB,UB,[],options);  

    %%Exitflag 1 corresponds to algorithm terminated when function converged to a

    solution x 

    if EXITFLAG(steps,1)==1 

    optimal_Va(steps,1)=round(FVAL/0.01)*0.01;

    optimal_x(steps,:)=x; 

    track_R(count)=1; 

    count=count+1; 

    else 

    P

    P

    P

  • 8/19/2019 250 Assignment 2 Optimisation 71726

    15/17

      optimal_Va(steps)=0; 

    optimal_x(steps,:)=0; 

    end 

    end % Sort feasible value from lowest to highest and returns 

    % corresponding array of indices IX(variance_index) 

    [feasible_variance variance_index] = sort(optimal_Va,'ascend'); 

    % Optimal variance where it is the minimum variance 

    Optimal_variance = feasible_variance(1); 

    % Optimal allocation value 

    x = optimal_x(variance_index(1),:)'; 

    % calculate returns (min, max and mean) each month on training and test data using

    your best x 

    % (designed to minimise variance on training data) 

     meanTrainreturn=mean(training*x); 

     minTrainreturn=min(training*x); 

     maxTrainreturn=max(training*x); 

     meanTestreturn=mean(testing*x); 

     minTestreturn=min(testing*x); 

     maxTestreturn=max(testing*x); 

    % calculate variance each month on training and test data using your best x 

    % (designed to minimise variance on training data) 

     meanTrainvariance=mean(x'*cov(training)*x); 

     meanTestvariance=mean(x'*cov(testing)*x); 

    figure(1) 

    %Subplot for expected return for training and testing set 

    subplot(2,1,1);

    Expected_return=training*x; 

     month=1:25; 

    plot(month,Expected_return,'*-b') 

    xlabel('Month') 

    ylabel('Expected Monthly Return ($)') 

    title('Training set Expected Monthly Return QP') 

    grid 

    subplot(2,1,2); 

    Expected_return=testing*x; 

  • 8/19/2019 250 Assignment 2 Optimisation 71726

    16/17

     month=26:49; 

    plot(month,Expected_return,'*-r') 

    xlabel('Month') 

    ylabel('Expected Monthly Return ($)') 

    title('Testing set Expected Monthly Return QP') grid 

    % Mapping Expected Monthly Return for both Training and testing 

    figure(2) 

    Expected_return=training*x; 

     month=1:25; 

    plot(month,Expected_return,'*-b') 

    grid 

    hold on 

    Expected_return=testing*x;  month=1:24; 

    plot(month,Expected_return,'*-r') 

    xlabel('Month number') 

    ylabel('Expected Monthly Return ($)') 

    title('Mapping Expected Monthly Return for both Training and testing QP') 

    legend('Training set','Testing set') 

    grid on 

    hold off 

    % Combined Plot of training and testing data for expected monthly return 

    % Training part 

    figure(3) 

    subplot(2,1,[1 2]);

    Expected_return=training*x; 

     month=1:25; 

    plot(month,Expected_return,'*-b') 

    hold on 

    % Testing part Expected_return=testing*x; 

     month=26:49; 

    plot(month,Expected_return,'*-r') 

    xlabel('Month') 

    ylabel('Expected Monthly Return ($)') 

    title('Combined Plot of training and testing data for Expected Monthly Return QP') 

    legend('Training set','Testing set') 

    grid

    % plot of Expected returns with the R range 

  • 8/19/2019 250 Assignment 2 Optimisation 71726

    17/17

    figure (4) 

    plot(R,optimal_Va) 

    xlabel('R value') 

    ylabel('Variance') 

    title('Variance Vs R value') grid