Hello, dear friend, you can consult us at any time if you have any questions, add WeChat: daixieit

Visual Basic in Finance

SMM231

GENERAL INSTRUCTIONS TO STUDENTS

-    Students should provide the Macro-Enabled Excel Workbook solution with VBA code in the case study.

-    Students may use only the Microsoft Excel with Visual Basic Editor on a PC. -     Students should upload the following on Moodle by the deadline:

•    Microsoft Excel Macro-Enabled Worksheet (*.xlsm)  with VBA code -  one file only


SPECIAL INSTRUCTIONS TO STUDENTS

-    Students should save Macro Enabled Excel Workbook  file with VBA code included in a StudentID named folder, for upload to Moodle

-    Students are expected to create structural programs only.


CASE STUDY

You have just received a positive response from Merrill Lynch on a recent graduate Financial Analyst’ role you had applied for and you are invited to a job interview. The job specification includes, among other things, knowledge of VBA at introductory level, but with the prospect of further training within the organisation. If successful you will work in a recently re-organisedasset pricing department and if you were to be successful, you’d work as part of a team dealing with financial analysis and asset  pricing that also  involves computational work. Your  prospective employer has prepared a trial test for you as part of the interview, entirely based on introductory VBA programming.

You’d be expected to be tested on programming skills in VBA, where a specific task is given that must be coded within a limited amount of time to a problem specification. You are expected to code  the  solution  with  user-defined  functions,  but  no  object  orientation,  or  graphical  user interface(GUI). Make use of good VBA-style comments, variable declaration, initialization, data processing,  control flow statements, function cohesion, and coupling. You arealso expected to demonstrate that you understand both the syntax, function design, and have good and timely programming skills in VBA.

PROBLEM SPECIFICATION

Consider a scenario where investor can select a number of investments to be part of a financial portfolio. Your VBA program should be able to process that information and create the  initial  Excel  layout with either default values or values you enter through prompts:

 

VBA program should be able to compute the V (variance covariance) matrix values:

 = [                       ]

VBA program should compute the capital weights for an n-security portfolio inferred by the following Lagrange system:

 

Security standard deviation, covariance, return rate, capital weight, and Lagrange

multipliers are denotes by  i ,  ij , E(Ri), xi ,  , and v, respectively.

This system may be applied regardless of the size of the portfolio. Where the number

of securities under consideration for the portfolio equals n, the square coefficients

matrix will have n+2 rows and n+2 columns.

The VBA  program should solve for the system of capital weights and  Lagrange

multipliers; optimal weights in a  n-security portfolio - I used n=2 for illustration here,

but n can be any value, preferable between 2 and 15. Use the target return of your

choice, securitiesexpected returns, standard deviations, and covariances.

VBA program should compute the parameters α ,  β , γ:

α = eTV −1e,       β = eTV −1r,  γ = rTV −1r

e:  is a unit vector, refer to it as an n x 1 matrix for computation purposes. Subscript

T indicates a transposed unit vector i.e. converted to an 1 x n matrix.

V: is the variance covariance matrix

r: rates of return vector. Consider it an n x  1 matrix for computation purposes. ),

subscript T indicates a transposed unit vector (converted to an 1 x n matrix).

 

These parameters are normally used to compute the global minimum,   diversified,

and  minimum  variance    portfolios:  such  portfolio  points  are  not  required  to  be

computed here.

You may start with any number of funds in the portfolio and for the purpose of computing the return and risk of the portfolio, you would need the capital weights. The capital weights are computed using the Lagrange system. The sum of all capital weights  should be 1.00. The values should be stored in one-dimensional arrays x1 (), x2 (), … ., etc.

VBA program should compute the expected return, volatility, quadratic utility, and sharp ratio of

the portfolio using the following corresponding expressions:

Portfolio expected rate of return:

( ) = xTr

where x and r are capital weight and fund returns vectors,              respectively.

Portfolio volatility:

p =(xTVx)0.5

where xT is the transposed capital   weights vector, V the variance-         covariance matrix, and x the capital weights vector.

Portfolio quadratic utility in expectation:

( ) = ( ) −  1  2

2        

(*) A is the risk aversion coefficient

Sharp Ratio:

 ( ) − ()

 

For each weight set, program should compute portfolio expected rate of return, volatility, quadratic utility, and Sharp ratio. The computed portfolio returns and volatilities should be storedin arrays rp (), and vp (), respectively. Program should then find the portfolio with the  highest utility and highest sharp ratio.

 

VBA program should use a range of target portfolio returns from 0% to 100% and the Lagrange system to compute the capital weight solutions. Portfolio risk should be computed using the Markowitz formula given above.

 

VBA program should also include a recorded macro that  plots the mean-variance efficient frontier

and capital allocation line as shown below:

 

You should also code a choice to increase the number of assets in portfolio by any number of assets. Your VBA program should have the capabilities to insert the relevant rows and columns in the macro-enabled excel  file to accommodate for the data of the new assets.

Your program should be organised in such a way that  some of it is done by macros (subs) and the rest in dedicated user-defined functions of your choice, but not less than 4 user defined functions. Make good  use of the VBA’s object  model as well as cohesion and coupling  programming principles. The finished product must contain at least four well designed user-defined functions. There is only one program file you are expected to submit within a macro-enabled excel workbook file.

The program should output the capital weight values within 4 decimal points and in a field with a reasonable character width, as well as the portfolio expected return, volatility, utility, and sharp ratio within a reasonable character width and 4 decimal places. The values should be sorted from the lowest portfolio return to the highest. It should print out the maximum utility and sharp ratio, clearly indicating the corresponding portfolio with its return and volatility attributes. The input must be robustly validated with error handling and the output should be properly formatted.

You must produce a running program saved in a Microsoft Excel Macro-Enabled Worksheet (.xlsm) file named studentID.xlsm” . You may make use of your own recorded macros to plot the portfolio mean-variance efficient frontier, CML, and identify the market portfolio, based on the program output data in the Macro enabled excel file. This would allow you to check with literature that the shape of the graph is as describedin literature. You may wish to note the maximum utility and sharp ratio in the graph. You do not need to produce any written work on the theorized financial portfolio elements. Focus is on the programming skills.

You have flexibility on how you organise the code, and the layout of data in Excel; both input and output should be in the same macro enabled excel workbook file. However pay attention to details and programming principles applied.

The program must run in order to be marked.

(100 marks)