Skip to content

Commit

Permalink
Create data_loader.py
Browse files Browse the repository at this point in the history
  • Loading branch information
KOSASIH authored Aug 27, 2024
1 parent 486cb99 commit 9520a5e
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions market_analysis/data_loader.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import pandas as pd
import yfinance as yf

class DataLoader:
def __init__(self, ticker, start_date, end_date):
self.ticker = ticker
self.start_date = start_date
self.end_date = end_date
self.data = self.load_data()

def load_data(self):
data = yf.download(self.ticker, start=self.start_date, end=self.end_date)
data.reset_index(inplace=True)
data.rename(columns={'Date': 'date', 'Open': 'open', 'High': 'high', 'Low': 'low', 'Close': 'close', 'Volume': 'volume'}, inplace=True)
return data

def preprocess_data(self):
data = self.data.copy()
data['date'] = pd.to_datetime(data['date'])
data.set_index('date', inplace=True)
data.dropna(inplace=True)
return data

0 comments on commit 9520a5e

Please sign in to comment.