question

Upvotes
Accepted
6 0 1 3

RDP IPA FX Volatility

I am trying to plot fx vol surf using the file I found on Git Hub in below link.

https://github.com/Refinitiv-API-Samples/Article.RDPLibrary.Python.VolatilitySurfaces_Curves

File name "Vol Surfaces Webinar.ipynb". It worked for ETI option but for FX Volatility Surface, it returned error. Vol Surfaces Webinar.zip

--------------------------------------------------------

fx_surfaces = fx_response.data.raw['data']

plot_surface(fx_surfaces, 'FxVol-USDSGD', True)

--------------------------------------------------------

TypeError                                 Traceback (most recent call last)
<ipython-input-23-1b085c0e4326> in <module>
      1 fx_surfaces = fx_response.data.raw['data']
----> 2 plot_surface(fx_surfaces, 'FxVol-USDSGD', True)

<ipython-input-5-0e89ac2f0bf9> in plot_surface(surfaces, surfaceTag, delta_plot)
     26         # When plotting FX Delta rather than Strike
     27         # I'm converting the x axis value from Delta to Put Delta
---> 28         delta_axis = list(map(convert_delta, strike_axis))
     29         x = np.array(delta_axis, dtype=float)
     30     else:

<ipython-input-5-10b94499ab72> in convert_delta(delta)
      1 def convert_delta(delta):
----> 2     if (delta<0):
      3         return -delta
      4     elif (delta>0):
      5         return 1-delta 
TypeError: '<' not supported between instances of 'str' and 'int'


rdp-apirefinitiv-data-platformrefinitiv-data-platform-librariesipa
icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 5.0 MiB each and 10.0 MiB total.

Upvotes
Accepted
20.3k 73 10 20

Hi @aya.nakamura3

The problem seems to be that for FX, the strike_axis values now contain an at the money text value:

[-0.1, -0.15, -0.2, -0.25, -0.3, -0.35, -0.4, -0.45, 'ATM', 0.45, 0.4, 0.35, 0.3, 0.25, 0.2, 0.15, 0.1]

So, it would appear there has been a change to the Vol Surfaces response since when I presented the Webinar and the notebooks.

I am not 100% sure but I think the following should fix this:

def convert_delta(delta):

    if (delta=='ATM'):
        return 0.5
    elif (delta<0):
        return -delta
    elif (delta>0):
        return 1-delta
    else:
        return 0.5

I have asked the IPA team to confirm if the above is correct and if there could be other text values I need to consider.

I will update the notebook on Github once they have confirmed the corrections.

icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 5.0 MiB each and 10.0 MiB total.

Upvotes
20.3k 73 10 20

Hi @aya.nakamura3

The IPA team advised a different solution, they suggested I change the original request to something like:

"universe": [
        {
              "underlyingType": "Fx",
              "surfaceTag": "FxVol-USDSGD",
              "underlyingDefinition": {
                "fxCrossCode": "USDSGD"
              },
              "surfaceLayout": {
                "format": "Matrix",
                "yValues": [ "-0.1","-0.15","-0.2","-0.25","-0.3","-0.35","-0.4","-0.45","0.5","0.45","0.4","0.35","0.3","0.25","0.2","0.15","0.1"]
              },
              "surfaceParameters": {
                "xAxis": "Date",
                "yAxis": "Delta",
                "calculationDate": "2018-08-20T00:00:00Z",
                "returnAtm": "False",
              }
        }
    ]

The changes above would avoid having to change the convert_delta() function.

I am holding off updating the Github file for now - as there is another issue in the notebook I have spotted (not related to the above Vol Surface)


icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 5.0 MiB each and 10.0 MiB total.

@umer.nalla Thank you very much! It worked!

Click below to post an Idea Post Idea