**Portfolio Risk in Excel:**

To build our concept of the portfolio risk, we shall calculate it first manually in EXCEL, then we shall replicate the results using matrix notations in Stata.

Consider the following set of returns for two assets, i.e asset A and B.

__A__

__B__

.249917 .819483

.739069 .821416

.895491 .276843

.902722 .001586

.078344 .714815

.429804 .027261

__.239556 .736011__

As we know, the portfolio standard deviation under the modern portfolio theory is calculated as =

Thus, we need standard deviation of the two assets, proportion of investment in each asset (weights), and the covariance term between the two assets.

In Excel, we can find the standard deviation by

**=STDEV(range)**

**=COVARIANCE.S(range1, range2)**

`Thus, standard deviation of asset A = 0.3387`

` `

standard deviation of asset A = 0.3713 Covariance between the two = -0.0683

And if we invest equally in both assets, then the weight of A = 0.5 and weight of B = 0.5

Portfolio SD =( (0.5^2*0.3387^2)+(0.5^2*0.3713^2)+(2*0.5*0.5*-0.0683))^0.5

=(0.02897)^0.5

=0.1702

Excel sheet showing the above example can be downloaded from here.

` `

**Portfolio Risk in Stata**

Finding portfolio standard deviation under the Modern Portfolio theory using matrix algebra requires three matrices

1. Weights of the assets in portfolio, in row format = W

2. Variance-Covariance matrix of assets returns = S

3. Weights of the assets in portfolio, in column format = W'

Portfolio SD = W * S * W'

NOTE: In order to find the variance-covariance matrix, you can install varrets program from ssc with:

1. Weights of the assets in portfolio, in row format = W

2. Variance-Covariance matrix of assets returns = S

3. Weights of the assets in portfolio, in column format = W'

Portfolio SD = W * S * W'

NOTE: In order to find the variance-covariance matrix, you can install varrets program from ssc with:

`ssc install mvport`

__Step 1 : Copy the example data to stata__

You can do either through copying the data from the excel file and pasting it to the stata editor.

Alternatively, you can copy the following and past it in the stata command line, or download the data file from here.

**input a b**

`.249917 `

`.819483`

`.739069 `

`.821416`

`.895491 `

`.276843`

`.902722 `

`.001586`

`.078344 `

`.714815`

`.429804 `

`.027261`

`.239556 `

`.736011`

**end**

__Step 2: Make variance covariance matrix__**varrets a b**

**mat S = r(cov)**

__Step 3: Make a weight matrix__Assuming that we assign equal weights, we define matrix W

**mat W = (0.5, 0.5)**

__Step 4 : Multiply the weight and variance-covariance matrix__**mat VAR = W * S * W'**

__Step 5: Show variance of the portfolio__

**mat list VAR**

Complete .do file of the example can be downloaded from here.

For more advanced example, you can visit page

**Portfolio Standard Deviation with Matrix in Stata**