In [87]:
#!/usr/bin/env python
# -*- coding: utf-8 -*-

from __future__ import (
    absolute_import, division, print_function, with_statement,
    unicode_literals
)

import numpy as np
import pandas as pd
import Quandl
import os
# from sqlalchemy import sqlalchemy  # from flask.ext.


class twitfin(object):
    """This is a description of the class."""

    #: An example class variable.
    aClassVariable = True

    def __init__(self, argumentName, anOptionalArg=None):
        """Initialization method.
        :param argumentName: an example argument.
        :type argumentName: string
        :param anOptionalArg: an optional argument.
        :type anOptionalArg: string
        :returns: New instance of :class:`twitfin`
        :rtype: twitfin
        """

        self.instanceVariable1 = argumentName

        if self.aClassVariable:
            print('Hello')

        if anOptionalArg:
            print('anOptionalArg: %s' % anOptionalArg)

def load(*args, **kwargs):
    """Load data from Quandl into a dataframe, modify column names and
    check for non-numeric values."""
    # Grab the Quandl token
    # token = os.environ.get('QUANDL_TOKEN')
    # if token is None:
    token = input("Enter Quandl token: ")
    ticker = input("Enter Quandl ticker symbol (or hit Enter for default of YAHOO/INDEX_GSPC): ")
    if len(ticker) < 1:
        ticker = 'YAHOO/INDEX_GSPC'
    print(ticker)
    start_date = input("Enter start date as YYYY-MM-DD (or hit ENTER for default of 1990-01-01): ")
    if len(start_date) < 1:
        start_date = '1990-01-01'
    print(start_date)
    # Call Quandl module, trim input by default from 1990 forward
    print('Pulling Quandl data...')
    df = Quandl.get(ticker, authtoken=token, trim_start=start_date)
    # Get the column labels
    # old_columns = list(df.columns.values)
    # Use the ticker symbol as our new prefix
    # ticker_tag = ticker.split('_')[-1] + '_'
    # Drop spaces and concatenate
    # new_labels = [ticker_tag + i.replace(' ', '') for i in old_columns]
    # Create a dictionary of old and new column labels
    # new_columns = dict(zip(old_columns, new_labels))
    # Rename the columns using our dictionary
    # df = df.rename(columns=new_columns)
    nulls = df[~df.applymap(np.isreal).all(1)]
    # Check for non-numeric values
    if len(nulls) > 0:
        raise ValueError('Dataframe contains non-numeric values')
    row_count = len(df)
    print('%d rows loaded into dataframe.' % row_count)
    return df

def long_sma(df, column, *args, **kwargs):
    """Given a dataframe, a column name and a period the function
    returns a dataframe with new column with a simple moving average
    for the period."""
    ### SMA function parameters
    # 1st parameter: target dataframe
    # 2nd parameter: target column
    # 3rd parameter: the period for the moving average
    # 4th paramter, optional: supply a label to be appended with period info,
    # for example df = twitfin.sma(df, 'GSPC_Close', 20, label='Close')
    # will result in a column label of 'Close_20-day'.
    # The default label is constructed as follows:
    # SMA_{ target column }_{ period }-day
    period = int(input("Enter the period in days for the long SMA: "))
    if 'label' in kwargs:
        column_label = kwargs['label'] + '_' + str(period) + '-day'
    else:
        column_label = 'SMA_' + column + '_' + str(period) + '-day'
    df[column_label] = pd.stats.moments.rolling_mean(df[column], period)
    return df

def short_sma(df, column, *args, **kwargs):
    """Given a dataframe, a column name and a period the function
    returns a dataframe with new column with a simple moving average
    for the period."""
    period = int(input("Enter the period in days for the short SMA: "))
    if 'label' in kwargs:
        column_label = kwargs['label'] + '_' + str(period) + '-day'
    else:
        column_label = 'SMA_' + column + '_' + str(period) + '-day'
    df[column_label] = pd.stats.moments.rolling_mean(df[column], period)
    return df

def diff(df, column_a, column_b, **kwargs):
    """Creates a new column from the differnce of column_a and column_b,
    as column_a minus column_b."""
    ### diff function parameters
    # 1st parameter: target dataframe
    # 2nd parameter: target column_a
    # 3rd parameter: target column_b
    # TODO: describe default label and custom label options
    column_a_suffix = column_a.split('_')[-1]
    column_b_suffix = column_b.split('_')[-1]
    column_prefix = "_".join(column_b.split('_')[0:2])
    if 'label' in kwargs:
        column_label = kwargs['label']
    else:
        column_label = 'Delta_' + column_prefix + '_' + column_a_suffix + '_' + column_b_suffix
    df[column_label] = df[column_a] - df[column_b]
    return df

def macd(df, column, *args, **kwargs):
    """Given a dataframe, a column name and a period the function
    returns a dataframe with new column with a simple moving average
    for the period."""
    period = int(input("Enter the period in days for the SMA of the MACD: "))
    if 'label' in kwargs:
        column_label = kwargs['label'] + '_' + str(period) + '-day'
    else:
        column_label = 'SMA_' + column + '_' + str(period) + '-day'
    df[column_label] = pd.stats.moments.rolling_mean(df[column], period)
    return df

def flag_swings(df, column, *args, **kwargs):
    """Given a dataframe and column and a minimum sequence period
    for the same sign, the function returns: "1" for upward swings,
    "-1" for downward swings, or "0" if niether condition is met."""
    ### flag_swings function parameters
    # 1st parameter: target dataframe
    # 2nd parameter: target column
    # 3rd parameter: minimum swing period
    # TODO: describe default label and custom label options
    period = int(input("Enter the period in days to flag swings: "))
    if 'label' in kwargs:
        # Append custom label with period days
        column_label = kwargs['label'] + '_' + str(period) + '-day'
    else:
        column_label = 'SwingFlag_' + str(period) + '-day'
    # Trim null value artifacts in SMA columns
    df = df.dropna()
    # Create a temporary dataframe
    tmp = df.copy()
    tmp['sum'] = 0
    # Determine the sign of each day and sum signs from prior days using the
    # "x-day" notation as "sign-'reference day'"
    tmp['sign-0'] = [1 if x >= 0 else -1 for x in df[column]]
    if period < 2:
        raise ValueError('The minimum swing period should be 2 days.')
    else:
        # Shift rows down for lateral comparison depending on period
        for i in range(1, period):
            label = 'sign-' + str(i)
            tmp[label] = tmp['sign-0'].shift(i)
            # The sum of consecutive signs agregates here
            tmp['sum'] = tmp['sum'] + tmp[label]

    # The we shift the sum signs by one to compare prior sequence history
    tmp['sum-shift'] = tmp['sum'].shift(1)

    def flagger(sign_now, sign_prior, sign_run, sign_sum, period):
        # flagger contains the logical for lateral comparison of time-shifted
        # sign data, agregations and time-shifted agregations
        if sign_now > sign_prior and abs(sign_run) >= period - 1 and sign_sum != 0:
            # Indicates a positive sign after a sufficient period of negative signs
            return 1  # Also referred to here as an upward swing or crossover
        else:
            if sign_now < sign_prior and abs(sign_run) >= period - 1 and sign_sum != 0:
                # Indicates a negative sign after a sufficient period of positive signs
                return -1  # Also referred to here as an downward swing or crossover
            else:
                # Otherwaise returning zero. Zero could still be a sign change
                # but prior minimum sign sequence period criteria was not met.
                return 0

    try:
        df = df.copy()
        df[column_label] = [flagger(n, p, r, s, period) for n, p, r, s in zip(tmp['sign-0'], tmp['sign-1'], tmp['sum-shift'], tmp['sum'])]
    except Exception as e:
        print(e)
        if e =='SettingWithCopyWarning':
            pass
    return df

def sign_sequence(df, column, *args, **kwargs):
    """Given a dataframe and column of signs (-1, 0, 1), returns a
    column with a list of prior signs for the given period."""
    period = int(input("Enter the days prior to list the signs: "))
    prior_signs_label = 'SignSequence_' + str(period) + '-days'
    # Trim null value artifacts in SMA columns
    df = df.dropna()
    # Create a temporary dataframe
    tmp = df.copy()
    # Determine the sign of each day and sum signs from prior days using the
    # "x-day" notation as "sign-'reference day'"
    tmp['sign-0'] = ['1' if x >= 0 else '-1' for x in df[column]]
    # Shift rows down for lateral comparison depending on period
    labels = ['sign-0']
    for i in range(1, period):
        label = 'sign-' + str(i)
        labels.append(label)
        tmp[label] = tmp['sign-0'].shift(i)
    tmp2 = tmp.ix[(period -1):]
    df2 = df.ix[(period -1):]
    labels = labels[::-1]
    try:
        df2 = df2.copy()
        df2[prior_signs_label] = tmp2[labels].apply(lambda x: ','.join(x), axis=1)
    except Exception as e:
        print(e)
        if e =='SettingWithCopyWarning':
            pass
    return df2

def x_days(df):
    """Add a column with a descending counter."""
    # One paramter: target dataframe
    df['x-day'] = ['x-' + str(i) for i in range(len(df) - 1, -1, -1)]
    return df

def x_transpose(df):
    """Transpose the dataframe and set the x-days as the column labels."""
    # One paramter: target dataframe, assumes an x-day column has been created
    df = df.set_index('x-day')
    df = df.transpose()
    pd.options.display.float_format = '{:.3f}'.format
    return df

def read_csv(filename, *args, **kwargs):
    """read_csv is a port of the Pandas read_csv module."""
    return pd.read_csv(filename, *args)

