Python talib.STOCHF Examples
The following are 9
code examples of talib.STOCHF().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
talib
, or try the search function
.
Example #1
Source File: talib_indicators.py From QUANTAXIS with MIT License | 5 votes |
def STOCHF(DataFrame, fastk_period=5, fastd_period=3, fastd_matype=0): fastk, fastd = talib.STOCHF(DataFrame.high.values, DataFrame.low.values, DataFrame.close.values, fastk_period, fastd_period, fastd_matype) return pd.DataFrame({'STOCHF_FASTK': fastk, 'STOCHF_FASTD': fastd}, index=DataFrame.index)
Example #2
Source File: technical_indicator.py From NowTrade with MIT License | 5 votes |
def __str__(self): return 'STOCHF(symbol=%s, fast_k_period=%s, fast_d_period=%s, \ fast_d_ma_type=%s)' %(self.symbol, self.fast_k_period, \ self.fast_d_period, self.fast_d_ma_type)
Example #3
Source File: technical_indicator.py From NowTrade with MIT License | 5 votes |
def results(self, data_frame): try: fastk, fastd = talib.STOCHF(data_frame['%s_High' %self.symbol].values, data_frame['%s_Low' %self.symbol].values, data_frame['%s_Close' %self.symbol].values, self.fast_k_period, self.fast_d_period, self.fast_d_ma_type) data_frame[self.fastk] = fastk data_frame[self.fastd] = fastd except KeyError: data_frame[self.fastk] = np.nan data_frame[self.fastd] = np.nan
Example #4
Source File: ta.py From dash-technical-charting with MIT License | 5 votes |
def add_STOCHF(self, fastk_period=5, fastd_period=3, fastd_matype=0, types=['line', 'line'], colors=['primary', 'tertiary'], **kwargs): """Fast Stochastic Oscillator. Note that the first argument of types and colors refers to Fast Stoch %K, while second argument refers to Fast Stoch %D (signal line of %K obtained by MA). """ if not (self.has_high and self.has_low and self.has_close): raise Exception() utils.kwargs_check(kwargs, VALID_TA_KWARGS) if 'kind' in kwargs: kwargs['type'] = kwargs['kind'] if 'kinds' in kwargs: types = kwargs['type'] if 'type' in kwargs: types = [kwargs['type']] * 2 if 'color' in kwargs: colors = [kwargs['color']] * 2 name = 'STOCHF({},{})'.format(str(fastk_period), str(fastd_period)) fastk = name + r'[%k]' fastd = name + r'[%d]' self.sec[fastk] = dict(type=types[0], color=colors[0]) self.sec[fastd] = dict(type=types[1], color=colors[1], on=fastk) self.ind[fastk], self.ind[fastd] = talib.STOCHF(self.df[self.hi].values, self.df[self.lo].values, self.df[self.cl].values, fastk_period, fastd_period, fastd_matype)
Example #5
Source File: stochf.py From jesse with MIT License | 5 votes |
def stochf(candles: np.ndarray, fastk_period=5, fastd_period=3, fastd_matype=0, sequential=False) -> StochasticFast: """ Stochastic Fast :param candles: np.ndarray :param fastk_period: int - default=5 :param fastd_period: int - default=3 :param fastd_matype: int - default=0 :param sequential: bool - default=False :return: StochasticFast(k, d) """ if not sequential and len(candles) > 240: candles = candles[-240:] k, d = talib.STOCHF( candles[:, 3], candles[:, 4], candles[:, 2], fastk_period=fastk_period, fastd_period=fastd_period, fastd_matype=fastd_matype ) if sequential: return StochasticFast(k, d) else: return StochasticFast(k[-1], d[-1])
Example #6
Source File: talib_wrapper.py From tia with BSD 3-Clause "New" or "Revised" License | 5 votes |
def STOCHF(frame, fastk=5, fastd=3, fastd_matype=0, high_col='high', low_col='low', close_col='close'): return _frame_to_frame(frame, [high_col, low_col, close_col], ['FAST_K', 'FAST_D'], talib.STOCHF, fastk, fastd, fastd_matype)
Example #7
Source File: test_indicator_momentum.py From pandas-ta with MIT License | 5 votes |
def test_stoch(self): result = pandas_ta.stoch(self.high, self.low, self.close, fast_k=14, slow_k=14, slow_d=14) self.assertIsInstance(result, DataFrame) self.assertEqual(result.name, 'STOCH_14_14_14') self.assertEqual(len(result.columns), 4) result = pandas_ta.stoch(self.high, self.low, self.close) self.assertIsInstance(result, DataFrame) self.assertEqual(result.name, 'STOCH_14_5_3') try: tal_stochf = tal.STOCHF(self.high, self.low, self.close) tal_stoch = tal.STOCH(self.high, self.low, self.close) tal_stochdf = DataFrame({'STOCHF_14': tal_stochf[0], 'STOCHF_3': tal_stochf[1], 'STOCH_5': tal_stoch[0], 'STOCH_3': tal_stoch[1]}) pdt.assert_frame_equal(result, tal_stochdf) except AssertionError as ae: try: stochfk_corr = pandas_ta.utils.df_error_analysis(result.iloc[:,0], tal_stochdf.iloc[:,0], col=CORRELATION) self.assertGreater(stochfk_corr, CORRELATION_THRESHOLD) except Exception as ex: error_analysis(result.iloc[:,0], CORRELATION, ex) try: stochfd_corr = pandas_ta.utils.df_error_analysis(result.iloc[:,1], tal_stochdf.iloc[:,1], col=CORRELATION) self.assertGreater(stochfd_corr, CORRELATION_THRESHOLD) except Exception as ex: error_analysis(result.iloc[:,1], CORRELATION, ex, newline=False) try: stochsk_corr = pandas_ta.utils.df_error_analysis(result.iloc[:,2], tal_stochdf.iloc[:,2], col=CORRELATION) self.assertGreater(stochsk_corr, CORRELATION_THRESHOLD) except Exception as ex: error_analysis(result.iloc[:,2], CORRELATION, ex, newline=False) try: stochsd_corr = pandas_ta.utils.df_error_analysis(result.iloc[:,3], tal_stochdf.iloc[:,3], col=CORRELATION) self.assertGreater(stochsd_corr, CORRELATION_THRESHOLD) except Exception as ex: error_analysis(result.iloc[:,3], CORRELATION, ex, newline=False)
Example #8
Source File: talib_indicators.py From qtpylib with Apache License 2.0 | 5 votes |
def STOCHF(data, **kwargs): _check_talib_presence() _, phigh, plow, pclose, _ = _extract_ohlc(data) return talib.STOCHF(phigh, plow, pclose, **kwargs)
Example #9
Source File: test_technical.py From catalyst with Apache License 2.0 | 4 votes |
def test_fso_expected_with_talib(self, seed): """ Test the output that is returned from the fast stochastic oscillator is the same as that from the ta-lib STOCHF function. """ window_length = 14 nassets = 6 rng = np.random.RandomState(seed=seed) input_size = (window_length, nassets) # values from 9 to 12 closes = 9.0 + (rng.random_sample(input_size) * 3.0) # Values from 13 to 15 highs = 13.0 + (rng.random_sample(input_size) * 2.0) # Values from 6 to 8. lows = 6.0 + (rng.random_sample(input_size) * 2.0) expected_out_k = [] for i in range(nassets): fastk, fastd = talib.STOCHF( high=highs[:, i], low=lows[:, i], close=closes[:, i], fastk_period=window_length, fastd_period=1, ) expected_out_k.append(fastk[-1]) expected_out_k = np.array(expected_out_k) today = pd.Timestamp('2015') out = np.empty(shape=(nassets,), dtype=np.float) assets = np.arange(nassets, dtype=np.float) fso = FastStochasticOscillator() fso.compute( today, assets, out, closes, lows, highs ) assert_equal(out, expected_out_k, array_decimal=6)