fmp_py.fmp_chart_data

Classes

FmpChartData

Module Contents

class fmp_py.fmp_chart_data.FmpChartData(symbol: str, from_date: str, to_date: str, interval: str = '1day', api_key: str = os.getenv('FMP_API_KEY'))

Bases: fmp_py.fmp_base.FmpBase

chart
nvi() None

Calculates the Negative Volume Index (NVI) for the chart data.

The Negative Volume Index (NVI) is a technical indicator that uses volume to predict changes in stock prices. It is calculated by summing the percentage changes in price on days with declining volume and subtracting the sum of the percentage changes on days with increasing volume.

This method modifies the chart attribute of the object by adding a new column called “nvi” that contains the NVI values.

Returns:

None

Example

>>> fmp = FmpCharts(symbol="AAPL", from_date="2021-01-01", to_date="2021-01-10")
>>> fmp.nvi()
>>> print(fmp.return_chart())
vpt() None

Calculates the Volume Price Trend (VPT) indicator for the chart data.

The Volume Price Trend (VPT) indicator measures the strength of a price trend by analyzing the relationship between volume and price. It is used to identify potential reversals or confirm the strength of a trend.

This method modifies the chart attribute of the object by adding a new column called “vpt” that contains the calculated VPT values.

Returns:

None

Example

>>> fmp = FmpCharts(symbol="AAPL", from_date="2021-01-01", to_date="2021-01-10")
>>> fmp.vpt()
>>> print(fmp.return_chart())
sma_eom(period: int = 14) None

Calculates the Simple Moving Average (SMA) of the Ease of Movement (EOM) indicator.

Parameters:

period (int) – The number of periods to consider for calculating the SMA. Default is 14.

Returns:

None

eom(period: int = 14) None

Calculates the Ease of Movement (EOM) indicator for the given chart data.

Parameters:

period (int) – The number of periods to consider for the EOM calculation. Default is 14.

Returns:

None

Notes

  • The EOM indicator measures the relationship between price change and volume.

  • It helps identify potential price reversals and divergences.

Example

>>> fmp = FmpCharts(symbol="AAPL", from_date="2021-01-01", to_date="2021-01-10")
>>> fmp.eom(14)
>>> print(fmp.return_chart())
fi(period: int = 13) None

Calculates and adds the Force Index (FI) to the chart data.

The Force Index is a technical indicator that measures the force behind price movements based on the combination of price change and trading volume. It helps identify strong trends and potential reversals.

Parameters:

period (int, optional) – The period used to calculate the Force Index. Defaults to 13.

Returns:

None

Example

>>> fmp = FmpCharts(symbol="AAPL", from_date="2021-01-01", to_date="2021-01-10")
>>> fmp.fi(13)
>>> print(fmp.return_chart())
cmf(period: int = 20) None

Calculates the Chaikin Money Flow (CMF) indicator for the chart data.

Parameters:

period (int) – The number of periods to consider for the CMF calculation. Default is 20.

Returns:

None. The CMF values are added as a new column ‘cmf’ to the chart data.

Example

>>> fmp = FmpCharts(symbol="AAPL", from_date="2021-01-01", to_date="2021-01-10")
>>> fmp.cmf()
>>> print(fmp.return_chart())
obv() None

Calculates the On-Balance Volume (OBV) indicator for the chart data.

The On-Balance Volume (OBV) indicator measures the cumulative buying and selling pressure based on the volume of trades. It is used to identify the strength of a trend and potential reversals.

Returns:

None

Example

>>> fmp = FmpCharts(symbol="AAPL", from_date="2021-01-01", to_date="2021-01-10")
>>> fmp.obv()
>>> print(fmp.return_chart())
adi(period: int = 14) None

Calculates the Accumulation/Distribution Index (ADI) for the given period.

Parameters:

period (int, optional) – The number of periods to consider. Defaults to 14.

Returns:

None

Example

>>> fmp = FmpCharts(symbol="AAPL", from_date="2021-01-01", to_date="2021-01-10")
>>> fmp.adi(14)
>>> print(fmp.return_chart())
mfi(period: int = 14) None

Calculates the Money Flow Index (MFI) for the given period.

Parameters:

period (int) – The number of periods to consider when calculating the MFI. Default is 14.

Returns:

None

Notes

The Money Flow Index (MFI) is a momentum oscillator that measures the strength and direction of money flowing in and out of a security. It uses price and volume data to identify overbought or oversold conditions in the market.

Example

>>> fmp = FmpCharts(symbol="AAPL", from_date="2021-01-01", to_date="2021-01-10")
>>> fmp.mfi(14)
>>> print(fmp.return_chart())
vwap() None

Calculates the Volume Weighted Average Price (VWAP) for the given chart data.

