{
"Version" : 2.2,
"CaseName" : "indexof.minion",
"DefaultUnitSet" : "SI",
"RootModel" : {
"DiagramY" : -12321,
"Objects" : [
{
"DiagramNotes" : "y",
"DiagramY" : 245,
"DiagramX" : 70,
"Type" : "Data Table",
"Notes" : "A table of quotes for stock symbols.",
"Columns" : [
{
"name" : "Symbol",
"sValues" : [
"MSFT",
"KO",
"APPL",
"KO",
"MSFT",
"INTC"
],
"defaultValue" : "' "
},
{
"displayUnit" : "date",
"unitDimensions" : "0 0 1 0 0 0 0",
"defaultValue" : "{now}",
"name" : "Date",
"nValues" : [
1370822400,
1370822400,
1370822400,
1370908800,
1370908800,
1370908800
]
},
{
"defaultValue" : "0",
"unitDimensions" : "0 0 0 0 0 0 0",
"name" : "quote",
"nValues" : [
37,
42,
440,
41,
35,
25
]
}
],
"name" : "Quotes",
"HideInfo" : "n"
},
{
"DiagramNotes" : "y",
"DiagramY" : 285,
"DiagramX" : 70,
"Type" : "Expression",
"Notes" : "A table with a column of names, a column of symbols and a column of share holdings. The object is to look up names for each value of object quotes by matching against the symbol column.",
"Formula" : {
"Formula" : "{table {cc \"Name\", \"Symbol\", \"Shares\"},\n\t{cc \"Microsoft\", \"Coke\", \"Apple\"},\n\t{cc \"MSFT\", \"KO\", \"APPL\"},\n\t{cc 100, 150, 200}\n}"
},
"name" : "Companies"
},
{
"DiagramNotes" : "y",
"DiagramY" : 310,
"DiagramX" : 155,
"Type" : "Expression",
"Notes" : "The indexof function returns a matrix with two columns with the same number of rows as there are values in Quotes.symbol. The first column contains the first row number in Companies.symbol which matches the value in Quotes.symbol.\n\nThus row 4 of Quotes.symbol contains MFST and the first row in Companies.symbol that contains MSFT is row 2. Thus row 4, column 1 in the returned value contains a 2.\n\nThe second column contains the column number of the first found value, but since we are only using single dimension arrays here, the values will all be 1, so the index [0,1] is used to just return the first column.\n\nNote that since the 6th row of a contains INTC, which is not present in Companies.Symbols, a 0 is returned in row 6.\n",
"Formula" : {
"Formula" : "{indexof quotes.symbol, Companies.symbol}[0,1]"
},
"name" : "i1"
},
{
"DiagramNotes" : "y",
"DiagramY" : 330,
"DiagramX" : 245,
"Type" : "Expression",
"Notes" : "To avoid getting an index out of range error for the 0 index in the 6th row, this if statement replaces any 0 values with 1.",
"Formula" : {
"Formula" : "{if i1, i1, 1}"
},
"name" : "i2"
},
{
"DiagramNotes" : "y",
"DiagramY" : 315,
"DiagramX" : 360,
"Type" : "Expression",
"Notes" : "The names corresponding to the indexes matching Quotes.symbol in Companies.symbol are returned. An if statement is used to return \"Unknown\" for any values of a that did not have a corresponding value in Companies.symbol.\n\nBecause Companies.symbol[i1] has to be computed before the if function is called, it would result in an index error due to the zero index in row 6. Thus the need to create the i2 index.\n\nIf you were sure that there were no mismatches, i2 could have been dispensed with an the formula here would just be:\n\nCompanies.Name[i1]",
"Formula" : {
"Formula" : "{if i1, Companies.name[i2], \"Unknown\"}"
},
"name" : "Names",
"HideInfo" : "n"
},
{
"DiagramNotes" : "y",
"DiagramY" : 240,
"tableUnits" : {
"2" : "date"
},
"DiagramX" : 440,
"Type" : "Expression",
"Notes" : "Here a new table is constructed using the companies names instead of symbols. Also a market value of the holdings is calculated by using the number of shares from the Companies table, with a similar indexing as with Names.",
"Formula" : {
"Formula" : "{table {cc \"Name\", \"Date\", \"Price\", \"Value\"},\n\tNames,\n\tQuotes.date, Quotes.quote,\n\tQuotes.quote * {if i1, Companies.Shares[i2], 0}\n}"
},
"name" : "Holdings",
"HideInfo" : "n"
}
],
"DiagramX" : -12321,
"diagramScale" : 1.497674465179443,
"Type" : "Model",
"diagramY" : -199.9378814697266,
"diagramX" : -60,
"name" : "Root",
"HideInfo" : "n"
},
"UserUnits" : [],
"DeviceWidth" : 768,
"Program" : "Rtm"
}