src/currency.py
def _add_currency_to_df(cls, currency, df, start_date, end_date):
        """Add the currency to the exchange rates database.
        If the first value is NaN, then look for an earlier value to start.
        """
        df_ = df.copy()
        if currency == cls._base_currency:
            df_[currency] = 1
            return df_
        start_date_ = datetime.strptime(start_date, '%Y-%m-%d').date()
        attempt = 0
        while attempt < 10:
            try:
                data = (web.DataReader(currency + cls._base_currency + '=X',
                                       data_source='yahoo', start=start_date_,
                                       end=end_date)['Adj Close'])
                break
            except KeyError:
                start_date_ = start_date_ - pd.Timedelta(days=1)
                attempt += 1
        data = data[~data.index.duplicated(keep='first')]
        df_[currency] = data
        if pd.isna(df_.loc[start_date, currency]):
            df_.loc[start_date, currency] = (
                cls._get_first_value(currency, start_date))
        df_[currency].ffill(inplace=True)
        return df_
Add the currency to the exchange rates database.
        If the first value is NaN, then look for an earlier value to start.
        
Add the currency to the exchange rates database.
If the first value is NaN, then look for an earlier value to start.
Add the currency to the exchange rates database . If the first value is NaN then look for an earlier value to start .
def _add_currency_to_df(cls, currency, df, start_date, end_date):
        df_ = df.copy()
        if currency == cls._base_currency:
            df_[currency] = 1
            return df_
        start_date_ = datetime.strptime(start_date, '%Y-%m-%d').date()
        attempt = 0
        while attempt < 10:
            try:
                data = (web.DataReader(currency + cls._base_currency + '=X',
                                       data_source='yahoo', start=start_date_,
                                       end=end_date)['Adj Close'])
                break
            except KeyError:
                start_date_ = start_date_ - pd.Timedelta(days=1)
                attempt += 1
        data = data[~data.index.duplicated(keep='first')]
        df_[currency] = data
        if pd.isna(df_.loc[start_date, currency]):
            df_.loc[start_date, currency] = (
                cls._get_first_value(currency, start_date))
        df_[currency].ffill(inplace=True)
        return df_
def _add_currency_to_df ( cls , currency , df , start_date , end_date ) : df_ = df . copy ( ) if currency == cls . _base_currency : df_ [ currency ] = 1 return df_ start_date_ = datetime . strptime ( start_date , '%Y-%m-%d' ) . date ( ) attempt = 0 while attempt < 10 : try : data = ( web . DataReader ( currency + cls . _base_currency + '=X' , data_source = 'yahoo' , start = start_date_ , end = end_date ) [ 'Adj Close' ] ) break except KeyError : start_date_ = start_date_ - pd . Timedelta ( days = 1 ) attempt += 1 data = data [ ~ data . index . duplicated ( keep = 'first' ) ] df_ [ currency ] = data if pd . isna ( df_ . loc [ start_date , currency ] ) : df_ . loc [ start_date , currency ] = ( cls . _get_first_value ( currency , start_date ) ) df_ [ currency ] . ffill ( inplace = True ) return df_
Add the currency to the exchange rates database.
Add the currency to the exchange rates database .
"""Add the currency to the exchange rates database.
        If the first value is NaN, then look for an earlier value to start.
        """
cls
currency
df
start_date
end_date