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]
- you need to return
- MACD_EMA_SHORT is a parameter used for a calculation in
_get_macdMACD_EMA_SHORT = 12ema_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 indef _get_macd(cls, df), comment outcls._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 OverflowPyPI
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
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
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
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
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
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
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
Videos
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%
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, ...
Reddit
reddit.com › r/algotrading › has anybody used the stockstats module , i can't get talib to work.
r/algotrading on Reddit: Has anybody used the stockstats module , I can't get Talib to work.
January 9, 2020 -
Ugh this has been killing my momentum bad on building this algo I'm so close but yet so far away from being done. I've come to terms that talib is just not going to install . I have stock stats installed and cannot get any of the functions to work and there seems to be know documentation. Idk this is just a shot in the dark but if anybody can help let me know
Top answer 1 of 3
1
I’m currently using the module and don’t have issues getting data from it. What kind of error do you get?
2 of 3
1
The code is far from being "readable" with the approach taken (which is in any case an interesting use of Python capabilities by getting to the desired combination of elements via string definition and parsing) But a couple of things are clear: The exponential moving averages, SMMA and EMA, which are respectively used in RSI and MACD are not properly defined (they are also used in several other indicators, so you guess ...) See this other thread in which several other Python libraries were mentioned ... all them make the same mistakes. https://www.reddit.com/r/algotrading/comments/ejveio/which_python_library_best_for_getting_technical/
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.
Roman Orac blog
romanorac.github.io › cryptocurrency › analysis › 2017 › 12 › 17 › cryptocurrency-analysis-with-python-part1.html
Cryptocurrency Analysis with Python - MACD | Roman Orac blog
December 17, 2017 - from stockstats import StockDataFrame df = StockDataFrame.retype(df) df['macd'] = df.get('macd') # calculate MACD