def setUpClass(cls): cls._df = pd.read_csv(cls._filename, sep=',') cls._params = dict(high=cls._df['High'], low=cls._df['Low'], close=cls._df['Close'], volume=cls._df['Volume'], fillna=False) cls._indicator = VolumeWeightedAveragePrice(**cls._params)
def add_volume_ta(df: pd.DataFrame, high: str, low: str, close: str, volume: str, fillna: bool = False, colprefix: str = "") -> pd.DataFrame: """Add volume technical analysis features to dataframe. Args: df (pandas.core.frame.DataFrame): Dataframe base. high (str): Name of 'high' column. low (str): Name of 'low' column. close (str): Name of 'close' column. volume (str): Name of 'volume' column. fillna(bool): if True, fill nan values. colprefix(str): Prefix column names inserted Returns: pandas.core.frame.DataFrame: Dataframe with new features. """ # Accumulation Distribution Index df[f'{colprefix}volume_adi'] = AccDistIndexIndicator( high=df[high], low=df[low], close=df[close], volume=df[volume], fillna=fillna).acc_dist_index() # On Balance Volume df[f'{colprefix}volume_obv'] = OnBalanceVolumeIndicator( close=df[close], volume=df[volume], fillna=fillna).on_balance_volume() # Chaikin Money Flow df[f'{colprefix}volume_cmf'] = ChaikinMoneyFlowIndicator( high=df[high], low=df[low], close=df[close], volume=df[volume], fillna=fillna).chaikin_money_flow() # Force Index df[f'{colprefix}volume_fi'] = ForceIndexIndicator( close=df[close], volume=df[volume], n=13, fillna=fillna).force_index() # Money Flow Indicator df[f'{colprefix}volume_mfi'] = MFIIndicator( high=df[high], low=df[low], close=df[close], volume=df[volume], n=14, fillna=fillna).money_flow_index() # Ease of Movement indicator = EaseOfMovementIndicator(high=df[high], low=df[low], volume=df[volume], n=14, fillna=fillna) df[f'{colprefix}volume_em'] = indicator.ease_of_movement() df[f'{colprefix}volume_sma_em'] = indicator.sma_ease_of_movement() # Volume Price Trend df[f'{colprefix}volume_vpt'] = VolumePriceTrendIndicator( close=df[close], volume=df[volume], fillna=fillna).volume_price_trend() # Negative Volume Index df[f'{colprefix}volume_nvi'] = NegativeVolumeIndexIndicator( close=df[close], volume=df[volume], fillna=fillna).negative_volume_index() # Volume Weighted Average Price df[f'{colprefix}volume_vwap'] = VolumeWeightedAveragePrice( high=df[high], low=df[low], close=df[close], volume=df[volume], n=14, fillna=fillna ).volume_weighted_average_price() return df
def setUpClass(cls): cls._df = pd.read_csv(cls._filename, sep=",") cls._params = dict( high=cls._df["High"], low=cls._df["Low"], close=cls._df["Close"], volume=cls._df["Volume"], fillna=False, ) cls._indicator = VolumeWeightedAveragePrice(**cls._params)
def get_vwap(client, symbol): df = get_bars(client, symbol) raw_vwap = VolumeWeightedAveragePrice(high=df['high'], low=df['low'], close=df['close'], volume=df['volume'], window=14) # print("vwap:") return raw_vwap.vwap[len(raw_vwap.vwap) - 1]
def start_test(count): cancel_all('all') client = build_client() if count < 1: count += 1 symbols = ['CRBP', 'QD', 'WPG', 'ANY'] for symbol in symbols: ph = client.get_price_history( symbol=symbol, period_type=client.PriceHistory.PeriodType.DAY, period=client.PriceHistory.Period.ONE_DAY, frequency_type=client.PriceHistory.FrequencyType.MINUTE, frequency=client.PriceHistory.Frequency.EVERY_FIFTEEN_MINUTES, start_datetime=None, end_datetime=None, need_extended_hours_data=None).json() print(ph['symbol']) df = pd.json_normalize(ph, 'candles') # pprint(len(df)) # pprint(df) # pprint(df['close']) # pprint(df['high']) # pprint(df['low']) # pprint(df['volume']) raw_vwap = VolumeWeightedAveragePrice(high=df['high'], low=df['low'], close=df['close'], volume=df['volume'], window=14) raw_ema = EMAIndicator(close=df['close'], window=9) print("vwap:") pprint(raw_vwap.vwap[len(raw_vwap.vwap) - 1]) print("ema:") pprint(raw_ema._close[len(raw_ema._close) - 1]) print("len ema:") print(len(raw_ema._close))