Created
January 16, 2024 07:39
-
-
Save kapilgarg/945feccfca1f50e0450ceca28937946d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
""" | |
@author: KGarg | |
""" | |
import pandas as pd | |
def get_stock_price(): | |
import requests | |
data_dict={} | |
symbols = ['MSFT','AAPL','NFLX'] | |
path = r"stocks.csv" | |
for symbol in symbols: | |
url=f"https://query1.finance.yahoo.com/v7/finance/download/{symbol}?period1=1673783050&period2=1705319050&interval=1d&events=history&includeAdjustedClose=True" | |
headers = {'User-Agent': 'Mozilla/5.0'} | |
response = requests.get(url, headers=headers) | |
data = response.text | |
df = pd.DataFrame(map(lambda x:x.split(","), data.split("\n")[1:]),columns=data.split("\n")[0].split(",")) | |
data_dict[symbol]=df['Close'] | |
pd.DataFrame(data_dict).to_csv(path,index=False) | |
return path | |
def clean(file_path): | |
df = pd.read_csv(file_path) | |
df = df.dropna() | |
df.to_csv(file_path,index=False) | |
return file_path | |
def compute(file_path): | |
output = r'corr.csv' | |
df = pd.read_csv(file_path) | |
for column in df.columns: | |
df[column] = df[column].astype(float) | |
corr = df.corr() | |
corr.to_csv(output,index=False) | |
return output |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment