Skip to content

Exchange Rate

ts_bolt.datasets.downloaders.ecb_exchange_rate¤

ECBExchangeRateDownloader ¤

Bases: BaseDownloader

Download the ECB Exchange Rate dataset and explore some basic features of the dataset.

Source code in ts_bolt/datasets/downloaders/ecb_exchange_rate.py
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
class ECBExchangeRateDownloader(BaseDownloader):
    """Download the ECB Exchange Rate dataset and explore some basic features of the dataset.

    - Dataset Website: https://www.ecb.europa.eu/stats/policy_and_exchange_rates/euro_reference_exchange_rates/html/index.en.html
    - Dataset Download Link: https://www.ecb.europa.eu/stats/eurofxref/eurofxref-hist.zip
    """

    def __init__(self) -> None:
        self.url = "https://www.ecb.europa.eu" "/stats/eurofxref/eurofxref-hist.zip"

    def __call__(self, target: Path) -> None:
        """Download the ECB Exchange Rate dataset and explore some basic features of the dataset.
        - Dataset Website: https://www.ecb.europa.eu/stats/policy_and_exchange_rates/euro_reference_exchange_rates/html/index.en.html
        - Dataset Download Link: https://www.ecb.europa.eu/stats/eurofxref/eurofxref-hist.zip
        """
        if target.exists():
            logger.warning(f"dataset exists in {target}, download skipped")
        else:
            df = pd.read_csv(
                self.url,
                compression="zip",
            )

            df["Date"] = pd.to_datetime(df["Date"]).dt.date

            # There are some empty columns.
            columns = [col for col in df.columns if not df[col].isna().all()]

            df = df[columns]

            df.to_csv(target, index=False)

__call__(target) ¤

Download the ECB Exchange Rate dataset and explore some basic features of the dataset. - Dataset Website: https://www.ecb.europa.eu/stats/policy_and_exchange_rates/euro_reference_exchange_rates/html/index.en.html - Dataset Download Link: https://www.ecb.europa.eu/stats/eurofxref/eurofxref-hist.zip

Source code in ts_bolt/datasets/downloaders/ecb_exchange_rate.py
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
def __call__(self, target: Path) -> None:
    """Download the ECB Exchange Rate dataset and explore some basic features of the dataset.
    - Dataset Website: https://www.ecb.europa.eu/stats/policy_and_exchange_rates/euro_reference_exchange_rates/html/index.en.html
    - Dataset Download Link: https://www.ecb.europa.eu/stats/eurofxref/eurofxref-hist.zip
    """
    if target.exists():
        logger.warning(f"dataset exists in {target}, download skipped")
    else:
        df = pd.read_csv(
            self.url,
            compression="zip",
        )

        df["Date"] = pd.to_datetime(df["Date"]).dt.date

        # There are some empty columns.
        columns = [col for col in df.columns if not df[col].isna().all()]

        df = df[columns]

        df.to_csv(target, index=False)