-
Notifications
You must be signed in to change notification settings - Fork 91
/
script_cpd_example.py
86 lines (72 loc) · 2.29 KB
/
script_cpd_example.py
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
79
80
81
82
83
84
85
86
import argparse
import datetime as dt
import pandas as pd
import src.changepoint_detection as cpd
from src.data_prep import calc_returns
from data.pull_data import pull_quandl_sample_data
from settings.default import CPD_DEFAULT_LBW, USE_KM_HYP_TO_INITIALISE_KC
def main(
ticker: str, output_file_path: str, start_date: dt.datetime, end_date: dt.datetime, lookback_window_length :int
):
data = pull_quandl_sample_data(ticker)
data["daily_returns"] = calc_returns(data["close"])
cpd.run_module(
data, lookback_window_length, output_file_path, start_date, end_date, USE_KM_HYP_TO_INITIALISE_KC
)
if __name__ == "__main__":
def get_args():
"""Returns settings from command line."""
parser = argparse.ArgumentParser(description="Run changepoint detection module")
parser.add_argument(
"ticker",
metavar="t",
type=str,
nargs="?",
default="ICE_SB",
# choices=[],
help="Ticker type",
)
parser.add_argument(
"output_file_path",
metavar="f",
type=str,
nargs="?",
default="data/test.csv",
# choices=[],
help="Output file location for csv.",
)
parser.add_argument(
"start_date",
metavar="s",
type=str,
nargs="?",
default="2005-01-01",
help="Start date in format yyyy-mm-dd",
)
parser.add_argument(
"end_date",
metavar="e",
type=str,
nargs="?",
default="2009-12-31",
help="End date in format yyyy-mm-dd",
)
parser.add_argument(
"lookback_window_length",
metavar="l",
type=int,
nargs="?",
default=CPD_DEFAULT_LBW,
help="CPD lookback window length",
)
args = parser.parse_known_args()[0]
start_date = dt.datetime.strptime(args.start_date, "%Y-%m-%d")
end_date = dt.datetime.strptime(args.end_date, "%Y-%m-%d")
return (
args.ticker,
args.output_file_path,
start_date,
end_date,
args.lookback_window_length
)
main(*get_args())