Imperial_1
New Member
- Joined
- Jul 13, 2017
- Messages
- 2
Hello all,
I’m looking to create a macro that will output to excel “all weight” permutations for a portfolio of 2 assets.
Now I’m actually looking to do this with quite a few assets (5 initially) but starting with 2 at this stage. To avoid too large a number of permutations, I will go up in steps of 0.1 (10%). Also note the combination of 2 numbers needs to equal 1 (100%).
For example, I have asset A and asset B. I see this as having 11 possible combinations; A – 100% and B – 0%, A-90% and B-10%....
I have written the macro below which seems to miss the first 2 combinations and the last 2 combinations and I’m not sure why.
Can someone please help me?
Regards
Dipesh
I’m looking to create a macro that will output to excel “all weight” permutations for a portfolio of 2 assets.
Now I’m actually looking to do this with quite a few assets (5 initially) but starting with 2 at this stage. To avoid too large a number of permutations, I will go up in steps of 0.1 (10%). Also note the combination of 2 numbers needs to equal 1 (100%).
For example, I have asset A and asset B. I see this as having 11 possible combinations; A – 100% and B – 0%, A-90% and B-10%....
I have written the macro below which seems to miss the first 2 combinations and the last 2 combinations and I’m not sure why.
Can someone please help me?
Regards
Dipesh
Code:
Sub every_Combo()
Dim i As Double
Dim j As Double
Dim x As Integer
x = 1
Sheets("perm").Cells.ClearContents
For i = 0 To 1 Step 0.1
For j = 0 To 1 Step 0.1
If i + j = 1 Or i = 1 Or j = 1 Then
Sheets("perm").Cells(x, 1).Value = i
Sheets("perm").Cells(x, 2).Value = j
x = x + 1
Else
GoTo ABC
End If
ABC:
Next j
Next i
End Sub