MACD_EMA_SHORT is only a class method

  • you can't get it, unless you update the class
    • you need to return fast = df[ema_short]
  • MACD_EMA_SHORT is a parameter used for a calculation in _get_macd
    • MACD_EMA_SHORT = 12
    • ema_short = 'close_{}_ema'.format(cls.MACD_EMA_SHORT)
    • ema_short = 'close_12_ema'
class StockDataFrame(pd.DataFrame):
    OPERATORS = ['le', 'ge', 'lt', 'gt', 'eq', 'ne']

    # Start of options.
    KDJ_PARAM = (2.0 / 3.0, 1.0 / 3.0)
    KDJ_WINDOW = 9

    BOLL_PERIOD = 20
    BOLL_STD_TIMES = 2

    MACD_EMA_SHORT = 12
    MACD_EMA_LONG = 26
    MACD_EMA_SIGNAL = 9
    @classmethod
    def _get_macd(cls, df):
        """ Moving Average Convergence Divergence
        This function will initialize all following columns.
        MACD Line (macd): (12-day EMA - 26-day EMA)
        Signal Line (macds): 9-day EMA of MACD Line
        MACD Histogram (macdh): MACD Line - Signal Line
        :param df: data
        :return: None
        """
        ema_short = 'close_{}_ema'.format(cls.MACD_EMA_SHORT)
        ema_long = 'close_{}_ema'.format(cls.MACD_EMA_LONG)
        ema_signal = 'macd_{}_ema'.format(cls.MACD_EMA_SIGNAL)
        fast = df[ema_short]
        slow = df[ema_long]
        df['macd'] = fast - slow
        df['macds'] = df[ema_signal]
        df['macdh'] = (df['macd'] - df['macds'])
        log.critical("NOTE: Behavior of MACDH calculation has changed as of "
                     "July 2017 - it is now 1/2 of previous calculated values")
        cls._drop_columns(df, [ema_short, ema_long, ema_signal])

Update:

  • find stockstats.py, then in def _get_macd(cls, df), comment out cls._drop_columns(df, [ema_short, ema_long, ema_signal]) (e.g. put # in front of it)
  • Then you can do stock['close_12_ema']

Code to get the table:

periods = '3600'
resp = requests.get('https://api.cryptowat.ch/markets/poloniex/ethusdt/ohlc', params={'periods': periods})
data = resp.json()
df = pd.DataFrame(data['result'][periods], columns=['date', 'open', 'high', 'low', 'close', 'volume', 'amount'])
df['date'] = pd.to_datetime(df['date'], unit='s')

stock = sdf.retype(df)
print(stock['macds'])

print(stock)
  • The extra columns don't get added until you do stock['macds'].

OUtput:

                           open        high         low       close      volume        amount  close_12_ema  close_26_ema      macd  macd_9_ema     macds     macdh
date                                                                                                                                                               
2019-08-20 00:00:00  201.000000  203.379326  201.000000  202.138224  349.209128  70720.937575    202.138224    202.138224  0.000000    0.000000  0.000000  0.000000
2019-08-20 01:00:00  202.187160  202.650000  200.701061  200.778709  329.485014  66411.899720    201.401820    201.432322 -0.030502   -0.016946 -0.016946 -0.013556
2019-08-20 02:00:00  201.200000  201.558777  200.133667  200.338312   12.812929   2572.209909    200.986733    201.039255 -0.052522   -0.031526 -0.031526 -0.020996
2019-08-20 03:00:00  200.915590  201.177018  200.396571  200.440000   21.910910   4395.692727    200.814151    200.871730 -0.057579   -0.040352 -0.040352 -0.017227
2019-08-20 04:00:00  200.979999  200.979999  198.282603  198.644618  360.432424  71712.376256    200.224696    200.355253 -0.130557   -0.067186 -0.067186 -0.063371
Answer from Trenton McKinney on Stack Overflow
🌐
PyPI
pypi.org › project › stockstats
stockstats · PyPI
February 16, 2026 - Requires Python 3.9+. CI tests against Python 3.10, 3.11, 3.12, and 3.13. ... StockDataFrame works as a wrapper for pandas.DataFrame. Initialize it with wrap or StockDataFrame.retype. import pandas as pd from stockstats import wrap # from CSV df = wrap(pd.read_csv('stock.csv')) # from yfinance (disable multi-level index for compatibility) import yfinance as yf df = wrap(yf.download('AAPL', multi_level_index=False))
      » pip install stockstats
    
Published   Feb 16, 2026
Version   0.6.8
🌐
GitHub
github.com › jealous › stockstats › blob › master › stockstats.py
stockstats/stockstats.py at master · jealous/stockstats
Supply a wrapper ``StockDataFrame`` based on the ``pandas.DataFrame`` with inline stock statistics/indicators support. - stockstats/stockstats.py at master · jealous/stockstats
Author   jealous
Discussions

python - How can i see MACD signal by using stockstats? - Stack Overflow
I'm trying to draw a Macd indicator. I am using stockstats to draw it. But I can only see the Macd value.(and can not add it to csv file if you help me to add it too I'll be glad) how can i see More on stackoverflow.com
🌐 stackoverflow.com
dataframe - Python: What structure of data is stockstats expecting? - Stack Overflow
Looks to me like you need to change the column names. stockstats() expects the closing price to be named close, your dataframe calls it C. ... See the files in the test_data directory for examples of the expected input format. More on stackoverflow.com
🌐 stackoverflow.com
Has anybody used the stockstats module , I can't get Talib to work.
I’m currently using the module and don’t have issues getting data from it. What kind of error do you get? More on reddit.com
🌐 r/algotrading
20
1
January 9, 2020
Python Finance: How to use macd indicator for signals strategy? - Stack Overflow
I am trying to get my head around stock data and it's implementation in python. In starting I am using MACD indicator in Python stockstats library. Thing I want to know, if I have 100 OHLC entries... More on stackoverflow.com
🌐 stackoverflow.com
People also ask