def read_sql(table, db, *args, **kwargs):
    """read_sql is a port of the Pandas read_sql module."""
    return pd.read_sql(table, db, *args, **kwargs)

def db_connection(uri):
    """db_connection is a port of the SQLAlchemy create_engine module."""
    return sqlalchemy.create_engine(uri)

In [62]:
df = load()
# print(df.tail())  # Inspect the loaded data via terminal output


Enter Quandl token: vQaiAyaQrUAaxpEdNijb
Enter Quandl ticker symbol (or hit Enter for default of YAHOO/INDEX_GSPC): 
YAHOO/INDEX_GSPC
Enter start date as YYYY-MM-DD (or hit ENTER for default of 1990-01-01): 
1990-01-01
Pulling Quandl data...
6573 rows loaded into dataframe.

In [63]:
df


Out[63]:
Open High Low Close Volume Adj Close
Date
1990-01-02 353.399994 359.690002 351.980011 359.690002 162070000 359.690002
1990-01-03 359.690002 360.589996 357.890015 358.760010 192330000 358.760010
1990-01-04 358.760010 358.760010 352.890015 355.670013 177000000 355.670013
1990-01-05 355.670013 355.670013 351.350006 352.200012 158530000 352.200012
1990-01-08 352.200012 354.239990 350.540009 353.790009 140110000 353.790009
1990-01-09 353.829987 354.170013 349.609985 349.619995 155210000 349.619995
1990-01-10 349.619995 349.619995 344.320007 347.309998 175990000 347.309998
1990-01-11 347.309998 350.140015 347.309998 348.529999 154390000 348.529999
1990-01-12 348.529999 348.529999 339.489990 339.929993 183880000 339.929993
1990-01-15 339.929993 339.940002 336.570007 337.000000 140590000 337.000000
1990-01-16 337.000000 340.750000 333.369995 340.750000 186070000 340.750000
1990-01-17 340.769989 342.010010 336.260010 337.399994 170470000 337.399994
1990-01-18 337.399994 338.380005 333.980011 338.190002 178590000 338.190002
1990-01-19 338.190002 340.480011 338.190002 339.149994 185590000 339.149994
1990-01-22 339.140015 339.959991 330.279999 330.380005 148380000 330.380005
1990-01-23 330.380005 332.760010 328.670013 331.609985 179300000 331.609985
1990-01-24 331.609985 331.709991 324.170013 330.260010 207830000 330.260010
1990-01-25 330.260010 332.329987 325.329987 326.079987 172270000 326.079987
1990-01-26 326.089996 328.579987 321.440002 325.799988 198190000 325.799988
1990-01-29 325.799988 327.309998 321.790009 325.200012 150770000 325.200012
1990-01-30 325.200012 325.730011 319.829987 322.980011 186030000 322.980011
1990-01-31 322.980011 329.079987 322.980011 329.079987 189660000 329.079987
1990-02-01 329.079987 329.859985 327.760010 328.790009 154580000 328.790009
1990-02-02 328.790009 332.100006 328.089996 330.920013 164400000 330.920013
1990-02-05 330.920013 332.160004 330.450012 331.850006 130950000 331.850006
1990-02-06 331.850006 331.859985 328.200012 329.660004 134070000 329.660004
1990-02-07 329.660004 333.760010 326.549988 333.750000 186710000 333.750000
1990-02-08 333.750000 336.089996 332.000000 332.959991 176240000 332.959991
1990-02-09 333.019989 334.600006 332.410004 333.619995 146910000 333.619995
1990-02-12 333.619995 333.619995 329.970001 330.079987 118390000 330.079987
... ... ... ... ... ... ...
2015-12-17 2073.760010 2076.370117 2041.660034 2041.890015 4327390000 2041.890015
2015-12-18 2040.810059 2040.810059 2005.329956 2005.550049 6683070000 2005.550049
2015-12-21 2010.270020 2022.900024 2005.930054 2021.150024 3760280000 2021.150024
2015-12-22 2023.150024 2042.739990 2020.489990 2038.969971 3520860000 2038.969971
2015-12-23 2042.199951 2064.729980 2042.199951 2064.290039 3484090000 2064.290039
2015-12-24 2063.520020 2067.360107 2058.729980 2060.989990 1411860000 2060.989990
2015-12-28 2057.770020 2057.770020 2044.199951 2056.500000 2492510000 2056.500000
2015-12-29 2060.540039 2081.560059 2060.540039 2078.360107 2542000000 2078.360107
2015-12-30 2077.340088 2077.340088 2061.969971 2063.360107 2367430000 2063.360107
2015-12-31 2060.590088 2062.540039 2043.619995 2043.939941 2655330000 2043.939941
2016-01-04 2038.199951 2038.199951 1989.680054 2012.660034 4304880000 2012.660034
2016-01-05 2013.780029 2021.939941 2004.170044 2016.709961 3706620000 2016.709961
2016-01-06 2011.709961 2011.709961 1979.050049 1990.260010 4336660000 1990.260010
2016-01-07 1985.319946 1985.319946 1938.829956 1943.089966 5076590000 1943.089966
2016-01-08 1985.319946 1985.319946 1918.459961 1922.030029 4664940000 1922.030029
2016-01-11 1926.119995 1935.650024 1901.099976 1923.670044 4607290000 1923.670044
2016-01-12 1927.829956 1947.380005 1914.349976 1938.680054 4887260000 1938.680054
2016-01-13 1940.339966 1950.329956 1886.410034 1890.280029 5087030000 1890.280029
2016-01-14 1891.680054 1934.469971 1878.930054 1921.839966 5241110000 1921.839966
2016-01-15 1916.680054 1916.680054 1857.829956 1880.329956 5468460000 1880.329956
2016-01-19 1888.660034 1901.439941 1864.599976 1881.329956 4928350000 1881.329956
2016-01-20 1876.180054 1876.180054 1812.290039 1859.329956 6416070000 1859.329956
2016-01-21 1861.459961 1889.849976 1848.979980 1868.989990 5078810000 1868.989990
2016-01-22 1877.400024 1908.849976 1877.400024 1906.900024 4901760000 1906.900024
2016-01-25 1906.280029 1906.280029 1875.969971 1877.079956 4401380000 1877.079956
2016-01-26 1878.790039 1906.729980 1878.790039 1903.630005 4357940000 1903.630005
2016-01-27 1902.520020 1916.989990 1872.699951 1882.949951 4754040000 1882.949951
2016-01-28 1885.219971 1902.959961 1873.650024 1893.359985 4693010000 1893.359985
2016-01-29 1894.000000 1940.239990 1894.000000 1940.239990 5497570000 1940.239990
2016-02-01 1936.939941 1947.199951 1920.300049 1939.380005 4322530000 1939.380005

6573 rows × 6 columns


In [64]:
# Add a columns with long and short simple moving average columns
df = long_sma(df, 'Close')
print('* Added column: ' + list(df.columns.values)[-1:][0])
df = short_sma(df, 'Close')
print('* Added column: ' + list(df.columns.values)[-1:][0])


Enter the period in days for the long SMA: 20
* Added column: SMA_Close_20-day
Enter the period in days for the short SMA: 10
* Added column: SMA_Close_10-day

In [65]:
df


