예제 #1
0
 def startUpdates(self):
     """Starts live feed from Bloomberg.
     """
     # Analytics stream
     self.blptsAnalytics = blpapiwrapper.BLPTS()
     self.streamWatcherAnalytics = StreamWatcher(self,
                                                 BloombergQuery.ANALYTICS)
     self.blptsAnalytics.register(self.streamWatcherAnalytics)
     # Price only stream
     self.blptsPriceOnly = blpapiwrapper.BLPTS()
     self.streamWatcherPriceOnly = StreamWatcher(self,
                                                 BloombergQuery.PRICEONLY)
     self.blptsPriceOnly.register(self.streamWatcherPriceOnly)
     # Price change subscription
     self.streamWatcherBID = StreamWatcher(self, BloombergQuery.BID)
     self.bbgstreamBIDEM = blpapiwrapper.BLPStream(
         list((self.embondsisins + BBGHand + ' Corp').astype(str)), 'BID',
         0)
     self.bbgstreamBIDEM.register(self.streamWatcherBID)
     self.bbgstreamBIDEM.start()
     # Risk free bonds: no streaming as too many updates - poll every 15 minutes
     rfRequest = blpapiwrapper.BLPTS(
         list((self.rfbondsisins + '@CBBT' + ' Corp').astype(str)),
         self.bbgPriceRFQuery)
     self.RFtimer = RFdata(900, rfRequest, self)
     self.BDMdata = BDMdata(900, self)  #15 MINUTES
     self.BDMEODsave = BDMEODsave(self)
예제 #2
0
    def firstPass(self, priorityBondList=[]):
        """Loads initial data upon start up. After downloading data on first pass, function will check for bonds
        in SPECIALBONDS and will overwrite downloaded data with new set of data. 

        Keyword arguments:
        priortyBondList : priorty bonds to be updated (defaults to [] if not specified)
        """
        self.lastRefreshTime = datetime.datetime.now()
        if priorityBondList == []:
            emptyLines = list(self.df.index)
            isins = self.embondsisins + BBGHand + ' Corp'
        else:
            emptyLines = priorityBondList
            isins = self.df.loc[priorityBondList, 'ISIN'] + BBGHand + ' Corp'
        isins = list(isins.astype(str))
        blpts = blpapiwrapper.BLPTS(isins, self.bbgPriceLongQuery)
        blptsStream = StreamWatcher(self, BloombergQuery.FIRSTPASS)
        blpts.register(blptsStream)
        blpts.get()
        blpts.closeSession()

        isins = self.rfbondsisins + ' @CBBT Corp'
        isins = list(isins.astype(str))
        blpts = blpapiwrapper.BLPTS(isins, self.bbgPriceRFQuery)
        blptsStream = StreamWatcher(self, BloombergQuery.FIRSTPASS)
        blpts.register(blptsStream)
        blpts.get()
        blpts.closeSession()

        specialBondList = list(set(emptyLines) & set(self.SPECIALBONDS))
        if len(specialBondList) > 0:
            specialIsins = map(
                lambda x: self.df.at[x, 'ISIN'] + BBGHand + ' Corp',
                specialBondList)
            blpts = blpapiwrapper.BLPTS(specialIsins,
                                        self.bbgPriceLongSpecialQuery)
            specialbondStream = StreamWatcher(self, BloombergQuery.FIRSTPASS)
            blpts.register(specialbondStream)
            blpts.get()
            blpts.closeSession()

        for bond in emptyLines:
            self.updateStaticAnalytics(
                bond
            )  # This will update benchmarks and fill grid. Has to be done here so all data for benchmarks is ready.
