Portfolio standard deviationAssume that you have a dataset of stocks for weekly or monthly frequency. Each stock is assigned to a given portfolio. So our the data looks like:
If we were to find the portfolio standard deviation over the last 60 days, this will pose a considerable programming challenge. The solution can be decomposed into several steps. Specifically, I list these steps below: 1. Make a group from two variables, portfolio and months, so we have a total of N groups in each month, identify which stocks is included in which group 2. Then for each stock, we shall go back and find its last 60 months returns 3. Since many stocks might have missing data, we need to rectangularize the data by including missing values, and filling the months series so that each stock has similar number of months, even though they might have no returns in some months. Later we shall delete the missing values 4. This is necessary as the variancecovariances need to be calculated on matching dates 5. Next, we shall make a matrix in each month for the included stocks from their available past 60 months returns 6. Then find variance covariance matrix in Stata or Mata (We can make a Mata function for that) 7. Find standard deviation by assigning equal weights to each stock 8. Get the SD from Mata and write it to the relevant portfolio 9. Delete the extra data points created in step 3
Our Stata CodeWe have developed easy to use yet robust codes for the above steps. The codes need just a basic understanding of Stata. Further, our comments on each line of code will surely help you to not only apply the code but also understand the process more clearly.
PricingThe code is available for $ 150, plus a $50 for raw data processing (in case the data is not in Stata format and variables are not already constructed). For further details, please contact us at:
attaullah.shah@imsciences.edu.pk
See our full list of completed projects
