Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

some formatting fixes #33

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions pyti/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
'''THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND
NON-INFRINGEMENT. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR ANYONE
DISTRIBUTING THE SOFTWARE BE LIABLE FOR ANY DAMAGES OR OTHER LIABILITY,
WHETHER IN CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.'''

# Bitcoin Cash (BCH) qpz32c4lg7x7lnk9jg6qg7s4uavdce89myax5v5nuk
# Ether (ETH) - 0x843d3DEC2A4705BD4f45F674F641cE2D0022c9FB
# Litecoin (LTC) - Lfk5y4F7KZa9oRxpazETwjQnHszEPvqPvu
# Bitcoin (BTC) - 34L8qWiQyKr8k4TnHDacfjbaSqQASbBtTd

# contact :- [email protected]



33 changes: 23 additions & 10 deletions pyti/accumulation_distribution.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,21 @@
'''THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND
NON-INFRINGEMENT. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR ANYONE
DISTRIBUTING THE SOFTWARE BE LIABLE FOR ANY DAMAGES OR OTHER LIABILITY,
WHETHER IN CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.'''

# Bitcoin Cash (BCH) qpz32c4lg7x7lnk9jg6qg7s4uavdce89myax5v5nuk
# Ether (ETH) - 0x843d3DEC2A4705BD4f45F674F641cE2D0022c9FB
# Litecoin (LTC) - Lfk5y4F7KZa9oRxpazETwjQnHszEPvqPvu
# Bitcoin (BTC) - 34L8qWiQyKr8k4TnHDacfjbaSqQASbBtTd

# contact :- [email protected]



from __future__ import absolute_import
import numpy as np
from pyti import catch_errors
Expand All @@ -11,17 +29,12 @@ def accumulation_distribution(close_data, high_data, low_data, volume):
Formula:
A/D = (Ct - Lt) - (Ht - Ct) / (Ht - Lt) * Vt + A/Dt-1
"""
catch_errors.check_for_input_len_diff(
close_data, high_data, low_data, volume
)
catch_errors.check_for_input_len_diff(close_data, high_data, low_data,
volume)

ad = np.zeros(len(close_data))
for idx in range(1, len(close_data)):
ad[idx] = (
(((close_data[idx] - low_data[idx]) -
(high_data[idx] - close_data[idx])) /
(high_data[idx] - low_data[idx]) *
volume[idx]) +
ad[idx-1]
)
ad[idx] = (((close_data[idx] - low_data[idx]) -
(high_data[idx] - close_data[idx])) /
(high_data[idx] - low_data[idx]) * volume[idx]) + ad[idx - 1]
return ad
30 changes: 24 additions & 6 deletions pyti/aroon.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,21 @@
'''THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND
NON-INFRINGEMENT. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR ANYONE
DISTRIBUTING THE SOFTWARE BE LIABLE FOR ANY DAMAGES OR OTHER LIABILITY,
WHETHER IN CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.'''

# Bitcoin Cash (BCH) qpz32c4lg7x7lnk9jg6qg7s4uavdce89myax5v5nuk
# Ether (ETH) - 0x843d3DEC2A4705BD4f45F674F641cE2D0022c9FB
# Litecoin (LTC) - Lfk5y4F7KZa9oRxpazETwjQnHszEPvqPvu
# Bitcoin (BTC) - 34L8qWiQyKr8k4TnHDacfjbaSqQASbBtTd

# contact :- [email protected]



from __future__ import absolute_import
import numpy as np
from pyti import catch_errors
Expand All @@ -15,9 +33,9 @@ def aroon_up(data, period):
catch_errors.check_for_period_error(data, period)
period = int(period)

a_up = [((period -
list(reversed(data[idx+1-period:idx+1])).index(np.max(data[idx+1-period:idx+1]))) /
float(period)) * 100 for idx in range(period-1, len(data))]
a_up = [((period - list(reversed(data[idx + 1 - period:idx + 1])).index(
np.max(data[idx + 1 - period:idx + 1]))) / float(period)) * 100
for idx in range(period - 1, len(data))]
a_up = fill_for_noncomputable_vals(data, a_up)
return a_up

Expand All @@ -32,8 +50,8 @@ def aroon_down(data, period):
catch_errors.check_for_period_error(data, period)
period = int(period)

a_down = [((period -
list(reversed(data[idx+1-period:idx+1])).index(np.min(data[idx+1-period:idx+1]))) /
float(period)) * 100 for idx in range(period-1, len(data))]
a_down = [((period - list(reversed(data[idx + 1 - period:idx + 1])).index(
np.min(data[idx + 1 - period:idx + 1]))) / float(period)) * 100
for idx in range(period - 1, len(data))]
a_down = fill_for_noncomputable_vals(data, a_down)
return a_down
20 changes: 19 additions & 1 deletion pyti/average_true_range.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,21 @@
'''THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND
NON-INFRINGEMENT. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR ANYONE
DISTRIBUTING THE SOFTWARE BE LIABLE FOR ANY DAMAGES OR OTHER LIABILITY,
WHETHER IN CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.'''

# Bitcoin Cash (BCH) qpz32c4lg7x7lnk9jg6qg7s4uavdce89myax5v5nuk
# Ether (ETH) - 0x843d3DEC2A4705BD4f45F674F641cE2D0022c9FB
# Litecoin (LTC) - Lfk5y4F7KZa9oRxpazETwjQnHszEPvqPvu
# Bitcoin (BTC) - 34L8qWiQyKr8k4TnHDacfjbaSqQASbBtTd

# contact :- [email protected]



from __future__ import absolute_import
import numpy as np
from pyti.true_range import true_range
Expand All @@ -14,5 +32,5 @@ def average_true_range(close_data, period):
"""
tr = true_range(close_data, period)
atr = smoothed_moving_average(tr, period)
atr[0:period-1] = tr[0:period-1]
atr[0:period - 1] = tr[0:period - 1]
return atr
22 changes: 19 additions & 3 deletions pyti/average_true_range_percent.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,25 @@
'''THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND
NON-INFRINGEMENT. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR ANYONE
DISTRIBUTING THE SOFTWARE BE LIABLE FOR ANY DAMAGES OR OTHER LIABILITY,
WHETHER IN CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.'''

