Ejemplo n.º 1
0
    def update_tables(self):
        #Actualiza el indice de referencia porque ha cambiado
        self.investment.op_actual.get_valor_benchmark(self.mem.data.benchmark)

        self.on_chkOperaciones_stateChanged(self.chkOperaciones.checkState())
        self.chkOperaciones.setEnabled(True)

        self.investment.op_actual.myqtablewidget(
            self.mqtwInvestmentCurrent,
            self.investment.product.result.basic.last,
            type=1)
        self.investment.op_historica.myqtablewidget(
            self.mqtwInvestmentHistorical, type=1)
        if self.investment.product.currency == self.investment.account.currency:  #Multidivisa
            self.grpCurrentAccountCurrency.hide()
            self.grpHistoricalAccountCurrency.hide()
        else:
            m = Money(self.mem, 1, self.investment.account.currency)

            self.grpCurrentAccountCurrency.setTitle(
                self.tr("Current status in account currency ( {} = {} at {} )"
                        ).format(
                            m.string(6),
                            m.convert(self.investment.product.currency,
                                      self.mem.localzone.now()).string(6),
                            m.conversionDatetime(
                                self.investment.product.currency,
                                self.mem.localzone.now())))
            self.investment.op_actual.myqtablewidget(
                self.mqtwInvestmentCurrentAccountCurrency,
                self.investment.product.result.basic.last,
                type=2)
            self.investment.op_historica.myqtablewidget(
                self.mqtwInvestmentHistoricalAccountCurrency, type=2)

        self.lblAge.setText(
            self.tr("Current operations average age: {0}".format(
                days2string(self.investment.op_actual.average_age()))))

        if self.investment != None:  #We are adding a new investment
            self.on_chkHistoricalDividends_stateChanged(
                self.chkHistoricalDividends.checkState())
            self.chkHistoricalDividends.setEnabled(True)
Ejemplo n.º 2
0
    def generate(self):
        self.amounts = string2list_of_integers(self.txtAmounts.text(), ";")
        logging.debug(self.amounts)
        wdgProductHistoricalChart.generate(self)

        percentage = Percentage(self.spnGainsPercentage.value(), 100)
        selected_datetime = dtaware_day_start_from_date(
            self.dtFrom.date().toPyDate(), self.mem.localzone_name)

        inv = Investment(self.mem).init__create("Buy Chart", None, None,
                                                self.product, None, True,
                                                False - 1)
        inv.op = InvestmentOperationHomogeneusManager(self.mem, inv)
        p_last_operation = Percentage(
            self.txtLastOperationPercentage.decimal(), 100)

        m_purchase = Money(self.mem, self.txtBuyPrice.decimal(),
                           self.product.currency)
        #index=0 purchase, 1 = first reinvestment
        lastIO = None
        for index, amount in enumerate(self.amounts):
            lastIO = InvestmentOperation(
                self.mem, self.mem.tiposoperaciones.find_by_id(4),
                self.mem.localzone.now(), inv,
                int(self.amounts[index] / m_purchase.amount), 0, 0,
                m_purchase.amount, "", True, 1, -10000)
            inv.op.append(lastIO)
            (inv.op_actual, inv.op_historica
             ) = inv.op.get_current_and_historical_operations()
            new_purchase_price = self.wdgTS.ts.appendTemporalSeries(
                self.tr("Purchase price {}: {}").format(
                    index, m_purchase.string()))
            new_purchase_price.setColor(
                self.__qcolor_by_reinvestment_line(ReinvestmentLines.Buy))
            new_purchase_price.setPen(
                self.__qpen_by_amounts_index(index, ReinvestmentLines.Buy))
            self.wdgTS.ts.appendTemporalSeriesData(new_purchase_price,
                                                   selected_datetime,
                                                   m_purchase.amount)
            self.wdgTS.ts.appendTemporalSeriesData(new_purchase_price,
                                                   self.mem.localzone.now(),
                                                   m_purchase.amount)

            m_new_average_price = inv.op_actual.average_price()
            m_new_selling_price = inv.op_actual.average_price_after_a_gains_percentage(
                percentage)
            new_average_price = self.wdgTS.ts.appendTemporalSeries(
                self.tr("Average price {}: {}".format(index,
                                                      m_new_average_price)))
            new_average_price.setColor(
                self.__qcolor_by_reinvestment_line(ReinvestmentLines.Average))
            new_average_price.setPen(
                self.__qpen_by_amounts_index(index, ReinvestmentLines.Average))
            self.wdgTS.ts.appendTemporalSeriesData(new_average_price,
                                                   selected_datetime,
                                                   m_new_average_price.amount)
            self.wdgTS.ts.appendTemporalSeriesData(new_average_price,
                                                   self.mem.localzone.now(),
                                                   m_new_average_price.amount)

            new_selling_price = self.wdgTS.ts.appendTemporalSeries(
                self.tr("Sell price {} at {} to gain {}".format(
                    index, m_new_selling_price,
                    inv.op_actual.gains_from_percentage(percentage))))
            new_selling_price.setColor(
                self.__qcolor_by_reinvestment_line(ReinvestmentLines.Sell))
            new_selling_price.setPen(
                self.__qpen_by_amounts_index(index, ReinvestmentLines.Sell))
            self.wdgTS.ts.appendTemporalSeriesData(new_selling_price,
                                                   selected_datetime,
                                                   m_new_selling_price.amount)
            self.wdgTS.ts.appendTemporalSeriesData(new_selling_price,
                                                   self.mem.localzone.now(),
                                                   m_new_selling_price.amount)

            m_purchase = Money(self.mem,
                               lastIO.price * (1 - p_last_operation.value),
                               self.product.currency)