# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: 'Python 3.8.10 64-bit (''crypto'': conda)'
#     name: python3
# ---

# # Indicators

import pandas as pd
import talib as ta

# ## Sources

btc_yahoo = pd.read_csv('/home/giujorge/datalake/lab/Crypto/crypto/data/external/yahoo/daily/usd/BTC-USD.csv', parse_dates=True, index_col=0)
btc_yahoo.head()

# ## Pattern Recognition

## CDL2CROWS - Two Crows
btc_yahoo['CDL2CROWS'] = ta.CDL2CROWS(btc_yahoo["Open"], btc_yahoo['High'], btc_yahoo['Low'], btc_yahoo["Adj Close"])

## CDL3BLACKCROWS - Three Black Crows
btc_yahoo['CDL3BLACKCROWS'] = ta.CDL3BLACKCROWS(btc_yahoo["Open"], btc_yahoo['High'], btc_yahoo['Low'], btc_yahoo["Adj Close"])

## CDL3INSIDE - Three Inside Up/Down
btc_yahoo['CDL3INSIDE'] = ta.CDL3INSIDE(btc_yahoo["Open"], btc_yahoo['High'], btc_yahoo['Low'], btc_yahoo["Adj Close"])

## CDL3LINESTRIKE - Three-Line Strike
btc_yahoo['CDL3LINESTRIKE'] = ta.CDL3LINESTRIKE(btc_yahoo["Open"], btc_yahoo['High'], btc_yahoo['Low'], btc_yahoo["Adj Close"])

## CDL3OUTSIDE - Three Outside Up/Down
btc_yahoo['CDL3OUTSIDE'] = ta.CDL3OUTSIDE(btc_yahoo["Open"], btc_yahoo['High'], btc_yahoo['Low'], btc_yahoo["Adj Close"])

## CDL3STARSINSOUTH - Three Stars In The South
btc_yahoo['CDL3STARSINSOUTH'] = ta.CDL3STARSINSOUTH(btc_yahoo["Open"], btc_yahoo['High'], btc_yahoo['Low'], btc_yahoo["Adj Close"])

## CDL3WHITESOLDIERS - Three Advancing White Soldiers
btc_yahoo['CDL3WHITESOLDIERS'] = ta.CDL3WHITESOLDIERS(btc_yahoo["Open"], btc_yahoo['High'], btc_yahoo['Low'], btc_yahoo["Adj Close"])

## CDLABANDONEDBABY - Abandoned Baby
btc_yahoo['CDLABANDONEDBABY'] = ta.CDLABANDONEDBABY(btc_yahoo["Open"], btc_yahoo['High'], btc_yahoo['Low'], btc_yahoo["Adj Close"])

## CDLADVANCEBLOCK - Advance Block
btc_yahoo['CDLADVANCEBLOCK'] = ta.CDLADVANCEBLOCK(btc_yahoo["Open"], btc_yahoo['High'], btc_yahoo['Low'], btc_yahoo["Adj Close"])

## CDLBELTHOLD - Belt-hold
btc_yahoo['CDLBELTHOLD'] =ta.CDLBELTHOLD(btc_yahoo["Open"], btc_yahoo['High'], btc_yahoo['Low'], btc_yahoo["Adj Close"])

## CDLBREAKAWAY - Breakaway
btc_yahoo['CDLBREAKAWAY'] =ta.CDLBREAKAWAY(btc_yahoo["Open"], btc_yahoo['High'], btc_yahoo['Low'], btc_yahoo["Adj Close"])

## CDLCLOSINGMARUBOZU - Closing Marubozu
btc_yahoo['CDLCLOSINGMARUBOZU'] =ta.CDLCLOSINGMARUBOZU(btc_yahoo["Open"], btc_yahoo['High'], btc_yahoo['Low'], btc_yahoo["Adj Close"])

## CDLCONCEALBABYSWALL - Concealing Baby Swallow
btc_yahoo['CDLCONCEALBABYSWALL'] =ta.CDLCONCEALBABYSWALL(btc_yahoo["Open"], btc_yahoo['High'], btc_yahoo['Low'], btc_yahoo["Adj Close"])

