Compute the Option Price

In this section you will do the following:

  • Create the pricing script in Financial Model Builder.
  • Create a flow in Flow editor to call the pricer from Financial Model Builder.
  • Create the UI components to call the pricing script and display the results.

Create a Form

To create a form in the UI

  1. Go to the Quandl workspace, and open the Option Pricer board.
  2. Switch to Design mode, and select the left frame. This is the location where you will add a form that you will use to send the requests for pricing to Financial Model Builder.
  3. On the components toolbar, find and select the Form component.
  4. Configure the form as follows:
    1. Title: Pricer.
    2. In the Options section, select Schema.
    3. Copy and paste the following schema definition into the text area:
    {
     "title": "EQ Option Pricer",
     "type": "object",
     "properties": {
         "strike": {
           "type": "number",
           "default": 0,
           "description": ""
         },
         "spot": {
           "type": "number",
           "default": 0,
           "description": ""
         },
         "as_of_date": {
           "type": "string",
           "format": "date",
           "default": "",
           "description": ""
         },
         "maturity_date": {
           "type": "string",
           "format": "date",
           "default": "",
           "description": ""
         },
         "type": {
           "type": "string",
           "enum": [
             "put",
             "call"
           ],
           "default": "call",
           "description": ""
         },
         "equity": {
           "type": "string",
           "enum": [
             "FB"
           ],
           "default": "FB",
           "description": ""
         },
         "comment": {
           "type": "string",
           "maxLength": 20,
           "description": ""
         }
     }
    }
    1. In the Actions section, select Create actions, and enter the following:
      • Display name: Price
      • Action name: call_price.
    2. Click to add the action to the form as the button that you use to trigger the pricing request.
Fig. 60: Configure the form used to send the pricing request.

Fig. 60: Configure the form used to send the pricing request.

  1. Switch off the Design mode to visualize the form in the Option Pricer board.
Fig. 61: The form for submitting the pricing request to .

Fig. 61: The form for submitting the pricing request to .

Define a Custom Pricer in FFDC Valuation

In this section you create the pricing script in Financial Model Builder. You start from the files that you created in the European Options section of Financial Model Builder documentation.

To define a custom pricer in Financial Model Builder

  1. Log into Financial Model Builder.
  2. Create a script file in src/main/resources/library/scripts/, and name it tutorial_OptionPricer.
  3. Open the newly created script, and paste the following code:
// DATA FROM THE DOCUMENT FILES
def tau = yearFraction(calculationDate(), maturity_date, "ACT/365.FIXED", YearFractionParameters()) // Time to expiry as a fraction of a year with basis 365

// DATA FROM THE PRICING DATA FILE
def S = getEquitySpot(stockdata.name, calculationDate())

def vol = data0D("Volatility", [stockdata.name], calculationDate())

// CALCULATION OF THE OPTION VALUE
def Option_Value = getVanillaBS(type, S, strike, vol, tau, r , D) // Option value

return Option_Value
  1. Deploy your Financial Model Builder library as explained in the Valuation Editor section of the Financial Model Builder documentation. Your option pricer script is now accessible via REST calls, through FusionFabric.cloud API Management.

Create the Flow of the EQ Option Pricer

To create the option pricer flow

  1. On the home page, click in the top-right corner to open the Tools hub, and then click to switch the UI to Flow editor mode.
Fig. 62: Switch the UI to Flow Editor module.

Fig. 62: Switch the UI to Flow Editor module.

  1. Create a new flow and name it EQ Option Pricer Flow. From the Flow Menu select Import > Clipboard.
  2. Copy the following code, and paste it into the text area of the Import nodes window.
