我对Python相当陌生,并尝试围绕一些Quantlib交换对象编写包装器类。问题是我试图使用已传递给构造函数或在构造函数中计算的属性来调用Qualtlib Schedule对象。问题是当我这样运行代码时;
import swapleg as sl
Leg1 = sl.SwapLeg("Fix","AUD",ql.Date(26, 9, 2018),ql.Date(26, 9, 2028),ql.Monthly)
print(Leg1.EffectiveDate)
Leg1.showSchedule()
我收到以下错误
Traceback (most recent call last):
September 26th, 2018
.......
AttributeError: type object 'SwapLeg' has no attribute 'EffectiveDate'
列出了代码-实例化Leg1对象,并设置了EffectiveDate。我的问题是,当showSchedule调用Quantlib调用ql.Schedule时,即使我使用self.EffectiveDate查找它,它也失去了对EffectiveDate的可见性。显然我在这里缺少什么。任何帮助将不胜感激。
import QuantLib as ql
class SwapLeg:
def __init__(self,LegType,CCY,EffectiveDate=None,TerminationDate=None,Tenor=None,Rate=None,Spread=None):
self.LegType=LegType
self.CCY=CCY
self.Tenor=Tenor
if EffectiveDate is None:
self.EffectiveDate = ql.Settings.instance().evaluationDate
else:
self.EffectiveDate =EffectiveDate
......
def _LegSchedule(self):
ls = ql.Schedule( self.EffectiveDate,
self.TerminationDate,
self.Tenor,
self.Calendar,
self.businessDayConvention,
self.businessDayConvention,
self.GenRule,
self.EndOfMonth,
self.FirstDate,
self.NextToLastDate)
return ls
@classmethod
def showSchedule(self):
for i, d in enumerate(self._LegSchedule(self)):
print("{0} {1}".format(i+1,d))