Ejemplo n.º 1
0
    def __calcular(self):
        #Setting self.investmentsoperations variable
        if self.chkPonderanAll.checkState()==Qt.Checked:#Results are in self.mem.localcurrency
            self.investmentsoperations=self.mem.data.investments_active().Investment_merging_current_operations_with_same_product(self.investment.product).op_actual
            self.investmentsoperations.myqtablewidget(self.mqtw)
        else:#Results in account currency
            self.investmentsoperations=InvestmentOperationCurrentHomogeneusManager(self.mem, self.investment)

            if self.chkGainsTime.checkState()==Qt.Checked:
                self.investmentsoperations=self.investment.op_actual.ObjectManager_copy_until_datetime(self.mem.localzone.now()-datetime.timedelta(days=365))
            else:
                self.investmentsoperations=self.investment.op_actual.ObjectManager_copy_until_datetime(self.mem.localzone.now())
            self.investmentsoperations.myqtablewidget(self.mqtw, self.investment.product.result.basic.last,  eMoneyCurrency.Account)
        sumacciones=self.investmentsoperations.shares()
        
        #Calculations
        if sumacciones==Decimal(0):
            self.puntoventa=Money(self.mem, 0, self.investment.account.currency)
        else:
            if self.radTPC.isChecked()==True:
                percentage=Percentage(self.spnGainsPercentage.value(), 100)
                self.puntoventa=self.investmentsoperations.selling_price_to_gain_percentage_of_invested(percentage, eMoneyCurrency.Account)
            elif self.radPrice.isChecked()==True:
                if self.txtPrice.isValid():#Si hay un number bien
                    self.puntoventa=Money(self.mem,  self.txtPrice.decimal(),  self.investment.product.currency)
                    self.cmd.setEnabled(True)
                else:
                    self.puntoventa=Money(self.mem, 0, self.investment.product.currency)
                    self.cmd.setEnabled(False)
            elif self.radGain.isChecked()==True:
                if self.txtGanancia.isValid():#Si hay un number bien
                    self.puntoventa=self.investmentsoperations.selling_price_to_gain_money(Money(self.mem, self.txtGanancia.decimal(), self.investment.product.currency))
                    self.cmd.setEnabled(True)
                else:
                    self.puntoventa=Money(self.mem, 0, self.investment.account.currency)
                    self.cmd.setEnabled(False)

        quote=Quote(self.mem).init__create(self.investment.product, self.mem.localzone.now(), self.puntoventa.amount)
        self.tab.setTabText(1, self.tr("Selling point: {0}".format(self.puntoventa)))
        self.tab.setTabText(0, self.tr("Current state: {0}".format(quote.money())))
        self.investmentsoperations.myqtablewidget(self.mqtwSP, quote, eMoneyCurrency.Account) 
        
        if self.chkPonderanAll.checkState()==Qt.Checked:
            self.cmd.setText(self.tr("Set selling price to all investments  of {0} to gain {1}").format(self.puntoventa, self.investmentsoperations.pendiente(quote, eMoneyCurrency.Account)))
        else:
            self.cmd.setText(self.tr("Set {0} shares selling price to {1} to gain {2}").format(sumacciones, self.puntoventa, self.investmentsoperations.pendiente(quote, eMoneyCurrency.Account)))