What is stockstats?
DataFrame with inline stock statistics support. Visit Snyk Advisor to see a · full health score report · for stockstats, including popularity, security, maintenance · & community analysis.
🌐
snyk.io
snyk.io › advisor › python packages › stockstats
stockstats - Python Package Health Analysis | Snyk
Is stockstats popular?
The python package stockstats receives a total · of 3,585 weekly downloads. As · such, stockstats popularity was classified as · a · recognized. Visit the · popularity section · on Snyk Advisor to see the full health analysis.
🌐
snyk.io
snyk.io › advisor › python packages › stockstats
stockstats - Python Package Health Analysis | Snyk
Is stockstats safe to use?
While scanning the latest version of stockstats, we found · that a security review is needed. A total of · 0 vulnerabilities or license issues were · detected. See the full · security scan results.
🌐
snyk.io
snyk.io › advisor › python packages › stockstats
stockstats - Python Package Health Analysis | Snyk
🌐
GitHub
github.com › jealous › stockstats
GitHub - jealous/stockstats: Supply a wrapper ``StockDataFrame`` based on the ``pandas.DataFrame`` with inline stock statistics/indicators support.
Requires Python 3.9+. CI tests against Python 3.10, 3.11, 3.12, and 3.13. ... StockDataFrame works as a wrapper for pandas.DataFrame. Initialize it with wrap or StockDataFrame.retype. import pandas as pd from stockstats import wrap # from CSV df = wrap(pd.read_csv('stock.csv')) # from yfinance (disable multi-level index for compatibility) import yfinance as yf df = wrap(yf.download('AAPL', multi_level_index=False))
Starred by 1.4K users
Forked by 313 users
Languages   Python 100.0% | Python 100.0%
Top answer
1 of 1
4

MACD_EMA_SHORT is only a class method

  • you can't get it, unless you update the class
    • you need to return fast = df[ema_short]
  • MACD_EMA_SHORT is a parameter used for a calculation in _get_macd
    • MACD_EMA_SHORT = 12
    • ema_short = 'close_{}_ema'.format(cls.MACD_EMA_SHORT)
    • ema_short = 'close_12_ema'
