Discover Refinitiv
MyRefinitiv Refinitiv Perspectives Careers
Created with Sketch.
All APIs Questions & Answers  Register |  Login
Ask a question
  • Questions
  • Tags
  • Badges
  • Unanswered
Search:
  • Home /
  • Refinitiv Data Platform /
  • Refinitiv Data Platform Libraries /
avatar image
REFINITIV
Question by hiroko.yamaguchi1 · Jun 14, 2021 at 04:29 AM · refinitiv-data-platformrefinitiv-data-platform-librariescodebookrdpipa

How to resolve the error 'The service failed to build the volatility surface'

When I executed the following script on CodeBook using RDP Libraries, I could plot a 3D chart of volatility surface, but I can NOT do so today having the following error message.

Can you please let me know the root cause of the error and how to resolve it?

INPUT:

import refinitiv.dataplatform as rdp
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import axes3d, Axes3D
import matplotlib.cm as cm
%matplotlib inline

session = rdp.open_desktop_session('DEFAULT_CODE_BOOK_APP_KEY')

endpoint = rdp.Endpoint(session, "https://api.refinitiv.com/data/quantitative-analytics-curves-and-surfaces/v1/surfaces")

request_body={
    "universe": [
        {   "surfaceTag": "RENAULT",
            "underlyingType": "Eti",
            "underlyingDefinition": {
                "instrumentCode": "RENA.PA"
            },
            "surfaceParameters": {
                "inputVolatilityType": "settle",
                "volatilityModel": "SSVI",
                "xAxis": "Date",
                "yAxis": "Moneyness"
            },
            "surfaceLayout": { "format": "Matrix" }
        },
        {   "surfaceTag": "PEUGEOT",
            "underlyingType": "Eti",
            "underlyingDefinition": {
                "instrumentCode": "PEUP.PA"
            },
            "surfaceParameters": {
                "inputVolatilityType": "settle",
                "volatilityModel": "SSVI",
                "xAxis": "Date",
                "yAxis": "Moneyness"
            },
            "surfaceLayout": { "format": "Matrix" }
        },
        {   "surfaceTag": "BMW",
            "underlyingType": "Eti",
            "underlyingDefinition": {
                "instrumentCode": "BMWG.DE"
            },
            "surfaceParameters": {
                "inputVolatilityType": "settle",
                "volatilityModel": "SSVI",
                "xAxis": "Date",
                "yAxis": "Moneyness"
            },
            "surfaceLayout": { "format": "Matrix" }
        },
        {   "surfaceTag": "VW",
            "underlyingType": "Eti",
            "underlyingDefinition": {
                "instrumentCode": "VOWG.DE"
            },
            "surfaceParameters": {
                "inputVolatilityType": "settle",
                "volatilityModel": "SSVI",
                "xAxis": "Date",
                "yAxis": "Moneyness"
            },
            "surfaceLayout": { "format": "Matrix" }
        }]
}

response = endpoint.send_request(
    method = rdp.Endpoint.RequestMethod.POST,
    body_parameters = request_body
)

def convert_yyyymmdd_to_float(time_axis):
    float_time_axis = []
    for time in time_axis:
        time = time.replace('-', '')
        float_time_axis.append(float(time))
    return float_time_axis

def plot_surface(surfaces, surfaceTag):
    #various imports removed for brevity
    surfaces = pd.DataFrame(data=surfaces)
    surfaces.set_index('surfaceTag', inplace=True)
    surface = surfaces[surfaces.index == surfaceTag]['surface'][0]
    
    strike_axis = surface[0][1:]
    surface = surface[1:]
    time_axis = []
    surface_grid = []
    for line in surface:
        time_axis.append(line[0])
        surface_grid_line = line[1:]
        surface_grid.append(surface_grid_line)

    time_axis = convert_yyyymmdd_to_float(time_axis)
    
    x = np.array(strike_axis, dtype=float)
    y = np.array(time_axis, dtype=float)
    ero = np.array(surface_grid, dtype=float)
    
    X,Y = np.meshgrid(x,y)
    Z = ero
    
    fig = plt.figure(figsize=[15,10])
    
    ax = plt.axes(projection='3d')
    ax.set_xlabel('moneyness')
    ax.set_ylabel('time to expiry')
    ax.set_zlabel('volatilities')
    
    surf = ax.plot_surface(X,Y,Z, cmap=cm.coolwarm, linewidth=0, antialiased=False)
    plt.show()

surfaces = response.data.raw['data']
plot_surface(surfaces, 'VW')

OUTPUT:

---------------------------------------------------------------------------
KeyError                                  Traceback (most recent call last)
/opt/conda/lib/python3.7/site-packages/pandas/core/indexes/base.py in get_loc(self, key, method, tolerance)
   2894             try:
-> 2895                 return self._engine.get_loc(casted_key)
   2896             except KeyError as err:

pandas/_libs/index.pyx in pandas._libs.index.IndexEngine.get_loc()

pandas/_libs/index.pyx in pandas._libs.index.IndexEngine.get_loc()

pandas/_libs/hashtable_class_helper.pxi in pandas._libs.hashtable.PyObjectHashTable.get_item()

pandas/_libs/hashtable_class_helper.pxi in pandas._libs.hashtable.PyObjectHashTable.get_item()

KeyError: 'surface'

The above exception was the direct cause of the following exception:

KeyError                                  Traceback (most recent call last)
<ipython-input-35-aa5486f52eab> in <module>
      1 surfaces = response.data.raw['data']
----> 2 plot_surface(surfaces, 'VW')
      3 # plot_surface(surfaces, 'BMW')