예제 #3
0
파일: spreads.py 프로젝트: dxcv/repo_dp
"""

import pandas as pd
import numpy as np
from  matplotlib import pyplot
import blpapiwrapper as blpapi
import seaborn as sns

instruments_data = pd.read_excel('L:\\Rates & FX\\Quant Analysis\\pytest\\instruments.xlsx')
instruments = instruments_data['CUSIP'].dropna()
curvaPesos = pd.DataFrame(instruments_data['Gob CERO Pesos'])
curvaPesos.index = instruments_data['Plazo']
curvaUF = pd.DataFrame(instruments_data['Gob CERO UF'])
curvaUF.index = instruments_data['Plazo']

bbgData = blpapi.BLPTS(instruments,['MTY_YEARS','DUR_BID','BID_YIELD','TRADE_CRNCY','RTG_FITCH_NATIONAL_LT','NAME'])
bbgData.get()
table = bbgData.output
bbgData.closeSession()
table =pd.DataFrame(data = [table['NAME'],pd.to_numeric(table['MTY_YEARS']), pd.to_numeric(table['DUR_BID']), 
                            pd.to_numeric(table['BID_YIELD']), table['TRADE_CRNCY'], table['RTG_FITCH_NATIONAL_LT']]).transpose()
gov_yield = []
i = 0
for maturity in table['MTY_YEARS']:
    if table['TRADE_CRNCY'][i] == 'CLP':
        gov_yield.append(np.interp(maturity, curvaPesos.index, curvaPesos['Gob CERO Pesos']))
    elif table['TRADE_CRNCY'][i] == 'CLF':
        gov_yield.append(np.interp(maturity, curvaUF.index, curvaUF['Gob CERO UF']))
    i += 1

table['Govt Equivalent'] = gov_yield
예제 #4
0
    def __init__(self, parent, mainframe=None):
        """
        Keyword arguments:
        parent : parent frame (Wx.Frame object)
        mainframe : FlowTradingGUI > MainForm class instance (defaults to [] if not specified)
        """
        self.parent = parent
        self.mainframe = mainframe
        self.th = None if mainframe is None else mainframe.th

        self.dtToday = datetime.datetime.today().replace(hour=0,
                                                         minute=0,
                                                         second=0,
                                                         microsecond=0)
        _offsets = (3, 1, 1, 1, 1, 1, 2)
        self.dtYesterday = self.dtToday - datetime.timedelta(
            days=_offsets[self.dtToday.weekday()])
        self.dtLastWeek = self.dtToday - datetime.timedelta(days=7)
        dtTemp = self.dtToday - datetime.timedelta(days=29)
        self.dtLastMonth = dtTemp - datetime.timedelta(
            days=_offsets[dtTemp.weekday()])

        # Static columns either in bonduniverse or directly derived from it
        colsDescription = [
            'ISIN', 'BOND', 'SERIES', 'CRNCY', 'MATURITY', 'COUPON',
            'AMT_OUTSTANDING', 'SECURITY_NAME', 'INDUSTRY_GROUP',
            'CNTRY_OF_RISK', 'TICKER', 'MATURITYDT'
        ]
        # these columns will feed from Bloomberg (or Front) and be regenerated only once
        colsPriceHistory = [
            'P1DFRT', 'P1D', 'P1W', 'P1M', 'Y1D', 'Y1W', 'Y1M', 'SAVG',
            'ISP1D', 'ISP1W', 'ISP1M', 'PRINCIPAL_FACTOR'
        ]  #'INTSWAP1D','INTSWAP1W','INTSWAP1M',
        # these will feed from Bloomberg only once
        colsRating = ['SNP', 'MDY', 'FTC']
        colsAccrued = ['ACCRUED', 'D2CPN']
        # these columns will feed from Bloomberg (or Front) and be regenerated all the time
        colsPrice = [
            'BID', 'ASK', 'MID', 'BID_SIZE', 'ASK_SIZE', 'BGN_MID', 'OLDBID',
            'OLDASK'
        ]
        colsAnalytics = [
            'YLDB', 'YLDA', 'YLDM', 'ZB', 'ZA', 'ZM', 'RSI14', 'RISK_MID'
        ]  #,'INTSWAP'
        colsChanges = [
            'DP1FRT', 'DP1D', 'DP1W', 'DP1M', 'DY1D', 'DY1W', 'DY1M', 'DISP1D',
            'DISP1W', 'DISP1M'
        ]
        colsPosition = ['POSITION', 'REGS', '144A', 'MV', 'RISK']
        self.colsAll = colsDescription + colsPriceHistory + colsRating + colsAccrued + colsPrice + colsAnalytics + colsChanges + colsPosition  # +colsPricingHierarchy+colsUpdate

        self.df = pandas.DataFrame(columns=self.colsAll, index=bonds.index)
        # self.df.drop(bonduniverseexclusionsList,inplace=True)
        self.df['BOND'] = self.df.index
        self.df['ISIN'] = bonds['REGS']
        self.df['SERIES'] = 'REGS'
        self.gridList = []
        self.lock = threading.Lock()
        for c in list(set(colsDescription) & set(bonds.columns)):
            self.df[c] = bonds[c]
        self.df.rename(columns={'AMT_OUTSTANDING': 'SIZE'}, inplace=True)
        #self.df['SIZE'] = self.df['SIZE'].apply(lambda x: '{:,.0f}'.format(float(x) / 1000000) + 'm')
        self.df['MATURITYDT'] = self.df['MATURITY'].apply(getMaturityDate)
        self.df = self.df[self.df['MATURITYDT'] >= self.dtToday]
        self.df['MATURITY'] = self.df['MATURITYDT'].apply(
            lambda x: x.strftime('%d/%m/%y'))
        self.df['POSITION'] = 0
        pub.subscribe(self.updatePositions, "POSITION_UPDATE")
        self.bondList = []
        self.bbgPriceOnlyQuery = ['BID', 'ASK', 'BID_SIZE', 'ASK_SIZE']
        self.bbgPriceQuery = ['YLD_CNV_BID', 'Z_SPRD_BID', 'RSI_14D']
        self.bbgPriceSpecialQuery = [
            'YLD_CNV_BID', 'OAS_SPREAD_BID', 'RSI_14D'
        ]
        self.bbgPriceLongQuery = [
            'BID', 'ASK', 'YLD_CNV_BID', 'Z_SPRD_BID', 'RSI_14D', 'BID_SIZE',
            'ASK_SIZE'
        ]
        self.bbgPriceLongSpecialQuery = [
            'BID', 'ASK', 'YLD_CNV_BID', 'OAS_SPREAD_BID', 'RSI_14D',
            'BID_SIZE', 'ASK_SIZE'
        ]

        # self.bbgPriceQuery = ['YLD_CNV_BID', 'YLD_CNV_ASK', 'Z_SPRD_BID', 'Z_SPRD_ASK','RSI_14D']
        # self.bbgPriceSpecialQuery = ['YLD_CNV_BID', 'YLD_CNV_ASK', 'OAS_SPREAD_BID', 'OAS_SPREAD_ASK','RSI_14D']
        # self.bbgPriceLongQuery = ['BID', 'ASK', 'YLD_CNV_BID', 'YLD_CNV_ASK', 'Z_SPRD_BID', 'Z_SPRD_ASK','RSI_14D', 'BID_SIZE', 'ASK_SIZE']
        # self.bbgPriceLongSpecialQuery = ['BID', 'ASK', 'YLD_CNV_BID', 'YLD_CNV_ASK', 'OAS_SPREAD_BID', 'OAS_SPREAD_ASK','RSI_14D', 'BID_SIZE', 'ASK_SIZE']

        # self.bbgPriceSinkableQuery = ['BID', 'ASK', 'YLD_CNV_BID', 'YLD_CNV_ASK', 'RSI_14D', 'BID_SIZE', 'ASK_SIZE']
        self.riskFreeIssuers = ['T', 'DBR', 'UKT', 'OBL']
        self.bbgPriceRFQuery = ['BID', 'ASK', 'BID_YIELD', 'ASK_YIELD']
        self.bbgSinkRequest = blpapiwrapper.BLPTS()
        pass