Ejemplo n.º 1
0
 def test_translate_currency_real(self, ticker):
     columns = ['equity','eps','revenue','netinccmn',
                 'cashneq','debt','ebit','ebitda']
     data_loader = SF1Data(config['sf1_data_path'])
     quarterly_df = data_loader.load_quarterly_data(ticker, 10)
     trans_df = SF1Data.translate_currency(quarterly_df, columns)
     for col in columns:
         diff = trans_df['{}usd'.format(col)] - trans_df[col]
         diff = np.abs(diff.values / trans_df['{}usd'.format(col)].values)
         diff = diff[~np.isnan(diff)]
         assert diff.max() < 0.1
Ejemplo n.º 2
0
    def test_translate_currency_synthetic(self, cnt):
        np.random.seed(0)
        currency_arr = np.array(range(1, cnt + 1))
        df = pd.DataFrame()
        df['debtusd'] = np.random.uniform(-1e5, 1e5, cnt) 
        df['debt'] = df['debtusd'] * currency_arr
        df['ebitusd'] = np.random.uniform(-10, 10, cnt)
        noise = np.random.uniform(-0.1, 0.1, cnt) 
        df['ebit'] = df['ebitusd'] * (currency_arr + noise)
        del_proba = np.random.uniform(0, 0.3)
        drop_mask = np.random.choice([True, False], cnt, 
                                     p=[del_proba, 1 - del_proba])
        df.loc[drop_mask, 'ebitusd'] = None

        trans_df = SF1Data.translate_currency(df, ['debt', 'ebit'])
        for col in ['debt', 'ebit']:
            diff = trans_df['{}usd'.format(col)] - trans_df[col]
            diff = np.abs(diff.values / trans_df['{}usd'.format(col)].values)
            diff = diff[~np.isnan(diff)]
            assert diff.max() < 0.1