Exemplo n.º 1
0
def getdataForMultipleTickers(tickerlist,start_date,end_date,dataset,company_name, company):
       
    combineddataset= web.DataReader(tickerlist,'yahoo',start_date,end_date)
    print("\n"+"*" *100)
    option = input("Choose\n1. For Basic Statistics View\n2. For Graphical View\n3. Previous Menu\n")
    print("\n"+"*" *100)
    try:
        if option == "1": 
            closeDataCombined = combineddataset['Close']
            print("Descriptive Analytics done on Close Price for Combined dataset:\n ",closeDataCombined.describe())
            getdataForMultipleTickers(tickerlist,start_date,end_date,dataset,company_name, company)
            
        elif option == "2":
            companyValues = "Multiple Companies"
            simple_moving_avg(combineddataset,start_date,end_date,companyValues)
            close = combineddataset['Close']
            close = close.fillna(method='ffill')
            ct.drawplot(close,title =f"Raw Time Series for closing price of {company}")
            getdataForMultipleTickers(tickerlist,start_date,end_date,dataset,company_name, company)
            
        elif option == "3":
            descriptive_mode(dataset,start_date,end_date,company_name,company)
            
        else:
            print("Please select correct option")
            getdataForMultipleTickers(tickerlist,start_date,end_date,dataset,company_name, company)
            
    except ValueError:
        print("Select from below the options")
        getdataForMultipleTickers(tickerlist,start_date,end_date,dataset,company_name, company)
def exponential_Weighted_MA(dataset, start_date, end_date, company_name):
    try:

        window_size = int(
            input(
                "Enter the n value for Weighted Moving Average, i.e Window size  \n"
            ))
        if window_size > 250:
            window_size = 100

        dataset['wm_avg'] = dataset['Adj Close'].ewm(span=window_size,
                                                     min_periods=0,
                                                     adjust=True,
                                                     ignore_na=True).mean()

        ct.drawplot(
            dataset['wm_avg'],
            title=
            f"Exponential Weighted Moving Average  of {company_name} for window size {window_size}"
        )

    except ValueError:
        print("The window size should be a number ")
        exponential_Weighted_MA(dataset, start_date, end_date, company_name)

    except:
        print(
            "Window size is to small test expect result for greater range values"
        )
        exponential_Weighted_MA(dataset, start_date, end_date, company_name)
Exemplo n.º 3
0
def MACD(dataset,start_date,end_date,company_name):
    close_26_ewma = dataset['Adj Close'].ewm(span=26, min_periods=0, adjust=True, ignore_na=True).mean()
    close_12_ewma = dataset['Adj Close'].ewm(span=12, min_periods=0, adjust=True, ignore_na=True).mean()
    dataset['26ema'] = close_26_ewma
    dataset['12ema'] = close_12_ewma
    dataset['MACD'] = (dataset['12ema'] - dataset['26ema'])
    ct.drawplot(dataset['MACD'],title =f"Moving Average Convergence Divergence (MACD) of {company_name}")
def simple_moving_avg(dataset, start_date, end_date, company_name):
    try:
        window_size = int(
            input("Enter the n value for Moving Average i.e Window size\n"))
        if window_size > 250:
            window_size = 100

    #print(rolling.head(20))
        rolling = dataset['Adj Close'].rolling(window=int(window_size)).mean()
        ct.drawplot(
            rolling,
            title=
            f"Simple Moving Average of {company_name} for rolling window size {window_size}"
        )
        print("Window size is not able to fit the graph")

    except ValueError:
        print("The window size should be a number ")
        simple_moving_avg(dataset, start_date, end_date, company_name)

    except:
        print(
            "Window size is to small test expect result for greater range values"
        )
        simple_moving_avg(dataset, start_date, end_date, company_name)