<ipython-input-16-d9df2e95c642> in plot_surface(surfaces, surfaceTag)
     10     surfaces = pd.DataFrame(data=surfaces)
     11     surfaces.set_index('surfaceTag', inplace=True)
---> 12     surface = surfaces[surfaces.index == surfaceTag]['surface'][0]
     13 
     14     strike_axis = surface[0][1:]

/opt/conda/lib/python3.7/site-packages/pandas/core/frame.py in __getitem__(self, key)
   2904             if self.columns.nlevels > 1:
   2905                 return self._getitem_multilevel(key)
-> 2906             indexer = self.columns.get_loc(key)
   2907             if is_integer(indexer):
   2908                 indexer = [indexer]

/opt/conda/lib/python3.7/site-packages/pandas/core/indexes/base.py in get_loc(self, key, method, tolerance)
   2895                 return self._engine.get_loc(casted_key)
   2896             except KeyError as err:
-> 2897                 raise KeyError(key) from err
   2898 
   2899         if tolerance is not None:

KeyError: 'surface'


INPUT:

surfaces

OUTPUT:

[{'surfaceTag': 'RENAULT',
  'error': {'id': '3b6ecb24-f876-4b9c-a965-9e05400fb629/e7b8fa38-c5b3-40b3-b1bb-8f7fad66fcde',
   'status': 'Error',
   'message': 'The service failed to build the volatility surface',
   'code': 'VolSurf.10300'}},
 {'surfaceTag': 'PEUGEOT',
  'error': {'id': '3b6ecb24-f876-4b9c-a965-9e05400fb629/4b652a29-ff3b-4277-9e44-d933273c8888',
   'status': 'Error',
   'message': 'Unknown underlying : PEUP.PA@RIC',
   'code': 'VolSurf.10008'}},
 {'surfaceTag': 'BMW',
  'error': {'id': '3b6ecb24-f876-4b9c-a965-9e05400fb629/854b01f4-a046-4340-a16e-8b5830496185',
   'status': 'Error',
   'message': 'The service failed to build the volatility surface',
   'code': 'VolSurf.10300'}},
 {'surfaceTag': 'VW',
  'error': {'id': '3b6ecb24-f876-4b9c-a965-9e05400fb629/2bee51a2-780f-40db-871b-15cdb883fc41',
   'status': 'Error',
   'message': 'The service failed to build the volatility surface',
   'code': 'VolSurf.10300'}}]

People who like this

0 Show 0
Comment
10 |1500 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

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

1 Reply

  • Sort: 
avatar image
REFINITIV
Best Answer
Answer by umer.nalla · Jun 14, 2021 at 08:32 AM

Hi @hiroko.yamaguchi1

If the code was working previously and has now stopped working - this is most likely due to a temporary issue with the IPA service.

I have just tried your code both in Codebook and as a standalone script connecting directly to RDP - and both are working fine.

If you are still having issues, and you have an RDP machineID + password etc, then I would recommend you try your code outside of Codebook.

If you continue to have issues, please raise a MyRefinitiv ticket for the 'Instrument Pricing Analytics - Refinitiv Data Platform ' Product or for Codebook - depending on whether your code works outside of Codebook or not.

Please attach your source code and output to the ticket.

Comment

People who like this

0 Show 1 · Share
10 |1500 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

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

avatar image
REFINITIV
hiroko.yamaguchi1 · Jun 15, 2021 at 01:33 AM 0
Share
I've confirmed I can retrieve the data successful again now. Thank you for looking into it!

Watch this question

Add to watch list
Add to your watch list to receive emailed updates for this question. Too many emails? Change your settings >
9 People are following this question.

Related Questions

IPA Volatility Surfaces API - The underlying connection was closed: An unexpected error occurred on a send

How to display all output of the request from RDP library at codebook?

ItemStream OpenAsync does not return a usable state or error code

IBES data with python

Use data/symbology/beta1/convert operation in .NET RDP Library

  • Copyright
  • Cookie Policy
  • Privacy Statement
  • Terms of Use
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Alpha
  • App Studio
  • Block Chain
  • Bot Platform
  • Connected Risk APIs
  • DSS
  • Data Fusion
  • Data Model Discovery
  • Datastream
  • Eikon COM
  • Eikon Data APIs
  • Electronic Trading
    • Generic FIX
    • Local Bank Node API
    • Trading API
  • Elektron
    • EMA
    • ETA
    • WebSocket API
  • Intelligent Tagging
  • Legal One
  • Messenger Bot
  • Messenger Side by Side
  • ONESOURCE
    • Indirect Tax
  • Open Calais
  • Open PermID
    • Entity Search
  • Org ID
  • PAM
    • PAM - Logging
  • ProView
  • ProView Internal
  • Product Insight
  • Project Tracking
  • RDMS
  • Refinitiv Data Platform
    • Refinitiv Data Platform Libraries
  • Rose's Space
  • Screening
    • Qual-ID API
    • Screening Deployed
    • Screening Online
    • World-Check One
    • World-Check One Zero Footprint
  • Side by Side Integration API
  • TR Knowledge Graph
  • TREP APIs
    • CAT
    • DACS Station
    • Open DACS
    • RFA
    • UPA
  • TREP Infrastructure
  • TRKD
  • TRTH
  • Thomson One Smart
  • Transactions
    • REDI API
  • Velocity Analytics
  • Wealth Management Web Services
  • Workspace SDK
    • Element Framework
    • Grid
  • World-Check Data File
  • 中文论坛
  • Explore
  • Tags
  • Questions
  • Badges