Ejemplo n.º 1
0
 def load_ingresos(self,  year,  month):
     self.viewIncomes.pie.clear()
     self.viewIncomes.pie.setTitle(self.tr("Concepts chart"))   
     
     (self.incomeslist, totalincomes,  totalaverageincomes)=self.incomes.percentage_monthly(year, month)
     self.mqtwIncomes.table.setColumnCount(4)
     self.mqtwIncomes.table.setHorizontalHeaderItem(0, qcenter(self.tr("Concept" )))
     self.mqtwIncomes.table.setHorizontalHeaderItem(1, qcenter(self.tr("Monthly expenses" )))
     self.mqtwIncomes.table.setHorizontalHeaderItem(2, qcenter(self.tr("% Monthly expenses" )))
     self.mqtwIncomes.table.setHorizontalHeaderItem(3, qcenter(self.tr("Monthly average" )))
     self.mqtwIncomes.applySettings()
     self.mqtwIncomes.table.clearContents()
     self.mqtwIncomes.table.setRowCount(len(self.incomeslist)+1)
     
     for i, a in enumerate(self.incomeslist):
         self.mqtwIncomes.table.setItem(i, 0, qleft(a[0].name))
         self.mqtwIncomes.table.setItem(i, 1, self.mem.localmoney(a[1]).qtablewidgetitem())
         self.mqtwIncomes.table.setItem(i, 2, Percentage(a[2], 100).qtablewidgetitem())#tpc
         self.mqtwIncomes.table.setItem(i, 3, self.mem.localmoney(a[3]).qtablewidgetitem())
         
         if a[1]!=0:
             if a[1]>a[3]:
                 self.mqtwIncomes.table.item(i, 1).setBackground( eQColor.Green)          
             else:
                 self.mqtwIncomes.table.item(i, 1).setBackground( eQColor.Red)      
             self.viewIncomes.pie.appendData(a[0].name.upper(), a[1])
     self.viewIncomes.display()
     self.mqtwIncomes.table.setItem(len(self.incomeslist), 0, qleft(self.tr('TOTAL')))
     self.mqtwIncomes.table.setItem(len(self.incomeslist), 1, self.mem.localmoney(totalincomes).qtablewidgetitem())
     self.mqtwIncomes.table.setItem(len(self.incomeslist), 2, Percentage(1, 1).qtablewidgetitem())
     self.mqtwIncomes.table.setItem(len(self.incomeslist), 3, self.mem.localmoney(totalaverageincomes).qtablewidgetitem())
Ejemplo n.º 2
0
        def row_mqtwTPV(quote, row):
            if quote == None:
                return
            self.tblTPC.setItem(
                row, 0, qdatetime(quote.datetime, self.mem.localzone_name))
            self.tblTPC.setItem(
                row, 1,
                self.product.money(quote.quote).qtablewidgetitem(
                    self.product.decimals))

            try:
                tpc = Percentage(
                    self.product.result.basic.last.quote - quote.quote,
                    quote.quote)
                days = (datetime.now(timezone(self.mem.localzone_name)) -
                        quote.datetime).days + 1
                self.tblTPC.setItem(row, 2, tpc.qtablewidgetitem())
                self.tblTPC.setItem(row, 3,
                                    (tpc * 365 / days).qtablewidgetitem())
                if self.investment:
                    self.grpHistoricos.setTitle(
                        self.
                        tr('Report of historic prices. You have {} shares valued at {}.'
                           ).format(self.investment.shares(),
                                    self.investment.balance()))
                    self.tblTPC.setItem(
                        row, 4,
                        self.product.money(
                            self.investment.shares() *
                            (self.product.result.basic.last.quote -
                             quote.quote)).qtablewidgetitem())
            except:
                self.tblTPC.setItem(row, 2, Percentage().qtablewidgetitem())
                self.tblTPC.setItem(row, 3, Percentage().qtablewidgetitem())
                self.tblTPC.setItem(row, 3, qcurrency(None))
Ejemplo n.º 3
0
 def percentage_tae_from_invested(self, emoneycurrency, current):
     try:
         dias = (date.today() -
                 self.investment.op_actual.first().datetime.date()).days + 1
         return Percentage(
             self.percentage_from_invested(emoneycurrency, current) * 365,
             dias)
     except:  #No first
         return Percentage()
Ejemplo n.º 4
0
 def percentage_by_year(self, year):
     """
         Calcula el porcentaje del mes partiendo del punto de cierre del mes anterior
     """
     ohcl=self.find(year)
     lastohcl=self.find(year-1)
     if lastohcl:
         return lastohcl.percentage(ohcl)
     if ohcl:
         return Percentage((ohcl.close-ohcl.open), ohcl.open)
     else:
         return Percentage()