Ejemplo n.º 2
0
    def cmbPrices_reload(self):
        if self.cmbPrices.currentIndex() >= 0:
            index = self.cmbPrices.currentIndex()
        else:
            index = 10

        #quotes
        quote_current = self.investment.product.result.basic.last
        quote_simulation = Quote(self.mem).init__create(
            self.investment.product, datetime.now(),
            self.txtValorAccion.decimal())
        moneybefore_0 = self.investment.op_actual.average_price()
        quotebefore_0 = Quote(self.mem).init__create(self.investment.product,
                                                     datetime.now(),
                                                     moneybefore_0.amount)
        moneybefore_2_5 = self.investment.op_actual.average_price_after_a_gains_percentage(
            Percentage(2.5, 100))
        quotebefore_2_5 = Quote(self.mem).init__create(self.investment.product,
                                                       datetime.now(),
                                                       moneybefore_2_5.amount)
        moneybefore_5 = self.investment.op_actual.average_price_after_a_gains_percentage(
            Percentage(5, 100))
        quotebefore_5 = Quote(self.mem).init__create(self.investment.product,
                                                     datetime.now(),
                                                     moneybefore_5.amount)
        moneybefore_7_5 = self.investment.op_actual.average_price_after_a_gains_percentage(
            Percentage(7.5, 100))
        quotebefore_7_5 = Quote(self.mem).init__create(self.investment.product,
                                                       datetime.now(),
                                                       moneybefore_7_5.amount)
        moneybefore_10 = self.investment.op_actual.average_price_after_a_gains_percentage(
            Percentage(10, 100))
        quotebefore_10 = Quote(self.mem).init__create(self.investment.product,
                                                      datetime.now(),
                                                      moneybefore_10.amount)
        moneybefore_15 = self.investment.op_actual.average_price_after_a_gains_percentage(
            Percentage(15, 100))
        quotebefore_15 = Quote(self.mem).init__create(self.investment.product,
                                                      datetime.now(),
                                                      moneybefore_15.amount)

        moneyafter_0 = self.investment_simulated.op_actual.average_price()
        quoteafter_0 = Quote(self.mem).init__create(self.investment.product,
                                                    datetime.now(),
                                                    moneyafter_0.amount)
        moneyafter_2_5 = self.investment_simulated.op_actual.average_price_after_a_gains_percentage(
            Percentage(2.5, 100))
        quoteafter_2_5 = Quote(self.mem).init__create(self.investment.product,
                                                      datetime.now(),
                                                      moneyafter_2_5.amount)
        moneyafter_5 = self.investment_simulated.op_actual.average_price_after_a_gains_percentage(
            Percentage(5, 100))
        quoteafter_5 = Quote(self.mem).init__create(self.investment.product,
                                                    datetime.now(),
                                                    moneyafter_5.amount)
        moneyafter_7_5 = self.investment_simulated.op_actual.average_price_after_a_gains_percentage(
            Percentage(7.5, 100))
        quoteafter_7_5 = Quote(self.mem).init__create(self.investment.product,
                                                      datetime.now(),
                                                      moneyafter_7_5.amount)
        moneyafter_10 = self.investment_simulated.op_actual.average_price_after_a_gains_percentage(
            Percentage(10, 100))
        quoteafter_10 = Quote(self.mem).init__create(self.investment.product,
                                                     datetime.now(),
                                                     moneyafter_10.amount)
        moneyafter_15 = self.investment_simulated.op_actual.average_price_after_a_gains_percentage(
            Percentage(15, 100))
        quoteafter_15 = Quote(self.mem).init__create(self.investment.product,
                                                     datetime.now(),
                                                     moneyafter_15.amount)

        #Combobox update
        self.cmbPrices.blockSignals(True)
        self.cmbPrices.clear()
        self.cmbPrices.addItem(
            self.tr("Before simulation: current price ({})").format(
                quote_current.money()))
        self.cmbPrices.addItem(
            self.tr("Before simulation: simulation price ({})").format(
                quote_simulation.money()))
        self.cmbPrices.addItem(
            self.tr("Before simulation: selling price to gain 0 % ({})").
            format(moneybefore_0))
        self.cmbPrices.addItem(
            self.tr("Before simulation: selling price to gain 2.5 % ({})").
            format(moneybefore_2_5))
        self.cmbPrices.addItem(
            self.tr("Before simulation: selling price to gain 5.0 % ({})").
            format(moneybefore_5))
        self.cmbPrices.addItem(
            self.tr("Before simulation: selling price to gain 7.5 % ({})").
            format(moneybefore_7_5))
        self.cmbPrices.addItem(
            self.tr("Before simulation: selling price to gain 10.0 % ({})").
            format(moneybefore_10))
        self.cmbPrices.addItem(
            self.tr("Before simulation: selling price to gain 15.0 % ({})").
            format(moneybefore_15))
        self.cmbPrices.insertSeparator(8)
        self.cmbPrices.addItem(
            self.tr("After simulation: current price ({})").format(
                quote_current.money()))
        self.cmbPrices.addItem(
            self.tr("After simulation: simulation price ({})").format(
                quote_simulation.money()))
        self.cmbPrices.addItem(
            self.tr("After simulation: selling price to gain 0 % ({})").format(
                moneyafter_0))
        self.cmbPrices.addItem(
            self.tr("After simulation: selling price to gain 2.5 % ({})").
            format(moneyafter_2_5))
        self.cmbPrices.addItem(
            self.tr("After simulation: selling price to gain 5.0 % ({})").
            format(moneyafter_5))
        self.cmbPrices.addItem(
            self.tr("After simulation: selling price to gain 7.5 % ({})").
            format(moneyafter_7_5))
        self.cmbPrices.addItem(
            self.tr("After simulation: selling price to gain 10.0 % ({})").
            format(moneyafter_10))
        self.cmbPrices.addItem(
            self.tr("After simulation: selling price to gain 15.0 % ({})").
            format(moneyafter_15))
        self.cmbPrices.setCurrentIndex(index)
        self.cmbPrices.blockSignals(False)

        #Show tables
        if index == 0:  #Before current price
            self.investment.op.myqtablewidget(self.mqtwOps, quote_current)
            self.investment.op_actual.myqtablewidget(self.mqtwCurrentOps,
                                                     quote_current)
            self.investment.op_historica.myqtablewidget(self.mqtwHistoricalOps)
        elif index == 1:  # Before simulation simulation price
            self.investment.op.myqtablewidget(self.mqtwOps, quote_simulation)
            self.investment.op_actual.myqtablewidget(self.mqtwCurrentOps,
                                                     quote_simulation)
            self.investment.op_historica.myqtablewidget(self.mqtwHistoricalOps)
        elif index == 2:  # Before current price to gain 0
            self.investment.op.myqtablewidget(self.mqtwOps, quotebefore_0)
            self.investment.op_actual.myqtablewidget(self.mqtwCurrentOps,
                                                     quotebefore_0)
            self.investment.op_historica.myqtablewidget(self.mqtwHistoricalOps)
        elif index == 3:  # Before current price to gain 2.5%
            self.investment.op.myqtablewidget(self.mqtwOps, quotebefore_2_5)
            self.investment.op_actual.myqtablewidget(self.mqtwCurrentOps,
                                                     quotebefore_2_5)
            self.investment.op_historica.myqtablewidget(self.mqtwHistoricalOps)
        elif index == 4:  # Before current price to gain 5%
            self.investment.op.myqtablewidget(self.mqtwOps, quotebefore_5)
            self.investment.op_actual.myqtablewidget(self.mqtwCurrentOps,
                                                     quotebefore_5)
            self.investment.op_historica.myqtablewidget(self.mqtwHistoricalOps)
        elif index == 5:  # Before current price to gain 7.5%
            self.investment.op.myqtablewidget(self.mqtwOps, quotebefore_7_5)
            self.investment.op_actual.myqtablewidget(self.mqtwCurrentOps,
                                                     quotebefore_7_5)
            self.investment.op_historica.myqtablewidget(self.mqtwHistoricalOps)
        elif index == 6:  # Before current price to gain 10%
            self.investment.op.myqtablewidget(self.mqtwOps, quotebefore_10)
            self.investment.op_actual.myqtablewidget(self.mqtwCurrentOps,
                                                     quotebefore_10)
            self.investment.op_historica.myqtablewidget(self.mqtwHistoricalOps)
        elif index == 7:  # Before current price to gain 15%
            self.investment.op.myqtablewidget(self.mqtwOps, quotebefore_15)
            self.investment.op_actual.myqtablewidget(self.mqtwCurrentOps,
                                                     quotebefore_15)
            self.investment.op_historica.myqtablewidget(self.mqtwHistoricalOps)
        elif index == 9:  # After current price
            self.investment_simulated.op.myqtablewidget(
                self.mqtwOps, quote_current)
            self.investment_simulated.op_actual.myqtablewidget(
                self.mqtwCurrentOps, quote_current)
            self.investment_simulated.op_historica.myqtablewidget(
                self.mqtwHistoricalOps)
        elif index == 10:  # After simulation price
            self.investment_simulated.op.myqtablewidget(
                self.mqtwOps, quote_simulation)
            self.investment_simulated.op_actual.myqtablewidget(
                self.mqtwCurrentOps, quote_simulation)
            self.investment_simulated.op_historica.myqtablewidget(
                self.mqtwHistoricalOps)
        elif index == 11:  # After current price to gain 0
            self.investment_simulated.op.myqtablewidget(
                self.mqtwOps, quoteafter_0)
            self.investment_simulated.op_actual.myqtablewidget(
                self.mqtwCurrentOps, quoteafter_0)
            self.investment_simulated.op_historica.myqtablewidget(
                self.mqtwHistoricalOps)
        elif index == 12:  # After current price to gain 2.5%
            self.investment_simulated.op.myqtablewidget(
                self.mqtwOps, quoteafter_2_5)
            self.investment_simulated.op_actual.myqtablewidget(
                self.mqtwCurrentOps, quoteafter_2_5)
            self.investment_simulated.op_historica.myqtablewidget(
                self.mqtwHistoricalOps)
        elif index == 13:  # After current price to gain 5%
            self.investment_simulated.op.myqtablewidget(
                self.mqtwOps, quoteafter_5)
            self.investment_simulated.op_actual.myqtablewidget(
                self.mqtwCurrentOps, quoteafter_5)
            self.investment_simulated.op_historica.myqtablewidget(
                self.mqtwHistoricalOps)
        elif index == 14:  # After current price to gain 7.5%
            self.investment_simulated.op.myqtablewidget(
                self.mqtwOps, quoteafter_7_5)
            self.investment_simulated.op_actual.myqtablewidget(
                self.mqtwCurrentOps, quoteafter_7_5)
            self.investment_simulated.op_historica.myqtablewidget(
                self.mqtwHistoricalOps)
        elif index == 15:  # After current price to gain 10%
            self.investment_simulated.op.myqtablewidget(
                self.mqtwOps, quoteafter_10)
            self.investment_simulated.op_actual.myqtablewidget(
                self.mqtwCurrentOps, quoteafter_10)
            self.investment_simulated.op_historica.myqtablewidget(
                self.mqtwHistoricalOps)
        elif index == 16:  # After current price to gain 15%
            self.investment_simulated.op.myqtablewidget(
                self.mqtwOps, quoteafter_15)
            self.investment_simulated.op_actual.myqtablewidget(
                self.mqtwCurrentOps, quoteafter_15)
            self.investment_simulated.op_historica.myqtablewidget(
                self.mqtwHistoricalOps)