top of page
Writer's pictureIntrendias

Exponential Moving Average in Python

Learn how to calculate one of the most popular technical analysis measurements in python! Similar to the Simple Moving Average (SMA), the Exponential Moving Average (EMA) is a rolling average value that adds some spice! The EMA has additional weight on values closer to the present day to increase the importance of most recent data. This blog post will show you how to perform Exponential Moving Averages in Python!



stock trader looking at charts


Import Needed Libraries

import yfinance as yf 
import pandas as pd 
import matplotlib.pyplot as plt 
from datetime import timedelta, datetime, date

Create a Custom Yahoo Finance GET Data Function

def GetYahooFinanceData(ticker, start, end):
    formatDate = "%Y-%m-%d"
    
    # Add 1 day to end date
    end = datetime.strptime(end, formatDate)
    end = end + timedelta(days = 1) #add one day to end date to get desired result
    end = end.strftime(formatDate) #converts back to a string type date 
    
    df = yf.download(ticker, start, end)
    return df 
symbol = 'AAPL'
stock_data = GetYahooFinanceData(symbol,'2022-01-01','2024-02-15')
stock_data

[*********************100%%**********************] 1 of 1 completed

Want to read more?

Subscribe to intrendias.com to keep reading this exclusive post.

38 views0 comments
bottom of page