Out[65]:
Open High Low Close Volume Adj Close SMA_Close_20-day SMA_Close_10-day
Date
1990-01-02 353.399994 359.690002 351.980011 359.690002 162070000 359.690002 NaN NaN
1990-01-03 359.690002 360.589996 357.890015 358.760010 192330000 358.760010 NaN NaN
1990-01-04 358.760010 358.760010 352.890015 355.670013 177000000 355.670013 NaN NaN
1990-01-05 355.670013 355.670013 351.350006 352.200012 158530000 352.200012 NaN NaN
1990-01-08 352.200012 354.239990 350.540009 353.790009 140110000 353.790009 NaN NaN
1990-01-09 353.829987 354.170013 349.609985 349.619995 155210000 349.619995 NaN NaN
1990-01-10 349.619995 349.619995 344.320007 347.309998 175990000 347.309998 NaN NaN
1990-01-11 347.309998 350.140015 347.309998 348.529999 154390000 348.529999 NaN NaN
1990-01-12 348.529999 348.529999 339.489990 339.929993 183880000 339.929993 NaN NaN
1990-01-15 339.929993 339.940002 336.570007 337.000000 140590000 337.000000 NaN 350.250003
1990-01-16 337.000000 340.750000 333.369995 340.750000 186070000 340.750000 NaN 348.356003
1990-01-17 340.769989 342.010010 336.260010 337.399994 170470000 337.399994 NaN 346.220001
1990-01-18 337.399994 338.380005 333.980011 338.190002 178590000 338.190002 NaN 344.472000
1990-01-19 338.190002 340.480011 338.190002 339.149994 185590000 339.149994 NaN 343.166998
1990-01-22 339.140015 339.959991 330.279999 330.380005 148380000 330.380005 NaN 340.825998
1990-01-23 330.380005 332.760010 328.670013 331.609985 179300000 331.609985 NaN 339.024997
1990-01-24 331.609985 331.709991 324.170013 330.260010 207830000 330.260010 NaN 337.319998
1990-01-25 330.260010 332.329987 325.329987 326.079987 172270000 326.079987 NaN 335.074997
1990-01-26 326.089996 328.579987 321.440002 325.799988 198190000 325.799988 NaN 333.661997
1990-01-29 325.799988 327.309998 321.790009 325.200012 150770000 325.200012 341.366000 332.481998
1990-01-30 325.200012 325.730011 319.829987 322.980011 186030000 322.980011 339.530501 330.704999
1990-01-31 322.980011 329.079987 322.980011 329.079987 189660000 329.079987 338.046500 329.872998
1990-02-01 329.079987 329.859985 327.760010 328.790009 154580000 328.790009 336.702500 328.932999
1990-02-02 328.790009 332.100006 328.089996 330.920013 164400000 330.920013 335.638500 328.110001
1990-02-05 330.920013 332.160004 330.450012 331.850006 130950000 331.850006 334.541499 328.257001
1990-02-06 331.850006 331.859985 328.200012 329.660004 134070000 329.660004 333.543500 328.062003
1990-02-07 329.660004 333.760010 326.549988 333.750000 186710000 333.750000 332.865500 328.411002
1990-02-08 333.750000 336.089996 332.000000 332.959991 176240000 332.959991 332.087000 329.099002
1990-02-09 333.019989 334.600006 332.410004 333.619995 146910000 333.619995 331.771500 329.881003
1990-02-12 333.619995 333.619995 329.970001 330.079987 118390000 330.079987 331.425499 330.369000
... ... ... ... ... ... ... ... ...
2015-12-17 2073.760010 2076.370117 2041.660034 2041.890015 4327390000 2041.890015 2068.108508 2052.488013
2015-12-18 2040.810059 2040.810059 2005.329956 2005.550049 6683070000 2005.550049 2064.324011 2043.874023
2015-12-21 2010.270020 2022.900024 2005.930054 2021.150024 3760280000 2021.150024 2060.923016 2038.282019
2015-12-22 2023.150024 2042.739990 2020.489990 2038.969971 3520860000 2038.969971 2058.542010 2035.820007
2015-12-23 2042.199951 2064.729980 2042.199951 2064.290039 3484090000 2064.290039 2057.299518 2037.487012
2015-12-24 2063.520020 2067.360107 2058.729980 2060.989990 1411860000 2060.989990 2055.905511 2038.363013
2015-12-28 2057.770020 2057.770020 2044.199951 2056.500000 2492510000 2056.500000 2054.225006 2042.776013
2015-12-29 2060.540039 2081.560059 2060.540039 2078.360107 2542000000 2078.360107 2054.122516 2048.418030
2015-12-30 2077.340088 2077.340088 2061.969971 2063.360107 2367430000 2063.360107 2052.159027 2050.413037
2015-12-31 2060.590088 2062.540039 2043.619995 2043.939941 2655330000 2043.939941 2050.380523 2047.500024
2016-01-04 2038.199951 2038.199951 1989.680054 2012.660034 4304880000 2012.660034 2048.532519 2044.577026
2016-01-05 2013.780029 2021.939941 2004.170044 2016.709961 3706620000 2016.709961 2044.783520 2045.693017
2016-01-06 2011.709961 2011.709961 1979.050049 1990.260010 4336660000 1990.260010 2040.443017 2042.604016
2016-01-07 1985.319946 1985.319946 1938.829956 1943.089966 5076590000 1943.089966 2034.418011 2033.016016
2016-01-08 1985.319946 1985.319946 1918.459961 1922.030029 4664940000 1922.030029 2028.138513 2018.790015
2016-01-11 1926.119995 1935.650024 1901.099976 1923.670044 4607290000 1923.670044 2021.710516 2005.058020
2016-01-12 1927.829956 1947.380005 1914.349976 1938.680054 4887260000 1938.680054 2018.026019 1993.276025
2016-01-13 1940.339966 1950.329956 1886.410034 1890.280029 5087030000 1890.280029 2011.443024 1974.468018
2016-01-14 1891.680054 1934.469971 1878.930054 1921.839966 5241110000 1921.839966 2005.364520 1960.316003
2016-01-15 1916.680054 1916.680054 1857.829956 1880.329956 5468460000 1880.329956 1995.727515 1943.955005
2016-01-19 1888.660034 1901.439941 1864.599976 1881.329956 4928350000 1881.329956 1987.699512 1930.821997
2016-01-20 1876.180054 1876.180054 1812.290039 1859.329956 6416070000 1859.329956 1980.388507 1915.083997
2016-01-21 1861.459961 1889.849976 1848.979980 1868.989990 5078810000 1868.989990 1972.780505 1902.956995
2016-01-22 1877.400024 1908.849976 1877.400024 1906.900024 4901760000 1906.900024 1966.177008 1899.338000
2016-01-25 1906.280029 1906.280029 1875.969971 1877.079956 4401380000 1877.079956 1956.816504 1894.842993
2016-01-26 1878.790039 1906.729980 1878.790039 1903.630005 4357940000 1903.630005 1948.948505 1892.838989
2016-01-27 1902.520020 1916.989990 1872.699951 1882.949951 4754040000 1882.949951 1940.271002 1887.265979
2016-01-28 1885.219971 1902.959961 1873.650024 1893.359985 4693010000 1893.359985 1931.020996 1887.573975
2016-01-29 1894.000000 1940.239990 1894.000000 1940.239990 5497570000 1940.239990 1924.864990 1889.413977
2016-02-01 1936.939941 1947.199951 1920.300049 1939.380005 4322530000 1939.380005 1919.636993 1895.318982

6573 rows × 8 columns


In [66]:
# Add a column with the MACD from the long and short simple moving average columns
sma_columns = list(df.columns.values)[-2:]
df = diff(df, sma_columns[0], sma_columns[1], label='MACD_Close')
print('* Added column: ' + list(df.columns.values)[-1:][0])


* Added column: MACD_Close

In [67]:
df


Out[67]:
Open High Low Close Volume Adj Close SMA_Close_20-day SMA_Close_10-day MACD_Close
Date
1990-01-02 353.399994 359.690002 351.980011 359.690002 162070000 359.690002 NaN NaN NaN
1990-01-03 359.690002 360.589996 357.890015 358.760010 192330000 358.760010 NaN NaN NaN
1990-01-04 358.760010 358.760010 352.890015 355.670013 177000000 355.670013 NaN NaN NaN
1990-01-05 355.670013 355.670013 351.350006 352.200012 158530000 352.200012 NaN NaN NaN
1990-01-08 352.200012 354.239990 350.540009 353.790009 140110000 353.790009 NaN NaN NaN
1990-01-09 353.829987 354.170013 349.609985 349.619995 155210000 349.619995 NaN NaN NaN
1990-01-10 349.619995 349.619995 344.320007 347.309998 175990000 347.309998 NaN NaN NaN
1990-01-11 347.309998 350.140015 347.309998 348.529999 154390000 348.529999 NaN NaN NaN
1990-01-12 348.529999 348.529999 339.489990 339.929993 183880000 339.929993 NaN NaN NaN
1990-01-15 339.929993 339.940002 336.570007 337.000000 140590000 337.000000 NaN 350.250003 NaN
1990-01-16 337.000000 340.750000 333.369995 340.750000 186070000 340.750000 NaN 348.356003 NaN
1990-01-17 340.769989 342.010010 336.260010 337.399994 170470000 337.399994 NaN 346.220001 NaN
1990-01-18 337.399994 338.380005 333.980011 338.190002 178590000 338.190002 NaN 344.472000 NaN
1990-01-19 338.190002 340.480011 338.190002 339.149994 185590000 339.149994 NaN 343.166998 NaN
1990-01-22 339.140015 339.959991 330.279999 330.380005 148380000 330.380005 NaN 340.825998 NaN
1990-01-23 330.380005 332.760010 328.670013 331.609985 179300000 331.609985 NaN 339.024997 NaN
1990-01-24 331.609985 331.709991 324.170013 330.260010 207830000 330.260010 NaN 337.319998 NaN
1990-01-25 330.260010 332.329987 325.329987 326.079987 172270000 326.079987 NaN 335.074997 NaN
1990-01-26 326.089996 328.579987 321.440002 325.799988 198190000 325.799988 NaN 333.661997 NaN
1990-01-29 325.799988 327.309998 321.790009 325.200012 150770000 325.200012 341.366000 332.481998 8.884003
1990-01-30 325.200012 325.730011 319.829987 322.980011 186030000 322.980011 339.530501 330.704999 8.825502
1990-01-31 322.980011 329.079987 322.980011 329.079987 189660000 329.079987 338.046500 329.872998 8.173502
1990-02-01 329.079987 329.859985 327.760010 328.790009 154580000 328.790009 336.702500 328.932999 7.769501
1990-02-02 328.790009 332.100006 328.089996 330.920013 164400000 330.920013 335.638500 328.110001 7.528499
1990-02-05 330.920013 332.160004 330.450012 331.850006 130950000 331.850006 334.541499 328.257001 6.284499
1990-02-06 331.850006 331.859985 328.200012 329.660004 134070000 329.660004 333.543500 328.062003 5.481497
1990-02-07 329.660004 333.760010 326.549988 333.750000 186710000 333.750000 332.865500 328.411002 4.454498
1990-02-08 333.750000 336.089996 332.000000 332.959991 176240000 332.959991 332.087000 329.099002 2.987997
1990-02-09 333.019989 334.600006 332.410004 333.619995 146910000 333.619995 331.771500 329.881003 1.890497
1990-02-12 333.619995 333.619995 329.970001 330.079987 118390000 330.079987 331.425499 330.369000 1.056499
... ... ... ... ... ... ... ... ... ...
2015-12-17 2073.760010 2076.370117 2041.660034 2041.890015 4327390000 2041.890015 2068.108508 2052.488013 15.620496
2015-12-18 2040.810059 2040.810059 2005.329956 2005.550049 6683070000 2005.550049 2064.324011 2043.874023 20.449988
2015-12-21 2010.270020 2022.900024 2005.930054 2021.150024 3760280000 2021.150024 2060.923016 2038.282019 22.640997
2015-12-22 2023.150024 2042.739990 2020.489990 2038.969971 3520860000 2038.969971 2058.542010 2035.820007 22.722003
2015-12-23 2042.199951 2064.729980 2042.199951 2064.290039 3484090000 2064.290039 2057.299518 2037.487012 19.812506
2015-12-24 2063.520020 2067.360107 2058.729980 2060.989990 1411860000 2060.989990 2055.905511 2038.363013 17.542499
2015-12-28 2057.770020 2057.770020 2044.199951 2056.500000 2492510000 2056.500000 2054.225006 2042.776013 11.448993
2015-12-29 2060.540039 2081.560059 2060.540039 2078.360107 2542000000 2078.360107 2054.122516 2048.418030 5.704486
2015-12-30 2077.340088 2077.340088 2061.969971 2063.360107 2367430000 2063.360107 2052.159027 2050.413037 1.745990
2015-12-31 2060.590088 2062.540039 2043.619995 2043.939941 2655330000 2043.939941 2050.380523 2047.500024 2.880499
2016-01-04 2038.199951 2038.199951 1989.680054 2012.660034 4304880000 2012.660034 2048.532519 2044.577026 3.955493
2016-01-05 2013.780029 2021.939941 2004.170044 2016.709961 3706620000 2016.709961 2044.783520 2045.693017 -0.909497
2016-01-06 2011.709961 2011.709961 1979.050049 1990.260010 4336660000 1990.260010 2040.443017 2042.604016 -2.160999
2016-01-07 1985.319946 1985.319946 1938.829956 1943.089966 5076590000 1943.089966 2034.418011 2033.016016 1.401996
2016-01-08 1985.319946 1985.319946 1918.459961 1922.030029 4664940000 1922.030029 2028.138513 2018.790015 9.348499
2016-01-11 1926.119995 1935.650024 1901.099976 1923.670044 4607290000 1923.670044 2021.710516 2005.058020 16.652496
2016-01-12 1927.829956 1947.380005 1914.349976 1938.680054 4887260000 1938.680054 2018.026019 1993.276025 24.749994
2016-01-13 1940.339966 1950.329956 1886.410034 1890.280029 5087030000 1890.280029 2011.443024 1974.468018 36.975006
2016-01-14 1891.680054 1934.469971 1878.930054 1921.839966 5241110000 1921.839966 2005.364520 1960.316003 45.048517
2016-01-15 1916.680054 1916.680054 1857.829956 1880.329956 5468460000 1880.329956 1995.727515 1943.955005 51.772510
2016-01-19 1888.660034 1901.439941 1864.599976 1881.329956 4928350000 1881.329956 1987.699512 1930.821997 56.877515
2016-01-20 1876.180054 1876.180054 1812.290039 1859.329956 6416070000 1859.329956 1980.388507 1915.083997 65.304510
2016-01-21 1861.459961 1889.849976 1848.979980 1868.989990 5078810000 1868.989990 1972.780505 1902.956995 69.823511
2016-01-22 1877.400024 1908.849976 1877.400024 1906.900024 4901760000 1906.900024 1966.177008 1899.338000 66.839008
2016-01-25 1906.280029 1906.280029 1875.969971 1877.079956 4401380000 1877.079956 1956.816504 1894.842993 61.973511
2016-01-26 1878.790039 1906.729980 1878.790039 1903.630005 4357940000 1903.630005 1948.948505 1892.838989 56.109515
2016-01-27 1902.520020 1916.989990 1872.699951 1882.949951 4754040000 1882.949951 1940.271002 1887.265979 53.005023
2016-01-28 1885.219971 1902.959961 1873.650024 1893.359985 4693010000 1893.359985 1931.020996 1887.573975 43.447021
2016-01-29 1894.000000 1940.239990 1894.000000 1940.239990 5497570000 1940.239990 1924.864990 1889.413977 35.451013
2016-02-01 1936.939941 1947.199951 1920.300049 1939.380005 4322530000 1939.380005 1919.636993 1895.318982 24.318012

