Beispiel #1
0
def main():
    import logging
    logging.basicConfig(level=logging.INFO)
    app = QtGui.QApplication(sys.argv)
    mainEngine = Singleton(MainEngine)
    mainEngine.refreshAll(datetime(2001, 7, 14).date(), datetime.now().date())
    sys.exit(app.exec_())
Beispiel #2
0
 def setAttr(self, OID, assetOID, buySell, acquisitionDate, 
                 quantity, price, rate, grossAmount, 
                 netAmount, commissionPercentage, commissionAmount, commissionVATAmount, 
                 tenor, custodyOID, maturityDate, externalID, 
                 comment, tax = None):
     from core.cache import Singleton, MainCache
     mainCache = Singleton(MainCache)
     self.OID = OID
     self.asset = mainCache.assetDictOID.get(assetOID,None)
     self.buySell = buySell
     self.acquisitionDate = acquisitionDate
     self.quantity = quantity
     self.price = price
     self.rate = rate
     self.grossAmount = grossAmount
     self.netAmount = netAmount
     self.commissionPercentage = commissionPercentage
     self.commissionAmount = commissionAmount
     self.commissionVATAmount = commissionVATAmount
     self.externalID = externalID
     self.custody = mainCache.custodyDictOID[custodyOID]
     self.comment = comment
     self.tenor = tenor
     self.maturityDate = maturityDate
     self.tax = tax
Beispiel #3
0
 def setReferenceData(self, fromDate, toDate):
     from core.cache import Singleton, MainCache
     mainCache = Singleton(MainCache)
     #build positions
     today = datetime.now().date()
     if today == toDate:
         setLastMarketData = True
     else:
         setLastMarketData = False    
     self.setPositionDict(fromDate, toDate, setLastMarketData)
     self.startWorkingDay = Function.getLastWorkingDay(fromDate)
     startUsdMxn = DaoCurrency.getCurrencyValueByDate("USD/MXN", self.startWorkingDay)
     if len(startUsdMxn) == 0:
             logging.warning("start USDMXN not found: " + str(self.startWorkingDay))
     if setLastMarketData:
         finalUsdMxn = mainCache.usdMXN
     else:
         self.finalWorkingDay = Function.getLastWorkingDay(toDate)
         currencyRS = DaoCurrency.getCurrencyValueByDate("USD/MXN", self.finalWorkingDay)
         if len(currencyRS) == 0:
             raise Exception("final USDMXN not found: " + str(self.finalWorkingDay))
         finalUsdMxn =  currencyRS[0][0]
     for position in (self.startPositionDict[Constant.CONST_POSITION_DICT]).itervalues():
         if position.asset.assetType != 'BOND':
             price = DaoPrice.getPriceByDate(position.getMainName(), self.startWorkingDay)
             if len(price) == 0:
                 raise Exception("price not found: " + position.getMainName() + " " + str(self.startWorkingDay))    
             position.setSpecificMarketData(price[0][0], startUsdMxn[0][0])
     if not setLastMarketData: 
         for position in (self.finalPositionDict[Constant.CONST_POSITION_DICT]).itervalues():
             if position.asset.assetType != 'BOND':
                 price = DaoPrice.getPriceByDate(position.getMainName(), self.finalWorkingDay)
                 if len(price) == 0:
                     raise Exception("price not found: " + position.getMainName() + " " + str(self.finalWorkingDay)) 
                 position.setSpecificMarketData(price[0][0], finalUsdMxn)
 def refreshAll(self, fromDate, toDate):
     progressBar = QtGui.QProgressDialog("Progress", "Stop", 0, 10)
     progressBar.setLabelText("BUILD POSITION")
     progressBar.setValue(1)
     progressBar.setWindowModality(QtCore.Qt.WindowModal)
     progressBar.setMinimumDuration(0)
     mainCache = Singleton(MainCache)
     mainCache.refreshReferenceData()
     self.mainWindow = MainWindow()
     self.mainWindow.clearTable()
     resultPositionDict = Engine.buildPositions(fromDate, toDate, True)
     mainCache.positionDict = resultPositionDict[
         Constant.CONST_POSITION_DICT]
     mainCache.oldPositionDict = resultPositionDict[
         Constant.CONST_OLD_POSITION_DICT]
     mainCache.setGlobalAttribute(
         resultPositionDict[Constant.CONST_POSITION_DICT])
     mainCache.corporateEventPositionDictAsset = resultPositionDict[
         Constant.CONST_CORPORATE_POSITION_DICT]
     progressBar.setLabelText("EQUITY")
     progressBar.setValue(3)
     self.mainWindow.renderPositions(mainCache.positionDict, 'EQUITY', 0)
     progressBar.setLabelText("EQUITY-SIC")
     progressBar.setValue(6)
     self.mainWindow.renderPositions(mainCache.positionDict, 'EQUITY', 1)
     progressBar.setLabelText("FUND")
     progressBar.setValue(7)
     self.mainWindow.renderPositions(mainCache.positionDict, 'FUND', 0)
     progressBar.setLabelText("BOND")
     progressBar.setValue(8)
     self.mainWindow.renderPositions(mainCache.positionDict, 'BOND', 0)
     progressBar.setValue(9)
     self.mainWindow.renderSubtotal(mainCache.positionDict, 'ALL', 0)
     progressBar.setLabelText("CORPORATE EVENT")
     progressBar.setValue(10)
     self.mainWindow.renderCorpEvent(
         mainCache.corporateEventPositionDictAsset)
     #======================================================================
     mainCache.summaryDict = Engine.buildSummaryByCustody(
         mainCache.positionDict, mainCache.oldPositionDict)
     self.mainWindow.renderSummary(mainCache.summaryDict)
     self.mainWindow.renderGeneralInfoPanel(mainCache.usdMXN)