# Bitcoin Cash (BCH) qpz32c4lg7x7lnk9jg6qg7s4uavdce89myax5v5nuk
# Ether (ETH) - 0x843d3DEC2A4705BD4f45F674F641cE2D0022c9FB
# Litecoin (LTC) - Lfk5y4F7KZa9oRxpazETwjQnHszEPvqPvu
# Bitcoin (BTC) - 34L8qWiQyKr8k4TnHDacfjbaSqQASbBtTd

# contact :- [email protected]



from __future__ import absolute_import
import numpy as np
from pyti import catch_errors
from pyti.average_true_range import (
average_true_range as atr
)
from pyti.average_true_range import average_true_range as atr


def average_true_range_percent(close_data, period):
Expand Down
43 changes: 27 additions & 16 deletions pyti/bollinger_bands.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,26 @@
'''THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND
NON-INFRINGEMENT. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR ANYONE
DISTRIBUTING THE SOFTWARE BE LIABLE FOR ANY DAMAGES OR OTHER LIABILITY,
WHETHER IN CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.'''

# Bitcoin Cash (BCH) qpz32c4lg7x7lnk9jg6qg7s4uavdce89myax5v5nuk
# Ether (ETH) - 0x843d3DEC2A4705BD4f45F674F641cE2D0022c9FB
# Litecoin (LTC) - Lfk5y4F7KZa9oRxpazETwjQnHszEPvqPvu
# Bitcoin (BTC) - 34L8qWiQyKr8k4TnHDacfjbaSqQASbBtTd

# contact :- [email protected]



from __future__ import absolute_import
import numpy as np
from pyti import catch_errors
from pyti.function_helper import fill_for_noncomputable_vals
from pyti.simple_moving_average import (
simple_moving_average as sma
)
from pyti.simple_moving_average import simple_moving_average as sma
from six.moves import range


Expand All @@ -18,7 +34,7 @@ def upper_bollinger_band(data, period, std_mult=2.0):
catch_errors.check_for_period_error(data, period)

period = int(period)
simple_ma = sma(data, period)[period-1:]
simple_ma = sma(data, period)[period - 1:]

upper_bb = []
for idx in range(len(data) - period + 1):
Expand Down Expand Up @@ -54,7 +70,7 @@ def lower_bollinger_band(data, period, std=2.0):
catch_errors.check_for_period_error(data, period)

period = int(period)
simple_ma = sma(data, period)[period-1:]
simple_ma = sma(data, period)[period - 1:]

lower_bb = []
for idx in range(len(data) - period + 1):
Expand All @@ -75,10 +91,8 @@ def bandwidth(data, period, std=2.0):
catch_errors.check_for_period_error(data, period)

period = int(period)
bandwidth = ((upper_bollinger_band(data, period, std) -
lower_bollinger_band(data, period, std)) /
middle_bollinger_band(data, period, std)
)
bandwidth = (upper_bollinger_band(data, period, std) - lower_bollinger_band(
data, period, std)) / middle_bollinger_band(data, period, std)

return bandwidth

Expand All @@ -93,9 +107,8 @@ def bb_range(data, period, std=2.0):
catch_errors.check_for_period_error(data, period)

period = int(period)
bb_range = (upper_bollinger_band(data, period, std) -
lower_bollinger_band(data, period, std)
)
bb_range = upper_bollinger_band(data, period, std) - lower_bollinger_band(
data, period, std)
return bb_range


Expand All @@ -109,10 +122,8 @@ def percent_bandwidth(data, period, std=2.0):
catch_errors.check_for_period_error(data, period)

period = int(period)
percent_bandwidth = ((np.array(data) -
lower_bollinger_band(data, period, std)) /
bb_range(data, period, std)
)
percent_bandwidth = (np.array(data) - lower_bollinger_band(
data, period, std)) / bb_range(data, period, std)

