-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #50 from iamkrish-coder/develop
- Loading branch information
Showing
8 changed files
with
173 additions
and
14 deletions.
There are no files selected for viewing
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
def atr(dataset, period=14): | ||
# Check if dataset contains the required columns | ||
data = dataset if 'close' in dataset and 'high' in dataset and 'low' in dataset else None | ||
if data is not None and not data.empty: | ||
# Extract the necessary columns from the data | ||
close_prices = data['close'].astype(float) | ||
high_prices = data['high'].astype(float) | ||
low_prices = data['low'].astype(float) | ||
|
||
# Check if the data has sufficient length for ATR calculations | ||
if len(data) < period: | ||
return None | ||
|
||
true_ranges = [] | ||
for i in range(1, len(data)): | ||
high_low = high_prices[i] - low_prices[i] | ||
high_close = abs(high_prices[i] - close_prices[i - 1]) | ||
low_close = abs(low_prices[i] - close_prices[i - 1]) | ||
true_range = max(high_low, high_close, low_close) | ||
true_ranges.append(true_range) | ||
|
||
atr = [sum(true_ranges[:period]) / period] | ||
for i in range(period, len(true_ranges)): | ||
atr.append((atr[-1] * (period - 1) + true_ranges[i]) / period) | ||
|
||
return atr |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import pandas as pd | ||
|
||
def sma(dataset, period=5): | ||
# Check if dataset contains the required columns | ||
data = dataset if 'close' in dataset else None | ||
if data is not None and not data.empty: | ||
# Check if the data has sufficient length for SMA calculations | ||
if len(data) < period: | ||
return None | ||
return data['close'].ewm(span=period, adjust=False).mean() | ||
|
||
def ema(dataset, period=5): | ||
# Check if dataset contains the required columns | ||
data = dataset if 'close' in dataset else None | ||
if data is not None and not data.empty: | ||
# Check if the data has sufficient length for EMA calculations | ||
if len(data) < period: | ||
return None | ||
return data['close'].rolling(window=period).mean() |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import numpy as np | ||
|
||
def rsi(dataset, period=14): | ||
# Check if dataset contains the required columns | ||
data = dataset['close'] if 'close' in dataset else None | ||
# Check if data has sufficient length for RSI calculations | ||
if len(data) < period: | ||
return None | ||
|
||
close_prices = [float(x) for x in data] | ||
deltas = np.diff(close_prices) | ||
seed = deltas[:period + 1] | ||
up_periods = [] | ||
down_periods = [] | ||
|
||
up_periods.append(sum(x for x in seed if x >= 0) / period) | ||
down_periods.append(abs(sum(x for x in seed if x < 0) / period)) | ||
|
||
for i in range(period + 1, len(close_prices)): | ||
delta = deltas[i - 1] | ||
if delta > 0: | ||
up_periods.append((up_periods[-1] * (period - 1) + delta) / period) | ||
down_periods.append((down_periods[-1] * (period - 1)) / period) | ||
else: | ||
up_periods.append((up_periods[-1] * (period - 1)) / period) | ||
down_periods.append((down_periods[-1] * (period - 1) - delta) / period) | ||
|
||
rs = np.array(up_periods) / np.array(down_periods) | ||
rsi_line = 100 - (100 / (1 + rs)) | ||
return rsi_line |