6573 rows × 9 columns


In [68]:
# Add a column with a SMA of the last MACD column
macd_column = list(df.columns.values)[-1:][0]
df = macd(df, macd_column, label='SMA_' + macd_column)
print('* Added column: ' + list(df.columns.values)[-1:][0])


Enter the period in days for the SMA of the MACD: 3
* Added column: SMA_MACD_Close_3-day

In [69]:
df


Out[69]:
Open High Low Close Volume Adj Close SMA_Close_20-day SMA_Close_10-day MACD_Close SMA_MACD_Close_3-day
Date
1990-01-02 353.399994 359.690002 351.980011 359.690002 162070000 359.690002 NaN NaN NaN NaN
1990-01-03 359.690002 360.589996 357.890015 358.760010 192330000 358.760010 NaN NaN NaN NaN
1990-01-04 358.760010 358.760010 352.890015 355.670013 177000000 355.670013 NaN NaN NaN NaN
1990-01-05 355.670013 355.670013 351.350006 352.200012 158530000 352.200012 NaN NaN NaN NaN
1990-01-08 352.200012 354.239990 350.540009 353.790009 140110000 353.790009 NaN NaN NaN NaN
1990-01-09 353.829987 354.170013 349.609985 349.619995 155210000 349.619995 NaN NaN NaN NaN
1990-01-10 349.619995 349.619995 344.320007 347.309998 175990000 347.309998 NaN NaN NaN NaN
1990-01-11 347.309998 350.140015 347.309998 348.529999 154390000 348.529999 NaN NaN NaN NaN
1990-01-12 348.529999 348.529999 339.489990 339.929993 183880000 339.929993 NaN NaN NaN NaN
1990-01-15 339.929993 339.940002 336.570007 337.000000 140590000 337.000000 NaN 350.250003 NaN NaN
1990-01-16 337.000000 340.750000 333.369995 340.750000 186070000 340.750000 NaN 348.356003 NaN NaN
1990-01-17 340.769989 342.010010 336.260010 337.399994 170470000 337.399994 NaN 346.220001 NaN NaN
1990-01-18 337.399994 338.380005 333.980011 338.190002 178590000 338.190002 NaN 344.472000 NaN NaN
1990-01-19 338.190002 340.480011 338.190002 339.149994 185590000 339.149994 NaN 343.166998 NaN NaN
1990-01-22 339.140015 339.959991 330.279999 330.380005 148380000 330.380005 NaN 340.825998 NaN NaN
1990-01-23 330.380005 332.760010 328.670013 331.609985 179300000 331.609985 NaN 339.024997 NaN NaN
1990-01-24 331.609985 331.709991 324.170013 330.260010 207830000 330.260010 NaN 337.319998 NaN NaN
1990-01-25 330.260010 332.329987 325.329987 326.079987 172270000 326.079987 NaN 335.074997 NaN NaN
1990-01-26 326.089996 328.579987 321.440002 325.799988 198190000 325.799988 NaN 333.661997 NaN NaN
1990-01-29 325.799988 327.309998 321.790009 325.200012 150770000 325.200012 341.366000 332.481998 8.884003 NaN
1990-01-30 325.200012 325.730011 319.829987 322.980011 186030000 322.980011 339.530501 330.704999 8.825502 NaN
1990-01-31 322.980011 329.079987 322.980011 329.079987 189660000 329.079987 338.046500 329.872998 8.173502 8.627669
1990-02-01 329.079987 329.859985 327.760010 328.790009 154580000 328.790009 336.702500 328.932999 7.769501 8.256168
1990-02-02 328.790009 332.100006 328.089996 330.920013 164400000 330.920013 335.638500 328.110001 7.528499 7.823834
1990-02-05 330.920013 332.160004 330.450012 331.850006 130950000 331.850006 334.541499 328.257001 6.284499 7.194166
1990-02-06 331.850006 331.859985 328.200012 329.660004 134070000 329.660004 333.543500 328.062003 5.481497 6.431498
1990-02-07 329.660004 333.760010 326.549988 333.750000 186710000 333.750000 332.865500 328.411002 4.454498 5.406831
1990-02-08 333.750000 336.089996 332.000000 332.959991 176240000 332.959991 332.087000 329.099002 2.987997 4.307998
1990-02-09 333.019989 334.600006 332.410004 333.619995 146910000 333.619995 331.771500 329.881003 1.890497 3.110998
1990-02-12 333.619995 333.619995 329.970001 330.079987 118390000 330.079987 331.425499 330.369000 1.056499 1.978331
... ... ... ... ... ... ... ... ... ... ...
2015-12-17 2073.760010 2076.370117 2041.660034 2041.890015 4327390000 2041.890015 2068.108508 2052.488013 15.620496 15.902991
2015-12-18 2040.810059 2040.810059 2005.329956 2005.550049 6683070000 2005.550049 2064.324011 2043.874023 20.449988 17.667491
2015-12-21 2010.270020 2022.900024 2005.930054 2021.150024 3760280000 2021.150024 2060.923016 2038.282019 22.640997 19.570494
2015-12-22 2023.150024 2042.739990 2020.489990 2038.969971 3520860000 2038.969971 2058.542010 2035.820007 22.722003 21.937663
2015-12-23 2042.199951 2064.729980 2042.199951 2064.290039 3484090000 2064.290039 2057.299518 2037.487012 19.812506 21.725169
2015-12-24 2063.520020 2067.360107 2058.729980 2060.989990 1411860000 2060.989990 2055.905511 2038.363013 17.542499 20.025669
2015-12-28 2057.770020 2057.770020 2044.199951 2056.500000 2492510000 2056.500000 2054.225006 2042.776013 11.448993 16.267999
2015-12-29 2060.540039 2081.560059 2060.540039 2078.360107 2542000000 2078.360107 2054.122516 2048.418030 5.704486 11.565326
2015-12-30 2077.340088 2077.340088 2061.969971 2063.360107 2367430000 2063.360107 2052.159027 2050.413037 1.745990 6.299823
2015-12-31 2060.590088 2062.540039 2043.619995 2043.939941 2655330000 2043.939941 2050.380523 2047.500024 2.880499 3.443658
2016-01-04 2038.199951 2038.199951 1989.680054 2012.660034 4304880000 2012.660034 2048.532519 2044.577026 3.955493 2.860661
2016-01-05 2013.780029 2021.939941 2004.170044 2016.709961 3706620000 2016.709961 2044.783520 2045.693017 -0.909497 1.975498
2016-01-06 2011.709961 2011.709961 1979.050049 1990.260010 4336660000 1990.260010 2040.443017 2042.604016 -2.160999 0.294999
2016-01-07 1985.319946 1985.319946 1938.829956 1943.089966 5076590000 1943.089966 2034.418011 2033.016016 1.401996 -0.556167
2016-01-08 1985.319946 1985.319946 1918.459961 1922.030029 4664940000 1922.030029 2028.138513 2018.790015 9.348499 2.863165
2016-01-11 1926.119995 1935.650024 1901.099976 1923.670044 4607290000 1923.670044 2021.710516 2005.058020 16.652496 9.134330
2016-01-12 1927.829956 1947.380005 1914.349976 1938.680054 4887260000 1938.680054 2018.026019 1993.276025 24.749994 16.916996
2016-01-13 1940.339966 1950.329956 1886.410034 1890.280029 5087030000 1890.280029 2011.443024 1974.468018 36.975006 26.125832
2016-01-14 1891.680054 1934.469971 1878.930054 1921.839966 5241110000 1921.839966 2005.364520 1960.316003 45.048517 35.591172
2016-01-15 1916.680054 1916.680054 1857.829956 1880.329956 5468460000 1880.329956 1995.727515 1943.955005 51.772510 44.598678
2016-01-19 1888.660034 1901.439941 1864.599976 1881.329956 4928350000 1881.329956 1987.699512 1930.821997 56.877515 51.232847
2016-01-20 1876.180054 1876.180054 1812.290039 1859.329956 6416070000 1859.329956 1980.388507 1915.083997 65.304510 57.984845
2016-01-21 1861.459961 1889.849976 1848.979980 1868.989990 5078810000 1868.989990 1972.780505 1902.956995 69.823511 64.001845
2016-01-22 1877.400024 1908.849976 1877.400024 1906.900024 4901760000 1906.900024 1966.177008 1899.338000 66.839008 67.322343
2016-01-25 1906.280029 1906.280029 1875.969971 1877.079956 4401380000 1877.079956 1956.816504 1894.842993 61.973511 66.212010
2016-01-26 1878.790039 1906.729980 1878.790039 1903.630005 4357940000 1903.630005 1948.948505 1892.838989 56.109515 61.640678
2016-01-27 1902.520020 1916.989990 1872.699951 1882.949951 4754040000 1882.949951 1940.271002 1887.265979 53.005023 57.029350
2016-01-28 1885.219971 1902.959961 1873.650024 1893.359985 4693010000 1893.359985 1931.020996 1887.573975 43.447021 50.853853
2016-01-29 1894.000000 1940.239990 1894.000000 1940.239990 5497570000 1940.239990 1924.864990 1889.413977 35.451013 43.967686
2016-02-01 1936.939941 1947.199951 1920.300049 1939.380005 4322530000 1939.380005 1919.636993 1895.318982 24.318012 34.405349

