This repository has been archived by the owner on Feb 20, 2019. It is now read-only.
forked from CryptoSignal/Crypto-Signal
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
shads2
committed
Dec 29, 2017
1 parent
eab9214
commit 18188e5
Showing
6 changed files
with
98 additions
and
62 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,48 +1,61 @@ | ||
# Improvemnts to calculate_rsi are courtesy of community contributor "pcartwright81" | ||
def calculate_rsi(coin_pair, period, unit): | ||
""" | ||
Runs the breakout strategy over the market data | ||
""" | ||
|
||
from strategies.strategy_utils import Utils | ||
|
||
class RelativeStrengthIndex(): | ||
""" | ||
Calculates the Relative Strength Index for a coin_pair | ||
If the returned value is above 70, it's overbought (SELL IT!) | ||
If the returned value is below 30, it's oversold (BUY IT!) | ||
Runs the breakout strategy over the market data | ||
""" | ||
closing_prices = get_closing_prices(coin_pair, period * 3, unit) | ||
count = 0 | ||
changes = [] | ||
# Calculating price changes | ||
for closing_price in closing_prices: | ||
if count != 0: | ||
changes.append(closing_price - closing_prices[count - 1]) | ||
count += 1 | ||
if count == 15: | ||
break | ||
|
||
# Calculating gains and losses | ||
advances = [] | ||
declines = [] | ||
for change in changes: | ||
if change > 0: | ||
advances.append(change) | ||
if change < 0: | ||
declines.append(abs(change)) | ||
# Improvemnts to calculate_rsi are courtesy of community contributor "pcartwright81" | ||
def find_rsi(self, historical_data): | ||
""" | ||
Calculates the Relative Strength Index for a coin_pair | ||
If the returned value is above 70, it's overbought (SELL IT!) | ||
If the returned value is below 30, it's oversold (BUY IT!) | ||
""" | ||
utils = Utils() | ||
closing_prices = utils.get_closing_prices(historical_data) | ||
count = 0 | ||
changes = [] | ||
|
||
average_gain = (sum(advances) / 14) | ||
average_loss = (sum(declines) / 14) | ||
new_average_gain = average_gain | ||
new_average_loss = average_loss | ||
for closing_price in closing_prices: | ||
if count > 14 and count < len(closing_prices): | ||
close = closing_prices[count] | ||
new_change = close - closing_prices[count - 1] | ||
add_loss = 0 | ||
add_gain = 0 | ||
if new_change > 0: | ||
add_gain = new_change | ||
if new_change < 0: | ||
add_loss = abs(new_change) | ||
new_average_gain = (new_average_gain * 13 + add_gain) / 14 | ||
new_average_loss = (new_average_loss * 13 + add_loss) / 14 | ||
# Calculating price changes | ||
for closing_price in closing_prices: | ||
if count != 0: | ||
changes.append(closing_price - closing_prices[count - 1]) | ||
count += 1 | ||
if count == 15: | ||
break | ||
|
||
# Calculating gains and losses | ||
advances = [] | ||
declines = [] | ||
for change in changes: | ||
if change > 0: | ||
advances.append(change) | ||
if change < 0: | ||
declines.append(abs(change)) | ||
|
||
average_gain = (sum(advances) / 14) | ||
average_loss = (sum(declines) / 14) | ||
new_average_gain = average_gain | ||
new_average_loss = average_loss | ||
for closing_price in closing_prices: | ||
if count > 14 and count < len(closing_prices): | ||
close = closing_prices[count] | ||
new_change = close - closing_prices[count - 1] | ||
add_loss = 0 | ||
add_gain = 0 | ||
if new_change > 0: | ||
add_gain = new_change | ||
if new_change < 0: | ||
add_loss = abs(new_change) | ||
new_average_gain = (new_average_gain * 13 + add_gain) / 14 | ||
new_average_loss = (new_average_loss * 13 + add_loss) / 14 | ||
count += 1 | ||
|
||
rs = new_average_gain / new_average_loss | ||
new_rs = 100 - 100 / (1 + rs) | ||
return new_rs | ||
rs = new_average_gain / new_average_loss | ||
new_rs = 100 - 100 / (1 + rs) | ||
return new_rs |
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,16 @@ | ||
""" | ||
Helper functions for the various strategies | ||
""" | ||
|
||
class Utils(): | ||
""" | ||
Helper functions for the various strategies | ||
""" | ||
def get_closing_prices(self, historical_data): | ||
""" | ||
Returns closing prices within a specified time frame for a coin pair | ||
""" | ||
closing_prices = [] | ||
for data_point in historical_data: | ||
closing_prices.append(data_point['C']) | ||
return closing_prices |
This file was deleted.
Oops, something went wrong.