Results 1 to 7 of 7

Thread: debug the code of portfolio optimization software

  1. #1

    Thread Starter
    New Member
    Join Date
    Apr 2011
    Posts
    4

    debug the code of portfolio optimization software

    Dear sir,
    Please debug and compile the following code I am using visual basic 6.5
    Code:
    Sub Frontier_Builder()
    SolverReset
    Application.ScreenUpdating = False
    'Finding Maximum Surplus
        SolverOk SetCell:="$K$38", MaxMinVal:=1, ValueOf:="0", ByChange:="$B$18:$B$27"
        SolverAdd CellRef:="$B$28", Relation:=2, FormulaText:="1"
        SolverAdd CellRef:="$B$18:$B$27", Relation:=1, FormulaText:="Optimal_Mix_Max"
        SolverAdd CellRef:="$B$18:$B$27", Relation:=3, FormulaText:="Optimal_Mix_Min"
        SolverAdd CellRef:="$H$31:$H$33", Relation:=1, FormulaText:="$I$31:$I$33"
        SolverOptions MaxTime:=1000, Iterations:=1000, Precision:=0.00000001, _
            AssumeLinear:=False, StepThru:=False, Estimates:=2, Derivatives:=2, _
            SearchOption:=1, IntTolerance:=0.000005, Scaling:=False, Convergence:=0, _
            AssumeNonNeg:=False
        Solution = SolverSolve(True)
    MaxSurplus = Range("Surplus").Value
    SolverReset
    'Finding Minimum Surplus Volatility and its Surplus
        SolverOk SetCell:="$K$36", MaxMinVal:=2, ValueOf:="0", ByChange:="$B$18:$B$27"
        SolverAdd CellRef:="$B$28", Relation:=2, FormulaText:="1"
        SolverAdd CellRef:="$B$18:$B$27", Relation:=1, FormulaText:="Optimal_Mix_Max"
        SolverAdd CellRef:="$B$18:$B$27", Relation:=3, FormulaText:="Optimal_Mix_Min"
        SolverAdd CellRef:="$H$31:$H$33", Relation:=1, FormulaText:="$I$31:$I$33"
        SolverOptions MaxTime:=1000, Iterations:=1000, Precision:=0.00000001, _
            AssumeLinear:=False, StepThru:=False, Estimates:=2, Derivatives:=2, _
            SearchOption:=1, IntTolerance:=0.000005, Scaling:=False, Convergence:=0, _
            AssumeNonNeg:=False
        Solution = SolverSolve(True)
    MinSurplus = Range("Surplus").Value
    SolverReset
    ReDim Asset_Mix_Array(1 To 10, 1 To 100) As Double
    ReDim Frontier_Check_Array(1, 1 To 100) As Double
    NextRow = 1
     Increment = (MaxSurplus - MinSurplus) / 100
         SolverOk SetCell:="$K$36", MaxMinVal:=2, ValueOf:="0", ByChange:="$B$18:$B$27"
         SolverAdd CellRef:="$B$28", Relation:=2, FormulaText:="1"
         SolverAdd CellRef:="$B$18:$B$27", Relation:=1, FormulaText:="Optimal_Mix_Max"
         SolverAdd CellRef:="$B$18:$B$27", Relation:=3, FormulaText:="Optimal_Mix_Min"
         SolverAdd CellRef:="$H$31:$H$33", Relation:=1, FormulaText:="$I$31:$I$33"
         SolverAdd CellRef:="$K$38", Relation:=2, FormulaText:="Desired_Surplus"
         SolverOptions MaxTime:=1000, Iterations:=1000, Precision:=0.00000001, _
             AssumeLinear:=False, StepThru:=False, Estimates:=2, Derivatives:=2, _
             SearchOption:=1, IntTolerance:=0.000005, Scaling:=False, Convergence:=0, _
             AssumeNonNeg:=False
     For i = MinSurplus To MaxSurplus - Increment Step Increment
         Range("Desired_Surplus").Value = i
         Solution = SolverSolve(True)
         If Solution = 0 Then
             Frontier_Check_Array(1, NextRow) = Range("Optimal_Mix_Total").Value
             Asset_Mix_Array(1, NextRow) = Range("Class1").Value
             Asset_Mix_Array(2, NextRow) = Range("Class2").Value
             Asset_Mix_Array(3, NextRow) = Range("Class3").Value
             Asset_Mix_Array(4, NextRow) = Range("Class4").Value
             Asset_Mix_Array(5, NextRow) = Range("Class5").Value
             Asset_Mix_Array(6, NextRow) = Range("Class6").Value
             Asset_Mix_Array(7, NextRow) = Range("Class7").Value
             Asset_Mix_Array(8, NextRow) = Range("Class8").Value
             Asset_Mix_Array(9, NextRow) = Range("Class9").Value
             Asset_Mix_Array(10, NextRow) = Range("Class10").Value
         NextRow = NextRow + 1
         End If
     Next
    Range("Desired_Surplus").Value = MaxSurplus
    Solution = SolverSolve(True)
    Asset_Mix_Array(1, 100) = Range("Class1").Value
    Asset_Mix_Array(2, 100) = Range("Class2").Value
    Asset_Mix_Array(3, 100) = Range("Class3").Value
    Asset_Mix_Array(4, 100) = Range("Class4").Value
    Asset_Mix_Array(5, 100) = Range("Class5").Value
    Asset_Mix_Array(6, 100) = Range("Class6").Value
    Asset_Mix_Array(7, 100) = Range("Class7").Value
    Asset_Mix_Array(8, 100) = Range("Class8").Value
    Asset_Mix_Array(9, 100) = Range("Class9").Value
    Asset_Mix_Array(10, 100) = Range("Class10").Value
    Worksheets("Frontier Points").Range("B1:CW10").Value = Asset_Mix_Array
    Application.ScreenUpdating = True
    SolverReset
    End Sub

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: debug the code of portfolio optimization software

    Dear sandeepgupta,
    No

    Thats not how it works here.

    You tell us what your issue is being as specific as possible. You post what you have done to solve your issue on your own, and we will try to help you along the rest of the way.

  3. #3

    Thread Starter
    New Member
    Join Date
    Apr 2011
    Posts
    4

    Re: debug the code of portfolio optimization software

    Dear sir on debugging the error is
    sub or function not defined.

  4. #4

    Thread Starter
    New Member
    Join Date
    Apr 2011
    Posts
    4

    Re: debug the code of portfolio optimization software

    Quote Originally Posted by sandeepgupta View Post
    Dear sir,
    Please debug and compile the following code I am using visual basic 6.5
    Code:
    Sub Frontier_Builder()
    SolverReset
    Application.ScreenUpdating = False
    'Finding Maximum Surplus
        SolverOk SetCell:="$K$38", MaxMinVal:=1, ValueOf:="0", ByChange:="$B$18:$B$27"
        SolverAdd CellRef:="$B$28", Relation:=2, FormulaText:="1"
        SolverAdd CellRef:="$B$18:$B$27", Relation:=1, FormulaText:="Optimal_Mix_Max"
        SolverAdd CellRef:="$B$18:$B$27", Relation:=3, FormulaText:="Optimal_Mix_Min"
        SolverAdd CellRef:="$H$31:$H$33", Relation:=1, FormulaText:="$I$31:$I$33"
        SolverOptions MaxTime:=1000, Iterations:=1000, Precision:=0.00000001, _
            AssumeLinear:=False, StepThru:=False, Estimates:=2, Derivatives:=2, _
            SearchOption:=1, IntTolerance:=0.000005, Scaling:=False, Convergence:=0, _
            AssumeNonNeg:=False
        Solution = SolverSolve(True)
    MaxSurplus = Range("Surplus").Value
    SolverReset
    'Finding Minimum Surplus Volatility and its Surplus
        SolverOk SetCell:="$K$36", MaxMinVal:=2, ValueOf:="0", ByChange:="$B$18:$B$27"
        SolverAdd CellRef:="$B$28", Relation:=2, FormulaText:="1"
        SolverAdd CellRef:="$B$18:$B$27", Relation:=1, FormulaText:="Optimal_Mix_Max"
        SolverAdd CellRef:="$B$18:$B$27", Relation:=3, FormulaText:="Optimal_Mix_Min"
        SolverAdd CellRef:="$H$31:$H$33", Relation:=1, FormulaText:="$I$31:$I$33"
        SolverOptions MaxTime:=1000, Iterations:=1000, Precision:=0.00000001, _
            AssumeLinear:=False, StepThru:=False, Estimates:=2, Derivatives:=2, _
            SearchOption:=1, IntTolerance:=0.000005, Scaling:=False, Convergence:=0, _
            AssumeNonNeg:=False
        Solution = SolverSolve(True)
    MinSurplus = Range("Surplus").Value
    SolverReset
    ReDim Asset_Mix_Array(1 To 10, 1 To 100) As Double
    ReDim Frontier_Check_Array(1, 1 To 100) As Double
    NextRow = 1
     Increment = (MaxSurplus - MinSurplus) / 100
         SolverOk SetCell:="$K$36", MaxMinVal:=2, ValueOf:="0", ByChange:="$B$18:$B$27"
         SolverAdd CellRef:="$B$28", Relation:=2, FormulaText:="1"
         SolverAdd CellRef:="$B$18:$B$27", Relation:=1, FormulaText:="Optimal_Mix_Max"
         SolverAdd CellRef:="$B$18:$B$27", Relation:=3, FormulaText:="Optimal_Mix_Min"
         SolverAdd CellRef:="$H$31:$H$33", Relation:=1, FormulaText:="$I$31:$I$33"
         SolverAdd CellRef:="$K$38", Relation:=2, FormulaText:="Desired_Surplus"
         SolverOptions MaxTime:=1000, Iterations:=1000, Precision:=0.00000001, _
             AssumeLinear:=False, StepThru:=False, Estimates:=2, Derivatives:=2, _
             SearchOption:=1, IntTolerance:=0.000005, Scaling:=False, Convergence:=0, _
             AssumeNonNeg:=False
     For i = MinSurplus To MaxSurplus - Increment Step Increment
         Range("Desired_Surplus").Value = i
         Solution = SolverSolve(True)
         If Solution = 0 Then
             Frontier_Check_Array(1, NextRow) = Range("Optimal_Mix_Total").Value
             Asset_Mix_Array(1, NextRow) = Range("Class1").Value
             Asset_Mix_Array(2, NextRow) = Range("Class2").Value
             Asset_Mix_Array(3, NextRow) = Range("Class3").Value
             Asset_Mix_Array(4, NextRow) = Range("Class4").Value
             Asset_Mix_Array(5, NextRow) = Range("Class5").Value
             Asset_Mix_Array(6, NextRow) = Range("Class6").Value
             Asset_Mix_Array(7, NextRow) = Range("Class7").Value
             Asset_Mix_Array(8, NextRow) = Range("Class8").Value
             Asset_Mix_Array(9, NextRow) = Range("Class9").Value
             Asset_Mix_Array(10, NextRow) = Range("Class10").Value
         NextRow = NextRow + 1
         End If
     Next
    Range("Desired_Surplus").Value = MaxSurplus
    Solution = SolverSolve(True)
    Asset_Mix_Array(1, 100) = Range("Class1").Value
    Asset_Mix_Array(2, 100) = Range("Class2").Value
    Asset_Mix_Array(3, 100) = Range("Class3").Value
    Asset_Mix_Array(4, 100) = Range("Class4").Value
    Asset_Mix_Array(5, 100) = Range("Class5").Value
    Asset_Mix_Array(6, 100) = Range("Class6").Value
    Asset_Mix_Array(7, 100) = Range("Class7").Value
    Asset_Mix_Array(8, 100) = Range("Class8").Value
    Asset_Mix_Array(9, 100) = Range("Class9").Value
    Asset_Mix_Array(10, 100) = Range("Class10").Value
    Worksheets("Frontier Points").Range("B1:CW10").Value = Asset_Mix_Array
    Application.ScreenUpdating = True
    SolverReset
    End Sub
    Dear sir the error given is as below
    sub or function not defined.

  5. #5
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: debug the code of portfolio optimization software

    sub or function not defined.
    which line?
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  6. #6

    Thread Starter
    New Member
    Join Date
    Apr 2011
    Posts
    4

    Re: debug the code of portfolio optimization software

    first problem is solved.the error given is in line 34 as follows

    compile error:
    Syntax error

  7. #7
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: debug the code of portfolio optimization software

    without having to count all the lines what line is that?
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width