|
1 | 1 | import os |
2 | | -import pandas as pd # type: ignore |
| 2 | +import pandas as pd # type: ignore |
3 | 3 | from collections import defaultdict |
4 | 4 | import pickle |
5 | 5 | import json |
| 6 | +from typing import DefaultDict, Dict, Any, BinaryIO |
6 | 7 |
|
7 | 8 | # Directory containing the daily CSV files |
8 | 9 | data_dir = "./aggregates_day/" |
|
34 | 35 | print("Building lookup table...") |
35 | 36 |
|
36 | 37 | # Now, build the lookup table with rolling averages and percentage price change |
37 | | -lookup_table = defaultdict(dict) # Nested dict: ticker -> date -> stats |
| 38 | +lookup_table: DefaultDict[str, Dict[str, Any]] = defaultdict( |
| 39 | + dict |
| 40 | +) # Nested dict: ticker -> date -> stats |
38 | 41 |
|
39 | 42 | for ticker, records in trades_data.items(): |
40 | 43 | # Convert records to DataFrame |
|
79 | 82 | print("Lookup table built successfully.") |
80 | 83 |
|
81 | 84 | # Convert defaultdict to regular dict for JSON serialization |
82 | | -lookup_table = {k: v for k, v in lookup_table.items()} |
| 85 | +lookup_table_dict = {k: v for k, v in lookup_table.items()} |
83 | 86 |
|
84 | 87 | # Save the lookup table to a JSON file |
85 | 88 | with open("lookup_table.json", "w") as f: |
86 | | - json.dump(lookup_table, f, indent=4) |
| 89 | + json.dump(lookup_table_dict, f, indent=4) |
87 | 90 |
|
88 | 91 | print("Lookup table saved to 'lookup_table.json'.") |
89 | 92 |
|
90 | 93 | # Save the lookup table to a file for later use |
91 | | -with open("lookup_table.pkl", "wb") as f: |
92 | | - pickle.dump(lookup_table, f) |
| 94 | +with open("lookup_table.pkl", "wb") as f: # type: BinaryIO |
| 95 | + pickle.dump(lookup_table_dict, f) |
93 | 96 |
|
94 | 97 | print("Lookup table saved to 'lookup_table.pkl'.") |
0 commit comments