The VWAP is a trading indicator that gives the average price at which a security has traded throughout the day, weighted by the volume of each trade. It is often used by traders to determine the fair value of a security and to identify potential buying or selling opportunities.

This method calculates the VWAP for the chart data and adds it as a new column named ‘vwap’ to the chart DataFrame.

Returns:

None

Example

>>> fmp = FmpCharts(symbol="AAPL", from_date="2021-01-01", to_date="2021-01-10")
>>> fmp.vwap()
>>> print(fmp.return_chart())
bb(period: int = 20, std: int = 2) None

Calculates Bollinger Bands and related indicators for the given period and standard deviation.

Parameters:
  • period (int) – The number of periods to consider for calculating the Bollinger Bands. Default is 20.

  • std (int) – The number of standard deviations to use for the Bollinger Bands. Default is 2.

Returns:

None

Modifies:

Updates the ‘chart’ attribute of the object with the calculated Bollinger Bands and related indicators.

Example

>>> fmp = FmpCharts(symbol="AAPL", from_date="2021-01-01", to_date="2021-01-10")
>>> fmp.bb(20, 2)
>>> print(fmp.return_chart())
atr(period: int = 14) None

Calculates the Average True Range (ATR) for the given period.

Parameters:

period (int) – The number of periods to consider for calculating the ATR. Default is 14.

Returns:

None

Notes

  • The ATR is a volatility indicator that measures the average range between the high and low prices over a specified period.

  • The ATR is commonly used to determine the volatility of an asset and to set stop-loss and take-profit levels.

Example

>>> fmp = FmpCharts(symbol="AAPL", from_date="2021-01-01", to_date="2021-01-10")
>>> fmp.atr(14)
>>> print(fmp.return_chart())
kst(roc1: int = 10, roc2: int = 15, roc3: int = 20, roc4: int = 30, window1: int = 10, window2: int = 10, window3: int = 10, window4: int = 15, nsig: int = 9) None

Calculates the Know Sure Thing (KST) indicator and adds it to the chart data.

Parameters: - roc1 (int): Rate of Change (ROC) for the first time period (default: 10) - roc2 (int): Rate of Change (ROC) for the second time period (default: 15) - roc3 (int): Rate of Change (ROC) for the third time period (default: 20) - roc4 (int): Rate of Change (ROC) for the fourth time period (default: 30) - window1 (int): Moving average window for the first time period (default: 10) - window2 (int): Moving average window for the second time period (default: 10) - window3 (int): Moving average window for the third time period (default: 10) - window4 (int): Moving average window for the fourth time period (default: 15) - nsig (int): Signal line window (default: 9)

Returns: None

Notes

  • The KST indicator is a momentum oscillator that measures the strength of a trend.

  • The KST indicator is commonly used to identify overbought and oversold conditions.

Example

>>> fmp = FmpCharts(symbol="AAPL", from_date="2021-01-01", to_date="2021-01-10")
>>> fmp.kst(10, 15, 20, 30, 10, 10, 10, 15, 9)
>>> print(fmp.return_chart())
dpo(period: int = 20) None

Calculates the Detrended Price Oscillator (DPO) for the given period.

Parameters: - period (int): The number of periods to consider for the calculation. Default is 20.

Returns: None

Notes

  • The DPO is a momentum indicator that measures the difference between the close price and the previous close price.

  • The DPO is commonly used to determine the strength of a trend.

Example

>>> fmp = FmpCharts(symbol="AAPL", from_date="2021-01-01", to_date="2021-01-10")
>>> fmp.dpo(20)
>>> print(fmp.return_chart())
cci(period: int = 20, constant: float = 0.015) None

Calculates the Commodity Channel Index (CCI) for the given period and constant.

Parameters:
  • period (int) – The number of periods to consider for calculating CCI. Default is 20.

  • constant (float) – The constant multiplier used in the CCI formula. Default is 0.015.

Returns:

None

Notes

  • The CCI is a momentum-based oscillator that measures the deviation of an asset’s price from its statistical mean.

  • The CCI is used to identify overbought and oversold levels, as well as potential trend reversals.

Example

>>> fmp = FmpCharts(symbol="AAPL", from_date="2021-01-01", to_date="2021-01-10")
>>> fmp.cci(14, 0.015)
>>> print(fmp.return_chart())
mi(period_fast: int = 9, period_slow: int = 25) None

Calculates the Mass Index (MI) for the chart data.

The Mass Index is a technical indicator used to identify potential reversals in the market. It is calculated based on the high and low prices of the chart data.

Parameters:
  • period_fast (int) – The number of periods to use for the fast EMA calculation. Default is 9.

  • period_slow (int) – The number of periods to use for the slow EMA calculation. Default is 25.

Returns:

None

Notes

  • The Mass Index is a trend following momentum indicator that uses the high and low price to identify trend reversals based on range expansions.

  • The Mass Index is calculated by using the high and low price to calculate the range of the chart data.

  • The Mass Index is typically used with a 9-day and 25-day EMA.

