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.
 
 

56 lines
1.5 KiB

"""SMA indicator, not ready yet."""
from calendar import c
from re import sub
import pandas as pd
from ..interfaces import Indicator
class SMA(Indicator):
"""Replay the value."""
def __init__(self, windowSize: int):
"""Save the value."""
super().__init__()
self.windowSize = windowSize
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
data3 = data2["close"]
# apply sma
sma = data3.rolling(window=self.windowSize).mean()
# computes slope at each point of the sma
smaDiff = sma.diff()
res = {}
for column in sma.columns:
# pour chaque type d'action
# print(column)
coeff = smaDiff[column].get(sma.index[-1])
# print(
# f"Coeff directeur : {coeff}\n Ultieme {ultieme}\n Penultieme {penultieme}"
# )
# TODO: ne pas hardcoder
trust = coeff / 5
res[column] = trust
print(trust)
return pd.Series(res)