## CDLCOUNTERATTACK - Counterattack
btc_yahoo['CDLCOUNTERATTACK'] =ta.CDLCOUNTERATTACK(btc_yahoo["Open"], btc_yahoo['High'], btc_yahoo['Low'], btc_yahoo["Adj Close"])

## CDLDARKCLOUDCOVER - Dark Cloud Cover
btc_yahoo['CDLDARKCLOUDCOVER'] =ta.CDLDARKCLOUDCOVER(btc_yahoo["Open"], btc_yahoo['High'], btc_yahoo['Low'], btc_yahoo["Adj Close"], penetration=0)

## CDLDOJI - Doji
btc_yahoo['CDLDOJI'] =ta.CDLDOJI(btc_yahoo["Open"], btc_yahoo['High'], btc_yahoo['Low'], btc_yahoo["Adj Close"])

## CDLDOJISTAR - Doji Star
btc_yahoo['CDLDOJISTAR'] =ta.CDLDOJISTAR(btc_yahoo["Open"], btc_yahoo['High'], btc_yahoo['Low'], btc_yahoo["Adj Close"])

## CDLDRAGONFLYDOJI - Dragonfly Doji
btc_yahoo['CDLDRAGONFLYDOJI'] =ta.CDLDRAGONFLYDOJI(btc_yahoo["Open"], btc_yahoo['High'], btc_yahoo['Low'], btc_yahoo["Adj Close"])

## CDLENGULFING - Engulfing Pattern
btc_yahoo['CDLENGULFING'] =ta.CDLENGULFING(btc_yahoo["Open"], btc_yahoo['High'], btc_yahoo['Low'], btc_yahoo["Adj Close"])

## CDLEVENINGDOJISTAR - Evening Doji Star
btc_yahoo['CDLEVENINGDOJISTAR'] =ta.CDLEVENINGDOJISTAR(btc_yahoo["Open"], btc_yahoo['High'], btc_yahoo['Low'], btc_yahoo["Adj Close"], penetration=0)

## CDLEVENINGSTAR - Evening Star
btc_yahoo['CDLEVENINGSTAR'] =ta.CDLEVENINGSTAR(btc_yahoo["Open"], btc_yahoo['High'], btc_yahoo['Low'], btc_yahoo["Adj Close"], penetration=0)

## CDLGAPSIDESIDEWHITE - Up/Down-gap side-by-side white lines
btc_yahoo['CDLGAPSIDESIDEWHITE'] =ta.CDLGAPSIDESIDEWHITE(btc_yahoo["Open"], btc_yahoo['High'], btc_yahoo['Low'], btc_yahoo["Adj Close"])

## CDLGRAVESTONEDOJI - Gravestone Doji
btc_yahoo['CDLGRAVESTONEDOJI'] =ta.CDLGRAVESTONEDOJI(btc_yahoo["Open"], btc_yahoo['High'], btc_yahoo['Low'], btc_yahoo["Adj Close"])

## CDLHAMMER - Hammer
btc_yahoo['CDLHAMMER'] = ta.CDLHAMMER(btc_yahoo["Open"], btc_yahoo['High'], btc_yahoo['Low'], btc_yahoo["Adj Close"])

## CDLHANGINGMAN - Hanging Man
btc_yahoo['CDLHANGINGMAN'] =ta.CDLHANGINGMAN(btc_yahoo["Open"], btc_yahoo['High'], btc_yahoo['Low'], btc_yahoo["Adj Close"])

## CDLHARAMI - Harami Pattern
btc_yahoo['CDLHARAMI'] = ta.CDLHARAMI(btc_yahoo["Open"], btc_yahoo['High'], btc_yahoo['Low'], btc_yahoo["Adj Close"])

## CDLHARAMICROSS - Harami Cross Pattern
btc_yahoo['CDLHARAMICROSS'] = ta.CDLHARAMICROSS(btc_yahoo["Open"], btc_yahoo['High'], btc_yahoo['Low'], btc_yahoo["Adj Close"])