Example

>>> fmp = FmpCharts(symbol="AAPL", from_date="2021-01-01", to_date="2021-01-10")
>>> fmp.mi(9, 25)
>>> print(fmp.return_chart())
trix(period: int = 15) None

Calculate the TRIX (Triple Exponential Moving Average) indicator for the given period.

Parameters:

period (int) – The number of periods to consider for the TRIX calculation. Default is 15.

Returns:

None

Notes

  • The TRIX indicator is a momentum indicator that shows the speed and direction of price changes.

  • The TRIX indicator is commonly used to identify overbought and oversold conditions.

  • The TRIX indicator is a multiplicative indicator, which means that the TRIX value is multiplied by the close price.

Example

>>> fmp = FmpCharts(symbol="AAPL", from_date="2021-01-01", to_date="2021-01-10")
>>> fmp.trix(14)
>>> print(fmp.return_chart())
vi(period: int = 14) None

Calculates the Vortex Indicator (VI) for the given period and updates the chart data.

Parameters: - period (int): The number of periods to consider when calculating the VI. Default is 14.

Returns: None

Example: >>> fmp = FmpCharts(symbol=”AAPL”, from_date=”2021-01-01”, to_date=”2021-01-10”) >>> fmp.vi(14) >>> print(fmp.return_chart())

macd(fast: int = 12, slow: int = 26, signal: int = 9) None

Calculate the Moving Average Convergence Divergence (MACD) indicators for the chart data.

Parameters:
  • fast (int) – The number of periods for the fast moving average. Default is 12.

  • slow (int) – The number of periods for the slow moving average. Default is 26.

  • signal (int) – The number of periods for the signal line. Default is 9.

Returns:

None

This method calculates the MACD, MACD signal line, and MACD histogram (MACD difference) for the chart data. The calculated values are added as new columns to the chart DataFrame.

Example

>>> fmp = FmpCharts(symbol="AAPL", from_date="2021-01-01", to_date="2021-01-10")
>>> fmp.macd(12, 26, 9)
>>> print(fmp.return_chart())
waddah_attar_explosion(n_fast: int = 20, n_slow: int = 40, channel_period: int = 20, mul: float = 2.0, sensitivity: int = 150) None

Calculate Waddah Attar Explosion indicator. :param df: DataFrame containing historical data with columns ‘close’, ‘high’, ‘low’. :type df: pd.DataFrame :param n_fast: Period for the fast EMA. :type n_fast: int :param n_slow: Period for the slow EMA. :type n_slow: int :param channel_period: Period for calculating the Bollinger Bands. :type channel_period: int :param mul: Multiplier for the Bollinger Bands. :type mul: float :param sensitivity: Sensitivity factor for explosion value. :type sensitivity: int

Returns:

DataFrame containing the Waddah Attar Explosion values.

Return type:

pd.DataFrame

Example

>>> fmp = FmpCharts(symbol="AAPL", from_date="2021-01-01", to_date="2021-01-10")
>>> fmp.waddah_attar_explosion(n_fast=20, n_slow=40, channel_period=20, mul=2.0, sensitivity=150)
>>> print(fmp.return_chart())
adx(period: int = 14) None

Calculates the Average Directional Index (ADX) for the given period.

Parameters: - period (int): The number of periods to consider when calculating the ADX. Default is 14.

Returns: None

Example

>>> fmp = FmpCharts(symbol="AAPL", from_date="2021-01-01", to_date="2021-01-10")
>>> fmp.adx(14)
>>> print(fmp.return_chart())
wma(period: int = 14) None

Calculates the Weighted Moving Average (WMA) for the given period.

Parameters:

period (int) – The number of periods to consider for the WMA calculation. Default is 14.

Returns:

None

Example

>>> fmp = FmpCharts(symbol="AAPL", from_date="2021-01-01", to_date="2021-01-10")
>>> fmp.wma(14)
>>> print(fmp.return_chart())
sma(period: int = 14) None

Calculates the Simple Moving Average (SMA) for the given period.

Parameters:

period (int) – The number of periods to consider for calculating the SMA. Default is 14.

Returns:

None

Example

>>> fmp = FmpCharts(symbol="AAPL", from_date="2021-01-01", to_date="2021-01-10")
>>> fmp.sma(14)
>>> print(fmp.return_chart())
ema(period: int = 14) None

Calculates the Exponential Moving Average (EMA) for the given period.

Parameters:

period (int) – The number of periods to consider for the EMA calculation. Default is 14.

Returns:

None

Example

>>> fmp = FmpCharts(symbol="AAPL", from_date="2021-01-01", to_date="2021-01-10")
>>> fmp.ema(14)
>>> print(fmp.return_chart())
rsi(period: int = 14) None

