text
stringlengths
1
93.6k
dataframe['bb_upperband_40'] = bbands['upperband']
# stochastic
# stochastic windows
for i in self.stock_periods.range:
dataframe[f'stoch_{i}'] = stoch_sma(dataframe, window=i)
dataframe = self.populate_informative_indicators(dataframe, metadata)
return dataframe
def populate_buy_trend(self, dataframe: DataFrame, metadata: dict) -> DataFrame:
conditions = []
# ewo < 0
conditions.append(dataframe['EWO'] < self.ewo_low.value)
# middleband 1h >= t3 1h
conditions.append(dataframe['bb_middleband_1h'] >= dataframe['T3_1h'])
# t3 <= ema
conditions.append(dataframe[f'T3_{self.t3_periods.value}'] <= dataframe['EMA'])
if conditions:
dataframe.loc[reduce(lambda x, y: x & y, conditions), 'buy'] = 1
return dataframe
def populate_sell_trend(self, dataframe: DataFrame, metadata: dict) -> DataFrame:
conditions = []
# stoch > 80
conditions.append(
dataframe[f'stoch_{self.stock_periods.value}'] > self.stoch_high.value
)
# t3 >= middleband_40
conditions.append(
dataframe[f'T3_{self.t3_periods.value}'] >= dataframe['bb_middleband_40']
)
if conditions:
dataframe.loc[reduce(lambda x, y: x | y, conditions), 'sell'] = 1
return dataframe
def T3(dataframe, length=5):
"""
T3 Average by HPotter on Tradingview
ERROR: type should be string, got " https://www.tradingview.com/script/qzoC9H1I-T3-Average/\n"
"""
df = dataframe.copy()
df['xe1'] = ta.EMA(df['close'], timeperiod=length)
df['xe2'] = ta.EMA(df['xe1'], timeperiod=length)
df['xe3'] = ta.EMA(df['xe2'], timeperiod=length)
df['xe4'] = ta.EMA(df['xe3'], timeperiod=length)
df['xe5'] = ta.EMA(df['xe4'], timeperiod=length)
df['xe6'] = ta.EMA(df['xe5'], timeperiod=length)
b = 0.7
c1 = -b * b * b
c2 = 3 * b * b + 3 * b * b * b
c3 = -6 * b * b - 3 * b - 3 * b * b * b
c4 = 1 + 3 * b + b * b * b + 3 * b * b
df['T3Average'] = c1 * df['xe6'] + c2 * df['xe5'] + c3 * df['xe4'] + c4 * df['xe3']
return df['T3Average']
def EWO(dataframe, ema_length=5, ema2_length=35):
df = dataframe.copy()
ema1 = ta.EMA(df, timeperiod=ema_length)
ema2 = ta.EMA(df, timeperiod=ema2_length)
emadif = (ema1 - ema2) / df["low"] * 100
return emadif
def stoch_sma(dataframe: DataFrame, window=80):
""""""
stoch = qtpylib.stoch(dataframe, window)
return qtpylib.sma((stoch['slow_k'] + stoch['slow_d']) / 2, 10)
# <FILESEP>
# Lint as: python3
from absl import app
from absl import flags
import numpy as np
import h5py
from os import path
from sklearn.svm import LinearSVC
from sklearn.cluster import KMeans
from scipy.optimize import linear_sum_assignment
FLAGS = flags.FLAGS
flags.DEFINE_string("data_dir", None, "path to the saved features")
flags.DEFINE_enum("feature_type",
"3d_pointcaps_net",
["3d_pointcaps_net", "pointnet", "caca"],
"type of the model that predicts the features.")
flags.DEFINE_enum("method_type",
"svm",
["svm", "equal_kmeans"],
"type of method used for classification.")
flags.DEFINE_bool("use_kpts",
True,
"use keypoints in features if true.")
def load_3d_pointcaps_net_features():
train_data = h5py.File(path.join(