Skip to content

Commit 9c5f6ba

Browse files
committed
0.1.2.1 Added simple return calculation
1 parent 5e80851 commit 9c5f6ba

File tree

3 files changed

+3028
-3002
lines changed

3 files changed

+3028
-3002
lines changed

correlationMatrix/utils/preprocessing.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ def construct_log_returns(in_filename, out_filename, drop_columns=None):
7272
"""
7373
Load a dataframe with level data from file
7474
Drop a list of columns that are not to be processed
75+
Construct log-returns
7576
Store to file
7677
7778
"""
@@ -89,6 +90,28 @@ def construct_log_returns(in_filename, out_filename, drop_columns=None):
8990
log_return_data.to_csv(out_filename, index=False)
9091

9192

93+
def construct_returns(in_filename, out_filename, drop_columns=None):
94+
"""
95+
Load a dataframe with level data from file
96+
Drop a list of columns that are not to be processed
97+
Construct simple returns
98+
Store to file
99+
100+
"""
101+
if drop_columns:
102+
level_data = pd.read_csv(in_filename).drop(columns=drop_columns)
103+
else:
104+
level_data = pd.read_csv(in_filename)
105+
106+
return_data = pd.DataFrame()
107+
108+
for column in level_data:
109+
return_data[column] = level_data[column] - level_data[column].shift(1)
110+
111+
return_data = return_data.dropna()
112+
return_data.to_csv(out_filename, index=False)
113+
114+
92115
def normalize_log_returns(in_filename, out_filename):
93116
"""
94117
Load a dataframe with log-return data from file

0 commit comments

Comments
 (0)