示例#1
0
def __get_model_for_portfolio_value(input_model: PortfolioValueInputModel
        ) -> PortfolioValueViewModel:
    """ loads the data for portfolio value """
    result = PortfolioValueViewModel()
    result.filter = input_model

    ref_datum = Datum()
    ref_datum.from_datetime(input_model.as_of_date)
    ref_date = ref_datum.end_of_day()

    result.stock_rows = []
    with BookAggregate() as svc:
        book = svc.book
        stocks_svc = svc.securities

        if input_model.stock:
            symbols = input_model.stock.split(",")
            stocks = stocks_svc.get_stocks(symbols)
        else:
            stocks = stocks_svc.get_all()

        for stock in stocks:
            row: StockViewModel = portfoliovalue.get_stock_model_from(
                book, stock, as_of_date=ref_date)
            if row and row.balance > 0:
                result.stock_rows.append(row)

    return result
示例#2
0
def test_security_info_report():
    """ debug the report generation """
    book = BookAggregate()
    report = SecurityInfoReport(book)
    # IPE has some capital returns.
    result = report.run("IPE")

    assert result is not None
示例#3
0
def test_null_quantity_security():
    """ WBCPD has 0 quantity """
    book = BookAggregate()
    report = SecurityInfoReport(book)

    result = report.run("WBCPD")

    assert result is not None
示例#4
0
def main(args=None):
    from gnucash_portfolio import BookAggregate

    book = BookAggregate()
    # Return next 15 transactions.
    txs = book.scheduled.get_upcoming(15)
    # display
    for tx in txs:
        agg = book.scheduled.get_aggregate_for(tx)
        next_date = agg.get_next_occurrence()
        print(f"{next_date}, {tx.name}")
示例#5
0
def main():
    """ Main entry point. Useful for unit testing """
    # Get parameter from command line
    args = read_parameters()

    book = BookAggregate()
    accounts = book.accounts.find_by_name(args.search_term)
    accounts = sorted(accounts, key=lambda account: account.fullname)

    for account in accounts:
        print(f"{account.fullname} {account.description}, {account.guid}")
示例#6
0
def main():
    """ Main method, for unit testing """
    # Get parameter from command line
    args = read_parameters()

    book = BookAggregate()
    securities = book.securities.find(args.search_term)
    securities = sorted(
        securities,
        key=lambda security: security.namespace + ":" + security.mnemonic)

    for security in securities:
        print(f"{security.namespace}:{security.mnemonic} {security.fullname}")
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}")
def run(args):
    """ Call this method if running from another module which parses arguments """
    symbol = args.symbol
    symbol = symbol.upper()

    book = BookAggregate()

    agg = book.securities.get_aggregate_for_symbol(symbol)
    security = agg.security

    report = SecurityInfoReport(book)
    model = report.run(symbol)

    # Display
    if security is None:
        print(f"No securities found for {symbol}.")
        exit

    display(model)
示例#9
0
    def get_symbols_with_positive_balances(self) -> List[str]:
        """ Identifies all the securities with positive balances """
        from gnucash_portfolio import BookAggregate

        holdings = []

        with BookAggregate() as book:
            # query = book.securities.query.filter(Commodity.)
            holding_entities = book.securities.get_all()
            for item in holding_entities:
                # Check holding balance
                agg = book.securities.get_aggregate(item)
                balance = agg.get_num_shares()
                if balance > Decimal(0):
                    holdings.append(f"{item.namespace}:{item.mnemonic}")
                else:
                    self.logger.debug(f"0 balance for {item}")
            # holdings = map(lambda x: , holding_entities)

        return holdings
示例#10
0
"""
Show scheduled transactions
"""
from gnucash_portfolio import BookAggregate

book = BookAggregate()
txs = book.scheduled.get_upcoming(10)
for tx in txs:
    print(tx)