Пример #1
0
def _create_financial_report_model(model_name):
    field_names = [to_pythonic_name(name) for name in get_numerical_column_names(model_name)]

    return type(
        model_name,
        (EventModel,),
        {name: pw.DoubleField(null=True) for name in field_names}
    )
Пример #2
0
def csv_rows_to_records(symbol, csv_rows):
    """ Returns a generator of database records that come from every row in <csv_rows>,
        with <symbol> added and the keys of each record being the pythonic version of column names.

        symbol: a string,
        csv_row: an iterator of csv rows (tuples), first row must be headers.
    """
    keys = [to_pythonic_name(verbose_name) for verbose_name in next(csv_rows)]  # headers to keys
    for row in csv_rows:
        record = dict(zip(keys, row))
        record["symbol_obj"] = symbol
        yield record
Пример #3
0
def load_fundamental_data(data_type, symbol, columns=None):
    """ Returns a DataFrame object containing <data_type> fundamental data of <symbol> with <columns>.

        data_type: name of *_updated_at fields in Symbol model without _updated_at
        symbol: e.g. 'C6L.SI'
        columns: a sequence of column names as defined in fa.database.*_numerical_columns modules.
            Default: None - include all.
    """
    if columns is None:
        model_name = data_type.replace("_", "")
        columns = get_numerical_column_names(model_name)

    columns = ["Date"] + list(columns)

    field_names = [to_pythonic_name(c) for c in columns]
    records = list(get_fundamentals(data_type, symbol, field_names))

    return pd.DataFrame.from_records(records, columns=columns, index="Date")
Пример #4
0
 def test_to_pythonic_name(self):
     name = fa_util.to_pythonic_name("Cash & ST Investments / Total Assets")
     self.assertEqual(name, "cash_st_investments_total_assets")