Introduction to RASON
About RASON Models and the RASON Server
Rason Subscriptions
Rason Web IDE
Creating and Running a Decision Flow
Defining Your Optimization Model
Defining Your Simulation Model
Performing Sensitivity Analysis
Defining Your Stochastic Optimization Model
Defining Your Data Science Model
Defining Custom Types
Defining Custom Functions
Defining Your Decision Table
Defining Contexts
Using the REST API
REST API Quick Call Endpoints
REST API Endpoints
Decision Flow REST API Endpoints
OData Endpoints
OData Service for Decision Flows
Creating Your Own Application
Using Arrays, For, Loops and Tables
Organization Accounts

Merging Decision Table Results

The DT Loan Recommend Model.json contains one decision table, tblLoanTypes and one "regular" table, bankRates. The decision table returns a loan or loans meeting four input parameters, reqObj (repayment type), reqType (loan type), conforming (conventional or conforming) and reqDown (percentage down), and returns three outputs, loanType (type of loan), confType (conventional or jumbo) and downPct (down payment percentage required).

The refTypes component requires the conforming input parameter to be Boolean (True or False), the reqDown input parameter to be a number and specifies that the downPct output parameter will return a number.

The inputValues component allows only 1 type of input, the text string "payment". The outputValues component allows only two types of text strings, "conventional" or "jumbo". Notice two arrays were utilized to enter two different strings for the same output. Notice the difference between refTypes and inputValues. The first component, refTypes, specifies the input type, Boolean or number, while inputValues and outputValues specifies the input and output parameter domains, "payment" and "conventional" or "jumbo", respectively.

The hit policy, C for Collect will return all results in the result collection.

The non-table array, bankRates, lists six banks offering loans in the area. Notice that no bank is offering the Fixed 40 loan. The remaining input parameters in the data section are defined constant values or text strings, reqObj = "payment", loanType = "fixed 30", conforming = True and downPct = 30.

Note that the "reqObj" data object is not named "objective" so as to not clash with the defined RASON property, "objective".


{
 modelName: "DTLoanRecommendExample",
 modelType: "calculation",
 modelDescription: "This model has been created from an Excel model 
  in the workbook DT Loan Recomend model.xlsx",
 decisionTables: {
   tblLoanTypes: {
	   inputs: ["reqObj", "reqType", "conforming", "reqDown"], 
	   outputs: ["loanType", "confType", "downPct"],
	   refTypes: ["", "", "boolean", "number", "", "", "number"],
	   inputValues: [["payment", "", "", ""]],
	   outputValues: [["", "conventional", ""], ["", "jumbo", ""]],
	   rules: [
		  ["payment", "Fixed 30, Fixed 20", "-", "<20.0", "ARM 3/1",   "conventional", 20],
		  ["payment", "Fixed 30, Fixed 20", false, ">=20", "ARM 3/1", "jumbo", "reqDown"],
		  ["payment", "Fixed 30, Fixed 20", true, ">=20", "'ARM 3/1'", "conventional", "reqDown"],
		  ["payment", "Fixed 15", "-", "<20", "Fixed 20", "conventional", 20],
		  ["payment", "Fixed 15", false, "<=20", "Fixed 20", "jumbo", "reqDown"],
		  ["payment", "Fixed 15", true, ">=20", "Fixed 20", "conventional", "reqDown"],
		  ["payment", "Fixed 20", "-", "<20", "Fixed 30", "conventional", 20],
	  	["payment", "Fixed 20", false, ">=20", "Fixed 30", "jumbo", "reqDown"],
		  ["payment", "Fixed 20", true, ">=20", "Fixed 30", "conventional", "reqDown"],
		  ["payment", "Fixed 30", "-", "<20", "Fixed 40", "conventional", 20],
		  ["payment", "Fixed 30", false, "<=20", "Fixed 40", "jumbo", "reqDown"],
		  ["payment", "Fixed 30", true, ">=20", "Fixed 40", "conventional",  "reqDown"],
		  ["payment", "'ARM 7/1','ARM 3/1'", "-", "<20", "ARM 3/1", "conventional", 20],
		  ["payment", "'ARM 7/1','ARM 3/1'", false, ">=20", "ARM 3/1", "jumbo", "reqDown"],
		  ["payment", "'ARM 7/1','ARM 3/1'", true, ">=20", "ARM 3/1",      "conventional", "reqDown"]
	   ],
	   hitPolicy: "C"
    }
 },
 data: {
   reqObj: { value: "payment", comment: "reqobj" },
   loanType: { value: "fixed 30", comment: "reqtype" },
   conforming: { value: true, comment: "conforming" },
   downPct: { value: 30, comment: "reqdown" },
   bankRates: { value: [
	['Lender','loanType',	'confType', 'minDown%','Term','APR%','Rate%','Points','feesAmt'],
	['MDL',"'ARM 3/1'", 'conventional', 20, 360, 3.002, 3, 0, 0],
	['AL', "'ARM 3/1'", 'conventional', 20, 360, 3.103, 2.875, 0, 1995],
	['AO', "'ARM 3/1'", 'conventional', 20, 360, 3.13, 2.875, 1, 899],
	['MDL', 'Fixed 30', 'conventional', 20, 360, 3.629, 3.625, 0, 0],
	['AL', 'Fixed 30', 'conventional', 20, 360, 3.682, 3.625, 0, 1068],
	['AO', 'Fixed 30', 'conventional', 20, 360, 3.79, 3.75, 0, 799]]
   }
 },
 formulas: {
	loanTypes: { 
    formula: "tblLoanTypes(,True,reqObj, loanType, conforming, downPct)", 
    comment: "it's important to include the header", finalValue: [] 
  },
	recom: { 
    formula: "PsiJoin(loanTypes, bankRates, 'loanType = loanType, confType = confType, downPct >= minDown%')", 
    finalValue: [] 
  }
 }
}

