-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.py
More file actions
42 lines (34 loc) · 1.41 KB
/
utils.py
File metadata and controls
42 lines (34 loc) · 1.41 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
import datetime
import pandas as pd
TF_EQUIV = {"1m": "1Min", "5m": "5Min", "15m": "15Min", "30m": "30Min", "1h": "1H", "4h": "4H", "12h": "12H", "1d": "D"}
STRAT_PARAMS = {
"obv": {
"ma_period": {"name": "MA Period", "type": int},
},
"ichimoku": {
"kijun": {"name": "Kijun Period", "type": int},
"tenkan": {"name": "Tenkan Period", "type": int},
},
"sup_res": {
"min_points": {"name": "Min. Points", "type": int},
"min_diff_points": {"name": "Min. Difference between Points", "type": int},
"rounding_nb": {"name": "Rounding Number", "type": float},
"take_profit": {"name": "Take Profit %", "type": float},
"stop_loss": {"name": "Stop Loss %", "type": float},
},
"sma": {
"slow_ma": {"name": "Slow MA Period", "type": int},
"fast_ma": {"name": "Fast MA Period", "type": int},
},
"psar": {
"initial_acc": {"name": "Initial Acceleration", "type": float},
"acc_increment": {"name": "Acceleration Increment", "type": float},
"max_acc": {"name": "Max. Acceleration", "type": float},
},
}
def ms_to_dt(ms: int) -> datetime.datetime:
return datetime.datetime.utcfromtimestamp(ms / 1000)
def resample_timeframe(data: pd.DataFrame, tf: str) -> pd.DataFrame:
return data.resample(TF_EQUIV[tf]).agg(
{"open": "first", "high": "max", "low": "min", "close": "last", "volume": "sum"}
)