Prepare the Files

In the previous tutorial, you hard-coded the values for volatility and dividends in the script file. This approach is limited when you need to price financial products with the same model but with different arguments (such as expiry, maturity, etc.).

In that case it is more convenient to change the values in the document and pricing data files according to the specific arguments of the product.

In this tutorial you use a flat volatility. However, this is not always the case in real scenarios. In fact, volatilities are not constant.

For more details about the math behind the functions see Mathematical Background.

If you need to refresh you knowledge on how to actually create the files, see the Get Started with Scripts Tutorial.

In this section you learn how to price different documents without hard-coding values in the script.

To prepare the files for running the model
  1. Create a script file: EUadvanced.psl, and enter the following code.
    • In this advanced script you use forwardRate(), a function from the FPP library. The function returns a forward rate from startDate to endDate computed at calculationDate() according to a basis and based on the input curve.
/**
 * This script is used to price a vanilla option by using values from the document and pricing data JSON files in order to introduce the user to more advanced methods of accessing data from these files:
 * Document file: tutorial_EUadvanced.json
 * Pricing data file: tutorial_EUadvanced.scn                                                                              
 */

// DATA FROM THE DOCUMENT FILES

  // time to expiry as a fraction of a year with basis 365
def tau = yearFraction(value_date, maturity_date, "ACT/365.FIXED", YearFractionParameters())

// DATA FROM THE PRICING DATA FILE

  // spot price
def S = getEquitySpot(stockdata.name, calculationDate())

  // continuously compounded dividend yield
def D = data0D("DIVIDEND", [stockdata.name, "CONTINUOUS"], calculationDate()) 

  // risk-free interest rate
def r = forwardRate(calculationDate(), maturity_date, metaData("YIELD_CURVE", [curve, "discountFactor"], "zeroCouponBasis"), YearFractionParameters(), curve)

  // volatility
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. Create a document file: EUadvanced.json, and enter the following code.
    • The document file is used as a placeholder for the deal information.
    • In the European Options Tutorial, you used an empty document file, the SampleDeal.json file. This is not the case with the EUadvanced.json document file that contains:
      • The option type,"call".
      • The strike of the option, "strike".
      • Different stock attributes, such as "maturity_date" and "stockdata" with "name", "instrument" and the quoted currency.
      • You can add even more information to this file, but, for the moment, you have a good starting point.
{
  "type": "call",
  "strike": 43,
  "maturity_date": "2019-04-25",
  "value_date": "2017-04-13",
  "dealStamp": "COCA_COLA",
  "stockdata": {
    "name": "COCA_COLA",
    "instrument": "EQUITY",
    "currency": "USD"
  },
  "curve":"projection_Libor_3M"
}
  1. Create a pricing data file: EUadvanced.scn, and copy the following code.
    • In the European Options Tutorial, you used the pricing data .json file to access only a single calculation date.
    • The pricing data file now contains the stock data, such as the dividend and the stock price, and yield curve data.
{
  "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
          }
        ]
      }
    }
  ]
}