## CDLHIGHWAVE - High-Wave Candle
btc_yahoo['CDLHIGHWAVE'] = ta.CDLHIGHWAVE(btc_yahoo["Open"], btc_yahoo['High'], btc_yahoo['Low'], btc_yahoo["Adj Close"])

## CDLHIKKAKE - Hikkake Pattern
btc_yahoo['CDLHIKKAKE'] = ta.CDLHIKKAKE(btc_yahoo["Open"], btc_yahoo['High'], btc_yahoo['Low'], btc_yahoo["Adj Close"])

## CDLHIKKAKEMOD - Modified Hikkake Pattern
btc_yahoo['CDLHIKKAKEMOD'] = ta.CDLHIKKAKEMOD(btc_yahoo["Open"], btc_yahoo['High'], btc_yahoo['Low'], btc_yahoo["Adj Close"])

## CDLHOMINGPIGEON - Homing Pigeon
btc_yahoo['CDLHOMINGPIGEON'] = ta.CDLHOMINGPIGEON(btc_yahoo["Open"], btc_yahoo['High'], btc_yahoo['Low'], btc_yahoo["Adj Close"])

## CDLIDENTICAL3CROWS - Identical Three Crows
btc_yahoo['CDLIDENTICAL3CROWS'] = ta.CDLIDENTICAL3CROWS(btc_yahoo["Open"], btc_yahoo['High'], btc_yahoo['Low'], btc_yahoo["Adj Close"])

## CDLINNECK - In-Neck Pattern
btc_yahoo['CDLINNECK'] = ta.CDLINNECK(btc_yahoo["Open"], btc_yahoo['High'], btc_yahoo['Low'], btc_yahoo["Adj Close"])

## CDLINVERTEDHAMMER - Inverted Hammer
btc_yahoo['CDLINVERTEDHAMMER'] = ta.CDLINVERTEDHAMMER(btc_yahoo["Open"], btc_yahoo['High'], btc_yahoo['Low'], btc_yahoo["Adj Close"])

## CDLKICKING - Kicking
btc_yahoo['CDLKICKING'] = ta.CDLKICKING(btc_yahoo["Open"], btc_yahoo['High'], btc_yahoo['Low'], btc_yahoo["Adj Close"])

## CDLKICKINGBYLENGTH - Kicking - bull/bear determined by the longer marubozu
btc_yahoo['CDLKICKINGBYLENGTH'] = ta.CDLKICKINGBYLENGTH(btc_yahoo["Open"], btc_yahoo['High'], btc_yahoo['Low'], btc_yahoo["Adj Close"])

## CDLLADDERBOTTOM - Ladder Bottom
btc_yahoo['CDLLADDERBOTTOM'] = ta.CDLLADDERBOTTOM(btc_yahoo["Open"], btc_yahoo['High'], btc_yahoo['Low'], btc_yahoo["Adj Close"])

## CDLLONGLEGGEDDOJI - Long Legged Doji
btc_yahoo['CDLLONGLEGGEDDOJI'] = ta.CDLLONGLEGGEDDOJI(btc_yahoo["Open"], btc_yahoo['High'], btc_yahoo['Low'], btc_yahoo["Adj Close"])

## CDLLONGLINE - Long Line Candle
btc_yahoo['CDLLONGLINE'] = ta.CDLLONGLINE(btc_yahoo["Open"], btc_yahoo['High'], btc_yahoo['Low'], btc_yahoo["Adj Close"])

## CDLMARUBOZU - Marubozu
btc_yahoo['CDLMARUBOZU'] = ta.CDLMARUBOZU(btc_yahoo["Open"], btc_yahoo['High'], btc_yahoo['Low'], btc_yahoo["Adj Close"])

## CDLMATCHINGLOW - Matching Low
btc_yahoo['CDLMATCHINGLOW'] = ta.CDLMATCHINGLOW(btc_yahoo["Open"], btc_yahoo['High'], btc_yahoo['Low'], btc_yahoo["Adj Close"])

## CDLMATHOLD - Mat Hold
btc_yahoo['CDLMATHOLD'] = ta.CDLMATHOLD(btc_yahoo["Open"], btc_yahoo['High'], btc_yahoo['Low'], btc_yahoo["Adj Close"], penetration=0)

