Standardize ohlc dtype

its_happening
Tyler Goodlet 2020-07-15 08:42:01 -04:00
parent 4a1bcf7626
commit c6b4b62228
1 changed files with 14 additions and 13 deletions

View File

@ -8,9 +8,9 @@ import numpy as np
import pandas as pd import pandas as pd
OHLC_dtype = np.dtype( ohlc_dtype = np.dtype(
[ [
('id', int), ('index', int),
('time', float), ('time', float),
('open', float), ('open', float),
('high', float), ('high', float),
@ -20,15 +20,16 @@ OHLC_dtype = np.dtype(
] ]
) )
# tf = { # map time frame "keys" to minutes values
# 1: TimeFrame.M1, tf_in_1m = {
# 5: TimeFrame.M5, '1m': 1,
# 15: TimeFrame.M15, '5m': 5,
# 30: TimeFrame.M30, '15m': 15,
# 60: TimeFrame.H1, '30m': 30,
# 240: TimeFrame.H4, '1h': 60,
# 1440: TimeFrame.D1, '4h': 240,
# } '1d': 1440,
}
def ohlc_zeros(length: int) -> np.ndarray: def ohlc_zeros(length: int) -> np.ndarray:
@ -37,7 +38,7 @@ def ohlc_zeros(length: int) -> np.ndarray:
For "why a structarray" see here: https://stackoverflow.com/a/52443038 For "why a structarray" see here: https://stackoverflow.com/a/52443038
Bottom line, they're faster then ``np.recarray``. Bottom line, they're faster then ``np.recarray``.
""" """
return np.zeros(length, dtype=OHLC_dtype) return np.zeros(length, dtype=ohlc_dtype)
@dataclass @dataclass
@ -87,7 +88,7 @@ def from_df(
df = df.rename(columns=columns) df = df.rename(columns=columns)
for name in df.columns: for name in df.columns:
if name not in OHLC_dtype.names: if name not in ohlc_dtype.names[1:]:
del df[name] del df[name]
# TODO: it turns out column access on recarrays is actually slower: # TODO: it turns out column access on recarrays is actually slower: