class MovingAverage:
    def __init__(self, days):
        # Moving average days
        self.days = days

    # Title of column for moving average
    def getMAColumn(self):
        return "Sma_" + str(self.days)

    def getMABeatsClosePercetage(self, df):
        # Creates column with the name from getMAColumn
        # That column is the rolling ma with a window size of our ma
        # Created from the 4th column in df which is adjusted close
        df[self.getMAColumn()] = df.iloc[:, 4].rolling(window=self.days).mean()

        # Cut out the first 50 days since they do not have a ma
        df = df.iloc[self.days:]

        # Track how often the close is greater than the ma
        higher = 0
        lower = 0
        for i in df.index:
            if(df["Adj Close"][i] > df[self.getMAColumn()][i]):
                higher += 1
            else:
                lower += 1

        percentage = round(higher / (higher + lower) * 100)

        return (str(percentage) + "%")


# Test
# ma = MovingAverage(50)
# print(ma.getMABeatsClosePercetage(df))

71cf4209d94f37de8b5e9ddfc213f72901c29b16
class MovingAverage:
    <mask token>
    <mask token>
    <mask token>

class MovingAverage:
    <mask token>

    def getMAColumn(self):
        return 'Sma_' + str(self.days)
    <mask token>

class MovingAverage:
    <mask token>

    def getMAColumn(self):
        return 'Sma_' + str(self.days)

    def getMABeatsClosePercetage(self, df):
        df[self.getMAColumn()] = df.iloc[:, 4].rolling(window=self.days).mean()
        df = df.iloc[self.days:]
        higher = 0
        lower = 0
        for i in df.index:
            if df['Adj Close'][i] > df[self.getMAColumn()][i]:
                higher += 1
            else:
                lower += 1
        percentage = round(higher / (higher + lower) * 100)
        return str(percentage) + '%'

class MovingAverage:

    def __init__(self, days):
        self.days = days

    def getMAColumn(self):
        return 'Sma_' + str(self.days)

    def getMABeatsClosePercetage(self, df):
        df[self.getMAColumn()] = df.iloc[:, 4].rolling(window=self.days).mean()
        df = df.iloc[self.days:]
        higher = 0
        lower = 0
        for i in df.index:
            if df['Adj Close'][i] > df[self.getMAColumn()][i]:
                higher += 1
            else:
                lower += 1
        percentage = round(higher / (higher + lower) * 100)
        return str(percentage) + '%'

class MovingAverage:
    def __init__(self, days):
        # Moving average days
        self.days = days

    # Title of column for moving average
    def getMAColumn(self):
        return "Sma_" + str(self.days)

    def getMABeatsClosePercetage(self, df):
        # Creates column with the name from getMAColumn
        # That column is the rolling ma with a window size of our ma
        # Created from the 4th column in df which is adjusted close
        df[self.getMAColumn()] = df.iloc[:, 4].rolling(window=self.days).mean()

        # Cut out the first 50 days since they do not have a ma
        df = df.iloc[self.days:]

        # Track how often the close is greater than the ma
        higher = 0
        lower = 0
        for i in df.index:
            if(df["Adj Close"][i] > df[self.getMAColumn()][i]):
                higher += 1
            else:
                lower += 1

        percentage = round(higher / (higher + lower) * 100)

        return (str(percentage) + "%")


# Test
# ma = MovingAverage(50)
# print(ma.getMABeatsClosePercetage(df))