Beispiel #5
0
 def setReferenceData(self, assetName, price, changePercentage):
     from core.cache import MainCache
     from core.cache import Singleton
     if (assetName == self.asset.name):
         self.setMarketPrice(price)
         self.changePercentage = str(changePercentage) + '%'
     elif (assetName == self.asset.originName):
         self.setMarketPriceOrig(Decimal(price))
         self.setMarketPrice(Decimal(price) * Singleton(MainCache).usdMXN
                             )  #Tal vez hay que quitar esta linea
         self.changePercentage = str(changePercentage) + '%'
Beispiel #6
0
 def __init__(self, assetRow):
     from core.cache import Singleton, MainCache
     mainCache = Singleton(MainCache)
     self.OID = assetRow[0]
     self.assetType = assetRow[1]
     self.name = assetRow[2]
     self.originName = assetRow[3]
     self.isSIC = assetRow[4]
     self.isOnlinePrice = assetRow[5]
     self.priceSource = assetRow[6]
     self.defaultCustody = mainCache.custodyDictOID[assetRow[7]]
Beispiel #7
0
 def getMarketPriceOrig(self):
     from pricingAPI.PricingInterface import PricingInterface
     from core.cache import MainCache
     from core.cache import Singleton
     if self.asset.isOnlinePrice and self.asset.isSIC:
         if (self.marketPriceOrig == 0):
             self.setMarketPriceOrig(
                 PricingInterface.getMarketPriceByAssetName(
                     self.asset.originName, self.asset.priceSource))
             self.marketPriceOrig = self.marketPriceOrig * Singleton(
                 MainCache).usdMXN
     return self.marketPriceOrig
 def setAttr(self, OID, custodyOID, corporateEventType, assetOID, paymentDate, grossAmount, netAmount, comment, externalID):
     from core.cache import Singleton, MainCache
     mainCache = Singleton(MainCache)
     self.OID = OID
     self.custody = mainCache.custodyDictOID[custodyOID]
     self.corporateEventType = corporateEventType
     self.asset = mainCache.assetDictOID.get(assetOID, None)
     self.paymentDate = paymentDate
     self.grossAmount = grossAmount
     self.netAmount = netAmount
     self.comment = comment
     self.externalID = externalID
Beispiel #9
0
 def getMarketPrice(self):
     from core.cache import MainCache
     from core.cache import Singleton
     from pricingAPI.PricingInterface import PricingInterface
     if self.asset.isOnlinePrice:
         if (self.marketPrice == 0):
             self.setMarketPrice(
                 PricingInterface.getMarketPriceByAssetName(
                     self.getAssetName(), self.asset.priceSource))
             if (self.marketPrice == 0 and self.asset.isSIC):
                 marketPriceOrigAux = PricingInterface.getMarketPriceByAssetName(
                     self.asset.originName, self.asset.priceSource)
                 self.setMarketPrice(marketPriceOrigAux *
                                     Singleton(MainCache).usdMXN)
     return self.marketPrice
 def setAttr(self,
             OID,
             amount,
             inOut,
             custodyOID,
             movementDate,
             comment,
             externalID,
             assetOID=None):
     from core.cache import Singleton, MainCache
     mainCache = Singleton(MainCache)
     self.OID = OID
     self.amount = amount
     self.inOut = inOut
     self.custody = mainCache.custodyDictOID[custodyOID]
     self.movementDate = movementDate
     self.comment = comment
     self.externalID = externalID
     self.asset = mainCache.assetDictOID.get(assetOID, None)
     self.tax = None
Beispiel #11
0
 def calculatePnl(self, custodyOID, fromDate, toDate):
     from core.cache import Singleton, MainCache
     from engine.engine import Engine
     mainCache = Singleton(MainCache)
     pnlVO = PnLVO() 
     custody = mainCache.custodyDictOID.get(custodyOID)
     if (custody is None):
         pnlVO.itemName = "Total"
     else:
         pnlVO.itemName = custody.name
         
     pnlVO.totalCashIn = self.getTotalCashIn(custodyOID)
     pnlVO.totalCashOut = self.getTotalCashOut(custodyOID)
     pnlVO.totalWeightedCashIn =  0 #self.getTotalWeightedCashIn(custodyOID, fromDate, toDate)
     pnlVO.totalWeightedCashOut = 0  #self.getTotalWeightedCashOut(custodyOID, fromDate, toDate)
     pnlVO.finalPosition = Engine.getSubTotalValuatedAmountByCustodyOID(self.finalPositionDict[Constant.CONST_POSITION_DICT], custodyOID)
     pnlVO.initialPosition = Engine.getSubTotalValuatedAmountByCustodyOID(self.startPositionDict[Constant.CONST_POSITION_DICT], custodyOID)
     pnlVO.pnlAmount =  pnlVO.finalPosition - pnlVO.initialPosition - (pnlVO.totalCashIn - pnlVO.totalCashOut)
     pnlVO.pnlWeightedAmount =  0 #pnlVO.finalPosition - pnlVO.initialPosition - (pnlVO.totalWeightedCashIn - pnlVO.totalWeightedCashOut)
     pnlVO.tir = (pnlVO.pnlAmount / (pnlVO.initialPosition + (pnlVO.totalCashIn - pnlVO.totalCashOut)))*100
     pnlVO.weightedTir = 0 #(pnlVO.pnlAmount / (pnlVO.initialPosition + (pnlVO.totalWeightedCashIn - pnlVO.totalWeightedCashOut)))*100
     return pnlVO
Beispiel #12
0
 def getAccPositionPercentage(positionDict, assetType, isSIC):
     from core.cache import Singleton, MainCache
     mainCache = Singleton(MainCache)
     accValuatedAmount = Engine.getSubTotalValuatedAmount(positionDict, assetType, isSIC)
     accPositionPercentage = (accValuatedAmount * 100) / mainCache.totalValuatedAmount
     return accPositionPercentage
Beispiel #13
0
 def getTotalValuatedAmount():
     from core.cache import Singleton, MainCache
     mainCache = Singleton(MainCache)
     return mainCache.totalValuatedAmount
Beispiel #14
0
 def getPositionPercentage(self):
     from core.cache import MainCache
     from core.cache import Singleton
     return (self.getValuatedAmount() *
             100) / Singleton(MainCache).totalValuatedAmount
Beispiel #15
0
import sys

from PySide.QtGui import QApplication, QTreeWidgetItem, QWidget, QTreeWidget

from engine.engine import Engine
from core.cache import Singleton, MainCache
mainCache = Singleton(MainCache)

if __name__ == '__main__':
    app = 0
    if QApplication.instance():
        app = QApplication.instance()
    else:
        app = QApplication(sys.argv)
    w = QWidget()
    w.resize(510, 210)
    tw = QTreeWidget(w)
    tw.resize(500, 200)
    tw.setColumnCount(3)
    tw.setHeaderLabels(["Asset", "Gross Amount", "Net Amount", "Payment Date"])
    mainCache = Singleton(MainCache)
    mainCache.refreshReferenceData()
    Engine.buildCorporateEventPosition()
    
    for key, cep in mainCache.corporateEventPositionDictAsset.items():
        l1 = QTreeWidgetItem([key, str(cep.accGrossAmount), str(cep.accNetAmount)])
        for ce in cep.corporateEventList:
            l1_child = QTreeWidgetItem([None, str(ce.grossAmount), str(ce.netAmount),str(ce.paymentDate)])
            l1.addChild(l1_child)
        tw.addTopLevelItem(l1)
 def doSubmit(self):
     from core.mainEngine import MainEngine
     mainEngine = Singleton(MainEngine)
     mainEngine.refreshAll((self.dateFromDate.date()).toPython(),
                           (self.dateToDate.date()).toPython())
 def __init__(self, corporateEventRow):
     from core.cache import Singleton, MainCache
     if(corporateEventRow is not None):
         mainCache = Singleton(MainCache)
         self.setAttr(corporateEventRow[0],corporateEventRow[1] , mainCache.corporateEventTypeOID[corporateEventRow[2]], corporateEventRow[3], corporateEventRow[4], corporateEventRow[5], corporateEventRow[6], corporateEventRow[7], corporateEventRow[8])