[
    {
        "id": "c03eeda6.50eb9",
        "type": "mb-http-in",
        "z": "58182884.f66d18",
        "name": "price",
        "method": "post",
        "url": "/5d575dab-7220-fa59-32ac-d3b3190a52a1/Price",
        "swaggerDoc": "",
        "x": 110,
        "y": 40,
        "wires": [
            [
                "78794f39.5b924"
            ]
        ]
    },
    {
        "id": "78794f39.5b924",
        "type": "function",
        "z": "58182884.f66d18",
        "name": "getFormPayload",
        "func": "\nmsg.strike = msg.payload.value.strike\nmsg.spot = msg.payload.value.spot\nmsg.maturity_date =  msg.payload.value.maturity_date\nmsg.asOfDate = msg.payload.value.as_of_date;\nmsg.type = msg.payload.value.type\nmsg.equity = msg.payload.value.equity\nmsg.volatility = 0.0221\n\n//today = new Date();\n//today = today.getFullYear() + \"-\" + (today.getMonth()+1) + \"-\" + today.getDate();\n//msg.asOfDate = today;\n\n//msg.asOfDate = \"2018-01-25\"\nmsg.D = 0.01\nmsg.r = 0.005444\n\n\n\n\nreturn msg;\n",
        "outputs": 1,
        "noerr": 0,
        "x": 200,
        "y": 100,
        "wires": [
            [
                "6188b503.401a9c"
            ]
        ]
    },
    {
        "id": "6188b503.401a9c",
        "type": "function",
        "z": "58182884.f66d18",
        "name": "getAuthorization",
        "func": "msg.headers = {\n\"Authorization\" : \"Bearer \" + msg.req.user.authTokens.master.access_token,\n\"Ocp-Apim-Subscription-Key\": \"<your_api_key>\"\n};\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "x": 320,
        "y": 160,
        "wires": [
            [
                "34dc344d.0c87fc"
            ]
        ]
    },
    {
        "id": "34dc344d.0c87fc",
        "type": "template",
        "z": "58182884.f66d18",
        "name": "fmb-document-template",
        "field": "payload",
        "fieldType": "msg",
        "format": "handlebars",
        "syntax": "mustache",
        "template": "{\n  \"documents\": [\n    {\n      \"dealStamp\": \"DOC1\",\n        \"type\" : \"{{type}}\",\n      \"maturity_date\": \"{{maturity_date}}\",\n      \"strike\": {{strike}},\n      \"D\": {{D}},\n      \"r\": {{r}},\n      \"value_date\": \"2017-04-25\",\n      \"stockdata\": {\n        \"currency\": \"USD\",\n        \"instrument\": \"EQUITY\",\n        \"name\": \"{{equity}}\"\n      }\n    }\n  ],\n  \"pricingData\": {\n    \"dates\": [\n      \"{{asOfDate}}\"\n    ],\n    \"scenarioData\": [\n      {\n        \"id\": {\n          \"parameters\": [\n            \"{{equity}}\"\n          ],\n          \"type\": \"EQUITY\"\n        },\n        \"metaData\": {},\n        \"points\": {\n          \"{{asOfDate}}\": [\n            {\n              \"values\": [\n                {{spot}}\n              ]\n            }\n          ]\n        }\n      },\n      {\n        \"id\": {\n          \"parameters\": [\n            \"{{equity}}\"\n            ],\n            \"type\": \"Volatility\"\n        },\n        \"points\": {\n           \"{{asOfDate}}\": [\n            {\n              \"values\": [\n                {{volatility}}\n              ]\n            }\n          ]\n        },\n        \"metaData\": {}\n      }\n    ]\n  }\n}",
        "output": "json",
        "x": 390,
        "y": 240,
        "wires": [
            [
                "512768f1.447418"
            ]
        ]
    },
    {
        "id": "512768f1.447418",
        "type": "http request",
        "z": "58182884.f66d18",
        "name": "getOptionPrice",
        "method": "POST",
        "ret": "obj",
        "url": "https://{host}{basePath}/library/FMB/script/tutorial_OptionPricer/execute ",
        "tls": "",
        "x": 440,
        "y": 320,
        "wires": [
            [
                "3bb42837.b950c8"
            ]
        ]
    },
    {
        "id": "3bb42837.b950c8",
        "type": "function",
        "z": "58182884.f66d18",
        "name": "prepareHtml",
        "func": "option = msg.payload.results[0].values[0];\noption = option.toPrecision(3);\nmsg.payload ='<!DOCTYPE html><html><body><h1>$heading</h1><p></p></body></html>'\nmsg.payload = msg.payload.replace('$heading', option)\nmsg.option = option;\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "x": 490,
        "y": 400,
        "wires": [
            [
                "5f40e33f.2b8eac"
            ]
        ]
    },
    {
        "id": "5f40e33f.2b8eac",
        "type": "mb-http-out",
        "z": "58182884.f66d18",
        "name": "html-out",
        "x": 620,
        "y": 480,
        "wires": []
    }
]
Fig. 63: Import a flow from Clipboard.

Fig. 63: Import a flow from Clipboard.

  1. Click Import to import the flow. The nodes that compose the flow are added to the dashboard in a new flow called EQ Option Pricer Flow. The flow is imported, but you must configure the connection to Financial Model Builder, as further explained.
Fig. 64: The flow for calling the option price computation from Financial Model Builder.

Fig. 64: The flow for calling the option price computation from Financial Model Builder.

  1. Double-click the Authorization node, and then replace <your_API_key> with your Financial Model Builder API key.
Fig. 65: Use your Financial Model Builder subscription key.

Fig. 65: Use your Financial Model Builder subscription key.

  1. Double-click the getOptionPrice node to open the node where you configure the connection to the Financial Model Builder to execute the pricing script.
  2. In the URL field, replace {host}{basePath} with the appropriate values from the API definition. To get the API definition, see Get Started with Finastra Open APIs.
Fig. 66: Set up the connection to Financial Model Builder to call the computation script.

Fig. 66: Set up the connection to Financial Model Builder to call the computation script.

  1. Click Deploy to deploy the EQ Option Pricer Flow to your FusionCreator App Builder environment. You can now call it through the Link Editor module of FusionCreator App Builder.

Notes

  • Your flow is now configured to connect to Financial Model Builder, and call the pricing script to retrieve the option price based on the input that you send from FusionCreator App Builder.
  • You configured a flow with two endpoints:
    • One action: the Price node. This node is of uxp in type, and it is designed to receive HTTP requests from the UI.
    • One event: the html_out node. This node is of uxp out type, and it is designed to send its message to UI components.
  • You can add debug nodes to your nodes. However, make sure you turn them off when you use the flow in production, as it may impact the performance of the application.