Ejemplo n.º 5
0
    def myqtablewidget(self, wdg):
        arr=[]#date, product1, product2
        productcloses1=self.product1PercentageEvolution()
        productcloses2=self.product2PercentageEvolution()
        for i, dat in enumerate(self.__commonDates):
            if i==0:
                arr.append((dat, self.set1.arr[i].close, self.set2.arr[i].close, Percentage(None), Percentage(None)))
            else:
                arr.append((dat, self.set1.arr[i].close, self.set2.arr[i].close, Percentage(productcloses1[i-1], 100), Percentage(productcloses2[i-1], 100)))

            
        hh=[self.tr("Date"), self.product1.name, self.product2.name, self.tr("Gains 1"), self.tr("Gains 2")]
        
        wdg.setData(hh, None, arr)
Ejemplo n.º 6
0
 def percentage_by_year_month(self, year, month):
     """
         Calcula el porcentaje del mes partiendo del punto de cierre del mes anterior
     """
     dat=date(year, month, 1)
     last=dat-timedelta(days=1)
     ohcl=self.find(year, month)
     lastohcl=self.find(last.year, last.month)
     if lastohcl:
         return lastohcl.percentage(ohcl)
     else:
         return Percentage()
Ejemplo n.º 7
0
    def load_data(self):
        self.product.needStatus(2)
        percentage_down=Percentage(self.spnDown.value(), 100)
        percentage_gains=Percentage(self.spnGains.value(), 100)
        self.prm=ProductRangeManager(self.mem, self.product, percentage_down, percentage_gains)
        self.prm.setInvestRecomendation(self.cmbRecomendations.currentIndex())
        
        onlyaccount=-1 if self.chkOnlyAccount.isChecked() is False else self.cmbOnlyAccount.itemData(self.cmbOnlyAccount.currentIndex())
        self.prm.mqtw(self.mqtw, self.chkOnlyFirst.isChecked(), onlyaccount)

        self.mem.settingsdb.setValue("wdgProductRange/spnDown_product_{}".format(self.product.id), self.spnDown.value())
        self.mem.settingsdb.setValue("wdgProductRange/spnGains_product_{}".format(self.product.id), self.spnGains.value())
        self.mem.settingsdb.setValue("wdgProductRange/invest_product_{}".format(self.product.id), self.txtInvertir.text())
        self.mem.settingsdb.setValue("wdgProductRange/invest_recomendation_{}".format(self.product.id), self.cmbRecomendations.currentIndex())
        self.mem.settingsdb.setValue("wdgProductRange/product", self.product.id)
        self.mem.settings.sync()

        s=self.tr("Product current price: {} at {}").format(
            self.product.result.basic.last.money(),
            self.product.result.basic.last.datetime, 
        )
        s=s + "\n" + self.tr("Product price limits: {}").format(self.product.result.ohclYearly.string_limits())
        s=s + "\n" + self.tr("Total invested: {}. Current balance: {} ({})").format(
            self.investment_merged.invertido(),  
            self.investment_merged.balance(), 
            self.investment_merged.op_actual.tpc_total(self.product.result.basic.last), 
        )
        s=s + "\n" + self.tr("Average price: {}").format(
            self.investment_merged.op_actual.average_price()
        )
        s=s + "\n" + self.tr("Selling price to gain {}: {}. Gains at this selling price: {} ({})").format(
            percentage_gains, 
            self.investment_merged.op_actual.selling_price_to_gain_percentage_of_invested(percentage_gains, eMoneyCurrency.Product), 
            self.investment_merged.op_actual.gains_from_percentage(percentage_gains, eMoneyCurrency.Product), 
            percentage_between(self.product.result.basic.last.money(), self.investment_merged.op_actual.selling_price_to_gain_percentage_of_invested(percentage_gains, eMoneyCurrency.Product)), 
        )
        
        s=s + "\n\n"+ self.tr("Zero risk assets: {}".format(Assets(self.mem).patrimonio_riesgo_cero(date.today())))

        self.lblTotal.setText(s)