The formulas section contains two calculations: loanTypes and recom. The first, loanTypes, passes the input data, found in data, reqObj = payment, loanType = "fixed 30", conforming = True and downPct = 30 along with the "ret_header" optional argument set to TRUE. As discussed earlier, with this argument set to True, the RASON Server will return the header for each column in the result collection.

The results for loanTypes includes two loans, an ARM loan and a Fixed 40 loan along with the headers for each output: loanType, confType and downPct.


"loantypes": { "value": 
	[ 
	["loanType", "confType", "downPct"], 
	["'ARM 3/1'", "conventional", 30], 
	["Fixed 40", "conventional", 30] 
	] 
},

The next formula, recom, uses the PsiJoin() function to join the loanTypes result with the bankRates array. This function takes three arguments, Table1, Table2 and Clause. The Table1 argument passes the first table, tblLoanTypes. The Table2 argument passes the second table or array, bankRates. The third argument, Clause, passes the conditions for joining the two. In this example, loanTypes, decision table results and the bankRates are joined via three columns: loanType, confType and downPct. The Clause argument must be surround by quotes.

Note that in this example, two conditions are the same, i.e. loanType = loanType and confType = confType. This is not a requirement; table headers can be different.

The third condition, downPct >= 'minDown %' requires that the downPct in the Loan Types decision table must be greater than the "minDown %" in the Bank Rates table. In other words, the down payment percentage in the Loan Types table must be greater than the minimum percentage down in the Bank Rates array in order for the loan to be selected and displayed by PsiJoin().

Note: Recall that the decision table formula for loanTypes included the optional "header" argument. If the results had not included this argument, it would not have been possible to use the PsiJoin() function to complete merge.

Notice how string values, which look like expressions are entered, "'ARM 3/1"', using inner single quotes. As discussed earlier, decision table values may be expressions and the way to distinguish expressions from text is by using the inner single quotes. "APR 1/3" will produce an error concerning a misspelled expression. Alternatively " 'ARM 3\1' " would have been a better choice since the back slash is not a valid operator in FEEL.

Another important point to notice is the double quotes surrounding each element in the bankRates table. Although typically there is no need to double quote the values in a non-table array, in this model, since we are joining the tblLoanTypes decision table with the non-table array "bankRates", double quotations in the non-table array must be present.

All three columns are common to both the loanTypes result and the Bank Rates table. Three banks offer a conventional ARM 3/1 loan: Mount Diablo, AimLoan and America One. The first three columns are passed to the Clause argument: loanType, confType, and downPct. The remaining columns contain the remaining information for each offered loan: Lender, loanType, confType, minDown%, Term, APR %, Rate %, Points and feesAmt.


"recom": { 
  "value": [ 
  ["loanType", "confType", "downPct", "Lender", "loanType", "confType", "minDown%", "Term", "APR%", "Rate%", "Points", "feesAmt"], 
  ["'ARM 3/1'", "conventional", 30, "MDL", "'ARM 3/1'", "conventional", 20, 360, 3.002, 3, 0, 0], 
  ["'ARM 3/1'", "conventional", 30, "AL", "'ARM 3/1'", "conventional", 20, 360, 3.103, 2.875, 0, 1995], 
  ["'ARM 3/1'", "conventional", 30, "AO", "'ARM 3/1'", "conventional", 20, 360, 3.13, 2.875, 1, 899] 
  ] 
}
Back to Scoring New Data