You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

49 lines
1.3 KiB

"""+1 when going up, -1 when going down, 0 when not moving enough."""
from calendar import c
from re import sub
import pandas as pd # type: ignore
from ..interfaces import Indicator
class Slopy(Indicator):
"""Replay the value."""
def __init__(self):
"""Save the value."""
super().__init__()
def __call__(self, data: pd.DataFrame) -> pd.Series:
"""Return a dataframe of valuation of each stock from the input data.
Args:
data (DataFrame): Time-Stock valuated candlestick data.
For each time and each stock give (high, low, open, close).
Returns:
DataFrame: Stock valuated float.
For each stock give -1 if realy bad and +1 if realy good.
"""
# only use date as index => actions become columns
data2 = data.unstack()
# select high prices for each action
highData = data2["close"]
coeffs = highData.diff()
res = {}
for column in coeffs.columns:
# pour chaque type d'action
# print(column)
coeff = coeffs[column].get(coeffs.index[-1])
# TODO: ne pas hardcoder
trust = 1 + (coeff / 5)
trust = min(trust, 1.0)
trust = max(trust, 0.0)
res[column] = trust
return pd.Series(res)