Ejemplo n.º 8
0
    def generate(self):
        wdgProductHistoricalChart.generate(self)

        if self.investment.op_actual.length() > 0:
            #Calcs
            percentage = Percentage(self.spnGainsPercentage.value(), 100)
            new_avg_1 = self.sim_opactual.average_price()
            new_sell_price_1 = self.sim_opactual.average_price_after_a_gains_percentage(
                percentage)
            new_purchase_price_1 = self.sim_opactual.last().money_price()
            gains_1 = self.sim_opactual.gains_from_percentage(percentage)

            #First reinvestment
            new_selling_price = self.wdgTS.ts.appendTemporalSeries(
                self.tr("Reinvestment selling price at {} to gain {}".format(
                    new_sell_price_1, gains_1)))
            new_selling_price.setColor(QColor(170, 85, 85))
            new_selling_price.setPen(
                self._pen(Qt.DashLine, QColor(170, 85, 85)))
            self.wdgTS.ts.appendTemporalSeriesData(
                new_selling_price,
                self.investment.op_actual.first().datetime,
                new_sell_price_1.amount)
            self.wdgTS.ts.appendTemporalSeriesData(new_selling_price,
                                                   self.mem.localzone.now(),
                                                   new_sell_price_1.amount)

            new_average_price = self.wdgTS.ts.appendTemporalSeries(
                self.tr("Reinvestment average price at {}").format(new_avg_1))
            new_average_price.setColor(QColor(85, 85, 170))
            new_average_price.setPen(
                self._pen(Qt.DashLine, QColor(85, 85, 170)))
            self.wdgTS.ts.appendTemporalSeriesData(
                new_average_price,
                self.investment.op_actual.first().datetime, new_avg_1.amount)
            self.wdgTS.ts.appendTemporalSeriesData(new_average_price,
                                                   self.mem.localzone.now(),
                                                   new_avg_1.amount)

            new_purchase_price = self.wdgTS.ts.appendTemporalSeries(
                self.tr("Reinvestment purchase at {}").format(
                    new_purchase_price_1))
            new_purchase_price.setColor(QColor(85, 170, 127))
            new_purchase_price.setPen(
                self._pen(Qt.DashLine, QColor(85, 170, 127)))
            self.wdgTS.ts.appendTemporalSeriesData(
                new_purchase_price,
                self.sim_opactual.first().datetime,
                new_purchase_price_1.amount)
            self.wdgTS.ts.appendTemporalSeriesData(new_purchase_price,
                                                   self.mem.localzone.now(),
                                                   new_purchase_price_1.amount)
Ejemplo n.º 9
0
 def on_chkHistoricalDividends_stateChanged(self, state):
     self.mqtwDividends.table.clearSelection()
     self.mqtwDividendsAccountCurrency.table.clearSelection()
     self.investment.dividends.selected = None
     (sumneto, sumbruto, sumretencion,
      sumcomision) = self.investment.dividends.myqtablewidget(
          self.mqtwDividends,
          eMoneyCurrency.Product,
          current=not c2b(state))
     if self.investment.account.currency == self.investment.product.currency:
         self.grpDividendsAccountCurrency.hide()
     else:
         self.investment.dividends.myqtablewidget(
             self.mqtwDividendsAccountCurrency, eMoneyCurrency.Product,
             not self.chkHistoricalDividends.isChecked())
     if state == Qt.Unchecked:
         estimacion = self.investment.product.estimations_dps.currentYear()
         if estimacion.estimation != None:
             shares = self.investment.shares()
             tpccalculado = Percentage(
                 estimacion.estimation,
                 self.investment.product.result.basic.last.quote)
             self.lblDivFechaRevision.setText(
                 self.tr('Estimation review date: {0}').format(
                     estimacion.date_estimation))
             self.lblDivAnualEstimado.setText(
                 self.tr("Estimated annual dividend is {0} ({1} per share)"
                         ).format(
                             tpccalculado,
                             self.investment.money(estimacion.estimation)))
             self.lblDivSaldoEstimado.setText(
                 self.tr("Estimated balance: {0} ({1} after taxes)").format(
                     self.investment.money(shares * estimacion.estimation),
                     self.investment.money(
                         shares * estimacion.estimation *
                         (1 - self.mem.dividendwithholding))))
         self.lblDivTPC.setText(
             self.tr("% Invested: {}").format(
                 self.investment.dividends.percentage_from_invested(
                     eMoneyCurrency.Product, current=True)))
         self.lblDivTAE.setText(
             self.tr("% APR from invested: {}").format(
                 self.investment.dividends.percentage_tae_from_invested(
                     eMoneyCurrency.Product, current=True)))
         self.grpDividendsEstimation.show()
         self.grpDividendsEfectivos.show()
     else:
         self.grpDividendsEstimation.hide()
         self.grpDividendsEfectivos.hide()
Ejemplo n.º 10
0
 def lblTotal_update(self):
     invested = self.investments.invested()
     pendiente = self.investments.pendiente()
     if invested.isZero():
         self.lblTotal.setText(self.tr("There aren't invested assets"))
     else:
         self.lblTotal.setText(
             self.
             tr("Invested assets: {0}. Current balance {7}\nPending: {1}{2} = {3} ({4} assets)\nDaily Diff: {5}. Investment average age: {6}"
                ).format(invested, self.investments.pendiente_positivo(),
                         self.investments.pendiente_negativo(), pendiente,
                         Percentage(pendiente, invested),
                         self.investments.gains_last_day(),
                         days2string(self.investments.average_age()),
                         self.investments.balance()))
Ejemplo n.º 11
0
    def setProduct(self, product, investment=None):
        self.product = product
        self.investment = investment
        self.mem = self.product.mem
        self.wdgTS.setSettings(self.mem.settings, "wdgProductHistoricalChart",
                               "wdgTS")
        from_ = datetime.datetime.today() - datetime.timedelta(days=365 * 3)
        if self.investment != None:
            if self.investment.op_actual.length() > 0:
                from_ = self.investment.op_actual.first(
                ).datetime - datetime.timedelta(days=30)
            elif self.investment.op.length() > 0:
                from_ = self.investment.op.first(
                ).datetime - datetime.timedelta(days=30)
        self.dtFrom.setDate(from_)
        self.dtFrom.blockSignals(False)

        if self.__class__.__name__ == "wdgProductHistoricalChart" and self.investment is not None and self.investment.selling_price is not None and self.investment.selling_price != 0:
            m_average_price = self.investment.op_actual.average_price(type=1)
            gains_percentage = Percentage(
                self.investment.money_selling_price().amount -
                m_average_price.amount, m_average_price.amount)
            self.spnGainsPercentage.blockSignals(True)
            self.spnGainsPercentage.setValue(gains_percentage.value_100())
            self.spnGainsPercentage.blockSignals(False)
        else:
            self.spnGainsPercentage.blockSignals(True)
            self.spnGainsPercentage.setValue(
                self.mem.settingsdb.value_float(
                    "frmSellingPoint/lastgainpercentage", "5"))
            self.spnGainsPercentage.blockSignals(False)

        self.cmbOHCLDuration.currentIndexChanged.disconnect()
        eOHCLDuration.qcombobox(self.cmbOHCLDuration, eOHCLDuration.Day)
        self.cmbOHCLDuration.currentIndexChanged.connect(
            self.on_cmbOHCLDuration_currentIndexChanged)
Ejemplo n.º 12
0
    def lblTotal_update(self):
        investments = self.investments.balance()
        accounts = self.mem.data.accounts_active().balance()
        total = Assets(self.mem).saldo_total(
            self.mem.data.investments_active(), self.mem.localzone.now())
        if self.chkInactivas.checkState() == Qt.Checked:
            self.lblTotal.setText(self.tr("There aren't invested assets"))
        else:
            self.lblTotal.setText(
                self.tr("""Accounts balance: {0}
Zero risk investments balance: {1}
Zero risk assests balance: {2} ( {3} from your total assets {4} )""").format(
                    accounts, investments, accounts + investments,
                    Percentage((accounts + investments).amount, total.amount),
                    total))
Ejemplo n.º 13
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.º 14
0
 def calculate(self):
     """Checks if compulsory fields are ok, if not changes style to red, else calculate mqtw and shares"""
     if self.txtAmount.isValid() and self.txtFinalPrice.isValid():
         finalprice = Money(self.mem, self.txtFinalPrice.decimal(),
                            self.product.currency).convert(
                                self.mem.localcurrency).amount
         if self.product.type.id in (eProductType.Share,
                                     eProductType.ETF):  #Shares
             self.txtShares.setText(
                 round(self.txtAmount.decimal() / finalprice, 0))
         else:
             self.txtShares.setText(
                 round(self.txtAmount.decimal() / finalprice, 6))
         porcentages = [2.5, 5, 7.5, 10, 15, 30]
         self.mqtw.table.setColumnCount(3)
         self.mqtw.table.setHorizontalHeaderItem(
             0, QTableWidgetItem(self.tr("% Gains")))
         self.mqtw.table.setHorizontalHeaderItem(
             1, QTableWidgetItem(self.tr("Price")))
         self.mqtw.table.setHorizontalHeaderItem(
             2, QTableWidgetItem(self.tr("Gains")))
         self.mqtw.table.clearContents()
         self.mqtw.applySettings()
         self.mqtw.table.setRowCount(len(porcentages))
         for i, tpc in enumerate(porcentages):
             self.mqtw.table.setItem(
                 i, 0,
                 Percentage(tpc, 100).qtablewidgetitem())
             tpcprice = self.txtFinalPrice.decimal() * Decimal(1 +
                                                               tpc / 100)
             self.mqtw.table.setItem(
                 i, 1,
                 self.product.money(tpcprice).qtablewidgetitem())
             self.mqtw.table.setItem(
                 i, 2,
                 self.product.money(
                     self.txtShares.decimal() *
                     (tpcprice -
                      self.txtFinalPrice.decimal())).qtablewidgetitem())
Ejemplo n.º 15
0
 def total_difference_percentage(self, totalmonth):
     return Percentage(self.total() - totalmonth.total(),
                       totalmonth.total())
Ejemplo n.º 16
0
 def percentage_from_current_price(self):
     """Calculates percentage from current price to order price"""
     return Percentage(
         self.price - self.investment.product.result.basic.last.quote,
         self.investment.product.result.basic.last.quote)
