def amount(self, type=eMoneyCurrency.Product): money = Money( self.mem, self.shares * self.price * self.investment.product.real_leveraged_multiplier(), self.investment.product.currency) if type == eMoneyCurrency.Product: return money elif type == eMoneyCurrency.Account: dt = dtaware_day_end_from_date(self.date, self.mem.localzone_name) return money.convert(self.investment.account.currency, dt) elif type == eMoneyCurrency.User: dt = dtaware_day_end_from_date(self.date, self.mem.localzone_name) return money.convert(self.investment.account.currency, dt).convert(self.mem.localcurrency, dt)
def myqtablewidget(self, wdg): wdg.table.setColumnCount(6) wdg.table.setHorizontalHeaderItem(0, qcenter(self.tr("Year"))) wdg.table.setHorizontalHeaderItem(1, qcenter(self.tr("Estimation"))) wdg.table.setHorizontalHeaderItem(2, qcenter(self.tr("PER"))) wdg.table.setHorizontalHeaderItem(3, qcenter(self.tr("Estimation date"))) wdg.table.setHorizontalHeaderItem(4, qcenter(self.tr("Source"))) wdg.table.setHorizontalHeaderItem(5, qcenter(self.tr("Manual"))) self.sort() wdg.applySettings() wdg.table.clearContents() wdg.table.setRowCount(len(self.arr)) for i, e in enumerate(self.arr): wdg.table.setItem(i, 0, qcenter(str(e.year))) wdg.table.setItem( i, 1, self.product.money(e.estimation).qtablewidgetitem()) wdg.table.setItem( i, 2, qnumber( e.PER( Quote(self.mem).init__from_query( self.product, dtaware_day_end_from_date( date(e.year, 12, 31), self.product.stockmarket.zone.name))))) wdg.table.setItem(i, 3, qdate(e.date_estimation)) wdg.table.setItem(i, 4, qleft(e.source)) wdg.table.setCellWidget(i, 5, wdgBool(e.manual)) wdg.table.setCurrentCell(len(self.arr) - 1, 0) wdg.table.setFocus()
def balance(self, fecha=None, type=eMoneyCurrency.User): """Función que calcula el balance de una cuenta Solo asigna balance al atributo balance si la fecha es actual, es decir la actual Parámetros: - pg_cursor cur Cursor de base de datos - date fecha Fecha en la que calcular el balance Devuelve: - Decimal balance Valor del balance type=2, account currency type=3 localcurrency """ cur = self.mem.con.cursor() if fecha == None: fecha = date.today() cur.execute( 'select sum(amount) from accountsoperations where accounts_id=' + str(self.id) + " and datetime::date<='" + str(fecha) + "';") res = cur.fetchone()[0] cur.close() if res == None: return Money(self.mem, 0, self.resultsCurrency(type)) if type == eMoneyCurrency.Account: return Money(self.mem, res, self.currency) elif type == eMoneyCurrency.User: if fecha == None: dt = self.mem.localzone.now() else: dt = dtaware_day_end_from_date(fecha, self.mem.localzone_name) return Money(self.mem, res, self.currency).convert(self.mem.localcurrency, dt)
def datetime(self): """Devuelve un datetime usado para dibujar en gráficos, con el último día de la semana""" d = date(self.year,1,1) d = d - timedelta(d.weekday()) dlt = timedelta(days = (self.week-1)*7) lastday= d + dlt + timedelta(days=6) return dtaware_day_end_from_date(lastday, self.product.stockmarket.zone.name)
def adjustPrice(self, datetime, price): """ Returns a new price adjusting """ r = price for dps in self.arr: if datetime > dtaware_day_end_from_date(dps.date, self.mem.localzone_name): r = r + dps.gross return r
def on_cmdComparation_released(self): inicio = datetime.now() if self.selector1.selected is None or self.selector2.selected is None: qmessagebox(self.tr("You must select a product to compare with")) return self.comparation = ProductComparation(self.mem, self.selector1.selected, self.selector2.selected) if self.comparation.canBeMade() == False: qmessagebox(self.tr("Comparation can't be made.")) return self.deCompare.setMinimumDate(self.comparation.dates()[0]) self.deCompare.setMaximumDate( self.comparation.dates()[len(self.comparation.dates()) - 1 - 1] ) #Es menos 2, ya que hay alguna funcion de comparation que lo necesita self.comparation.setFromDate(self.deCompare.date()) self.__hide_or_show_views() if self.cmbCompareTypes.currentIndex() in (0, 7, 8): #Not changed data self.viewTwoAxis.clear() ls1 = self.viewTwoAxis.ts.appendTemporalSeries( self.comparation.product1.name.upper()) #Line seies ls2 = self.viewTwoAxis.ts.appendTemporalSeriesAxis2( self.comparation.product2.name.upper()) #Line seies dates = self.comparation.dates() closes1 = self.comparation.product1Closes() closes2 = self.comparation.product2Closes() for i, date_ in enumerate(dates): self.viewTwoAxis.ts.appendTemporalSeriesData( ls1, dtaware_day_end_from_date(date_, self.mem.localzone_name), closes1[i]) self.viewTwoAxis.ts.appendTemporalSeriesDataAxis2( ls2, dtaware_day_end_from_date(date_, self.mem.localzone_name), closes2[i]) self.viewTwoAxis.display() if self.cmbCompareTypes.currentIndex() == 1: #Scatter prices self.viewScatter.clear() self.viewScatter.scatter.setTitle("Scatter chart") self.viewScatter.scatter.appendScatterSeries( "Correlation", self.comparation.product1Closes(), self.comparation.product2Closes()) self.viewScatter.scatter.setXFormat("float", self.comparation.product1.name) self.viewScatter.scatter.setYFormat("float", self.comparation.product2.name) self.viewScatter.display() if self.cmbCompareTypes.currentIndex( ) == 2: #Scatter daily gains percentage self.viewScatter.clear() self.viewScatter.scatter.setTitle("Scatter chart") self.viewScatter.scatter.appendScatterSeries( "Correlation", self.comparation.product1PercentageEvolution(), self.comparation.product2PercentageEvolution()) self.viewScatter.scatter.setXFormat("float", self.comparation.product1.name) self.viewScatter.scatter.setYFormat("float", self.comparation.product2.name) self.viewScatter.display() if self.cmbCompareTypes.currentIndex( ) == 3: #Controlling percentage evolution. self.viewCompare.clear() ls1 = self.viewCompare.ts.appendTemporalSeries( self.comparation.product1.name.upper()) #Line seies ls2 = self.viewCompare.ts.appendTemporalSeries( self.comparation.product2.name.upper()) #Line seies dates = self.comparation.dates() closes1 = self.comparation.product1PercentageFromFirstProduct2Price( ) closes2 = self.comparation.product2Closes() for i, date_ in enumerate(dates): self.viewCompare.ts.appendTemporalSeriesData( ls1, dtaware_day_end_from_date(date_, self.mem.localzone_name), closes1[i]) self.viewCompare.ts.appendTemporalSeriesData( ls2, dtaware_day_end_from_date(date_, self.mem.localzone_name), closes2[i]) self.viewCompare.display() if self.cmbCompareTypes.currentIndex( ) == 4: #Controlling percentage evolution reducing leverage. self.viewCompare.clear() ls1 = self.viewCompare.ts.appendTemporalSeries( self.comparation.product1.name.upper()) #Line seies ls2 = self.viewCompare.ts.appendTemporalSeries( self.comparation.product2.name.upper()) #Line seies dates = self.comparation.dates() closes1 = self.comparation.product1PercentageFromFirstProduct2PriceLeveragedReduced( ) closes2 = self.comparation.product2Closes() for i, date_ in enumerate(dates): self.viewCompare.ts.appendTemporalSeriesData( ls1, dtaware_day_end_from_date(date_, self.mem.localzone_name), closes1[i]) self.viewCompare.ts.appendTemporalSeriesData( ls2, dtaware_day_end_from_date(date_, self.mem.localzone_name), closes2[i]) self.viewCompare.display() if self.cmbCompareTypes.currentIndex( ) == 5: #Controlling inverse percentage evolution. self.viewCompare.clear() ls1 = self.viewCompare.ts.appendTemporalSeries( self.comparation.product1.name.upper()) #Line seies ls2 = self.viewCompare.ts.appendTemporalSeries( self.comparation.product2.name.upper()) #Line seies dates = self.comparation.dates() closes1 = self.comparation.product1PercentageFromFirstProduct2InversePrice( ) closes2 = self.comparation.product2Closes() for i, date_ in enumerate(dates): self.viewCompare.ts.appendTemporalSeriesData( ls1, dtaware_day_end_from_date(date_, self.mem.localzone_name), closes1[i]) self.viewCompare.ts.appendTemporalSeriesData( ls2, dtaware_day_end_from_date(date_, self.mem.localzone_name), closes2[i]) self.viewCompare.display() if self.cmbCompareTypes.currentIndex( ) == 6: #Controlling inverse percentage evolution reducing leverage. self.viewCompare.clear() ls1 = self.viewCompare.ts.appendTemporalSeries( self.comparation.product1.name.upper()) #Line seies ls2 = self.viewCompare.ts.appendTemporalSeries( self.comparation.product2.name.upper()) #Line seies dates = self.comparation.dates() closes1 = self.comparation.product1PercentageFromFirstProduct2InversePriceLeveragedReduced( ) closes2 = self.comparation.product2Closes() for i, date_ in enumerate(dates): self.viewCompare.ts.appendTemporalSeriesData( ls1, dtaware_day_end_from_date(date_, self.mem.localzone_name), closes1[i]) self.viewCompare.ts.appendTemporalSeriesData( ls2, dtaware_day_end_from_date(date_, self.mem.localzone_name), closes2[i]) self.viewCompare.display() if self.cmbCompareTypes.currentIndex( ) == 7: # Spreading prices joining first scaling. self.viewCompare.clear() ls = self.viewCompare.ts.appendTemporalSeries( self.tr("Spread of {} - {}").format( self.comparation.product1.name, self.comparation.product2.name)) #Line seies dates = self.comparation.dates() closes1 = self.comparation.product1Closes() closes2 = self.comparation.product2Closes() multiplier = closes2[0] / closes1[0] for i, date_ in enumerate(dates): diff = closes2[i] - closes1[i] * multiplier self.viewCompare.ts.appendTemporalSeriesData( ls, dtaware_day_end_from_date(date_, self.mem.localzone_name), diff) self.viewCompare.display() if self.cmbCompareTypes.currentIndex() == 8: # Price ratio A/B self.viewCompare.clear() ls = self.viewCompare.ts.appendTemporalSeries( self.tr("Price Ratio of {} / {}").format( self.comparation.product1.name, self.comparation.product2.name)) #Line seies dates = self.comparation.dates() closes1 = self.comparation.product1Closes() closes2 = self.comparation.product2Closes() for i, date_ in enumerate(dates): ratio = closes1[i] / closes2[i] self.viewCompare.ts.appendTemporalSeriesData( ls, dtaware_day_end_from_date(date_, self.mem.localzone_name), ratio) self.viewCompare.display() self.mem.settings.setValue("wdgProductsComparation/product1", str(self.comparation.product1.id)) self.mem.settings.setValue("wdgProductsComparation/product2", str(self.comparation.product2.id)) self.mem.settings.setValue("wdgProductsComparation/cmbCompareTypes", str(self.cmbCompareTypes.currentIndex())) self.mem.settings.sync() self.lblCorrelation.setText(self.comparation.correlacion_lineal()) print("Comparation took {}".format(datetime.now() - inicio))
def datetime(self): """Devuelve un datetime usado para dibujar en gráficos""" return dtaware_day_end_from_date(self.date, self.product.stockmarket.zone.name)
def datetime(self): """Devuelve un datetime usado para dibujar en gráficos, pongo el día 28 para no calcular el último""" return dtaware_day_end_from_date(date(self.year, self.month, 28), self.product.stockmarket.zone.name)