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.
 
 

58 lines
1.7 KiB

"""Dumb indicator, for testing purposes."""
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"]
# select only last two days
lastND = highData.last("2D")
# lastND.rolling(window=2).mean()
res = {}
for column in lastND.columns:
# pour chaque type d'action
# print(column)
if len(lastND.index) > 1:
# print(last2D[column].get(last2D.index[-1]), last2D[column].get(last2D.index[-2]))
ultieme = lastND[column].get(lastND.index[-1])
penultieme = lastND[column].get(lastND.index[-2])
if ultieme / penultieme > 1.05:
res[column] = 1
elif ultieme / penultieme < 0.95:
res[column] = -1
else:
res[column] = 0
else:
res[column] = 1
return pd.Series(res)