Ejemplo n.º 17
0
    def body(self):
        # About
        self.header(self.tr("About Xulpymoney"), 1)
        
        # Assets
        self.header(self.tr("Assets"), 1)
        self.simpleParagraph(self.tr("Total assets of the user are {}.").format(self.vTotal))
        if self.vTotalLastYear.isZero()==False:
            moreorless=self.tr("more")
            if (self.vTotal-self.vTotalLastYear).isLTZero():
                moreorless=self.tr("less")
            self.simpleParagraph(self.tr("It's a {} {} of the total assets at the end of the last year.").format(Percentage(self.vTotal-self.vTotalLastYear, self.vTotalLastYear), moreorless))
        
        # Assets by bank
        self.header(self.tr("Assets by bank"), 2)
        self.mem.frmMain.on_actionBanks_triggered()
        
        model=self.mem.frmMain.w.mqtwBanks.officegeneratorModel()
        model.removeColumns([1,])
        model.odt_table(self, 10,  8 )

        self.simpleParagraph(self.tr("Sum of all bank balances is {}").format(self.mem.frmMain.w.banks.balance()))
        self.pageBreak(True)

        # Assests current year
        self.header(self.tr("Assets current year evolution"), 2)
        
        #wdgTotal
        self.mem.frmMain.on_actionTotalReport_triggered()
        model=self.mem.frmMain.w.mqtw.officegeneratorModel("mqtwTotal")
        model.odt_table(self, 26, 6)
                
        ## Target
        target=AnnualTarget(self.mem).init__from_db(date.today().year)
        self.simpleParagraph(self.tr("The investment system has established a {} year target.").format(target.percentage)+" " +
                self.tr("With this target you will gain {} at the end of the year.").format(self.mem.localmoney(target.annual_balance())) +" " +
                self.tr("Up to date you have got  {} (gains + dividends) what represents a {} of the target.").format(self.mem.frmMain.w.tmm.dividends()+self.mem.frmMain.w.tmm.gains(), Percentage(self.mem.frmMain.w.tmm.gains()+self.mem.frmMain.w.tmm.dividends(), target.annual_balance())))
        self.pageBreak(True)
        
        ### Assets evolution graphic
        self.header(self.tr("Assets graphical evolution"), 2)
        
        self.mem.frmMain.w.load_graphic(animations=False)
        self.mem.frmMain.w.tab.setCurrentIndex(1)
        savefile="{}/wdgTotal.png".format(self.dir)
        self.mem.frmMain.w.wdgTS.ts.save(savefile)
        self.addImage(savefile, savefile)
        self.illustration([savefile, ], 25, 13, savefile)
        self.pageBreak()
        
        
        ### Current year investment gains by product type
        self.header(self.tr("Current year investment gains group by product type"), 2)
        self.mem.frmMain.w.on_actionGainsByProductType_triggered()
        model=self.mem.frmMain.w.tab.currentWidget().children()[1].officegeneratorModel("mqtwTotal")#Widget generated dinamically. mqtw is childre[1]
        model.odt_table(self, 18, 9)
        self.pageBreak()

        ## Accounts
        self.header(self.tr("Current Accounts"), 1)
        data=[]
        self.mem.data.accounts_active().order_by_name()
        for account in self.mem.data.accounts_active().arr:
            data.append((account.name, account.bank.name, account.balance()))
        self.table( [self.tr("Account"), self.tr("Bank"),  self.tr("Balance")], data, [6, 6, 3], 9)       
        
        self.simpleParagraph(self.tr("Sum of all account balances is {}").format(self.mem.data.accounts_active().balance()))

        
        self.pageBreak(True)
        
        ## Investments
        self.header(self.tr("Current investments"), 1)
        
        self.header(self.tr("Investments list"), 2)
        self.simpleParagraph(self.tr("Next list is sorted by the distance in percent to the selling point."))
        self.mem.frmMain.on_actionInvestments_triggered()
        
        model=self.mem.frmMain.w.mqtwInvestments.officegeneratorModel()
        model.removeColumns([1, 2, 3, 4])
        model.odt_table(self, 26,  8 )
        
        suminvertido=self.mem.data.investments_active().invested()
        sumpendiente=self.mem.data.investments_active().pendiente()
        if suminvertido.isZero()==False:
            self.simpleParagraph(self.tr("Sum of all invested assets is {}.").format(suminvertido))
            self.simpleParagraph(self.tr("Investment gains (positive minus negative results): {} - {} are {}, what represents a {} of total assets.").format(self.mem.data.investments_active().pendiente_positivo(), self.mem.data.investments_active().pendiente_negativo(), sumpendiente, Percentage(sumpendiente, suminvertido)))
            self.simpleParagraph(self.tr(" Assets average age: {}").format(  days2string(self.mem.data.investments_active().average_age())))
        else:
            self.simpleParagraph(self.tr("There aren't invested assets"))
        self.pageBreak(True)
        
        
        ### Current Investment Operations list
        self.header(self.tr("Current investment operations"), 2)
        self.mem.frmMain.on_actionInvestmentsOperations_triggered()
        model=self.mem.frmMain.w.mqtwCurrent.officegeneratorModel(self.tr("CurrentInvestmentOperations"))
        model.removeColumns([8, 9, 11])        
        model.odt_table(self, 26,  6)       
        self.pageBreak(True)
        
        ### Graphics wdgInvestments clases
        self.mem.frmMain.on_actionInvestmentsClasses_triggered()
        self.mem.frmMain.w.open_all_tabs()#Load tabs to finish animations
        self.mem.frmMain.w.viewTPC.on_actionShowData_triggered()
        self.mem.frmMain.w.viewTipo.on_actionShowData_triggered()
        self.mem.frmMain.w.viewApalancado.on_actionShowData_triggered()
        self.mem.frmMain.w.viewProduct.on_actionShowData_triggered()
        self.mem.frmMain.w.viewCountry.on_actionShowData_triggered()
        self.mem.frmMain.w.viewPCI.on_actionShowData_triggered()
        
        self.header(self.tr("Investments group by variable percentage"), 2)
        savefile="{}/wdgInvestmentsClasses_canvasTPC_legend.png".format(self.dir)
        self.mem.frmMain.w.tab.setCurrentIndex(0)
        self.sleep(2)
        self.mem.frmMain.w.viewTPC.pie.save(savefile)
        self.addImage(savefile, savefile)
        self.illustration([savefile, ], 25, 13, savefile)
        self.pageBreak(True)
        
        self.header(self.tr("Investments group by investment type"), 2)
        savefile="{}/wdgInvestmentsClasses_canvasTipo_legend.png".format(self.dir)
        self.mem.frmMain.w.tab.setCurrentIndex(2)
        self.sleep(2)
        self.mem.frmMain.w.viewTipo.pie.save(savefile)
        self.addImage(savefile, savefile)
        self.illustration([savefile, ], 25, 13, savefile)
        self.pageBreak(True)
        
        self.header(self.tr("Investments group by leverage"), 2)        
        savefile="{}/wdgInvestmentsClasses_canvasApalancado_legend.png".format(self.dir)
        self.mem.frmMain.w.tab.setCurrentIndex(3)
        self.sleep(2)
        self.mem.frmMain.w.viewApalancado.pie.save(savefile)
        self.addImage(savefile, savefile)
        self.illustration([savefile, ], 25, 13, savefile)
        self.pageBreak(True)
        
        self.header(self.tr("Investments group by investment product"), 2)
        savefile="{}/wdgInvestmentsClasses_canvasProduct_legend.png".format(self.dir)
        self.mem.frmMain.w.tab.setCurrentIndex(5)
        self.sleep(2)
        self.mem.frmMain.w.viewProduct.pie.save(savefile)
        self.addImage(savefile, savefile)
        self.illustration([savefile, ], 25, 13, savefile)
        self.pageBreak(True)
        
        self.header(self.tr("Investments group by country"), 2)
        savefile="{}/wdgInvestmentsClasses_canvasCountry_legend.png".format(self.dir)
        self.mem.frmMain.w.tab.setCurrentIndex(4)
        self.sleep(2)
        self.mem.frmMain.w.viewCountry.pie.save(savefile)
        self.addImage(savefile, savefile)
        self.illustration([savefile, ], 25, 13, savefile)
        self.pageBreak(True)
        
        self.header(self.tr("Investments group by Call/Put/Inline"), 2)
        savefile="{}/wdgInvestmentsClasses_canvasPCI_legend.png".format(self.dir)
        self.mem.frmMain.w.tab.setCurrentIndex(1)
        self.sleep(2)
        self.mem.frmMain.w.viewPCI.pie.save(savefile)
        self.addImage(savefile, savefile)
        self.illustration([savefile, ], 25, 13, savefile)
        
        self.mem.frmMain.showMaximized()
        self.pageBreak(True)
        
        #Orders report
        self.header(self.tr("Investments orders"), 1)
        self.mem.frmMain.on_actionOrders_triggered()        
        self.simpleParagraph(self.tr("These are the current investment orders that have been set in your banks"))
        model=self.mem.frmMain.w.mqtwOrders.officegeneratorModel("mqtwOrders")
        model.odt_table(self, 26, 8)
        self.pageBreak(True)
        
        #Dividend report
        self.header(self.tr("Dividend estimations report"), 1)
        self.mem.frmMain.on_actionDividendsReport_triggered()
        model=self.mem.frmMain.w.mqtw.officegeneratorModel("mqtwDividendsReport")
        model.odt_table(self, 26, 8)
        self.simpleParagraph(self.tr("If I keep this investment during a year, I'll get {0}").format(Assets(self.mem).dividends_estimated()))
        self.pageBreak(True)
        
        # Ranking de investments
        self.header(self.tr("Historical investments ranking"), 1)    
        self.mem.frmMain.on_actionInvestmentRanking_triggered()
        model=self.mem.frmMain.w.mqtwCurrentOperations.officegeneratorModel("mqtwCurrentOperations")
        model.vh=list(range(1, len(model.data)+1))
        model.odt_table(self, 26, 8)        
