/* To use this model, you will need to set up a DSN called PortfolioData and point it at the Portfolio.mdb database */ set FUNDS; set ASSETCLASSES; param Target{ASSETCLASSES}; param Rating{FUNDS, ASSETCLASSES} default 0; table FundsTable IN "ODBC" "DSN=PortfolioData" "Funds": FUNDS <- [Fund]; read table FundsTable; table TargetsTable IN "ODBC" "DSN=PortfolioData" "Targets": ASSETCLASSES <- [AssetClass], Target; read table TargetsTable; table RankingsTable IN "ODBC" "DSN=PortfolioData" "Rankings": [Fund, AssetClass], Rating~Rank; read table RankingsTable; var Investment{FUNDS} >= 0; var AmtOver{ASSETCLASSES} >= 0; var AmtUnder{ASSETCLASSES} >= 0; minimize TotalDeviations: sum{class in ASSETCLASSES} (AmtOver[class] + AmtUnder[class]); s.t. InvestAll: sum{fund in FUNDS} Investment[fund] = 1; s.t. DefineDeviations{class in ASSETCLASSES}: sum{fund in FUNDS} Rating[fund, class]*Investment[fund] + AmtUnder[class] - AmtOver[class] = Target[class]; solve; table AllocationOut OUT "ODBC" "DSN=PortfolioData" "AllocationOut": {Fund in FUNDS: Investment[Fund] > 0} -> [Fund], Investment[Fund]~Allocation; write table AllocationOut;