# Copyright 2019 The TensorTrade Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import talib
import numpy as np
import pandas as pd
from gym import Space
from copy import copy
from abc import abstractmethod
from typing import Union, List, Callable
from tensortrade.features.feature_transformer import FeatureTransformer
[docs]class TAlibIndicator(FeatureTransformer):
"""Adds one or more TAlib indicators to a data frame, based on existing open, high, low, and close column values."""
def __init__(self, indicators: List[str], lows: Union[List[float], List[int]] = None, highs: Union[List[float], List[int]] = None):
self._indicator_names = indicators
self._indicators = list(
map(lambda indicator_name: self._str_to_indicator(indicator_name), indicators))
self._lows = lows or np.zeros(len(indicators))
self._highs = highs or np.ones(len(indicators))
def _str_to_indicator(self, indicator_name: str):
return getattr(talib, indicator_name.upper())