Ejemplo n.º 18
0
 def tpc_anual(self):
     if self.lastyear.quote == None or self.lastyear.quote == 0 or self.last.quote == None:
         return Percentage()
     else:
         return Percentage(self.last.quote - self.lastyear.quote,
                           self.lastyear.quote)
Ejemplo n.º 19
0
 def currentPriceMiddleVariation(self):
     return Percentage(self.middle - self.current, self.current)
Ejemplo n.º 20
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)
Ejemplo n.º 21
0
 def tpc_diario(self):
     if self.last.quote == None or self.penultimate.quote == None:
         return Percentage()
     else:
         return Percentage(self.last.quote - self.penultimate.quote,
                           self.penultimate.quote)
Ejemplo n.º 22
0
    def generate(self):
        selected_datetime = dtaware_day_start_from_date(
            self.dtFrom.date().toPyDate(), self.mem.localzone_name)
        self.setohcl = self.product.result.ohcl(
            self.cmbOHCLDuration.itemData(self.cmbOHCLDuration.currentIndex()),
            eHistoricalChartAdjusts.Splits)

        self.wdgTS.ts.clear()
        if self.cmbChartType.currentIndex() == 0:  #Lines
            ls = self.wdgTS.ts.appendTemporalSeries(
                self.product.name.upper())  #Line seies
            for ohcl in self.setohcl.arr:
                if ohcl.datetime() >= selected_datetime:
                    self.wdgTS.ts.appendTemporalSeriesData(
                        ls, ohcl.datetime(), ohcl.close
                    )  #Added day_start to show the purchase circle the first day
        elif self.cmbChartType.currentIndex() == 1:  #Candles
            candle = self.wdgTS.ts.appendCandlestickSeries(
                self.product.name)  #Candle series
            for ohcl in self.setohcl.arr:
                if ohcl.datetime() >= selected_datetime:
                    self.wdgTS.ts.appendCandlestickSeriesData(
                        candle, ohcl.datetime(), ohcl.open, ohcl.high,
                        ohcl.close, ohcl.low)

        dvm = self.setohcl.DatetimeValueManager("close")

        if self.chkSMA10.isChecked(
        ) and self.setohcl.length() > 10:  #SMA10 line series
            sma10 = self.wdgTS.ts.appendTemporalSeries(self.tr("SMA10"))
            sma10.setColor(QColor(255, 165, 165))
            for dv in dvm.sma(10).arr:
                if dv.datetime >= selected_datetime:
                    self.wdgTS.ts.appendTemporalSeriesData(
                        sma10, dv.datetime, dv.value)

        if self.chkSMA50.isChecked(
        ) and self.setohcl.length() > 50:  #SMA50 line series
            sma50 = self.wdgTS.ts.appendTemporalSeries(self.tr("SMA50"))
            sma50.setColor(QColor(255, 170, 255))
            for dv in dvm.sma(50).arr:
                if dv.datetime >= selected_datetime:
                    self.wdgTS.ts.appendTemporalSeriesData(
                        sma50, dv.datetime, dv.value)

        if self.chkSMA200.isChecked(
        ) and self.setohcl.length() > 200:  #SMA200 line series
            sma200 = self.wdgTS.ts.appendTemporalSeries(self.tr("SMA200"))
            sma200.setColor(QColor(165, 165, 165))
            for dv in dvm.sma(200).arr:
                if dv.datetime >= selected_datetime:
                    self.wdgTS.ts.appendTemporalSeriesData(
                        sma200, dv.datetime, dv.value)

        if self.chkMedian.isChecked():  #Median value
            median = self.setohcl.closes_median_value()
            med = self.wdgTS.ts.appendTemporalSeries(
                self.tr("Median at {}".format(self.product.money(median))))
            med.setColor(QColor(165, 165, 0))
            self.wdgTS.ts.appendTemporalSeriesData(med, selected_datetime,
                                                   median)
            self.wdgTS.ts.appendTemporalSeriesData(med,
                                                   self.mem.localzone.now(),
                                                   median)

        if not self.chkAdjustSplits.isChecked():  #
            ls = self.wdgTS.ts.appendTemporalSeries(
                self.product.name.upper() + " (No adjust)")  #Line seies
            for ohcl in self.product.result.ohcl(
                    self.cmbOHCLDuration.itemData(
                        self.cmbOHCLDuration.currentIndex()),
                    eHistoricalChartAdjusts.NoAdjusts).arr:
                if ohcl.datetime() >= selected_datetime:
                    self.wdgTS.ts.appendTemporalSeriesData(
                        ls, dt_day_start(ohcl.datetime()), ohcl.close)

        if self.chkAdjustDividends.isChecked():  #
            ls = self.wdgTS.ts.appendTemporalSeries(
                self.product.name.upper() +
                (" (Dividend adjust)"))  #Line seies
            for ohcl in self.product.result.ohcl(
                    self.cmbOHCLDuration.itemData(
                        self.cmbOHCLDuration.currentIndex()),
                    eHistoricalChartAdjusts.SplitsAndDividends).arr:
                if ohcl.datetime() >= selected_datetime:
                    self.wdgTS.ts.appendTemporalSeriesData(
                        ls, dt_day_start(ohcl.datetime()), ohcl.close)

        #INVESTMENT
        if self.investment is not None:
            #Buy sell operations
            buy = self.wdgTS.ts.appendScatterSeries(self.tr("Buy operations"))
            buy.setColor(QColor(85, 170, 127))
            sell = self.wdgTS.ts.appendScatterSeries(
                self.tr("Sell operations"))
            sell.setColor(QColor(170, 85, 85))
            for op in self.investment.op.arr:
                if (op.tipooperacion.id in
                    (eOperationType.SharesAdd, eOperationType.SharesPurchase,
                     eOperationType.TransferSharesDestiny) or
                    (op.tipooperacion.id == eOperationType.TransferFunds
                     and op.shares > 0)) and op.datetime >= selected_datetime:
                    self.wdgTS.ts.appendScatterSeriesData(
                        buy, op.datetime, op.price)
                if (op.tipooperacion.id
                        in (eOperationType.TransferSharesOrigin,
                            eOperationType.SharesSale) or
                    (op.tipooperacion.id == eOperationType.TransferFunds
                     and op.shares < 0)) and op.datetime >= selected_datetime:
                    self.wdgTS.ts.appendScatterSeriesData(
                        sell, op.datetime, op.price)

            #Average price
            if self.investment.op_actual.length() > 0:
                gains_percentage = Percentage(self.spnGainsPercentage.value(),
                                              100)
                m_average_price = self.investment.op_actual.average_price(
                    type=1)
                m_selling_price = self.investment.op_actual.average_price_after_a_gains_percentage(
                    gains_percentage)

                selling_price = self.wdgTS.ts.appendTemporalSeries(
                    self.tr("Selling price at {} to gain {}".format(
                        m_selling_price,
                        self.investment.op_actual.gains_from_percentage(
                            gains_percentage))))
                selling_price.setColor(QColor(170, 85, 85))
                self.wdgTS.ts.appendTemporalSeriesData(
                    selling_price,
                    self.investment.op_actual.first().datetime,
                    m_selling_price.amount)
                self.wdgTS.ts.appendTemporalSeriesData(
                    selling_price,
                    self.mem.localzone.now() + datetime.timedelta(days=1),
                    m_selling_price.amount)

                average_price = self.wdgTS.ts.appendTemporalSeries(
                    self.tr("Average price at {}".format(m_average_price)))
                average_price.setColor(QColor(85, 85, 170))
                self.wdgTS.ts.appendTemporalSeriesData(
                    average_price,
                    self.investment.op_actual.first().datetime,
                    m_average_price.amount)
                self.wdgTS.ts.appendTemporalSeriesData(
                    average_price,
                    self.mem.localzone.now() + datetime.timedelta(days=1),
                    m_average_price.amount)

        if hasattr(self, "_drawRangeLines") is True:  #Draws range linbes
            for range in self._drawRangeLines:
                range = round(range, self.product.decimals)
                m_range = self.product.money(range)
                tsrange = self.wdgTS.ts.appendTemporalSeries(
                    self.tr("Range at {}".format(m_range)))
                tsrange.setColor(QColor(95, 154, 12))
                self.wdgTS.ts.appendTemporalSeriesData(tsrange,
                                                       selected_datetime,
                                                       range)
                self.wdgTS.ts.appendTemporalSeriesData(
                    tsrange, self.mem.localzone.now(), range)
