![]() |
loops
I am a beginner programmer and I am trying to understand looping to optimize
a investment portfolio with 3 types of assets S, B & C. Does anyone have experience with such a routine? I want to find the optimal weights for this portfolio by changing each asset wieght. A portfolio cant hold more than 100%. In other words, what weights will optimize my return? i.e. S = 70%, B = 25% and C = 5% Total (S + B + C) cant exceed 100%. Therefore I am looping 3 different variables. I have tried a couple of methods but keep getting errors. Does anyone have a template for something similar I can try to work through?? ANy help is much appreciate! Capp |
loops
Run this with a blank sheet active and see if it gives you some ideas:
Sub AF() Dim i As Long, s As Long Dim b As Long i = 1 Cells(i, 1).Resize(1, 3).Value = Array("s", "b", "c") For s = 1 To 100 For b = 0 To 100 - s i = i + 1 Cells(i, 1) = s Cells(i, 2) = b Cells(i, 3) = 100 - (b + s) Next Next End Sub -- Regards, Tom Ogilvy "Capp" wrote in message ... I am a beginner programmer and I am trying to understand looping to optimize a investment portfolio with 3 types of assets S, B & C. Does anyone have experience with such a routine? I want to find the optimal weights for this portfolio by changing each asset wieght. A portfolio cant hold more than 100%. In other words, what weights will optimize my return? i.e. S = 70%, B = 25% and C = 5% Total (S + B + C) cant exceed 100%. Therefore I am looping 3 different variables. I have tried a couple of methods but keep getting errors. Does anyone have a template for something similar I can try to work through?? ANy help is much appreciate! Capp |
All times are GMT +1. The time now is 07:27 AM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com