voice32 / stock_market_indicators Goto Github PK
View Code? Open in Web Editor NEWA small Python library with most common stock market indicators
A small Python library with most common stock market indicators
Thanks for sharing this work. I try to understand it by running some sscripts. In the script for calculating the 'Accumulation Distribution', it returns the error that I mention in the title.
`import pandas as pd
import yfinance as yf
def acc_dist(data, trend_periods=21, open_col='Open', high_col='High', low_col='Low', close_col='Close', vol_col='Volume'):
for index, row in data.iterrows():
if row[high_col] != row[low_col]:
ac = ((row[close_col] - row[low_col]) - (row[high_col] - row[close_col])) / (row[high_col] - row[low_col]) * row[vol_col]
else:
ac = 0
data.set_value(index, 'acc_dist', ac)
data['acc_dist_ema' + str(trend_periods)] = data['acc_dist'].ewm(ignore_na=False, min_periods=0, com=trend_periods, adjust=True).mean()
return data
n = 14
data = df = yf.download('AAPL', start= start_day, end = end_day)
data = acc_dist(df_val, trend_periods=21, open_col='Open>', high_col='High', low_col='Low', close_col=nom_val, vol_col='Volume')
`
Me devuelve,
`[100%**] 1 of 1 completed
AttributeError Traceback (most recent call last)
/tmp/ipykernel_2963/3008653052.py in
33
34 data = df = yf.download('AAPL', start= start_day, end = end_day)
---> 35 data = acc_dist(df_val, trend_periods=21, open_col='Open>', high_col='High', low_col='Low', close_col=nom_val, vol_col='Volume')
36
/tmp/ipykernel_2963/3008653052.py in acc_dist(data, trend_periods, open_col, high_col, low_col, close_col, vol_col)
27 else:
28 ac = 0
---> 29 data.set_value(index, 'acc_dist', ac)
30 data['acc_dist_ema' + str(trend_periods)] = data['acc_dist'].ewm(ignore_na=False, min_periods=0, com=trend_periods, adjust=True).mean()
31
~/anaconda3/envs/yfinance/lib/python3.9/site-packages/pandas/core/generic.py in getattr(self, name)
5485 ):
5486 return self[name]
-> 5487 return object.getattribute(self, name)
5488
5489 def setattr(self, name: str, value) -> None:
AttributeError: 'DataFrame' object has no attribute 'set_value'`
What can be the cause?
Dear all. When executing the function that calculates the MACD, it gives me the following error show on the titlle.
`import pandas as pd
import yfinance as yf
def macd(data, period_long=26, period_short=12, period_signal=9, column='Close'):
remove_cols = []
if not 'ema' + str(period_long) in data.columns:
data = ema(data, period_long)
remove_cols.append('ema' + str(period_long))
if not 'ema' + str(period_short) in data.columns:
data = ema(data, period_short)
remove_cols.append('ema' + str(period_short))
data['macd_val'] = data['ema' + str(period_short)] - data['ema' + str(period_long)]
data['macd_signal_line'] = data['macd_val'].ewm(ignore_na=False, min_periods=0, com=period_signal, adjust=True).mean()
data = data.drop(remove_cols, axis=1)
return data
data = yf.download('AAPL', start= '2016-1-4', end = '2021-12-30')
data = macd(data, period_long=26, period_short=12, period_signal=9, column='Close')
data
NameError Traceback (most recent call last)
/tmp/ipykernel_12947/116451859.py in
21 data = yf.download('AAPL', start= '2016-1-4', end = '2021-12-30')
22
---> 23 data = macd(data, period_long=26, period_short=12, period_signal=9, column='Close')
24 data
/tmp/ipykernel_12947/116451859.py in macd(data, period_long, period_short, period_signal, column)
5 remove_cols = []
6 if not 'ema' + str(period_long) in data.columns:
----> 7 data = ema(data, period_long)
8 remove_cols.append('ema' + str(period_long))
9
NameError: name 'ema' is not defined`
I don't understand this error. I will appreciate clarification
I don't understand this error.
There was an indentation problem that didn't allow the library to be imported.
problem solved in this version.
I posted and solved the problem here https://stackoverflow.com/questions/53404707/python-import-a-non-standard-library/53404742#53404742
Hi! thank you for the code! looks promissing, cant wait to use it.
Im having problems importing the library though. any suggestions on how to do it?
I posted the problem here:
https://stackoverflow.com/questions/53404707/python-import-a-non-standard-library/53404742#53404742
Money Flow Multiplier = [(Close - Low) - (High - Close)] /(High - Low)
Money Flow Volume = Money Flow Multiplier x Volume for the Period
ADL = Previous ADL + Current Period's Money Flow Volume
Chaikin Oscillator = (3-day EMA of ADL) - (10-day EMA of ADL)
Функция не учитывает предыдущее значение ADL, а в целом спасибо!
ADL = Previous ADL + Current Period's Money Flow Volume
def chaikin_oscillator(data, periods_short=3, periods_long=10, high_col='',
low_col='', close_col='', vol_col=''):
ac = pd.Series([])
val_last = 0
for index, row in data.iterrows():
if row[high_col] != row[low_col]:
val = val_last + ((row[close_col] - row[low_col]) - (row[high_col] - row[close_col])) / (row[high_col] - row[low_col]) * row[vol_col]
else:
val = val_last
ac.set_value(index, val)
val_last = val
ema_long = ac.ewm(ignore_na=False, min_periods=0, com=periods_long, adjust=True).mean()
ema_short = ac.ewm(ignore_na=False, min_periods=0, com=periods_short, adjust=True).mean()
data['ch_osc'] = ema_short - ema_long
return data
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.