File size: 3,259 Bytes
9f82e6a
 
 
 
 
c71a614
9f82e6a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
from datasets import DatasetBuilder, DownloadManager, DatasetInfo
import datasets
import os
import pandas as pd

class TradingDataset(datasets.GeneratorBasedBuilder):
    # Replace 'your_dataset_name' with an actual name for your dataset
    BUILDER_CONFIGS = [
        datasets.BuilderConfig(name="all",      version=datasets.Version("1.0.0")), 
        datasets.BuilderConfig(name="stocks",   version=datasets.Version("1.0.0")),
        datasets.BuilderConfig(name="etfs",     version=datasets.Version("1.0.0"))
    ]

    def _info(self):
        return datasets.DatasetInfo(
            # This is the description that will appear on the datasets page.
            description="This is my custom dataset.",

            # datasets.features.FeatureConnectors
            features=datasets.Features({
                "File": datasets.Value("string"),
                "Date": datasets.Value("datetime"),
                "Open": datasets.Value("float64"),
                "High": datasets.Value("float64"),
                "Low": datasets.Value("float64"),
                "Close": datasets.Value("float64"),
                "Adj Close": datasets.Value("float64"),
                "Volume": datasets.Value("float64"),
            }),
            # If there's a common (input, target) tuple from the features,
            # specify them here. They'll get used if as_supervised=True in
            # builder.as_dataset.
            supervised_keys=None,
            # Homepage of the dataset for documentation
            homepage="https://huggingface.co/datasets/sebdg/trading_data/",
            citation="Your Citation Here",
        )

    def _split_generators(self, dl_manager: DownloadManager):
        """Returns SplitGenerators."""
        print('Split generators')
        # If your dataset is hosted online, use the DownloadManager to download and extract it
        # For local data, you can skip the DownloadManager and use the local paths directly
        
        # For example, if your dataset is online:
        # downloaded_files = dl_manager.download_and_extract("Your dataset URL")
        # For local files, directly point to the file paths
        urls_to_download = {"data_file": "path/to/your/local/file.csv"}
        downloaded_files = dl_manager.download_and_extract(urls_to_download)

        return [
            datasets.SplitGenerator(
                name=datasets.Split.TRAIN,
                # These kwargs will be passed to _generate_examples
                gen_kwargs={
                    "filepath": downloaded_files["data_file"],
                    "split": "train",
                },
            ),
        ]

    def _generate_examples(self, filepath, split):
        """Yields examples."""
        # Load the CSV file
        print('Yielding examples')
        data = pd.read_csv(filepath)
        for id, row in data.iterrows():
            yield id, {
                "File": row["File"],  # Adjust field names based on your CSV
                "Date": row["Date"],
                "Open": row["Open"],
                "High": row["High"],
                "Low": row["Low"],
                "Close": row["Close"],
                "Adj Close": row["Adj Close"],
                "Volume": row["Volume"],
            }