def renko_DF(DF): "function to convert ohlc data into renko bricks" df = DF.copy() df.reset_index(inplace=True) df = df.iloc[:, [0, 1, 2, 3, 4, 5]] df.columns = ["date", "open", "high", "low", "close", "volume"] df2 = Renko(df) df2.brick_size = max(0.5, round(ATR(DF, 120)["ATR"][-1], 0)) #120 days ATR renko_df = df2.get_ohlc_data() #button, if its uptrend then 1, if downtrend then -1 renko_df["bar_num"] = np.where( renko_df["uptrend"] == True, 1, np.where(renko_df["uptrend"] == False, -1, 0)) #adding the bar_num to the prev number if they are in the same direction #if bar_num[i] = 1 && bar_num[i-1] = 1, add them #if they are negative subtract, -1 -- 1 = 0 for i in range(1, len(renko_df["bar_num"])): if renko_df["bar_num"][i] > 0 and renko_df["bar_num"][i - 1] > 0: renko_df["bar_num"][i] += renko_df["bar_num"][i - 1] elif renko_df["bar_num"][i] < 0 and renko_df["bar_num"][i - 1] < 0: renko_df["bar_num"][i] += renko_df["bar_num"][i - 1] renko_df.drop_duplicates(subset="date", keep="last", inplace=True) #this removes all the duplicate values, if there are duplicate roll indicies, #and keep the prev number (for spikes) return renko_df
def calculate(self): """function to convert ohlc data into renko bricks""" super().calculate() df_result = [] for ticker in self.tickers: df_data_atr = self.df[[ticker]].copy() atr = ATR(df_data_atr, 120) df_atr = atr.calculate() df_data = self.df_renko_input[ticker].copy() self.df_renko = Renko(df_data) atr_key = Constants.get_key("ATR") self.df_renko.brick_size = round(df_atr[ticker][atr_key][-1], 0) self.brick_size = self.df_renko.brick_size # renko_df = df2.get_bricks() #if get_bricks() does not work try using get_ohlc_data() instead self.renko_data = self.df_renko.get_ohlc_data() df_result.append(self.renko_data) self.df = pd.concat(df_result, axis=1, keys=self.tickers) return self.df
def renko_df(df_raw, ATR): df_raw = df_raw[-500:] df_raw.reset_index(inplace=True) renko = Renko(df_raw[['date', 'open', 'high', 'low', 'close', 'volume']]) renko.brick_size = ATR df = renko.get_ohlc_data() df = df.copy() df['bar_num'] = np.where(df['uptrend'] == True, 1, np.where(df['uptrend'] == False, -1, 0)) for i in range(1, len(df["bar_num"])): if df["bar_num"][i] > 0 and df["bar_num"][i - 1] > 0: df["bar_num"][i] += df["bar_num"][i - 1] elif df["bar_num"][i] < 0 and df["bar_num"][i - 1] < 0: df["bar_num"][i] += df["bar_num"][i - 1] df.drop_duplicates(subset="date", keep="last", inplace=True) df_raw = df_raw.merge(df.loc[:, ["date", "bar_num"]], how="outer", on="date") df_raw["bar_num"].fillna(method='ffill', inplace=True) df_raw['OBV'] = ta.OBV(df_raw['close'], df_raw['volume']) df_raw["obv_slope"] = slope(df_raw['OBV'], 5) return df_raw
def renko_DF(DF): "function to convert ohlc data into renko bricks" try: print("Nishant") df = DF.copy() df.reset_index(inplace=True) df = df.iloc[:,[0,1,2,3,4,5]] df.columns = ["date","open","high","low","close","volume"] df2 = Renko(df) # TODO: Investigate what brick size is good df2.brick_size = max(5, round(Indicator.ATR(DF, 14)["ATR"][-1], 0)) print("Brick size: ", df2.brick_size) renko_df = df2.get_ohlc_data() renko_df["bar_num"] = np.where(renko_df["uptrend"] == True, 1, np.where(renko_df["uptrend"] == False, -1, 0)) for i in range(1,len(renko_df["bar_num"])): if renko_df["bar_num"][i] > 0 and renko_df["bar_num"][i-1] > 0: renko_df["bar_num"][i] += renko_df["bar_num"][i-1] elif renko_df["bar_num"][i] < 0 and renko_df["bar_num"][i-1] < 0: renko_df["bar_num"][i] += renko_df["bar_num"][i-1] renko_df.drop_duplicates(subset="date",keep="last", inplace=True) return renko_df except : print("Failed to get renko")
def get_basic_renko(stock_df, period): "function to convert ohlc data into renko bricks" df = stock_df.copy() df.reset_index(inplace=True) df = df.iloc[:,[0,1,2,3,4,5]] df.columns = ["date","open","high","low","close","volume"] df2 = Renko(df) # completely not sure about this renko brick calculation atr_df = get_ATR_column_for_stock(stock_df, 120, False) df2.brick_size = max(0.5, round(atr_df["ATR"][-1],0)) print(f'brick size: {df2.brick_size}') renko_df = df2.get_ohlc_data() renko_df["bar_num"] = np.where(renko_df["uptrend"]==True,1,np.where(renko_df["uptrend"]==False,-1,0)) for i in range(1,len(renko_df["bar_num"])): if renko_df["bar_num"][i]>0 and renko_df["bar_num"][i-1]>0: renko_df["bar_num"][i]+=renko_df["bar_num"][i-1] elif renko_df["bar_num"][i]<0 and renko_df["bar_num"][i-1]<0: renko_df["bar_num"][i]+=renko_df["bar_num"][i-1] renko_df.drop_duplicates(subset="date",keep="last",inplace=True) renko_df.columns = ["Date","open","high","low","close","uptrend","bar_num"] df_to_merge = stock_df.copy() df_to_merge["Date"] = df_to_merge.index df_to_merge = df_to_merge.merge(renko_df.loc[:,["Date","bar_num"]],how="outer",on="Date") df_to_merge.set_index('Date', inplace=True) df_to_merge["bar_num"].fillna(method='ffill',inplace=True) return df_to_merge['bar_num']
def renko_DF(DF): "function to convert ohlc data into renko bricks" df = DF.copy() df.reset_index(inplace=True) df = df.iloc[:, [0, 1, 2, 3, 4, 5]] df.columns = ["date", "open", "high", "low", "close", "volume"] df2 = Renko(df) df2.brick_size = max(0.5, round(ATR(DF, 120)["ATR"][-1], 0)) df2.chart_type = Renko.PERIOD_CLOSE renko_df = df2.get_ohlc_data() renko_df["bar_num"] = np.where( renko_df["uptrend"] == True, 1, np.where(renko_df["uptrend"] == False, -1, 0) ) #Add a column where put 1 and -1 instead of the True/False we had in the uptrend column for i in range( 1, len(renko_df["bar_num"]) ): #Counts the amount of blocks generated in a trend Ex.: If we have 1,1,1,1,-1,-1,1,1... --> 1,2,3,4,-1,-2,1,2... if renko_df["bar_num"][i] > 0 and renko_df["bar_num"][i - 1] > 0: renko_df["bar_num"][i] += renko_df["bar_num"][i - 1] elif renko_df["bar_num"][i] < 0 and renko_df["bar_num"][i - 1] < 0: renko_df["bar_num"][i] += renko_df["bar_num"][i - 1] renko_df.drop_duplicates( subset="date", keep="last", inplace=True ) #Some of the indexes are repeated (for example if there is a spike in a 5 min period and 2 ranko blocks are generated). Drop the duplicate indexes (same 5 min period), but keep the last return renko_df
def renko(df_original): df = df_original.copy() df.reset_index(inplace=True) # convert index to column df.drop(['Close'], axis=1) df.columns = ['date', 'open', 'high', 'low', 'close', 'volume'] # change column names renko_df = Renko(df) renko_df.brick_size = int(round(atr(df_original, 14)['atr'][-1], 0)) return renko_df.get_ohlc_data()
def renko_DF(DF): df = DF.copy() df.reset_index(inplace=True) df = df.iloc[:,[0,1,2,3,4,5]] df.columns = ["date", "low", "high", "open", "close", "volume"] df2 = Renko(df) df2.brick_size = max(0.5, round(ATR(DF,120)["ATR"][-1],0))
def data_frame(data, size, period1, period2): df = pd.DataFrame(data) df['date'], df['time'] = df['date'].dt.date, df['date'].dt.strftime('%H:%M:%S') df = Renko(df) df.brick_size = size data = df.get_bricks() data['MA4'] = data['close'].rolling(window=period1).mean() data['MA10'] = data['close'].rolling(window=period2).mean() return data
def Renko_trend(DF, n): df8 = DF.copy() df8 = df8.reset_index() df8 = df8.iloc[:, [0, 1, 2, 3, 4]] df8.columns = ['date', 'open', 'high', 'low', 'close'] renko_df = Renko(df8) x = statistics.mean(((ATR(ohclv_data, 200)).iloc[:, -1].dropna())) renko_df.brick_size = x df8 = renko_df.get_ohlc_data() return df8
def renko_DF(DF): "function to convert ohlc data into renko bricks" df = DF.copy() df.reset_index(inplace=True) df = df.iloc[:,[0,1,2,3,5,6]] df.rename(columns = {"Date" : "date", "High" : "high","Low" : "low", "Open" : "open","Adj Close" : "close", "Volume" : "volume"}, inplace = True) df2 = Renko(df) df2.brick_size = round(ATR(DF,120)["ATR"][-1],0) renko_df = df2.get_ohlc_data() #if using older version of the library please use get_bricks() instead return renko_df
def renko_DF(DF): df = DF.copy() df.reset_index(inplace=True) df = df.iloc[:,[0,1,2,3,5,6]] df.rename(columns = {"Date" : "date", "High" : "high","Low" : "low", "Open" : "open","Adj Close" : "close", "Volume" : "volume"}, inplace = True) df2 = Renko(df) df2.brick_size = round(ATR(DF,120)["ATR"][-1],0) renko_df = df2.get_ohlc_data() return renko_df
def renko_df(dataframe): """function to convert ohlc data into renko bricks""" df_ = dataframe.copy() df_.reset_index(inplace=True) df_ = df_.iloc[:, [0, 1, 2, 3, 5, 6]] df_.rename(columns={"Date": "date", "High": "high", "Low": "low", "Open": "open", "Adj Close": "close", "Volume": "volume"}, inplace=True) df2 = Renko(df_) df2.brick_size = round(atr(dataframe, 120)["ATR"][-1], 0) # renko_df = df2.get_bricks() # if get_bricks() does not work try using get_ohlc_data() instead RENKO_df = df2.get_ohlc_data() return RENKO_df
def GetRenko(DF, n): df = DF.copy() df.reset_index(inplace=True) df = df.iloc[:, [0, 1, 2, 3, 5, 6]] df.columns = ["date", "open", "high", "low", "close", "volume"] renko_df = Renko(df) renko_df.brick_size = round(ATR(DF, 120)['ATR'][-1], 0) df2 = renko_df.get_bricks() return df2
def __setIndicator(self, a_df: pandas.DataFrame): """function to convert ohlc data into renko bricks""" df: pandas.DataFrame = a_df.copy() df.reset_index(inplace=True) df = df.iloc[:, [0, 1, 2, 3, 5, 6]] df.rename(columns={"Date": "date", "High": "high", "Low": "low", "Open": "open", "Adj Close": "close", "Volume": "volume"}, inplace=True) ren = Renko(df) ren.brick_size = round(self.__getAvgTrueRange(a_df.copy(), 120)["AvgTrueRate"][-1], 0) # if get_bricks() does not work try using get_ohlc_data() instead # df2.get_bricks() error => using get_ohlc_data() # renkoDataFrame = df2.get_bricks() renDf: pandas.DataFrame = ren.get_ohlc_data() self.IndicatorDf = renDf
def renko_DF(df_): """ converts ohlc data into renko bricks must include the following columns: 'date' 'open' 'high' 'low' 'close' """ df = copy.deepcopy(df_) if 'adj_close' in df.columns: df['close'] = df['adj_close'] df.reset_index(inplace=True) df2 = Renko(df) df2.brick_size = round(ATR(df_, 120)['ATR'][-1], 0) renko_df = df2.get_ohlc_data() return renko_df
def renko_DF(DF): "function to convert ohlc data into renko bricks" df = DF.copy() df.reset_index(inplace=True) df = df.iloc[:, [0, 1, 2, 3, 6, 5]] df.columns = ["date", "open", "high", "low", "close", "volume"] df2 = Renko(df) df2.brick_size = round( ATR(DF, 120)["ATR"][-1], 0 ) #We just want the last number of the column. We use ATR as the brick size in here but it can also be fix. df2.chart_type = Renko.PERIOD_CLOSE #Renko box calcuation based on periodic close #df2.chart_type = Renko.PRICE_MOVEMENT #Renko box calcuation based on price movement renko_df = df2.get_ohlc_data( ) #Adds a column to df called "uptrend" with boolean values depending on whether the ranko chart goes up or down return renko_df
def renko_DF(DF): "function to convert ohlc data into renko bricks" df = DF.copy() df.reset_index(inplace=True) df = df.iloc[:, [0, 1, 2, 3, 4, 5]] df.columns = ["date", "open", "high", "low", "close", "volume"] df2 = Renko(df) df2.brick_size = max(0.5, round(ATR(DF, 120)["ATR"][-1], 0)) renko_df = df2.get_bricks() renko_df["bar_num"] = np.where(renko_df["uptrend"] == True, 1, np.where(renko_df["uptrend"] == False, -1, 0)) for i in range(1, len(renko_df["bar_num"])): if renko_df["bar_num"][i] > 0 and renko_df["bar_num"][i - 1] > 0: renko_df["bar_num"][i] += renko_df["bar_num"][i - 1] elif renko_df["bar_num"][i] < 0 and renko_df["bar_num"][i - 1] < 0: renko_df["bar_num"][i] += renko_df["bar_num"][i - 1] renko_df.drop_duplicates(subset="date", keep="last", inplace=True) return renko_df
def renko_bars(self, DF, n, instrument): df = DF.copy() df2 = Renko(df) real = talib.ATR(df["high"], df["low"], df["close"], timeperiod = n) brick_sizing = round(real[len(real) - 1], 5) print("BRICK_SIZE: ", brick_sizing) df2.brick_size = brick_sizing renko_df = df2.get_bricks() renko_df["bar_num"] = np\ .where(renko_df["uptrend"]==True,1,np\ .where(renko_df["uptrend"]==False,-1,0)) for i in range(1,len(renko_df["bar_num"])): if renko_df["bar_num"][i]>0 and renko_df["bar_num"][i-1]>0: renko_df["bar_num"][i]+=renko_df["bar_num"][i-1] elif renko_df["bar_num"][i]<0 and renko_df["bar_num"][i-1]<0: renko_df["bar_num"][i]+=renko_df["bar_num"][i-1] renko_df.drop_duplicates(subset="date",keep="last",inplace=True) return renko_df, brick_sizing
def renko_DF(DF): df = DF.copy() df2 = Renko(df) "Using ATR as renko brick size" real = talib.ATR(df["high"], df["low"], df["close"], timeperiod=14) brick_sizing = round(real[len(real) - 1], 6) df2.brick_size = brick_sizing renko_df = df2.get_bricks() renko_df["bar_num"] = np\ .where(renko_df["uptrend"]==True,1,np\ .where(renko_df["uptrend"]==False,-1,0)) for i in range(1, len(renko_df["bar_num"])): if renko_df["bar_num"][i] > 0 and renko_df["bar_num"][i - 1] > 0: renko_df["bar_num"][i] += renko_df["bar_num"][i - 1] elif renko_df["bar_num"][i] < 0 and renko_df["bar_num"][i - 1] < 0: renko_df["bar_num"][i] += renko_df["bar_num"][i - 1] renko_df.drop_duplicates(subset="date", keep="last", inplace=True) return renko_df
def renko_DF(DF): "function to convert ohlc data into renko bricks" df = DF.copy() df.reset_index(inplace=True) df2 = Renko(df) atr_df = ATR(DF, 120) #print(atr_df["ATR"]) df2.brick_size = max(0.5, round(atr_df["ATR"].iloc[-1], 0)) renko_df = df2.get_ohlc_data() renko_df["bar_num"] = np.where( renko_df["uptrend"] == True, 1, np.where(renko_df["uptrend"] == False, -1, 0)) for i in range(1, len(renko_df["bar_num"])): if renko_df["bar_num"][i] > 0 and renko_df["bar_num"][i - 1] > 0: renko_df["bar_num"][i] += renko_df["bar_num"][i - 1] elif renko_df["bar_num"][i] < 0 and renko_df["bar_num"][i - 1] < 0: renko_df["bar_num"][i] += renko_df["bar_num"][i - 1] renko_df.drop_duplicates(subset="date", keep="last", inplace=True) return renko_df
def renko_DF(DF): df = DF.copy() df.reset_index(inplace=True) df = df.iloc[:, [0, 1, 2, 3, 4, 5]] #different from 40mycode df.columns = ['date', 'open', 'high', 'low', 'close', 'volume'] df2 = Renko(df) df2.brick_size = round(ATR(DF, 120)['ATR'][-1], 4) #different from 40mycode renko_df = df2.get_ohlc_data() renko_df['bar_num'] = np.where( renko_df['uptrend'] == True, 1, np.where(renko_df['uptrend'] == False, -1, 0)) for i in range(1, len(renko_df['bar_num'])): if renko_df['bar_num'][i] > 0 and renko_df['bar_num'][i - 1] > 0: renko_df['bar_num'][i] += renko_df['bar_num'][i - 1] elif renko_df['bar_num'][i] < 0 and renko_df['bar_num'][i - 1] < 0: renko_df['bar_num'][i] += renko_df['bar_num'][i - 1] renko_df.drop_duplicates(subset='date', keep='last', inplace=True) return renko_df
def renko_dataframe(DF): df = DF.copy() df.reset_index(inplace=True) #make index as a seperate column, convert index to column #adding this allows the date to be its own column #For renko, all we need to look at is a couple rows df = df.iloc[:, [0, 1, 2, 3, 5, 6]] #only include columns 0,1,2,3,5,6 df.columns = ["date", "open", "high", "low", "close", "volume"] #simply rename the columns, respectively renko_df = Renko(df) renko_df.brick_size = round(ATR( df, 120)["ATR"][-1]) #use atr to assign bricksize #-1 takes the latest point/last point df2 = renko_df.get_ohlc_data()
def renko(o, h, l, c, v): ''' Computes Ranko values for the given price series Parameters ========== o: pandas.Series(): Open price h: pandas.Series(): High price l: pandas.Series(): Low price c: pandas.Series(): Closeprice v: pandas.Series(): Volume Returns ======= renko_df: pandas.DataFrame() ''' df = pd.concat([ copy.deepcopy(o), copy.deepcopy(h), copy.deepcopy(l), copy.deepcopy(c), copy.deepcopy(v) ], axis=1) df.reset_index(inplace=True) df.columns = ['date', 'open', 'high', 'low', 'close', 'volume'] df2 = Renko(df) renko_df = df2.get_bricks() renko_df['bar_num'] = np.where( renko_df['uptrend'] == True, 1, np.where(renko_df['uptrend'] == False, -1, 0)) for i in range(1, len(renko_df['bar_num'])): if renko_df['bar_num'][i] > 0 & renko_df['bar_num'][i - 1] > 0: renko_df['bar_num'][i] += renko_df['bar_num'][i - 1] elif renko_df['bar_num'][i] < 0 & renko_df['bar_num'][i - 1] < 0: renko_df['bar_num'][i] += renko_df['bar_num'][i - 1] renko_df.drop_duplicates(subset='Date', keep='last', inplace=True) return renko_df
def renko_DF(DF): "function to convert ohlc data into renko bricks" df = DF.copy() # copio el dataframe df.reset_index( inplace=True ) # pongo un indice secuencial y la fecha pasa a la primera columna df = df.iloc[:, [0, 1, 2, 3, 5, 6]] # Quito la colunna 4 df.rename(columns={ "Date": "date", "High": "high", "Low": "low", "Open": "open", "Adj Close": "close", "Volume": "volume" }, inplace=True) df2 = Renko(df) df2.brick_size = round( ATR(DF, 120)["ATR"][-1], 0) #marcamos el incremento basado en ATR para pintar un brick renko_df = df2.get_ohlc_data( ) #if using older version of the library please use get_bricks() instead return renko_df
def renko(Df): ''' Converts ohlc data to Renko bricks Parameters ========== Df: pandas.DataFrame(): enter a regular OHLCv dataframe with pandas.Date index Returns ======= Renko_df: pandas.DataFrame(): Renko bric indicators ''' df = Df.copy() df.reset_index(inplace=True) df = df.iloc[:, [0, 1, 2, 3, 4, 5]] df.rename(columns={ 'Date': 'date', 'Open': 'open', 'High': 'high', 'Low': 'low', 'Adj Close': 'close', 'Volume': 'volume' }, inplace=True) df2 = Renko(df) df2.brick_size = max(0.5, round(ATR(Df, 120)['ATR'][-1], 0)) renko_df = df2.get_ohlc_data() renko_df['bar_num'] = np.where( renko_df['uptrend'] == True, 1, np.where(renko_df['uptrend'] == False, -1, 0)) for i in range(1, len(renko_df['bar_num'])): if renko_df['bar_num'][i] > 0 and renko_df['bar_num'][i - 1] > 0: renko_df['bar_num'][i] += renko_df['bar_num'][i - 1] elif renko_df['bar_num'][i] < 0 and renko_df['bar_num'][i - 1] < 0: renko_df['bar_num'][i] += renko_df['bar_num'][i - 1] renko_df.drop_duplicates(subset='date', keep='last', inplace=True) return renko_df
def renko(dataframe): """atr A Renko chart is built using price movement without standardized time intervals. A new brick is created when the price moves a specified price amount. Each block is positioned at a 45-degree angle (up or down) to the prior brick. An up brick is typically colored white or green, while a down brick is typically colored black or red. Brick size is determined by ATR. Args: dataframe (pd.Dataframe): Dataframe with ohlcv data. Returns: pd.Dataframe: Frame with renko col appended. """ df = dataframe.copy() brick_size = max(0.5, round(atr(df, 120)['atr'][-1], 0)) df.reset_index(inplace=True) df_renko = Renko(col_rename(df)) df_renko.brick_size = brick_size df_ohlc_renko = df_renko.get_ohlc_data() df_ohlc_renko["renko_bar_num"] = np.where(df_ohlc_renko["uptrend"], 1, np.where(df_ohlc_renko["uptrend"] == False, -1, 0)) for i in range(1, len(df_ohlc_renko["renko_bar_num"])): if df_ohlc_renko["renko_bar_num"][i] > 0 and df_ohlc_renko["renko_bar_num"][i-1] > 0: df_ohlc_renko["renko_bar_num"][i] += df_ohlc_renko["renko_bar_num"][i-1] elif df_ohlc_renko["renko_bar_num"][i] < 0 and df_ohlc_renko["renko_bar_num"][i-1] < 0: df_ohlc_renko["renko_bar_num"][i] += df_ohlc_renko["renko_bar_num"][i-1] df_ohlc_renko.drop_duplicates(subset="date", keep="last", inplace=True) df_merged = df.merge(df_ohlc_renko.loc[:, ["date", "renko_bar_num"]], how="outer", on="date") df_merged["renko_bar_num"].fillna(method='ffill', inplace=True) df_merged.set_index('date', inplace=True) return df_merged[['renko_bar_num']]
import numpy as np import pandas as pd import nsepy from stocktrends import Renko if len(sys.argv) > 1: fname = sys.argv[1] print('Reading local file {}'.format(fname)) df = pd.read_csv(sys.argv[1]) else: symbol='SBIN' print('Downloading {} data from nsepy'.format(symbol)) df = nsepy.get_history( symbol=symbol, start=dt.date(2017,1,1), end=dt.date(2018,1,19) ) if df.empty: print('No data is received from nsepy.') sys.exit() debug = True # print(df.tail(20)) renko = Renko(df) renko.brick_size = 4 r = renko.get_bricks() print(r.tail(33))
import pandas_datareader as pdr
class RENKOIND(Indicator): def __init__(self, df=None, n=120): super().__init__() self.collapse = False self.n = n # Set dataframe keys self.low_key = None self.high_key = None self.open_key = None self.date_key = "Date" self.prices_key = None self.brick_size = None self.df_renko_input = None self.df_renko = None self.renko_data = None if df is not None: self.set_input_data(df) def set_input_data(self, df): super().set_input_data(df) self.low_key = Constants.get_low_key() self.high_key = Constants.get_high_key() self.open_key = Constants.get_open_key() # Set dataframe keys prices_temp = pd.DataFrame() df_list = [] for ticker in self.tickers: if ticker in df: df_temp = df[ticker].loc[:, [ self.high_key, self.low_key, self.open_key, self.prices_key ]] df_list.append( pd.concat([df_temp, prices_temp], axis=1, keys=[ticker])) df_indicator = pd.concat(df_list, axis=1) self.df = df_indicator.copy() prices_temp = pd.DataFrame() df_list = [] for ticker in self.tickers: df_temp = df[ticker] df_temp.reset_index(level=0, inplace=True) df_temp = df_temp.loc[:, [ self.date_key, self.high_key, self.low_key, self.open_key, self.prices_key ]] # TODO: Is this rebundant??? df_temp.rename(columns={ "Date": "date", self.high_key: "high", self.low_key: "low", self.open_key: "open", self.prices_key: "close" }, inplace=True) df_list.append( pd.concat([df_temp, prices_temp], axis=1, keys=[ticker])) df_indicator = pd.concat(df_list, axis=1) self.df_renko_input = df_indicator.copy() def calculate(self): """function to convert ohlc data into renko bricks""" super().calculate() df_result = [] for ticker in self.tickers: df_data_atr = self.df[[ticker]].copy() atr = ATR(df_data_atr, 120) df_atr = atr.calculate() df_data = self.df_renko_input[ticker].copy() self.df_renko = Renko(df_data) atr_key = Constants.get_key("ATR") self.df_renko.brick_size = round(df_atr[ticker][atr_key][-1], 0) self.brick_size = self.df_renko.brick_size # renko_df = df2.get_bricks() #if get_bricks() does not work try using get_ohlc_data() instead self.renko_data = self.df_renko.get_ohlc_data() df_result.append(self.renko_data) self.df = pd.concat(df_result, axis=1, keys=self.tickers) return self.df
def renko(): renko_data = Renko(transform_data(SetUp.data)) renko_data.brick_size = round(atr(SetUp.data, 120)['ATR'][-1], 0) renko_df = renko_data.get_ohlc_data() return renko_df