class StockDataFrame(pd.DataFrame):
    OPERATORS = ['le', 'ge', 'lt', 'gt', 'eq', 'ne']

    # Start of options.
    KDJ_PARAM = (2.0 / 3.0, 1.0 / 3.0)
    KDJ_WINDOW = 9

    BOLL_PERIOD = 20
    BOLL_STD_TIMES = 2

    MACD_EMA_SHORT = 12
    MACD_EMA_LONG = 26
    MACD_EMA_SIGNAL = 9
    @classmethod
    def _get_macd(cls, df):
        """ Moving Average Convergence Divergence
        This function will initialize all following columns.
        MACD Line (macd): (12-day EMA - 26-day EMA)
        Signal Line (macds): 9-day EMA of MACD Line
        MACD Histogram (macdh): MACD Line - Signal Line
        :param df: data
        :return: None
        """
        ema_short = 'close_{}_ema'.format(cls.MACD_EMA_SHORT)
        ema_long = 'close_{}_ema'.format(cls.MACD_EMA_LONG)
        ema_signal = 'macd_{}_ema'.format(cls.MACD_EMA_SIGNAL)
        fast = df[ema_short]
        slow = df[ema_long]
        df['macd'] = fast - slow
        df['macds'] = df[ema_signal]
        df['macdh'] = (df['macd'] - df['macds'])
        log.critical("NOTE: Behavior of MACDH calculation has changed as of "
                     "July 2017 - it is now 1/2 of previous calculated values")
        cls._drop_columns(df, [ema_short, ema_long, ema_signal])