## CDLMORNINGDOJISTAR - Morning Doji Star
btc_yahoo['CDLMORNINGDOJISTAR'] = ta.CDLMORNINGDOJISTAR(btc_yahoo["Open"], btc_yahoo['High'], btc_yahoo['Low'], btc_yahoo["Adj Close"], penetration=0)

## CDLMORNINGSTAR - Morning Star
btc_yahoo['CDLMORNINGSTAR'] = ta.CDLMORNINGSTAR(btc_yahoo["Open"], btc_yahoo['High'], btc_yahoo['Low'], btc_yahoo["Adj Close"], penetration=0)

## CDLONNECK - On-Neck Pattern
btc_yahoo['CDLONNECK'] = ta.CDLONNECK(btc_yahoo["Open"], btc_yahoo['High'], btc_yahoo['Low'], btc_yahoo["Adj Close"])

## CDLPIERCING - Piercing Pattern
btc_yahoo['CDLPIERCING'] = ta.CDLPIERCING(btc_yahoo["Open"], btc_yahoo['High'], btc_yahoo['Low'], btc_yahoo["Adj Close"])

## CDLRICKSHAWMAN - Rickshaw Man
btc_yahoo['CDLRICKSHAWMAN'] = ta.CDLRICKSHAWMAN(btc_yahoo["Open"], btc_yahoo['High'], btc_yahoo['Low'], btc_yahoo["Adj Close"])

## CDLRISEFALL3METHODS - Rising/Falling Three Methods
btc_yahoo['CDLRISEFALL3METHODS'] = ta.CDLRISEFALL3METHODS(btc_yahoo["Open"], btc_yahoo['High'], btc_yahoo['Low'], btc_yahoo["Adj Close"])

## CDLSEPARATINGLINES - Separating Lines
btc_yahoo['CDLSEPARATINGLINES'] = ta.CDLSEPARATINGLINES(btc_yahoo["Open"], btc_yahoo['High'], btc_yahoo['Low'], btc_yahoo["Adj Close"])

## CDLSHOOTINGSTAR - Shooting Star
btc_yahoo['CDLSHOOTINGSTAR'] = ta.CDLSHOOTINGSTAR(btc_yahoo["Open"], btc_yahoo['High'], btc_yahoo['Low'], btc_yahoo["Adj Close"])

## CDLSHORTLINE - Short Line Candle
btc_yahoo['CDLSHORTLINE'] = ta.CDLSHORTLINE(btc_yahoo["Open"], btc_yahoo['High'], btc_yahoo['Low'], btc_yahoo["Adj Close"])

## CDLSPINNINGTOP - Spinning Top
btc_yahoo['CDLSPINNINGTOP'] = ta.CDLSPINNINGTOP(btc_yahoo["Open"], btc_yahoo['High'], btc_yahoo['Low'], btc_yahoo["Adj Close"])

## CDLSTALLEDPATTERN - Stalled Pattern
btc_yahoo['CDLSTALLEDPATTERN'] = ta.CDLSTALLEDPATTERN(btc_yahoo["Open"], btc_yahoo['High'], btc_yahoo['Low'], btc_yahoo["Adj Close"])

## CDLSTICKSANDWICH - Stick Sandwich
btc_yahoo['CDLSTICKSANDWICH'] = ta.CDLSTICKSANDWICH(btc_yahoo["Open"], btc_yahoo['High'], btc_yahoo['Low'], btc_yahoo["Adj Close"])

## CDLTAKURI - Takuri (Dragonfly Doji with very long lower shadow)
btc_yahoo['CDLTAKURI'] = ta.CDLTAKURI(btc_yahoo["Open"], btc_yahoo['High'], btc_yahoo['Low'], btc_yahoo["Adj Close"])

## CDLTASUKIGAP - Tasuki Gap
btc_yahoo['CDLTASUKIGAP'] = ta.CDLTASUKIGAP(btc_yahoo["Open"], btc_yahoo['High'], btc_yahoo['Low'], btc_yahoo["Adj Close"])

## CDLTHRUSTING - Thrusting Pattern
btc_yahoo['CDLTASUKIGAP'] = ta.CDLTASUKIGAP(btc_yahoo["Open"], btc_yahoo['High'], btc_yahoo['Low'], btc_yahoo["Adj Close"])

## CDLTRISTAR - Tristar Pattern
btc_yahoo['CDLTRISTAR'] = ta.CDLTRISTAR(btc_yahoo["Open"], btc_yahoo['High'], btc_yahoo['Low'], btc_yahoo["Adj Close"])

## CDLUNIQUE3RIVER - Unique 3 River
btc_yahoo['CDLUNIQUE3RIVER'] = ta.CDLUNIQUE3RIVER(btc_yahoo["Open"], btc_yahoo['High'], btc_yahoo['Low'], btc_yahoo["Adj Close"])

## CDLUPSIDEGAP2CROWS - Upside Gap Two Crows
btc_yahoo['CDLUPSIDEGAP2CROWS'] = ta.CDLUPSIDEGAP2CROWS(btc_yahoo["Open"], btc_yahoo['High'], btc_yahoo['Low'], btc_yahoo["Adj Close"])

## CDLXSIDEGAP3METHODS - Upside/Downside Gap Three Methods
btc_yahoo['CDLXSIDEGAP3METHODS'] = ta.CDLXSIDEGAP3METHODS(btc_yahoo["Open"], btc_yahoo['High'], btc_yahoo['Low'], btc_yahoo["Adj Close"])


# ## Exploration

pattern_rec = ['CDL2CROWS','CDL3BLACKCROWS','CDL3INSIDE','CDL3LINESTRIKE','CDL3OUTSIDE','CDL3STARSINSOUTH','CDL3WHITESOLDIERS','CDLABANDONEDBABY','CDLADVANCEBLOCK','CDLBELTHOLD','CDLBREAKAWAY','CDLCLOSINGMARUBOZU','CDLCONCEALBABYSWALL','CDLCOUNTERATTACK','CDLDOJI','CDLDOJISTAR','CDLDRAGONFLYDOJI','CDLENGULFING','CDLGAPSIDESIDEWHITE','CDLGRAVESTONEDOJI','CDLHAMMER','CDLHANGINGMAN','CDLHARAMI','CDLHARAMICROSS','CDLHIGHWAVE','CDLHIKKAKE','CDLHIKKAKEMOD','CDLHOMINGPIGEON','CDLIDENTICAL3CROWS','CDLINNECK','CDLINVERTEDHAMMER','CDLKICKING','CDLKICKINGBYLENGTH','CDLLADDERBOTTOM','CDLLONGLEGGEDDOJI','CDLLONGLINE','CDLMARUBOZU','CDLMATCHINGLOW','CDLORNINGDOJISTAR','CDLONNECK','CDLPIERCING','CDLRICKSHAWMAN','CDLRISEFALL3METHODS','CDLSEPARATINGLINES','CDLSHOOTINGSTAR','CDLSHORTLINE','CDLSPINNINGTOP','CDLSTALLEDPATTERN','CDLSTICKSANDWICH','CDLTAKURI','CDLTASUKIGAP','CDLTHRUSTING','CDLTRISTAR','CDLUNIQUE3RIVER','CDLUPSIDEGAP2CROWS','CDLXSIDEGAP3METHODS']

pattern_rec_pen = ['CDLDARKCLOUDCOVER', 'CDLEVENINGDOJISTAR', 'CDLEVENINGSTAR', 'CDLMATHOLD', 'CDLMORNINGDOJISTAR', 'CDLMORNINGSTAR']

# for i in pattern_rec:
#     btc_yahoo['{}'] = ta.s'{}(btc_yahoo["Open"], btc_yahoo['High'], btc_yahoo['Low'], btc_yahoo["Adj Close"]).format(i,i)

btc_yahoo.shape

btc_yahoo.isnull().sum()

btc_yahoo.describe()

# Zero columns

btc_yahoo.columns[(btc_yahoo == 0).all()]

StarcoderdataJupyterScriptsDedupFiltered