-1

Checked my loop several times. I cannot spot a mistake need another pair of eyes to help out. The code below is returning none while it should return a particular value.

I have checked the value of self.mdlname it is correct. I think there is something to do with with first function curr. It is not correctly reassigning value to self.currency. I see no other reason why it should return a none value.

Below ommitted functions after spartSABR function

import string

datatype = "Inflation SABR Vol ATM ZC"
dataconvention = "UK-RPI-ZERO-COUPON-SWAP-RATE"
mdlname = 'INFLATION_SABR'
t1 = 'should-send-back-none'


class srtqualifier:
    def __init__(self,mdlname,datatype, dataconvention,t1):
        self.mdlname = mdlname
        self.datatype = datatype
        self.dataconvention = dataconvention
        self.t1 = t1 ##TO BE REMOVED, ONLY USE FOR TESTING##
        self.tempholder =  self.dataconvention.split("-")
        self.currency = self.tempholder[0]

    def curr(self):
        if self.mdlname == 'INFLATION_SABR':
            inflationcurrency = {'UK':'GBP','FR':'EUR','EU':'EUR','US':'USD'}
            self.currency = inflationcurrency.get(self.currency)
            return self.currency

    def spartSABR(self):
        if self.dataconvention == 'JPY-SWAPTION-CLEAREDPHYSICAL-SEMI-ACT365F':
            return 'LIBOR_JPY_6M'
        elif self.dataconvention == 'USD-SIFMA Municipal Swap Index-1W-SWAPTION-PHYSICAL-SEMI-BOND':
            secondpartsp = self.tempholder[1].split(" ")
            secondpartsp.append(self.tempholder[2])
            separator = "_"
            secondpart = separator.join(secondpartsp[1:len(secondpartsp)])
            secondpart = secondpart.upper()
            return secondpart
        elif self.mdlname == 'INFLATION_SABR':
            secondpartsp = self.tempholder[0:2]
            secondpartsp = secondpartsp.append([self.currency,'1Y'])
            return secondpartsp
        else:
            secondpartsp = self.tempholder[1].split(" ")
            secondpartsp.append(self.tempholder[2])
            secondpartsp.insert(1,self.currency)
            separator = "_"
            secondpart = separator.join(secondpartsp)
            secondpart = secondpart.upper()
            return secondpart

test1 = srtqualifier(mdlname,datatype,dataconvention,t1)
print (test1.curr())
print (test1.spartSABR())
petezurich
  • 9,280
  • 9
  • 43
  • 57
Varun Yadav
  • 43
  • 2
  • 11

2 Answers2

0

secondpartsp = secondpartsp.append([self.currency,'1Y']) this appends [self.currency,'1Y'] onto secondpartsp.But the append method doesn't return anything(it returns None),it doesn't return the list as you might be thinking.So then what happens is the result (None) gets assigned to secondpartsp, and now secondpartsp is empty.

import string

datatype = "Inflation SABR Vol ATM ZC"
dataconvention = "UK-RPI-ZERO-COUPON-SWAP-RATE"
mdlname = 'INFLATION_SABR'
t1 = 'should-send-back-none'


class srtqualifier:
    def __init__(self,mdlname,datatype, dataconvention,t1):
        self.mdlname = mdlname
        self.datatype = datatype
        self.dataconvention = dataconvention
        self.t1 = t1 ##TO BE REMOVED, ONLY USE FOR TESTING##
        self.tempholder =  self.dataconvention.split("-")
        self.currency = self.tempholder[0]

    def curr(self):
        if self.mdlname == 'INFLATION_SABR':
            inflationcurrency = {'UK':'GBP','FR':'EUR','EU':'EUR','US':'USD'}
            self.currency = inflationcurrency.get(self.currency)
            return self.currency

    def spartSABR(self):
        if self.dataconvention == 'JPY-SWAPTION-CLEAREDPHYSICAL-SEMI-ACT365F':
            return 'LIBOR_JPY_6M'
        elif self.dataconvention == 'USD-SIFMA Municipal Swap Index-1W-SWAPTION-PHYSICAL-SEMI-BOND':
            secondpartsp = self.tempholder[1].split(" ")
            secondpartsp.append(self.tempholder[2])
            separator = "_"
            secondpart = separator.join(secondpartsp[1:len(secondpartsp)])
            secondpart = secondpart.upper()
            return secondpart
        elif self.mdlname == 'INFLATION_SABR':
            secondpartsp = self.tempholder[0:2]
            secondpartsp.append([self.currency,'1Y'])
            return secondpartsp
        else:
            secondpartsp = self.tempholder[1].split(" ")
            secondpartsp.append(self.tempholder[2])
            secondpartsp.insert(1,self.currency)
            separator = "_"
            secondpart = separator.join(secondpartsp)
            secondpart = secondpart.upper()
            return secondpart

test1 = srtqualifier(mdlname,datatype,dataconvention,t1)
print (test1.curr())
print (test1.spartSABR())
-1

Based on the logic provided by Ganga Siva Krishna. I figured out the problem. I didnt need to assign and append together. Solution is below:

def spartSABR(self):
        if self.dataconvention == 'JPY-SWAPTION-CLEAREDPHYSICAL-SEMI-ACT365F':
            return 'LIBOR_JPY_6M'
        elif self.dataconvention == 'USD-SIFMA Municipal Swap Index-1W-SWAPTION-PHYSICAL-SEMI-BOND':
            secondpartsp = self.tempholder[1].split(" ")
            secondpartsp.append(self.tempholder[2])
            separator = "_"
            secondpart = separator.join(secondpartsp[1:len(secondpartsp)])
            secondpart = secondpart.upper()
            return secondpart
        elif self.mdlname == 'INFLATION_SABR':
            secondpartsp = self.tempholder[0:2]
            print(self.tempholder[0:2])
            secondpartsp.append(self.currency)## I was doing secondpartsp= secondpartsp.append(self.currency)
            secondpartsp.append('1Y')
            separator = "_"
            secondpartsp = separator.join(secondpartsp)
            return secondpartsp
        else:
            secondpartsp = self.tempholder[1].split(" ")
            secondpartsp.append(self.tempholder[2])
            secondpartsp.insert(1,self.currency)
            separator = "_"
            secondpart = separator.join(secondpartsp)
            secondpart = secondpart.upper()
            return secondpart
Varun Yadav
  • 43
  • 2
  • 11