예제 #1
0
def download(filename,
             load=True,
             n_tries=100,
             sleep_seconds=300,
             verbose=False,
             include_train=True,
             single_precision=False):
    """
    Download current Numerai dataset; overwrites if file exists.

    If `load` is True (default) then return data object; otherwise return
    None. It will include train data if `include_train` is True as well.

    Set `single_precision` to True in order to load data in float32 precision.

    If download fails then retry download `n_tries` times, pausing
    `sleep_seconds` between each try.

    Unlike nx.download() this function loads and returns the data object.
    """
    # line below expands e.g. ~/tmp to /home/me/tmp...
    filename = os.path.expanduser(filename)
    count = 0
    while count < n_tries:
        try:
            if verbose:
                print("Download dataset {}".format(filename))
            napi = NumerAPI()
            url = napi.get_dataset_url(tournament=8)
            download_file(url, filename)
            break
        except:  # noqa
            print('download failed')
            time.sleep(sleep_seconds)
        count += 1
    if load:
        data = nx.load_zip(filename,
                           verbose=verbose,
                           include_train=include_train,
                           single_precision=single_precision)
    else:
        data = None
    return data
예제 #2
0
    def download_validation_data(self, dest_path: str = ".",
                                 dest_filename: str = None) -> str:
        """download CSV file with historical targets and ticker universe

        Returns:
            str: path to csv file

        Example:
            >>> SignalsAPI().download_validation_data()
            signals_train_val_bbg.csv
        """
        # set up download path
        if dest_filename is None:
            dest_filename = "numerai_signals_historical.csv"

        path = os.path.join(dest_path, dest_filename)

        # create parent folder if necessary
        utils.ensure_directory_exists(dest_path)
        utils.download_file(
            self.HISTORICAL_DATA_URL, path, self.show_progress_bars)
        return path