Esempio n. 1
0
    def __init__(self):
        self.zcrv = ql.ZCurve()
        self.bma = ql.RatioCurve(datadivisor=100.0)
        self.govt = GovtCurve()
        self.bcrv = self.govt.termstructure
        self.ussv = VolCurve(datadivisor=100.0)
        self.mmascale = Scale(call=("10Y", 100.0), datadivisor=100.0,
                          coupon="par")
        self.mmdscale = Scale(call=("10Y", 100.0), datadivisor=100.0,
                          coupon=.05)

        self.curvenames_ = ('zcrv', 'bma', 'govt', 'bcrv', 'ussv',
                            'mmascale', 'mmdscale')
Esempio n. 2
0
class marketcurves(object):
    def __init__(self):
        self.zcrv = ql.ZCurve()
        self.bma = ql.RatioCurve(datadivisor=100.0)
        self.govt = GovtCurve()
        self.bcrv = self.govt.termstructure
        self.ussv = VolCurve(datadivisor=100.0)
        self.mmascale = Scale(call=("10Y", 100.0), datadivisor=100.0,
                          coupon="par")
        self.mmdscale = Scale(call=("10Y", 100.0), datadivisor=100.0,
                          coupon=.05)

        self.curvenames_ = ('zcrv', 'bma', 'govt', 'bcrv', 'ussv',
                            'mmascale', 'mmdscale')

    @property
    def curves_(self):
        return dict(zip(self.curvenames_,
                        tuple([getattr(self, crv, None)
                               for crv in self.curvenames_])))
        
    def update(self, curvedate, _swapsettle, _marketdata):
        """
        Update from MarketFile structure.
        
        """
        
        print("updating")
        self.curvedate = curvedate
        self.swapsettle = _swapsettle
        
        self.zcrv.from_pfile(_swapsettle, _marketdata['pfile'])
        self.bma.update(self.zcrv, _marketdata['bmaswaps'])

        self.govt.update(_marketdata['ustotr'], curvedate)
        
        self.ussv.update(_marketdata['ussv'])
        self.mmascale.update(_marketdata['mma'], curvedate)

        self.tenorlevels_ = {'zcrv': self.zcrv.tenorpar,
                'bma': self.bma.parRatio,
                'bcrv': self.bcrv.tenorpar,
                'ussv': self.ussv,
                'mma': lambda tnr: marketdata['mma'].get(tnr, " ")/100.,
                'govt': lambda tnr: self.govt.tenor(tnr)['yield']
                }
        
    def updateMMD(self, tenors, curve):
        '''
        TODO:  need to be able to create bonds without curve
        '''
        if hasattr(self, "curvedate"):
            tenors = tuple(rowIfColumn(tenors))
            curve = tuple(rowIfColumn(curve))
            _marketdata = dict(zip(tenors, curve))
            
            self.mmdscale.update(_marketdata, self.curvedate)
        
    def tenorlevels(self, tenor):
        tnr = tenor.upper()
        return dict([(crv, self.tenorlevels_[crv](tenor))
                     for crv in self.tenorlevels_])
    
    def __getitem__(self, key):
        return getattr(self, key, None)
    
    def get(self, key, defvalue=None):
        return getattr(self, key, defvalue)

    def modelCurve(self, spreaddata):
        self.modelcurve = ModelScale(self.zcrv,
                                spreaddata,
                                self.mmascale.curvedate)
        self.model = self.modelcurve.termstructure
        
        # add to directory
        self.curvenames_ += ('model',)        
        self.tenorlevels_['model'] = self.model.tenorpar