return percent_bandwidth

Expand Down
17 changes: 17 additions & 0 deletions pyti/catch_errors.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,20 @@
'''THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND
NON-INFRINGEMENT. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR ANYONE
DISTRIBUTING THE SOFTWARE BE LIABLE FOR ANY DAMAGES OR OTHER LIABILITY,
WHETHER IN CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.'''

# Bitcoin Cash (BCH) qpz32c4lg7x7lnk9jg6qg7s4uavdce89myax5v5nuk
# Ether (ETH) - 0x843d3DEC2A4705BD4f45F674F641cE2D0022c9FB
# Litecoin (LTC) - Lfk5y4F7KZa9oRxpazETwjQnHszEPvqPvu
# Bitcoin (BTC) - 34L8qWiQyKr8k4TnHDacfjbaSqQASbBtTd

# contact :- [email protected]



def check_for_period_error(data, period):
"""
Expand Down
37 changes: 31 additions & 6 deletions pyti/chaikin_money_flow.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,21 @@
'''THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND
NON-INFRINGEMENT. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR ANYONE
DISTRIBUTING THE SOFTWARE BE LIABLE FOR ANY DAMAGES OR OTHER LIABILITY,
WHETHER IN CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.'''

# Bitcoin Cash (BCH) qpz32c4lg7x7lnk9jg6qg7s4uavdce89myax5v5nuk
# Ether (ETH) - 0x843d3DEC2A4705BD4f45F674F641cE2D0022c9FB
# Litecoin (LTC) - Lfk5y4F7KZa9oRxpazETwjQnHszEPvqPvu
# Bitcoin (BTC) - 34L8qWiQyKr8k4TnHDacfjbaSqQASbBtTd

# contact :- [email protected]



from __future__ import absolute_import
import numpy as np
from pyti import catch_errors
Expand All @@ -12,17 +30,24 @@ def chaikin_money_flow(close_data, high_data, low_data, volume, period):
Formula:
CMF = SUM[(((Cn - Ln) - (Hn - Cn)) / (Hn - Ln)) * V] / SUM(Vn)
"""
catch_errors.check_for_input_len_diff(
close_data, high_data, low_data, volume)
catch_errors.check_for_input_len_diff(close_data, high_data, low_data,
volume)
catch_errors.check_for_period_error(close_data, period)

close_data = np.array(close_data)
high_data = np.array(high_data)
low_data = np.array(low_data)
volume = np.array(volume)
cmf = [sum((((close_data[idx+1-period:idx+1] - low_data[idx+1-period:idx+1]) -
(high_data[idx+1-period:idx+1] - close_data[idx+1-period:idx+1])) /
(high_data[idx+1-period:idx+1] - low_data[idx+1-period:idx+1])) *
volume[idx+1-period:idx+1]) / sum(volume[idx+1-period:idx+1]) for idx in range(period-1, len(close_data))]
cmf = [
sum((((close_data[idx + 1 - period:idx + 1] -
low_data[idx + 1 - period:idx + 1]) -
(high_data[idx + 1 - period:idx + 1] -
close_data[idx + 1 - period:idx + 1])) /
(high_data[idx + 1 - period:idx + 1] -
low_data[idx + 1 - period:idx + 1])) *
volume[idx + 1 - period:idx + 1]) /
sum(volume[idx + 1 - period:idx + 1])
for idx in range(period - 1, len(close_data))
]
cmf = fill_for_noncomputable_vals(close_data, cmf)
return cmf
26 changes: 24 additions & 2 deletions pyti/chande_momentum_oscillator.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,21 @@
'''THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND
NON-INFRINGEMENT. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR ANYONE
DISTRIBUTING THE SOFTWARE BE LIABLE FOR ANY DAMAGES OR OTHER LIABILITY,
WHETHER IN CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.'''

# Bitcoin Cash (BCH) qpz32c4lg7x7lnk9jg6qg7s4uavdce89myax5v5nuk
# Ether (ETH) - 0x843d3DEC2A4705BD4f45F674F641cE2D0022c9FB
# Litecoin (LTC) - Lfk5y4F7KZa9oRxpazETwjQnHszEPvqPvu
# Bitcoin (BTC) - 34L8qWiQyKr8k4TnHDacfjbaSqQASbBtTd

# contact :- [email protected]



from __future__ import absolute_import
import numpy as np
import warnings
Expand All @@ -16,8 +34,12 @@ def chande_momentum_oscillator(close_data, period):

close_data = np.array(close_data)

moving_period_diffs = [[(close_data[idx+1-period:idx+1][i] -
close_data[idx+1-period:idx+1][i-1]) for i in range(1, len(close_data[idx+1-period:idx+1]))] for idx in range(0, len(close_data))]
moving_period_diffs = [[
(close_data[idx + 1 - period:idx + 1][i] -
close_data[idx + 1 - period:idx + 1][i - 1])
for i in range(1, len(close_data[idx + 1 - period:idx + 1]))
]
for idx in range(0, len(close_data))]

sum_up = []
sum_down = []
Expand Down
Loading