Interest Rate Swap Calculator via API vs Workspace

bartolacci
bartolacci Newcomer

I am trying to replicate the function SWPR I can use directly on Workspace using the lseg-data python library. Unfortunately I have not been able to match the results and I ask you help in this sense.

At this time I am interested to the metrics resulting in the "RISK" tab highlighted, specifically DV01 and Modified Duration.

The parameters I used on SWPR are shown in the picture I have attached to this message.

Below the code snipped I am using to try and replicate, what am I missing?

Regards


import pandas as pd
import lseg.data as rdp
import lseg.data.content.ipa.financial_contracts as rdf

session = rdp.open_session(app_key='XXX')
session.open()

swap_definition = {
"instrumentType":"Swap",
"instrumentDefinition": {
"instrumentTag":"TestIRS",
"startDate":'2025-09-03',
"tradeDate":'2025-09-03',
"tenor":"5Y",
"legs":[
{
"legTag": "Fixed",
"interestType": "Fixed",
"notionalCcy": 'BRL',
"notionalAmount": 10000000,
"interestCalculationMethod": rdf.swap.DayCountBasis.DCB_WORKING_DAYS_252,
"interestcalculationconvention": rdf.swap.InterestCalculationConvention.MONEY_MARKET,
"direction":"Received",
"interestPaymentFrequency": rdf.swap.Frequency.ANNUAL,
},
{
"legTag": "Float",
"direction":"Paid",
"interestType":"Float",
"notionalCcy": 'BRL',
"notionalAmount": 10000000,
"interestPaymentFrequency": rdf.swap.Frequency.ANNUAL,
"indexTenor": "1D",
"interestCalculationMethod": rdf.swap.DayCountBasis.DCB_WORKING_DAYS_252,
"interestcalculationconvention": rdf.swap.InterestCalculationConvention.MONEY_MARKET,
"indexResetFrequency": rdf.swap.Frequency.EVERYDAY,
"indexName": 'CDI',
"indexResetType": rdf.swap.IndexResetType.IN_ADVANCE,
}]
},

  "pricingParameters": {
"valuationDate": '2025-09-03',
},

}

request_body = {

"fields" : ["InstrumentTag","LegTag",
"Direction",
"MarketValueInDealCcy",
"AccruedPercent",
"AccruedAmountInDealCcy",
'ModifiedDuration',
"ErrorCode","ErrorMessage"],

"universe" : [
swap_definition
],

"outputs" : ["Data","Headers"],

}

request_definition = rdp.delivery.endpoint_request.Definition(
url = "/data/quantitative-analytics/v1/financial-contracts",
method = rdp.delivery.endpoint_request.RequestMethod.POST,
body_parameters = request_body)
response = request_definition.get_data()

if response.is_success:
headers = [h['name'] for h in response.data.raw['headers']]
df = pd.DataFrame(data=response.data.raw['data'], columns=headers)

print(df)

Answers