Calculates the Relative Strength Index (RSI) for the given period.

Parameters:

period (int) – The number of periods to consider when calculating RSI. Default is 14.

Returns:

None

Example

>>> fmp = FmpCharts(symbol="AAPL", from_date="2021-01-01", to_date="2021-01-10")
>>> fmp.rsi(14)
>>> print(fmp.return_chart())
srsi(period: int = 14, smooth1: int = 3, smooth2: int = 3) None

Calculates the Stochastic RSI (Relative Strength Index) for the given period. :param period: The number of periods to consider for the calculation. Default is 14. :type period: int :param smooth1: The number of periods to use for smoothing the Stochastic RSI. Default is 3. :type smooth1: int :param smooth2: The number of periods to use for smoothing the Stochastic RSI’s signal line. Default is 3. :type smooth2: int

Returns:

None

stoch(period: int = 14, smooth: int = 3) None

Calculates the Stochastic Oscillator for the given period.

Parameters:
  • period (int) – The number of periods to consider for the calculation. Default is 14.

  • smooth (int) – The number of periods to use for smoothing the Stochastic Oscillator. Default is 3.

Returns:

None

Example

>>> fmp = FmpCharts(symbol="AAPL", from_date="2021-01-01", to_date="2021-01-10")
>>> fmp.stoch(14, 3)
>>> print(fmp.return_chart())
tsi(period_slow: int = 25, period_fast: int = 13) None

Calculates the True Strength Index (TSI) for the given chart data. :param period_slow: The number of periods to use for the slow TSI calculation. Default is 25. :type period_slow: int :param period_fast: The number of periods to use for the fast TSI calculation. Default is 13. :type period_fast: int

Returns:

None

Example

>>> fmp = FmpCharts(symbol="AAPL", from_date="2021-01-01", to_date="2021-01-10")
>>> fmp.tsi(25, 13)
>>> print(fmp.return_chart())
uo(period1: int = 7, period2: int = 14, period3: int = 28, weight1: float = 4.0, weight2: float = 2.0, weight3: float = 1.0) None

Calculate the Ultimate Oscillator (UO) for the given chart data. :param period1: The number of periods to use for the first UO calculation. Default is 7. :type period1: int :param period2: The number of periods to use for the second UO calculation. Default is 14. :type period2: int :param period3: The number of periods to use for the third UO calculation. Default is 28. :type period3: int :param weight1: The weight to apply to the first UO calculation. Default is 4.0. :type weight1: float :param weight2: The weight to apply to the second UO calculation. Default is 2.0. :type weight2: float :param weight3: The weight to apply to the third UO calculation. Default is 1.0. :type weight3: float

Returns:

None

Example

>>> fmp = FmpCharts(symbol="AAPL", from_date="2021-01-01", to_date="2021-01-10")
>>> fmp.uo(7, 14, 28, 4.0, 2.0, 1.0)
>>> print(fmp.return
wr(period: int = 14) None

Calculate the Williams %R for the given chart data. :param period: The number of periods to consider for the calculation. Default is 14. :type period: int

Returns:

None

Example

>>> fmp = FmpCharts(symbol="AAPL", from_date="2021-01-01", to_date="2021-01-10")
>>> fmp.wr(14)
>>> print(fmp.return_chart())
ao(period1: int = 5, period2: int = 34) None

Calculate the Awesome Oscillator (AO) for the given chart data. :param period1: The number of periods to use for the first AO calculation. Default is 5. :type period1: int :param period2: The number of periods to use for the second AO calculation. Default is 34. :type period2: int

Returns:

None

Example

>>> fmp = FmpCharts(symbol="AAPL", from_date="2021-01-01", to_date="2021-01-10")
>>> fmp.ao(5, 34)
>>> print(fmp.return_chart())
kama(period: int = 10, pow1: int = 2, pow2: int = 30) None

Calculate the Kaufman’s Adaptive Moving Average (KAMA) for the given chart data. :param period: The number of periods to consider for the calculation. Default is 10. :type period: int :param pow1: The number of periods to consider for the first power factor. Default is 2. :type pow1: int :param pow2: The number of periods to consider for the second power factor. Default is 30. :type pow2: int

Returns:

None

Example

>>> fmp = FmpCharts(symbol="AAPL", from_date="2021-01-01", to_date="2021-01-10")
>>> fmp.kama(10, 2, 30)
>>> print(fmp.return_chart
roc(period: int = 12) None

Calculate the Rate of Change (ROC) for the given chart data. :param period: The number of periods to consider for the calculation. Default is 12. :type period: int

Returns:

None

Example

>>> fmp = FmpCharts(symbol="AAPL", from_date="2021-01-01", to_date="2021-01-10")
>>> fmp.roc(12)
>>> print(fmp.return_chart())
return_chart() pandas.DataFrame