本文整理匯總了Python中talib.NATR屬性的典型用法代碼示例。如果您正苦於以下問題:Python talib.NATR屬性的具體用法?Python talib.NATR怎麽用?Python talib.NATR使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在類talib
的用法示例。
在下文中一共展示了talib.NATR屬性的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: natr
# 需要導入模塊: import talib [as 別名]
# 或者: from talib import NATR [as 別名]
def natr(candles: np.ndarray, period=14, sequential=False) -> Union[float, np.ndarray]:
"""
NATR - Normalized Average True Range
:param candles: np.ndarray
:param period: int - default=14
:param sequential: bool - default=False
:return: float | np.ndarray
"""
if not sequential and len(candles) > 240:
candles = candles[-240:]
res = talib.NATR(candles[:, 3], candles[:, 4], candles[:, 2], timeperiod=period)
if sequential:
return res
else:
return None if np.isnan(res[-1]) else res[-1]
示例2: get_indicator
# 需要導入模塊: import talib [as 別名]
# 或者: from talib import NATR [as 別名]
def get_indicator(df, indicator):
ret_df = df
if 'MACD' in indicator:
macd, macdsignal, macdhist = ta.MACD(df.close.values, fastperiod=12, slowperiod=26, signalperiod=9)
ret_df = KlineData._merge_dataframe(pd.DataFrame([macd, macdsignal, macdhist]).T.rename(columns={0: "macddif", 1: "macddem", 2: "macdhist"}), ret_df)
ret_df = KlineData._merge_dataframe(line_intersections(ret_df, columns=['macddif', 'macddem']), ret_df)
if 'MFI' in indicator:
real = ta.MFI(df.high.values, df.low.values, df.close.values, df.volume.values, timeperiod=14)
ret_df = KlineData._merge_dataframe(pd.DataFrame([real]).T.rename(columns={0: "mfi"}), ret_df)
if 'ATR' in indicator:
real = ta.NATR(df.high.values, df.low.values, df.close.values, timeperiod=14)
ret_df = KlineData._merge_dataframe(pd.DataFrame([real]).T.rename(columns={0: "atr"}), ret_df)
if 'ROCR' in indicator:
real = ta.ROCR(df.close.values, timeperiod=10)
ret_df = KlineData._merge_dataframe(pd.DataFrame([real]).T.rename(columns={0: "rocr"}), ret_df)
ret_df['date'] = pd.to_datetime(ret_df['date'], format='%Y-%m-%d')
return ret_df
示例3: natr
# 需要導入模塊: import talib [as 別名]
# 或者: from talib import NATR [as 別名]
def natr(self, sym, frequency, period=14):
if not self.kbars_ready(sym, frequency):
return []
highs = self.high(sym, frequency)
lows = self.low(sym, frequency)
closes = self.close(sym, frequency)
natr = ta.NATR(highs, lows, closes, timeperiod=period)
return natr
示例4: NATR
# 需要導入模塊: import talib [as 別名]
# 或者: from talib import NATR [as 別名]
def NATR(frame, n=14, high_col='high', low_col='low', close_col='close'):
return _frame_to_series(frame, [high_col, low_col, close_col], talib.NATR, n)
示例5: test_natr
# 需要導入模塊: import talib [as 別名]
# 或者: from talib import NATR [as 別名]
def test_natr(self):
result = pandas_ta.natr(self.high, self.low, self.close)
self.assertIsInstance(result, Series)
self.assertEqual(result.name, 'NATR_14')
try:
expected = tal.NATR(self.high, self.low, self.close)
pdt.assert_series_equal(result, expected, check_names=False)
except AssertionError as ae:
try:
corr = pandas_ta.utils.df_error_analysis(result, expected, col=CORRELATION)
self.assertGreater(corr, CORRELATION_THRESHOLD)
except Exception as ex:
error_analysis(result, CORRELATION, ex)
示例6: NATR
# 需要導入模塊: import talib [as 別名]
# 或者: from talib import NATR [as 別名]
def NATR(data, **kwargs):
_check_talib_presence()
_, phigh, plow, pclose, _ = _extract_ohlc(data)
return talib.NATR(phigh, plow, pclose, **kwargs)