6573 rows × 10 columns


In [70]:
# Add a column with a MACD the last two columns
macd_sma_columns = list(df.columns.values)[-2:]
df = diff(df, macd_sma_columns[0], macd_sma_columns[1])
print('* Added column: ' + list(df.columns.values)[-1:][0])


* Added column: Delta_SMA_MACD_Close_3-day

In [71]:
df


Out[71]:
Open High Low Close Volume Adj Close SMA_Close_20-day SMA_Close_10-day MACD_Close SMA_MACD_Close_3-day Delta_SMA_MACD_Close_3-day
Date
1990-01-02 353.399994 359.690002 351.980011 359.690002 162070000 359.690002 NaN NaN NaN NaN NaN
1990-01-03 359.690002 360.589996 357.890015 358.760010 192330000 358.760010 NaN NaN NaN NaN NaN
1990-01-04 358.760010 358.760010 352.890015 355.670013 177000000 355.670013 NaN NaN NaN NaN NaN
1990-01-05 355.670013 355.670013 351.350006 352.200012 158530000 352.200012 NaN NaN NaN NaN NaN
1990-01-08 352.200012 354.239990 350.540009 353.790009 140110000 353.790009 NaN NaN NaN NaN NaN
1990-01-09 353.829987 354.170013 349.609985 349.619995 155210000 349.619995 NaN NaN NaN NaN NaN
1990-01-10 349.619995 349.619995 344.320007 347.309998 175990000 347.309998 NaN NaN NaN NaN NaN
1990-01-11 347.309998 350.140015 347.309998 348.529999 154390000 348.529999 NaN NaN NaN NaN NaN
1990-01-12 348.529999 348.529999 339.489990 339.929993 183880000 339.929993 NaN NaN NaN NaN NaN
1990-01-15 339.929993 339.940002 336.570007 337.000000 140590000 337.000000 NaN 350.250003 NaN NaN NaN
1990-01-16 337.000000 340.750000 333.369995 340.750000 186070000 340.750000 NaN 348.356003 NaN NaN NaN
1990-01-17 340.769989 342.010010 336.260010 337.399994 170470000 337.399994 NaN 346.220001 NaN NaN NaN
1990-01-18 337.399994 338.380005 333.980011 338.190002 178590000 338.190002 NaN 344.472000 NaN NaN NaN
1990-01-19 338.190002 340.480011 338.190002 339.149994 185590000 339.149994 NaN 343.166998 NaN NaN NaN
1990-01-22 339.140015 339.959991 330.279999 330.380005 148380000 330.380005 NaN 340.825998 NaN NaN NaN
1990-01-23 330.380005 332.760010 328.670013 331.609985 179300000 331.609985 NaN 339.024997 NaN NaN NaN
1990-01-24 331.609985 331.709991 324.170013 330.260010 207830000 330.260010 NaN 337.319998 NaN NaN NaN
1990-01-25 330.260010 332.329987 325.329987 326.079987 172270000 326.079987 NaN 335.074997 NaN NaN NaN
1990-01-26 326.089996 328.579987 321.440002 325.799988 198190000 325.799988 NaN 333.661997 NaN NaN NaN
1990-01-29 325.799988 327.309998 321.790009 325.200012 150770000 325.200012 341.366000 332.481998 8.884003 NaN NaN
1990-01-30 325.200012 325.730011 319.829987 322.980011 186030000 322.980011 339.530501 330.704999 8.825502 NaN NaN
1990-01-31 322.980011 329.079987 322.980011 329.079987 189660000 329.079987 338.046500 329.872998 8.173502 8.627669 -0.454167
1990-02-01 329.079987 329.859985 327.760010 328.790009 154580000 328.790009 336.702500 328.932999 7.769501 8.256168 -0.486667
1990-02-02 328.790009 332.100006 328.089996 330.920013 164400000 330.920013 335.638500 328.110001 7.528499 7.823834 -0.295335
1990-02-05 330.920013 332.160004 330.450012 331.850006 130950000 331.850006 334.541499 328.257001 6.284499 7.194166 -0.909667
1990-02-06 331.850006 331.859985 328.200012 329.660004 134070000 329.660004 333.543500 328.062003 5.481497 6.431498 -0.950001
1990-02-07 329.660004 333.760010 326.549988 333.750000 186710000 333.750000 332.865500 328.411002 4.454498 5.406831 -0.952333
1990-02-08 333.750000 336.089996 332.000000 332.959991 176240000 332.959991 332.087000 329.099002 2.987997 4.307998 -1.320000
1990-02-09 333.019989 334.600006 332.410004 333.619995 146910000 333.619995 331.771500 329.881003 1.890497 3.110998 -1.220501
1990-02-12 333.619995 333.619995 329.970001 330.079987 118390000 330.079987 331.425499 330.369000 1.056499 1.978331 -0.921832
... ... ... ... ... ... ... ... ... ... ... ...
2015-12-17 2073.760010 2076.370117 2041.660034 2041.890015 4327390000 2041.890015 2068.108508 2052.488013 15.620496 15.902991 -0.282495
2015-12-18 2040.810059 2040.810059 2005.329956 2005.550049 6683070000 2005.550049 2064.324011 2043.874023 20.449988 17.667491 2.782497
2015-12-21 2010.270020 2022.900024 2005.930054 2021.150024 3760280000 2021.150024 2060.923016 2038.282019 22.640997 19.570494 3.070504
2015-12-22 2023.150024 2042.739990 2020.489990 2038.969971 3520860000 2038.969971 2058.542010 2035.820007 22.722003 21.937663 0.784340
2015-12-23 2042.199951 2064.729980 2042.199951 2064.290039 3484090000 2064.290039 2057.299518 2037.487012 19.812506 21.725169 -1.912663
2015-12-24 2063.520020 2067.360107 2058.729980 2060.989990 1411860000 2060.989990 2055.905511 2038.363013 17.542499 20.025669 -2.483171
2015-12-28 2057.770020 2057.770020 2044.199951 2056.500000 2492510000 2056.500000 2054.225006 2042.776013 11.448993 16.267999 -4.819006
2015-12-29 2060.540039 2081.560059 2060.540039 2078.360107 2542000000 2078.360107 2054.122516 2048.418030 5.704486 11.565326 -5.860840
2015-12-30 2077.340088 2077.340088 2061.969971 2063.360107 2367430000 2063.360107 2052.159027 2050.413037 1.745990 6.299823 -4.553833
2015-12-31 2060.590088 2062.540039 2043.619995 2043.939941 2655330000 2043.939941 2050.380523 2047.500024 2.880499 3.443658 -0.563159
2016-01-04 2038.199951 2038.199951 1989.680054 2012.660034 4304880000 2012.660034 2048.532519 2044.577026 3.955493 2.860661 1.094832
2016-01-05 2013.780029 2021.939941 2004.170044 2016.709961 3706620000 2016.709961 2044.783520 2045.693017 -0.909497 1.975498 -2.884995
2016-01-06 2011.709961 2011.709961 1979.050049 1990.260010 4336660000 1990.260010 2040.443017 2042.604016 -2.160999 0.294999 -2.455998
2016-01-07 1985.319946 1985.319946 1938.829956 1943.089966 5076590000 1943.089966 2034.418011 2033.016016 1.401996 -0.556167 1.958162
2016-01-08 1985.319946 1985.319946 1918.459961 1922.030029 4664940000 1922.030029 2028.138513 2018.790015 9.348499 2.863165 6.485333
2016-01-11 1926.119995 1935.650024 1901.099976 1923.670044 4607290000 1923.670044 2021.710516 2005.058020 16.652496 9.134330 7.518166
2016-01-12 1927.829956 1947.380005 1914.349976 1938.680054 4887260000 1938.680054 2018.026019 1993.276025 24.749994 16.916996 7.832998
2016-01-13 1940.339966 1950.329956 1886.410034 1890.280029 5087030000 1890.280029 2011.443024 1974.468018 36.975006 26.125832 10.849174
2016-01-14 1891.680054 1934.469971 1878.930054 1921.839966 5241110000 1921.839966 2005.364520 1960.316003 45.048517 35.591172 9.457345
2016-01-15 1916.680054 1916.680054 1857.829956 1880.329956 5468460000 1880.329956 1995.727515 1943.955005 51.772510 44.598678 7.173832
2016-01-19 1888.660034 1901.439941 1864.599976 1881.329956 4928350000 1881.329956 1987.699512 1930.821997 56.877515 51.232847 5.644668
2016-01-20 1876.180054 1876.180054 1812.290039 1859.329956 6416070000 1859.329956 1980.388507 1915.083997 65.304510 57.984845 7.319666
2016-01-21 1861.459961 1889.849976 1848.979980 1868.989990 5078810000 1868.989990 1972.780505 1902.956995 69.823511 64.001845 5.821665
2016-01-22 1877.400024 1908.849976 1877.400024 1906.900024 4901760000 1906.900024 1966.177008 1899.338000 66.839008 67.322343 -0.483335
2016-01-25 1906.280029 1906.280029 1875.969971 1877.079956 4401380000 1877.079956 1956.816504 1894.842993 61.973511 66.212010 -4.238499
2016-01-26 1878.790039 1906.729980 1878.790039 1903.630005 4357940000 1903.630005 1948.948505 1892.838989 56.109515 61.640678 -5.531163
2016-01-27 1902.520020 1916.989990 1872.699951 1882.949951 4754040000 1882.949951 1940.271002 1887.265979 53.005023 57.029350 -4.024327
2016-01-28 1885.219971 1902.959961 1873.650024 1893.359985 4693010000 1893.359985 1931.020996 1887.573975 43.447021 50.853853 -7.406832
2016-01-29 1894.000000 1940.239990 1894.000000 1940.239990 5497570000 1940.239990 1924.864990 1889.413977 35.451013 43.967686 -8.516673
2016-02-01 1936.939941 1947.199951 1920.300049 1939.380005 4322530000 1939.380005 1919.636993 1895.318982 24.318012 34.405349 -10.087337

