<jupyter_start><jupyter_text>4 Common Stock Indicators Trend<jupyter_code>import numpy as np
import pandas as pd
import matplotlib.pyplot as plt

import warnings
warnings.filterwarnings("ignore")

# fix_yahoo_finance is used to fetch data 
import fix_yahoo_finance as yf
yf.pdr_override()
# input
symbol = 'AAPL'
start = '2014-01-01'
end = '2018-12-31'

# Read data 
df = yf.download(symbol,start,end)

# View Columns
df.head()
import talib as ta<jupyter_output><empty_output><jupyter_text>Simple Moving Averages Moving averages is a "smooth" price data that is created in a single flowing line. Therefore, the line represents the average price over a period of time. Traders use the moving average to decides to determined the time frame in which he or she trades. On the other hand, investors use moving averages for long-term trend and they use the 200-day, 100-day and 50-day simple moving average.<jupyter_code>sma = ta.SMA(df['Adj Close'])
sma
plt.figure(figsize=(14,10))
plt.plot(df['Adj Close'])
plt.plot(sma.dropna(), label='SMA')
plt.legend(loc='best')
plt.title('SMA')
plt.xlabel('Date')
plt.ylabel('Price')
plt.show()<jupyter_output><empty_output><jupyter_text>RSI (Relative Strength Index)  RSI is similar to oscillator because its movement that is between 0 and 100.<jupyter_code>rsi = ta.RSI(df['Adj Close'], timeperiod=14)
rsi = rsi.dropna()
rsi
fig, ax = plt.subplots(figsize=(14,10))
plt.plot(df['Adj Close'])
plt.plot(rsi)
ax.axhline(y=80,color='r')
ax.axhline(y=20,color='r')
plt.text(s='Overbought', x=rsi.index[0], y=80, fontsize=14)
plt.text(s='OverSold', x=rsi.index[0], y=20, fontsize=14)
plt.legend()
p = plt.setp(ax.xaxis.get_majorticklabels(), rotation=90, fontsize=8)<jupyter_output><empty_output><jupyter_text>MACD (Moving Average Convergence Divergence) MACD is an oscillating indicator and it has trend-following and momentum indicator.<jupyter_code>macd, macdsignal, macdhist = ta.MACD(df['Adj Close'], fastperiod=12, slowperiod=26, signalperiod=9)
macd = macd.dropna()
macd
fig, ax = plt.subplots(figsize=(14,10))
plt.plot(df['Adj Close'])
plt.plot(macd)
plt.plot(macdhist.dropna())
plt.plot(macdsignal.dropna())
ax.axhline(y=0,color='r', label='Base Line', linestyle='--')
plt.legend()
plt.show()<jupyter_output><empty_output><jupyter_text>On-Balance Volume (OBV)  OBV is a valuable indicator that uses volumen information to created single line indicator. On the other hand, the indicator is a measurement of cumulative buying and selling pressure by adding the bolume on up days and minus volume on down days.<jupyter_code>obv = ta.OBV(df['Adj Close'], df['Volume'])
obv
plt.subplots(figsize=(14,10))
plt.subplot(2, 1, 1)
plt.plot(df['Adj Close'], color ='g', label='Close')
plt.title('Closing Price')
plt.ylabel('Price')
plt.legend()

plt.subplot(2, 1, 2)
plt.plot(obv, '-', label='OBV')
plt.xlabel('Date')
plt.legend()

plt.show()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1407381855812349, 'fraction_numerical': 0.026215936529837874, 'mean_word_length': 6.512953367875648, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '535423', 'license': 'MIT', 'n_tokens_mistral': 1145, 'n_tokens_neox': 1049, 'n_words': 283, 'path': '16_SimpleStockIndicators.ipynb', 'repo_name': 'rogerolowski/SimpleStockAnalysisPython', 'size': '2899'}