Ejemplo n.º 23
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)
Ejemplo n.º 24
0
 def currentPriceBottomVariation(self):
     """Calcs variation percentage from current price to bottom price"""
     return Percentage(self.bottom - self.current, self.current)
Ejemplo n.º 25
0
 def currentPriceTopVariation(self):
     return Percentage(self.top - self.current, self.current)
Ejemplo n.º 26
0
 def percentage_from_current_price(self):
     return Percentage(self.entry-self.product.result.basic.last.quote, self.product.result.basic.last.quote)
Ejemplo n.º 27
0
 def percentage_from_invested(self, emoneycurrency, current):
     return Percentage(self.gross(emoneycurrency, current),
                       self.investment.invertido(None, emoneycurrency))
Ejemplo n.º 28
0
 def variance_percentage(self):
     """Gives variance percentage, using the lowest quote to calculate it to see daily volatility only. It's always a positive number"""
     h = self.high().quote
     l = self.low().quote
     return Percentage(h - l, l)
Ejemplo n.º 29
0
 def percentage(self):
     """Hay que tener presente que lastyear (Objeto Quote) es el lastyear del año actual
     Necesita tener cargado en id el lastyear """
     return Percentage(self.estimation,
                       self.product.result.basic.last.quote)
Ejemplo n.º 30
0
 def mqtwInvestments_reload(self):
     self.investments.myqtablewidget_lastCurrent(
         self.mqtwInvestments, Percentage(self.spin.value(), 100))
     self.mqtwInvestments.setOrderBy(6, True)