Пример #1
0
 def get_end_balance(self, after: date) -> Decimal:
     """ Calculates account balance """
     # create a new date without hours
     #date_corrected = datetimeutils.end_of_day(after)
     datum = Datum()
     datum.from_date(after)
     datum.end_of_day()
     #log(DEBUG, "getting balance on %s", date_corrected)
     return self.get_balance_on(datum.value)
 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)
Пример #3
0
    def get_start_balance(self, before: date) -> Decimal:
        """ Calculates account balance """
        assert isinstance(before, datetime)

        # create a new date without hours
        datum = Datum()
        datum.from_date(before)
        #date_corrected = datetimeutils.start_of_day(before)
        # now subtract 1 second.
        #date_corrected -= timedelta(seconds=1)
        #log(DEBUG, "getting balance on %s", date_corrected)
        datum.yesterday()
        datum.end_of_day()
        return self.get_balance_on(datum.value)
Пример #4
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
Пример #5
0
    def get_transactions(self, date_from: datetime, date_to: datetime) -> List[Transaction]:
        """ Returns account transactions """
        assert isinstance(date_from, datetime)
        assert isinstance(date_to, datetime)

        # fix up the parameters as we need datetime
        dt_from = Datum()
        dt_from.from_datetime(date_from)
        dt_from.start_of_day()
        dt_to = Datum()
        dt_to.from_datetime(date_to)
        dt_to.end_of_day()

        query = (
            self.book.session.query(Transaction)
            .join(Split)
            .filter(Split.account_guid == self.account.guid)
            .filter(Transaction.post_date >= dt_from.date, Transaction.post_date <= dt_to.date)
            .order_by(Transaction.post_date)
        )
        return query.all()