Skip to content

Commit

Permalink
task two moduls added
Browse files Browse the repository at this point in the history
  • Loading branch information
dagiteferi committed Dec 15, 2024
1 parent b662ab3 commit 95514a9
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 0 deletions.
22 changes: 22 additions & 0 deletions scripts/task2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import sys
import os

# Add src directory to the Python path
src_path = os.path.abspath(os.path.join(os.path.dirname(__file__), '../src'))
sys.path.append(src_path)

import preprocessing as dp
import indicat as ind
import visual as vis

# Example usage
def main():
file_path = '../data/amazon.csv'
data = dp.load_data(file_path)
data = ind.calculate_indicators(data)
vis.plot_moving_averages(data, 'Stock_price_moving_average.png')
vis.plot_rsi(data, 'relative_strength_index.png')
vis.plot_macd(data, 'macd_signals.png')

if __name__ == '__main__':
main()
13 changes: 13 additions & 0 deletions src/indicat.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import pandas_ta as ta

def calculate_indicators(data):
"""Calculate technical indicators."""
data['SMA_50'] = ta.sma(data['Close'], length=50)
data['SMA_200'] = ta.sma(data['Close'], length=200)
data['RSI'] = ta.rsi(data['Close'], length=14)

macd = ta.macd(data['Close'], fast=12, slow=26, signal=9)
data['MACD'] = macd['MACD_12_26_9']
data['MACD_signal'] = macd['MACDs_12_26_9']
data['MACD_hist'] = macd['MACDh_12_26_9']
return data
13 changes: 13 additions & 0 deletions src/preprocessing.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import pandas_ta as ta

def calculate_indicators(data):
"""Calculate technical indicators."""
data['SMA_50'] = ta.sma(data['Close'], length=50)
data['SMA_200'] = ta.sma(data['Close'], length=200)
data['RSI'] = ta.rsi(data['Close'], length=14)

macd = ta.macd(data['Close'], fast=12, slow=26, signal=9)
data['MACD'] = macd['MACD_12_26_9']
data['MACD_signal'] = macd['MACDs_12_26_9']
data['MACD_hist'] = macd['MACDh_12_26_9']
return data
13 changes: 13 additions & 0 deletions src/visual.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import pandas_ta as ta

def calculate_indicators(data):
"""Calculate technical indicators."""
data['SMA_50'] = ta.sma(data['Close'], length=50)
data['SMA_200'] = ta.sma(data['Close'], length=200)
data['RSI'] = ta.rsi(data['Close'], length=14)

macd = ta.macd(data['Close'], fast=12, slow=26, signal=9)
data['MACD'] = macd['MACD_12_26_9']
data['MACD_signal'] = macd['MACDs_12_26_9']
data['MACD_hist'] = macd['MACDh_12_26_9']
return data

0 comments on commit 95514a9

Please sign in to comment.