Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Create 10 portfolios with monthly rebalancing

    Hi! I have a big set of historical data on stock forecasts and prices. These stocks should be equally divided into ten portfolios based on the forecasts. In the next step the real outcome of these portfolios should be calculated based on the prices. The portfolios should also be rebalanced each month with regard to changes in forecasts. I think my biggest issue right is how to structure the data in my excel-file. Company, date, stock price, forecast. Should I do it in two steps manually or is it possible to do it all at once?

    Summary of what I need to do:
    1. Divide all stocks up in 10 portfolios based on the forecasts
    2. Calculate the actual return based on the prices of the stocks
    3. Do 1) and 2) for every new month to constantly rebalance the portfolios to account for changes in forecasts.

    As a beginner at Stata all help is appreciated!

    Regards

  • #2

    Dear David, you have not provided a data to play with. Here is one example.
    Code:
    use http://fintechprofessor.com/stocks.dta, clear
    
    
    * Convert to monthly frequency
    * install ascol for changing data frequency
    ssc install ascol
    
    ascol close, p(symbol) t(date) prices tomonth
    
    encode symbol, gen(id)
    tsset id month_id
    
    * generate returns
    gen ri = ln(month_close / L.month_close)
    
    
    * Install astile for creating groups
    ssc install astile
    
    bys month_id: astile p10 = ri, nq(10)
    bys p10 month_id : egen rpi = mean(ri)
    tsset
    If you are interested in more customized help, please visit my web page

    https://fintechprofessor.com/paid-help/



    Regards
    --------------------------------------------------
    Attaullah Shah, PhD.
    Professor of Finance, Institute of Management Sciences Peshawar, Pakistan
    FinTechProfessor.com
    https://asdocx.com
    Check out my asdoc program, which sends outputs to MS Word.
    For more flexibility, consider using asdocx which can send Stata outputs to MS Word, Excel, LaTeX, or HTML.

    Comment

    Working...
    X