Tutorial Files

Workflow Input

You are provided with the workflow input file in /src/test/resources/documents/tutorial_EmbedScript.json. Here you have the information about the document and the pricing data. The document part contains a "script" field. This script is called by the workflow. The file is listed below.

{
  "documents": [
    {
      "dealStamp": "Option_Document_1",
      "script": "tutorial_EUadvanced",
      "type": "call",
      "strike": 43,
      "maturity_date": "2019-04-25",
      "value_date": "2017-04-13",
      "stockdata": {
        "name": "COCA_COLA",
        "instrument": "EQUITY",
        "currency": "USD"
      },
      "curve": "projection_Libor_3M"
    }
  ],
  "pricingData": {
    "dates": [
      "2017-04-13"
    ],
    "scenarioData": [
      {
        "id": {
          "type": "Volatility",
          "parameters": [
            "COCA_COLA"
          ]
        },
        "points": {
          "2017-04-13": [
            {
              "values": [
                0.0221
              ]
            }
          ]
        },
        "metaData": {}
      },
      {
        "id": {
          "type": "DIVIDEND",
          "parameters": [
            "COCA_COLA",
            "CONTINUOUS"
          ]
        },
        "points": {
          "2017-04-13": [
            {
              "values": [
                0.01
              ]
            }
          ]
        },
        "metaData": {}
      },
      {
        "id": {
          "type": "EQUITY",
          "parameters": [
            "COCA_COLA"
          ]
        },
        "points": {
          "2017-04-13": [
            {
              "values": [
                46
              ]
            }
          ]
        }
      },
      {
        "id": {
          "parameters": [
            "projection_Libor_3M",
            "discountFactor"
          ],
          "type": "YIELD_CURVE"
        },
        "metaData": {
          "currency": "USD",
          "interpolationMethods": [
            "flat"
          ],
          "interpolationVariables": [
            "discountFactor"
          ],
          "switchDates": [],
          "zeroCouponBasis": "ACT/365.FIXED",
          "zeroCouponFormula": "exponential"
        },
        "points": {
          "2017-04-13": [
            {
              "values": [
                1
              ],
              "x": 17269
            },
            {
              "values": [
                0.99943
              ],
              "x": 17294
            },
            {
              "values": [
                0.99886
              ],
              "x": 17319
            },
            {
              "values": [
                0.99829
              ],
              "x": 17344
            },
            {
              "values": [
                0.99772
              ],
              "x": 17369
            },
            {
              "values": [
                0.99715
              ],
              "x": 17394
            },
            {
              "values": [
                0.99658
              ],
              "x": 17419
            },
            {
              "values": [
                0.99629
              ],
              "x": 17444
            },
            {
              "values": [
                0.99601
              ],
              "x": 17469
            },
            {
              "values": [
                0.99572
              ],
              "x": 17494
            },
            {
              "values": [
                0.99544
              ],
              "x": 17519
            },
            {
              "values": [
                0.99515
              ],
              "x": 17544
            },
            {
              "values": [
                0.99486
              ],
              "x": 17569
            },
            {
              "values": [
                0.99458
              ],
              "x": 17594
            },
            {
              "values": [
                0.99403
              ],
              "x": 17619
            },
            {
              "values": [
                0.99347
              ],
              "x": 17644
            },
            {
              "values": [
                0.99292
              ],
              "x": 17669
            },
            {
              "values": [
                0.99236
              ],
              "x": 17694
            },
            {
              "values": [
                0.99181
              ],
              "x": 17719
            },
            {
              "values": [
                0.99125
              ],
              "x": 17787
            }
          ]
        }
      }
    ]
  }
}

Workflow and Box

In the workflow, the tutorial_EmbedScript box is called with the request input and the results output.

Fig. 80: The tutorial_EmbedScript Workflow.

Fig. 80: The tutorial_EmbedScript Workflow.

The content of the tutorial_EmbedScript box is displayed below:

// Input management
def request(value) {
    // Create a jackson Object mapper
    mapper = new ObjectMapper()
    // Read value, put it in an valueNode node
    valueNode = mapper.readTree(value)
    // Extract the document and pricingData part from node
    tradeNode = valueNode["documents"]
    pricingDataNode = valueNode["pricingData"]
    // JSON converted to ProcessingData Java object
    pricingData = mapper.readValue(pricingDataNode.toString(), ProcessingData.class)
}
 
// Create the dataManager from the pricingData
DataManager dataManager = DataManagerRestUtils.create(pricingData)  
 
// Register the documents assigning them a script
documents = []
tradeNode.each {
    def id = it.get("dealStamp").asText()
    documents.add(new JsonDocument(it.get("script").asText(), it, id)) // Select the script
}
 
// Run the execution (returns a non ordered map of results)
resultById = engine().buildSession(dataManager)
        .process(documents)
        .collect()  
        
// Prepare results
final ArrayNode results = mapper.createArrayNode()
documents.each {
    ObjectNode docresults = mapper.createObjectNode()
    docresults.put("id",it.getId())
    result = resultById[it.getId()]
    docresults.put("type",result.type().name())
    docresults.set("values", mapper.readTree(result.toString()))
    results.add(docresults)    
}
 
 // Output the result
output("results",mapper.writeValueAsString(results))
close("results") 

Several functions from the FPP Javadoc are leveraged.