This repository was archived by the owner on Nov 11, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathutils.py
More file actions
55 lines (40 loc) · 1.3 KB
/
utils.py
File metadata and controls
55 lines (40 loc) · 1.3 KB
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
import pandas as pd
import ast
from configparser import ConfigParser
def read_data(instrument, predictions=False):
instrument_file = "data/stock_dfs/{}.csv".format(instrument)
next_month_returns_file = "data/returns/{}.csv".format(instrument)
returns = pd.read_csv(next_month_returns_file, index_col=0)
if predictions:
prediction = pd.read_csv("data/predictions/{}_predictions.csv".format(instrument))
return returns, prediction
else:
stocks = pd.read_csv(instrument_file, index_col=0)
stocks["monthID"] = pd.to_datetime(stocks.index.values).year * 100 + pd.to_datetime(stocks.index.values).month
return stocks, returns
def convert(x):
if "[" in x:
try:
return ast.literal_eval(x)
except ValueError:
pass
if "." in x:
try:
return float(x)
except ValueError:
pass
elif any(char.isdigit() for char in x):
try:
return int(x)
except ValueError:
return x
else:
return x
def read_config(option):
config = ConfigParser()
config.optionxform = str
config.read("configuration.ini")
config = dict(config.items(option))
for key in config.keys():
config[key] = convert(config[key])
return config