Update:

  • find stockstats.py, then in def _get_macd(cls, df), comment out cls._drop_columns(df, [ema_short, ema_long, ema_signal]) (e.g. put # in front of it)
  • Then you can do stock['close_12_ema']

Code to get the table:

periods = '3600'
resp = requests.get('https://api.cryptowat.ch/markets/poloniex/ethusdt/ohlc', params={'periods': periods})
data = resp.json()
df = pd.DataFrame(data['result'][periods], columns=['date', 'open', 'high', 'low', 'close', 'volume', 'amount'])
df['date'] = pd.to_datetime(df['date'], unit='s')

stock = sdf.retype(df)
print(stock['macds'])

print(stock)
  • The extra columns don't get added until you do stock['macds'].

OUtput:

                           open        high         low       close      volume        amount  close_12_ema  close_26_ema      macd  macd_9_ema     macds     macdh
date                                                                                                                                                               
2019-08-20 00:00:00  201.000000  203.379326  201.000000  202.138224  349.209128  70720.937575    202.138224    202.138224  0.000000    0.000000  0.000000  0.000000
2019-08-20 01:00:00  202.187160  202.650000  200.701061  200.778709  329.485014  66411.899720    201.401820    201.432322 -0.030502   -0.016946 -0.016946 -0.013556
2019-08-20 02:00:00  201.200000  201.558777  200.133667  200.338312   12.812929   2572.209909    200.986733    201.039255 -0.052522   -0.031526 -0.031526 -0.020996
2019-08-20 03:00:00  200.915590  201.177018  200.396571  200.440000   21.910910   4395.692727    200.814151    200.871730 -0.057579   -0.040352 -0.040352 -0.017227
2019-08-20 04:00:00  200.979999  200.979999  198.282603  198.644618  360.432424  71712.376256    200.224696    200.355253 -0.130557   -0.067186 -0.067186 -0.063371
🌐
The Python Code
thepythoncode.com › article › introduction-to-finance-and-technical-indicators-with-python
Introduction to Finance and Technical Indicators with Python - The Python Code
You will also learn to use many technical indicators using stockstats library. ... To import the stock prices data, we need to specify the symbol of the Market Index or Share, in this example, we will import data from S&P 500 and AAPL.
Find elsewhere
🌐
Medium
medium.com › codex › this-python-library-will-help-you-get-stock-technical-indicators-in-one-line-of-code-c11ed2c8e45f
This Python library will help you get Stock technical indicators in one line of code | by Nikhil Adithyan | CodeX | Medium
June 20, 2022 - pip install pandas pip install requests pip install numpy pip install matplotlib pip install stockstats · After finishing installing the packages, it’s time to import those into our python environment.
🌐
Medium
medium.com › @science4trading › introduction-to-stockstats-and-performance-of-some-key-indicators-d1af7274dde
Introduction to Stockstats and Performance of Some Key Indicators | by TradingScience | Medium
August 11, 2023 - To start using stockstats, it’s essential to install it first. Using pip: ... Once installed, simply import the library and use it on a pandas dataframe with your stock data. Here is a simple example importing historical data for AAPL using the yfinance library:
🌐
Towards Data Science
towardsdatascience.com › home › latest › stockstats – a handy, stocks-oriented pandas dataframe wrapper
Stockstats - a handy, stocks-oriented pandas DataFrame wrapper | Towards Data Science
March 5, 2025 - statistics – which measure we want to calculate. In the example above, we used the simple moving average (sma). For a list of all available metrics and their corresponding column names, you need to check the GitHub repo of stockstats.
🌐
Snyk
snyk.io › advisor › python packages › stockstats
stockstats - Python Package Health Analysis | Snyk
Visit Snyk Advisor to see a full health score report for stockstats, including popularity, security, maintenance & community analysis. The python package stockstats receives a total of 3,585 weekly downloads. As such, stockstats popularity was classified as a recognized.
🌐
Stack Overflow
stackoverflow.com › questions › 50123883 › python-what-structure-of-data-is-stockstats-expecting
dataframe - Python: What structure of data is stockstats expecting? - Stack Overflow
Looks to me like you need to change the column names. stockstats() expects the closing price to be named close, your dataframe calls it C. ... See the files in the test_data directory for examples of the expected input format.
🌐
Pydigger
pydigger.com › pypi › stockstats
stockstats
Examples: * Count how many typical prices are larger than close in the past 10 periods ``` python In [22]: tp = df['middle'] In [23]: df['res'] = df['middle'] > df['close'] In [24]: df[['middle', 'close', 'res', 'res_10_c']] Out[24]: middle close res res_10_c date 20040817 11.480000 11.20 True ...
🌐
GitHub
github.com › jealous › stockstats › blob › master › setup.py
stockstats/setup.py at master · jealous/stockstats
py_modules=['stockstats'], · platforms=['any'], · long_description=get_long_description(), · classifiers=[ · "Programming Language :: Python", · "Programming Language :: Python :: 3.9", · "Programming Language :: Python :: 3.10", ·
Author   jealous
🌐
Insider Finance
wire.insiderfinance.io › how-to-get-the-7-most-popular-trading-indicators-using-stockstats-in-python-8814bc6e6923
How to Get the 7 Most Popular Trading Indicators Using Stockstats in Python | by Kevin Meneses González | InsiderFinance Wire
September 2, 2024 - Using stockstats, you can easily compute the most popular trading indicators in Python, which can help you make more informed trading decisions. Each of these indicators has its unique advantages and can be used in combination to develop robust trading strategies. With the code examples provided, ...
🌐
GitHub
github.com › MarketLeader › Stock_Stats
GitHub - MappingSystem/syntax: Supply a wrapper ``StockDataFrame`` based on the ``pandas.DataFrame`` with inline stock statistics/indicators support.
The build checks the compatibility for the last two major releases of python3 and the last release of python2. ... StockDataFrame works as a wrapper for the pandas.DataFrame. You need to Initialize the StockDataFrame with wrap or StockDataFrame.retype. import pandas as pd from stockstats import wrap data = pd.read_csv('stock.csv') df = wrap(data)
Author   MappingSystem
🌐
Medium
medium.datadriveninvestor.com › simplify-your-stock-analysis-with-this-python-library-f86a7208b3d8
Simplify Your Stock Analysis with this Python Library | by Himanshu Sharma | DataDrivenInvestor
March 27, 2024 - Fortunately, there is a Python library that simplifies this task and allows you to get stock technical indicators in just one line of code. In this article, we will explore the power of this library and how it can enhance your stock analysis strategy. Stockstats, is a Python library that serves as a wrapper for Pandas data frames, offering a wide range of basic stock information and advanced technical indicators.
🌐
Pythonrepo
pythonrepo.com › repo › jealous-stockstats-python-finance
Supply a wrapper ``StockDataFrame`` based on the ``pandas.DataFrame`` with inline stock statistics/indicators support. | PythonRepo
December 9, 2021 - jealous/stockstats, Stock Statistics/Indicators Calculation Helper VERSION: 0.3.2 Introduction Supply a wrapper StockDataFrame based on the pandas.DataFrame with inline s