Beispiel #1
0
    def save_portfolio_nav(self, nav_date, shares=None, cashflows=0.0) -> bool:
        """
        method to insert new net asset values in the mongo
        :param nav_date: date the net asset value
        :param shares: new total amount of shares, if no cashflows, leave it to None
        :param cashflows: amount of cashflows
        :return: True
        """
        if shares is None:
            shares = mongo.find_document('net_asset_values',
                                         'net_asset_values',
                                         [("date", -1)])['shares']
        if nav_date is None:
            nav_date = self._portfolio_date

        assets = self._portfolio_market_value
        data = {
            "date": nav_date,
            "assets": assets,
            "cashflows": cashflows,
            "shares": shares
        }

        mongo.insert_documents('net_asset_values', 'net_asset_values', [data])
        return True
Beispiel #2
0
def update_indices_quotes(is_async: bool = True) -> True:
    filtered_indices = [(stock_index['isin'], stock_index['mic'], 'max')
                        for stock_index in euronext.all_indices
                        if stock_index['mic'] in ['XPAR', 'ALXP', 'XBRU']]
    all_quotes = euronext.get_quotes(filtered_indices, asynchronously=is_async)
    quotes = [quote for quotes in all_quotes
              for quote in quotes]  # List flatten
    mongo.insert_documents('quotes', 'equities', quotes)
    return True
Beispiel #3
0
 def add_transaction(transaction: List[dict]) -> bool:
     """
     insert transactions in mongo
     :param transaction: list of transactions in a json format
     :return: True
     """
     mongo.insert_documents(database_name='transactions',
                            collection_name='transactions',
                            documents=transaction)
     return True
Beispiel #4
0
def update_fundamentals():
    app_path = Path(__file__).parents[1]
    with open(rf"{app_path}\static\rics.json", "r") as f:
        ric_codes = json.load(f)

    data_to_insert = {'income': [], 'balance_sheet': [], 'cash_flow': []}

    for symbol in ric_codes.values():
        if symbol is None:
            continue

        logger.log.info(f'{symbol}: Getting financials')

        try:
            financials = reuters.get_financial_data(symbol)
        except HTTPError as http_error:
            logger.log.warning(f'{symbol}: {http_error}')
            continue

        try:
            financial_statements = financials['market_data'].get(
                'financial_statements')
            assert financial_statements is not None, 'could not find financials from reuters'
        except KeyError as key_error:
            logger.log.warning(f'{symbol}: {key_error}')
            continue
        except AssertionError as assertion_error:
            logger.log.warning(f'{symbol}: {assertion_error}')
            continue

        for statement, statement_data in financial_statements.items():
            for period, income_statements in statement_data.items():
                for report_elem, reports in income_statements.items():
                    assert isinstance(reports, list)
                    for report in reports:
                        data = {
                            'ric': financials['ric'],
                            'period': period,
                            'date': dt.datetime.fromisoformat(report['date']),
                            'report_elem': report_elem,
                            'value': float(report['value'])
                        }

                        data_to_insert[statement].append(data)
    for statement in data_to_insert:
        mongo.insert_documents(database_name='financials',
                               collection_name=statement,
                               documents=data_to_insert[statement])

    return True