def main(args):
    """ Main entry point. Useful for calling from cli script or unit tests """
    from pydatum import Datum
    from gnucash_portfolio.reports import portfolio_value
    from gnucash_portfolio.reports.portfolio_models import PortfolioValueInputModel
    

    parameters = PortfolioValueInputModel()
    today = Datum()
    today.today()
    parameters.as_of_date = today.value
    model = portfolio_value.run(parameters)

    # Display
    print_row("security", "cost", "balance", "gain/loss", "%", "income", "inc.12m", "%")
    print("-" * 120)

    rows = sorted(model.stock_rows, key=lambda row: f"{row.exchange}:{row.symbol}")

    for row in rows:
        col1 = f"{row.exchange}:{row.symbol}"
        col2 = f"{row.shares_num:,} @ {row.avg_price:,.2f} {row.currency} = {row.cost:>7,.2f}"
        col3 = f"@ {row.price:,.2f} = {row.balance:>9,.2f}"
        col4 = f"{row.gain_loss:,.2f}"
        col5 = f"{row.gain_loss_perc:,.2f}%"
        col6 = f"{row.income:,.2f}"
        col7 = f"{row.income_last_12m:,.2f}"
        col8 = f"{row.income_last_12m_perc:,.2f}"

        print_row(col1, col2, col3, col4, col5, col6, col7, col8)
Ejemplo n.º 2
0
    def get_todays_file_path(self):
        """ path to today's cached file """
        datum = Datum()
        datum.today()
        today = datum.get_iso_date_string()

        return self.__get_rate_file_path(today)
Ejemplo n.º 3
0
    def __init__(self):
        from pydatum import Datum

        today = Datum()
        today.today()

        self.as_of_date: datetime = today.value
        # Only the stock symbols, without exchange, comma-separated.
        self.stock: str = ""
 def get_quantity(self) -> Decimal:
     """
     Returns the number of shares for the given security.
     It gets the number from all the accounts in the book.
     """
     from pydatum import Datum
     # Use today's date but reset hour and lower.
     today = Datum()
     today.today()
     today.end_of_day()
     return self.get_num_shares_on(today.value)
Ejemplo n.º 5
0
def test_add_days():
    datum = Datum()
    datum.today()
    datum.start_of_day()

    today = datetime.today()
    #day = today.day + 1
    tomorrow = today + relativedelta(days=1)
    tomorrow = tomorrow.replace(hour=0, minute=0, second=0, microsecond=0)
    
    actual = datum.add_days(1)
    
    assert actual == tomorrow
def main(args=None):
    """ Show the list of favorite accounts """
    print("Favourite accounts:\n")
    book = BookAggregate()
    favourites = book.accounts.get_favourite_account_aggregates()
    favourites = sorted(favourites,
                        key=lambda aggregate: aggregate.account.name)

    for aggregate in favourites:
        #balance = aggregate.get_balance()
        today = Datum()
        today.today()

        balance = aggregate.get_balance_on(today.value)
        currency = aggregate.account.commodity.mnemonic

        print(f"{aggregate.account.name:<25}{balance:>10,.2f} {currency}")
Ejemplo n.º 7
0
 def get_balance(self):
     """ Current account balance """
     on_date = Datum()
     on_date.today()
     return self.get_balance_on(on_date.value)