I'm dealing with some datasets of OHLC data, and I'm trying to find a way to determine the steepness of that data at a given point.
Literally, given a specific point, I need to find a way to know if at that point the line is going up, down, or sideways, so I would need to find some sort of coefficient that tells how steep the line is at the specific point.
Here is a sample of a dataset, it's very specific stuff:
Close
2021-03-04 07:00:00 1571.53
2021-03-04 08:00:00 1571.11
2021-03-04 09:00:00 1547.29
2021-03-04 10:00:00 1557.74
2021-03-04 11:00:00 1561.59
2021-03-04 12:00:00 1561.28
2021-03-04 13:00:00 1567.00
2021-03-04 14:00:00 1574.28
2021-03-04 15:00:00 1577.22
2021-03-04 16:00:00 1584.92
2021-03-04 17:00:00 1562.29
2021-03-04 18:00:00 1507.77
2021-03-04 19:00:00 1526.71
2021-03-04 20:00:00 1531.00
2021-03-04 21:00:00 1517.97
2021-03-04 22:00:00 1529.71
2021-03-04 23:00:00 1539.23
2021-03-05 00:00:00 1478.94
2021-03-05 01:00:00 1463.28
2021-03-05 02:00:00 1480.97
2021-03-05 03:00:00 1481.67
2021-03-05 04:00:00 1465.48
2021-03-05 05:00:00 1472.41
2021-03-05 06:00:00 1479.99
2021-03-05 07:00:00 1474.17
2021-03-05 08:00:00 1456.06
2021-03-05 09:00:00 1469.80
2021-03-05 10:00:00 1471.51
2021-03-05 11:00:00 1480.15
2021-03-05 12:00:00 1482.47
2021-03-05 13:00:00 1489.47
2021-03-05 14:00:00 1493.41
2021-03-05 15:00:00 1481.41
2021-03-05 16:00:00 1477.98
2021-03-05 17:00:00 1507.11
2021-03-05 18:00:00 1521.66
2021-03-05 19:00:00 1533.58
2021-03-05 20:00:00 1533.36
2021-03-05 21:00:00 1531.68
2021-03-05 22:00:00 1536.38
2021-03-05 23:00:00 1528.31
2021-03-06 00:00:00 1542.00
2021-03-06 01:00:00 1534.70
2021-03-06 03:00:00 1531.70
2021-03-06 04:00:00 1529.28
2021-03-06 05:00:00 1574.67
2021-03-06 06:00:00 1578.37
2021-03-06 07:00:00 1589.31
2021-03-06 08:00:00 1574.99
2021-03-06 09:00:00 1564.03
2021-03-06 10:00:00 1563.93
2021-03-06 11:00:00 1564.07
2021-03-06 12:00:00 1542.18
2021-03-06 13:00:00 1528.55
2021-03-06 14:00:00 1541.65
2021-03-06 15:00:00 1544.41
2021-03-06 16:00:00 1580.20
2021-03-06 17:00:00 1600.98
2021-03-06 18:00:00 1615.63
2021-03-06 19:00:00 1620.71
2021-03-06 20:00:00 1653.09
2021-03-06 21:00:00 1642.97
2021-03-06 22:00:00 1665.29
2021-03-06 23:00:00 1650.35
2021-03-07 00:00:00 1671.00
2021-03-07 01:00:00 1641.96
2021-03-07 02:00:00 1656.10
2021-03-07 03:00:00 1648.98
2021-03-07 04:00:00 1656.85
2021-03-07 05:00:00 1663.31
2021-03-07 06:00:00 1662.99
2021-03-07 07:00:00 1684.54
2021-03-07 08:00:00 1668.45
2021-03-07 09:00:00 1684.10
2021-03-07 10:00:00 1675.01
2021-03-07 11:00:00 1678.36
2021-03-07 12:00:00 1669.22
2021-03-07 13:00:00 1663.43
2021-03-07 14:00:00 1648.96
2021-03-07 15:00:00 1652.00
2021-03-07 16:00:00 1669.16
2021-03-07 17:00:00 1675.99
2021-03-07 18:00:00 1655.52
2021-03-07 19:00:00 1658.26
2021-03-07 20:00:00 1649.31
2021-03-07 21:00:00 1664.14
2021-03-07 22:00:00 1678.61
2021-03-07 23:00:00 1726.16
2021-03-08 00:00:00 1742.21
2021-03-08 01:00:00 1736.80
2021-03-08 02:00:00 1723.35
2021-03-08 03:00:00 1723.68
Here is what I tried:
I tried to find a way to calculate the slope of the line, and it partially works. I used a library called pandas_ta, here is the code it uses:
def slope( close, length=None, as_angle=None, to_degrees=None, vertical=None, offset=None, **kwargs):
"""Indicator: Slope"""
# Validate arguments
length = int(length) if length and length > 0 else 1
as_angle = True if isinstance(as_angle, bool) else False
to_degrees = True if isinstance(to_degrees, bool) else False
close = verify_series(close, length)
offset = get_offset(offset)
if close is None: return
# Calculate Result
slope = close.diff(length) / length
if as_angle:
slope = slope.apply(npAtan)
if to_degrees:
slope *= 180 / npPi
# Offset
if offset != 0:
slope = slope.shift(offset)
# Handle fills
if "fillna" in kwargs:
slope.fillna(kwargs["fillna"], inplace=True)
if "fill_method" in kwargs:
slope.fillna(method=kwargs["fill_method"], inplace=True)
# Name and Categorize it
slope.name = f"SLOPE_{length}" if not as_angle else f"ANGLE{'d' if to_degrees else 'r'}_{length}"
slope.category = "momentum"
return slope
Here is the problem: The problem now is that the output of that function works and it gives me what I'm looking for but it depends heavily on the magnitude of the data I'm feeding (of course) and this is a problem because I'm using other datasets with much lower numbers.
Instead, is there a way to get some sort of coefficient or number that tells me the inclination of the line for every point? Any kind of advice is appreciated