6573 rows × 11 columns


In [72]:
# Add a column that flags the crossovers or sign swings over a given period
delta_column = list(df.columns.values)[-1:][0]
df = flag_swings(df, delta_column)
print('* Added column: ' + list(df.columns.values)[-1:][0])


Enter the period in days to flag swings: 3
* Added column: SwingFlag_3-day

In [73]:
df


Out[73]:
Open High Low Close Volume Adj Close SMA_Close_20-day SMA_Close_10-day MACD_Close SMA_MACD_Close_3-day Delta_SMA_MACD_Close_3-day SwingFlag_3-day
Date
1990-01-31 322.980011 329.079987 322.980011 329.079987 189660000 329.079987 338.046500 329.872998 8.173502 8.627669 -0.454167 0
1990-02-01 329.079987 329.859985 327.760010 328.790009 154580000 328.790009 336.702500 328.932999 7.769501 8.256168 -0.486667 0
1990-02-02 328.790009 332.100006 328.089996 330.920013 164400000 330.920013 335.638500 328.110001 7.528499 7.823834 -0.295335 0
1990-02-05 330.920013 332.160004 330.450012 331.850006 130950000 331.850006 334.541499 328.257001 6.284499 7.194166 -0.909667 0
1990-02-06 331.850006 331.859985 328.200012 329.660004 134070000 329.660004 333.543500 328.062003 5.481497 6.431498 -0.950001 0
1990-02-07 329.660004 333.760010 326.549988 333.750000 186710000 333.750000 332.865500 328.411002 4.454498 5.406831 -0.952333 0
1990-02-08 333.750000 336.089996 332.000000 332.959991 176240000 332.959991 332.087000 329.099002 2.987997 4.307998 -1.320000 0
1990-02-09 333.019989 334.600006 332.410004 333.619995 146910000 333.619995 331.771500 329.881003 1.890497 3.110998 -1.220501 0
1990-02-12 333.619995 333.619995 329.970001 330.079987 118390000 330.079987 331.425499 330.369000 1.056499 1.978331 -0.921832 0
1990-02-13 330.079987 331.609985 327.920013 331.019989 144490000 331.019989 330.938998 331.172998 -0.234000 0.904332 -1.138332 0
1990-02-14 331.019989 333.200012 330.640015 332.010010 138530000 332.010010 330.669499 331.466000 -0.796501 0.008666 -0.805167 0
1990-02-15 332.010010 335.209991 331.609985 334.890015 174620000 334.890015 330.504500 332.076001 -1.571501 -0.867334 -0.704167 0
1990-02-16 334.890015 335.640015 332.420013 332.720001 166840000 332.720001 330.183000 332.256000 -2.073000 -1.480334 -0.592666 0
1990-02-20 332.720001 332.720001 326.260010 327.989990 147300000 327.989990 330.063499 331.869998 -1.806499 -1.817000 0.010501 1
1990-02-21 327.910004 328.170013 324.470001 327.670013 159240000 327.670013 329.866501 331.670999 -1.804498 -1.894665 0.090167 0
1990-02-22 327.670013 330.980011 325.700012 325.700012 184320000 325.700012 329.638501 330.866000 -1.227499 -1.612832 0.385333 0
1990-02-23 325.700012 326.149994 322.100006 324.149994 148490000 324.149994 329.542001 329.985001 -0.442999 -1.158332 0.715333 0
1990-02-26 324.160004 328.670013 323.980011 328.670013 148900000 328.670013 329.685503 329.490002 0.195500 -0.491666 0.687166 0
1990-02-27 328.679993 331.940002 328.470001 330.260010 152590000 330.260010 329.938502 329.508005 0.430498 0.061000 0.369498 0
1990-02-28 330.260010 333.480011 330.160004 331.890015 184400000 331.890015 330.384003 329.595007 0.788995 0.471664 0.317331 0
1990-03-01 331.890015 334.399994 331.079987 332.739990 157930000 332.739990 330.567003 329.668005 0.898998 0.706164 0.192834 0
1990-03-02 332.739990 335.540009 332.720001 335.540009 164330000 335.540009 330.904503 329.733005 1.171498 0.953164 0.218334 0
1990-03-05 335.540009 336.380005 333.489990 333.739990 140110000 333.739990 331.045502 329.835004 1.210498 1.093665 0.116834 0
1990-03-06 333.739990 337.929993 333.570007 337.929993 143640000 337.929993 331.349501 330.829004 0.520497 0.967498 -0.447001 -1
1990-03-07 337.929993 338.839996 336.329987 336.950012 163580000 336.950012 331.714001 331.757004 -0.043002 0.562664 -0.605667 0
1990-03-08 336.950012 340.660004 336.950012 340.269989 170900000 340.269989 332.040001 333.214002 -1.174001 -0.232169 -0.941832 0
1990-03-09 340.119995 340.269989 336.839996 337.929993 150410000 337.929993 332.288501 334.592001 -2.303500 -1.173501 -1.129999 0
1990-03-12 337.929993 339.079987 336.140015 338.670013 114790000 338.670013 332.541002 335.592001 -3.051000 -2.176167 -0.874833 0
1990-03-13 338.670013 338.670013 335.359985 336.000000 145440000 336.000000 332.837003 336.166000 -3.328998 -2.894499 -0.434499 0
1990-03-14 336.000000 337.630005 334.929993 336.869995 145060000 336.869995 333.129503 336.663998 -3.534496 -3.304831 -0.229665 0
... ... ... ... ... ... ... ... ... ... ... ... ...
2015-12-17 2073.760010 2076.370117 2041.660034 2041.890015 4327390000 2041.890015 2068.108508 2052.488013 15.620496 15.902991 -0.282495 -1
2015-12-18 2040.810059 2040.810059 2005.329956 2005.550049 6683070000 2005.550049 2064.324011 2043.874023 20.449988 17.667491 2.782497 0
2015-12-21 2010.270020 2022.900024 2005.930054 2021.150024 3760280000 2021.150024 2060.923016 2038.282019 22.640997 19.570494 3.070504 0
2015-12-22 2023.150024 2042.739990 2020.489990 2038.969971 3520860000 2038.969971 2058.542010 2035.820007 22.722003 21.937663 0.784340 0
2015-12-23 2042.199951 2064.729980 2042.199951 2064.290039 3484090000 2064.290039 2057.299518 2037.487012 19.812506 21.725169 -1.912663 -1
2015-12-24 2063.520020 2067.360107 2058.729980 2060.989990 1411860000 2060.989990 2055.905511 2038.363013 17.542499 20.025669 -2.483171 0
2015-12-28 2057.770020 2057.770020 2044.199951 2056.500000 2492510000 2056.500000 2054.225006 2042.776013 11.448993 16.267999 -4.819006 0
2015-12-29 2060.540039 2081.560059 2060.540039 2078.360107 2542000000 2078.360107 2054.122516 2048.418030 5.704486 11.565326 -5.860840 0
2015-12-30 2077.340088 2077.340088 2061.969971 2063.360107 2367430000 2063.360107 2052.159027 2050.413037 1.745990 6.299823 -4.553833 0
2015-12-31 2060.590088 2062.540039 2043.619995 2043.939941 2655330000 2043.939941 2050.380523 2047.500024 2.880499 3.443658 -0.563159 0
2016-01-04 2038.199951 2038.199951 1989.680054 2012.660034 4304880000 2012.660034 2048.532519 2044.577026 3.955493 2.860661 1.094832 1
2016-01-05 2013.780029 2021.939941 2004.170044 2016.709961 3706620000 2016.709961 2044.783520 2045.693017 -0.909497 1.975498 -2.884995 0
2016-01-06 2011.709961 2011.709961 1979.050049 1990.260010 4336660000 1990.260010 2040.443017 2042.604016 -2.160999 0.294999 -2.455998 0
2016-01-07 1985.319946 1985.319946 1938.829956 1943.089966 5076590000 1943.089966 2034.418011 2033.016016 1.401996 -0.556167 1.958162 0
2016-01-08 1985.319946 1985.319946 1918.459961 1922.030029 4664940000 1922.030029 2028.138513 2018.790015 9.348499 2.863165 6.485333 0
2016-01-11 1926.119995 1935.650024 1901.099976 1923.670044 4607290000 1923.670044 2021.710516 2005.058020 16.652496 9.134330 7.518166 0
2016-01-12 1927.829956 1947.380005 1914.349976 1938.680054 4887260000 1938.680054 2018.026019 1993.276025 24.749994 16.916996 7.832998 0
2016-01-13 1940.339966 1950.329956 1886.410034 1890.280029 5087030000 1890.280029 2011.443024 1974.468018 36.975006 26.125832 10.849174 0
2016-01-14 1891.680054 1934.469971 1878.930054 1921.839966 5241110000 1921.839966 2005.364520 1960.316003 45.048517 35.591172 9.457345 0
2016-01-15 1916.680054 1916.680054 1857.829956 1880.329956 5468460000 1880.329956 1995.727515 1943.955005 51.772510 44.598678 7.173832 0
2016-01-19 1888.660034 1901.439941 1864.599976 1881.329956 4928350000 1881.329956 1987.699512 1930.821997 56.877515 51.232847 5.644668 0
2016-01-20 1876.180054 1876.180054 1812.290039 1859.329956 6416070000 1859.329956 1980.388507 1915.083997 65.304510 57.984845 7.319666 0
2016-01-21 1861.459961 1889.849976 1848.979980 1868.989990 5078810000 1868.989990 1972.780505 1902.956995 69.823511 64.001845 5.821665 0
2016-01-22 1877.400024 1908.849976 1877.400024 1906.900024 4901760000 1906.900024 1966.177008 1899.338000 66.839008 67.322343 -0.483335 -1
2016-01-25 1906.280029 1906.280029 1875.969971 1877.079956 4401380000 1877.079956 1956.816504 1894.842993 61.973511 66.212010 -4.238499 0
2016-01-26 1878.790039 1906.729980 1878.790039 1903.630005 4357940000 1903.630005 1948.948505 1892.838989 56.109515 61.640678 -5.531163 0
2016-01-27 1902.520020 1916.989990 1872.699951 1882.949951 4754040000 1882.949951 1940.271002 1887.265979 53.005023 57.029350 -4.024327 0
2016-01-28 1885.219971 1902.959961 1873.650024 1893.359985 4693010000 1893.359985 1931.020996 1887.573975 43.447021 50.853853 -7.406832 0
2016-01-29 1894.000000 1940.239990 1894.000000 1940.239990 5497570000 1940.239990 1924.864990 1889.413977 35.451013 43.967686 -8.516673 0
2016-02-01 1936.939941 1947.199951 1920.300049 1939.380005 4322530000 1939.380005 1919.636993 1895.318982 24.318012 34.405349 -10.087337 0

6552 rows × 12 columns


In [88]:
df = sign_sequence(df, delta_column)
print('* Added column: ' + list(df.columns.values)[-1:][0])


Enter the days prior to list the signs: 3
* Added column: SignSequence_3-days

In [89]:
df


Out[89]:
Open High Low Close Volume Adj Close SMA_Close_20-day SMA_Close_10-day MACD_Close SMA_MACD_Close_3-day Delta_SMA_MACD_Close_3-day SwingFlag_3-day PriorSigns_3-days SignSequence_3-days
Date
1990-02-12 333.619995 333.619995 329.970001 330.079987 118390000 330.079987 331.425499 330.369000 1.056499 1.978331 -0.921832 0 -1,-1,-1 -1,-1,-1
1990-02-13 330.079987 331.609985 327.920013 331.019989 144490000 331.019989 330.938998 331.172998 -0.234000 0.904332 -1.138332 0 -1,-1,-1 -1,-1,-1
1990-02-14 331.019989 333.200012 330.640015 332.010010 138530000 332.010010 330.669499 331.466000 -0.796501 0.008666 -0.805167 0 -1,-1,-1 -1,-1,-1
1990-02-15 332.010010 335.209991 331.609985 334.890015 174620000 334.890015 330.504500 332.076001 -1.571501 -0.867334 -0.704167 0 -1,-1,-1 -1,-1,-1
1990-02-16 334.890015 335.640015 332.420013 332.720001 166840000 332.720001 330.183000 332.256000 -2.073000 -1.480334 -0.592666 0 -1,-1,-1 -1,-1,-1
1990-02-20 332.720001 332.720001 326.260010 327.989990 147300000 327.989990 330.063499 331.869998 -1.806499 -1.817000 0.010501 1 1,-1,-1 -1,-1,1
1990-02-21 327.910004 328.170013 324.470001 327.670013 159240000 327.670013 329.866501 331.670999 -1.804498 -1.894665 0.090167 0 1,1,-1 -1,1,1
1990-02-22 327.670013 330.980011 325.700012 325.700012 184320000 325.700012 329.638501 330.866000 -1.227499 -1.612832 0.385333 0 1,1,1 1,1,1
1990-02-23 325.700012 326.149994 322.100006 324.149994 148490000 324.149994 329.542001 329.985001 -0.442999 -1.158332 0.715333 0 1,1,1 1,1,1
1990-02-26 324.160004 328.670013 323.980011 328.670013 148900000 328.670013 329.685503 329.490002 0.195500 -0.491666 0.687166 0 1,1,1 1,1,1
1990-02-27 328.679993 331.940002 328.470001 330.260010 152590000 330.260010 329.938502 329.508005 0.430498 0.061000 0.369498 0 1,1,1 1,1,1
1990-02-28 330.260010 333.480011 330.160004 331.890015 184400000 331.890015 330.384003 329.595007 0.788995 0.471664 0.317331 0 1,1,1 1,1,1
1990-03-01 331.890015 334.399994 331.079987 332.739990 157930000 332.739990 330.567003 329.668005 0.898998 0.706164 0.192834 0 1,1,1 1,1,1
1990-03-02 332.739990 335.540009 332.720001 335.540009 164330000 335.540009 330.904503 329.733005 1.171498 0.953164 0.218334 0 1,1,1 1,1,1
1990-03-05 335.540009 336.380005 333.489990 333.739990 140110000 333.739990 331.045502 329.835004 1.210498 1.093665 0.116834 0 1,1,1 1,1,1
1990-03-06 333.739990 337.929993 333.570007 337.929993 143640000 337.929993 331.349501 330.829004 0.520497 0.967498 -0.447001 -1 -1,1,1 1,1,-1
1990-03-07 337.929993 338.839996 336.329987 336.950012 163580000 336.950012 331.714001 331.757004 -0.043002 0.562664 -0.605667 0 -1,-1,1 1,-1,-1
1990-03-08 336.950012 340.660004 336.950012 340.269989 170900000 340.269989 332.040001 333.214002 -1.174001 -0.232169 -0.941832 0 -1,-1,-1 -1,-1,-1
1990-03-09 340.119995 340.269989 336.839996 337.929993 150410000 337.929993 332.288501 334.592001 -2.303500 -1.173501 -1.129999 0 -1,-1,-1 -1,-1,-1
1990-03-12 337.929993 339.079987 336.140015 338.670013 114790000 338.670013 332.541002 335.592001 -3.051000 -2.176167 -0.874833 0 -1,-1,-1 -1,-1,-1
1990-03-13 338.670013 338.670013 335.359985 336.000000 145440000 336.000000 332.837003 336.166000 -3.328998 -2.894499 -0.434499 0 -1,-1,-1 -1,-1,-1
1990-03-14 336.000000 337.630005 334.929993 336.869995 145060000 336.869995 333.129503 336.663998 -3.534496 -3.304831 -0.229665 0 -1,-1,-1 -1,-1,-1
1990-03-15 336.869995 338.910004 336.869995 338.070007 144410000 338.070007 333.432503 337.197000 -3.764497 -3.542664 -0.221834 0 -1,-1,-1 -1,-1,-1
1990-03-16 338.070007 341.910004 338.070007 341.910004 222520000 341.910004 333.783502 337.834000 -4.050497 -3.783163 -0.267334 0 -1,-1,-1 -1,-1,-1
1990-03-19 341.910004 343.760010 339.119995 343.529999 142300000 343.529999 334.324002 338.813001 -4.488998 -4.101331 -0.387667 0 -1,-1,-1 -1,-1,-1
1990-03-20 343.529999 344.489990 340.869995 341.570007 177320000 341.570007 335.003003 339.177002 -4.173999 -4.237832 0.063833 1 1,-1,-1 -1,-1,1
1990-03-21 341.570007 342.339996 339.559998 339.739990 130990000 339.739990 335.606502 339.456000 -3.849498 -4.170832 0.321334 0 1,1,-1 -1,1,1
1990-03-22 339.739990 339.769989 333.619995 335.690002 175930000 335.690002 336.106001 338.998001 -2.892000 -3.638499 0.746499 0 1,1,1 1,1,1
1990-03-23 335.690002 337.579987 335.690002 337.220001 132070000 337.220001 336.759502 338.927002 -2.167500 -2.969666 0.802166 0 1,1,1 1,1,1
1990-03-26 337.220001 339.739990 337.220001 337.630005 116110000 337.630005 337.207501 338.823001 -1.615500 -2.225000 0.609500 0 1,1,1 1,1,1
... ... ... ... ... ... ... ... ... ... ... ... ... ... ...
2015-12-17 2073.760010 2076.370117 2041.660034 2041.890015 4327390000 2041.890015 2068.108508 2052.488013 15.620496 15.902991 -0.282495 -1 -1,1,1 1,1,-1
2015-12-18 2040.810059 2040.810059 2005.329956 2005.550049 6683070000 2005.550049 2064.324011 2043.874023 20.449988 17.667491 2.782497 0 1,-1,1 1,-1,1
2015-12-21 2010.270020 2022.900024 2005.930054 2021.150024 3760280000 2021.150024 2060.923016 2038.282019 22.640997 19.570494 3.070504 0 1,1,-1 -1,1,1
2015-12-22 2023.150024 2042.739990 2020.489990 2038.969971 3520860000 2038.969971 2058.542010 2035.820007 22.722003 21.937663 0.784340 0 1,1,1 1,1,1
2015-12-23 2042.199951 2064.729980 2042.199951 2064.290039 3484090000 2064.290039 2057.299518 2037.487012 19.812506 21.725169 -1.912663 -1 -1,1,1 1,1,-1
2015-12-24 2063.520020 2067.360107 2058.729980 2060.989990 1411860000 2060.989990 2055.905511 2038.363013 17.542499 20.025669 -2.483171 0 -1,-1,1 1,-1,-1
2015-12-28 2057.770020 2057.770020 2044.199951 2056.500000 2492510000 2056.500000 2054.225006 2042.776013 11.448993 16.267999 -4.819006 0 -1,-1,-1 -1,-1,-1
2015-12-29 2060.540039 2081.560059 2060.540039 2078.360107 2542000000 2078.360107 2054.122516 2048.418030 5.704486 11.565326 -5.860840 0 -1,-1,-1 -1,-1,-1
2015-12-30 2077.340088 2077.340088 2061.969971 2063.360107 2367430000 2063.360107 2052.159027 2050.413037 1.745990 6.299823 -4.553833 0 -1,-1,-1 -1,-1,-1
2015-12-31 2060.590088 2062.540039 2043.619995 2043.939941 2655330000 2043.939941 2050.380523 2047.500024 2.880499 3.443658 -0.563159 0 -1,-1,-1 -1,-1,-1
2016-01-04 2038.199951 2038.199951 1989.680054 2012.660034 4304880000 2012.660034 2048.532519 2044.577026 3.955493 2.860661 1.094832 1 1,-1,-1 -1,-1,1
2016-01-05 2013.780029 2021.939941 2004.170044 2016.709961 3706620000 2016.709961 2044.783520 2045.693017 -0.909497 1.975498 -2.884995 0 -1,1,-1 -1,1,-1
2016-01-06 2011.709961 2011.709961 1979.050049 1990.260010 4336660000 1990.260010 2040.443017 2042.604016 -2.160999 0.294999 -2.455998 0 -1,-1,1 1,-1,-1
2016-01-07 1985.319946 1985.319946 1938.829956 1943.089966 5076590000 1943.089966 2034.418011 2033.016016 1.401996 -0.556167 1.958162 0 1,-1,-1 -1,-1,1
2016-01-08 1985.319946 1985.319946 1918.459961 1922.030029 4664940000 1922.030029 2028.138513 2018.790015 9.348499 2.863165 6.485333 0 1,1,-1 -1,1,1
2016-01-11 1926.119995 1935.650024 1901.099976 1923.670044 4607290000 1923.670044 2021.710516 2005.058020 16.652496 9.134330 7.518166 0 1,1,1 1,1,1
2016-01-12 1927.829956 1947.380005 1914.349976 1938.680054 4887260000 1938.680054 2018.026019 1993.276025 24.749994 16.916996 7.832998 0 1,1,1 1,1,1
2016-01-13 1940.339966 1950.329956 1886.410034 1890.280029 5087030000 1890.280029 2011.443024 1974.468018 36.975006 26.125832 10.849174 0 1,1,1 1,1,1
2016-01-14 1891.680054 1934.469971 1878.930054 1921.839966 5241110000 1921.839966 2005.364520 1960.316003 45.048517 35.591172 9.457345 0 1,1,1 1,1,1
2016-01-15 1916.680054 1916.680054 1857.829956 1880.329956 5468460000 1880.329956 1995.727515 1943.955005 51.772510 44.598678 7.173832 0 1,1,1 1,1,1
2016-01-19 1888.660034 1901.439941 1864.599976 1881.329956 4928350000 1881.329956 1987.699512 1930.821997 56.877515 51.232847 5.644668 0 1,1,1 1,1,1
2016-01-20 1876.180054 1876.180054 1812.290039 1859.329956 6416070000 1859.329956 1980.388507 1915.083997 65.304510 57.984845 7.319666 0 1,1,1 1,1,1
2016-01-21 1861.459961 1889.849976 1848.979980 1868.989990 5078810000 1868.989990 1972.780505 1902.956995 69.823511 64.001845 5.821665 0 1,1,1 1,1,1
2016-01-22 1877.400024 1908.849976 1877.400024 1906.900024 4901760000 1906.900024 1966.177008 1899.338000 66.839008 67.322343 -0.483335 -1 -1,1,1 1,1,-1
2016-01-25 1906.280029 1906.280029 1875.969971 1877.079956 4401380000 1877.079956 1956.816504 1894.842993 61.973511 66.212010 -4.238499 0 -1,-1,1 1,-1,-1
2016-01-26 1878.790039 1906.729980 1878.790039 1903.630005 4357940000 1903.630005 1948.948505 1892.838989 56.109515 61.640678 -5.531163 0 -1,-1,-1 -1,-1,-1
2016-01-27 1902.520020 1916.989990 1872.699951 1882.949951 4754040000 1882.949951 1940.271002 1887.265979 53.005023 57.029350 -4.024327 0 -1,-1,-1 -1,-1,-1
2016-01-28 1885.219971 1902.959961 1873.650024 1893.359985 4693010000 1893.359985 1931.020996 1887.573975 43.447021 50.853853 -7.406832 0 -1,-1,-1 -1,-1,-1
2016-01-29 1894.000000 1940.239990 1894.000000 1940.239990 5497570000 1940.239990 1924.864990 1889.413977 35.451013 43.967686 -8.516673 0 -1,-1,-1 -1,-1,-1
2016-02-01 1936.939941 1947.199951 1920.300049 1939.380005 4322530000 1939.380005 1919.636993 1895.318982 24.318012 34.405349 -10.087337 0 -1,-1,-1 -1,-1,-1

6544 rows × 14 columns


In [90]:
print('\n')
print('* Current columns: ' + str(list(df.columns.values)))

del_columns = input("Enter the names of columns to delete (seperated by commas): ")

del_columns.split()

for i in del_columns.split():
    df.drop(i, axis=1, inplace=True)
    
file_name = input("Enter the file name to save as a csv: ")
file_name = file_name.split('/')[-1]



* Columns: ['Open', 'High', 'Low', 'Close', 'Volume', 'Adj Close', 'SMA_Close_20-day', 'SMA_Close_10-day', 'MACD_Close', 'SMA_MACD_Close_3-day', 'Delta_SMA_MACD_Close_3-day', 'SwingFlag_3-day', 'PriorSigns_3-days', 'SignSequence_3-days']