forked from jjakimoto/finance_ml
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
232 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
from .importance import feat_importance | ||
from .importance import feat_importance, feat_imp_MDA, feat_imp_MDI, feat_imp_SFI | ||
from .orth import get_e_vec, orth_feats |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,46 @@ | ||
def get_train_times(t1, test_times): | ||
trn = t1.copy(deep=True) | ||
for i, j in test_times.iteritems(): | ||
df0 = trn[(i <= trn.index) & (trn.index <= j)].index | ||
df1 = trn[(i <= trn) & (trn <= j)].index | ||
df2 = trn[(trn.index <= i) & (j <= trn)].index | ||
trn = trn.drop(df0.union(df1.union(df2))) | ||
import pandas as pd | ||
|
||
|
||
def get_train_times(train_times, test_times): | ||
"""Sample train points without overlapping with test period | ||
Params | ||
------ | ||
train_times: pd.Series | ||
Trainig points with index for initial and values for end time | ||
test_times: pd.Series | ||
Testing points with index for initial and values for end time | ||
Returns | ||
------- | ||
pd.Series | ||
""" | ||
trn = train_times.copy(deep=True) | ||
for init, end in test_times.iteritems(): | ||
df0 = trn[(init <= trn.index) & (trn.index <= end)].index | ||
df1 = trn[(init <= trn) & (trn <= end)].index | ||
df2 = trn[(trn.index <= init) & (end <= trn)].index | ||
trn = trn.drop(df0 | df1 | df2) | ||
return trn | ||
|
||
|
||
def get_embargo_times(times, pct_embargo): | ||
"""Get embargo time index for each timestamp | ||
times: | ||
times: Timestamps | ||
Entire timestamps which you want to apply embargo | ||
pct_embargo: float ranged at [0, 1] | ||
The ratio to embargo with respect to the size of timestamps | ||
Returns: | ||
pd.Series: For each valud corresponds to a point which you should take | ||
out before from the other forward dataset | ||
""" | ||
step = int(times.shape[0] * pct_embargo) | ||
if step == 0: | ||
embg = pd.Series(times, index=times) | ||
else: | ||
embg = pd.Series(times[step:], index=times[:-step]) | ||
embg = embg.append(pd.Series(times[-1], index=times[-step:])) | ||
return embg |