Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Keep only the data for the last year for all companies. We shall be taking only latest data into consideration.
- nyse_data.drop_duplicates(subset='ticker_symbol', keep='last', inplace=True)
- Svm_model = {}
- Svm_model.fit()
- # Adding in the predicted values for bankruptcy in the original dataset
- nyse_data["stability"] = Svm_model.fit(scaler.transform(nyse_data[["total_assets", "total_liabilities"]]))
- print ("Companies predicted to go bankrupt over a 4 year period: ", len(nyse_data.loc[nyse_data["stability"] != 1, "ticker_symbol"]))
- AttributeError Traceback (most recent call last)
- in
- 2 nyse_data.drop_duplicates(subset='ticker_symbol', keep='last', inplace=True)
- 3 Svm_model = {}
- ----> 4 Svm_model.fit()
- 5 # Adding in the predicted values for bankruptcy in the original dataset
- 6 nyse_data["stability"] = Svm_model.fit(scaler.transform(nyse_data[["total_assets", "total_liabilities"]]))
- AttributeError: 'dict' object has no attribute 'fit'
- count = 0
- stock_predictions = {}
- stats.normaltest = {}
- for i in weekly_stock_prices_log:
- # Splitting available data into training for accuracy check using remaining data points
- split_point = len(weekly_stock_prices_log[i]) - 20
- # Number of weeks from last date in dataset to 2018-12-31 = 117
- num_of_predictions = len(weekly_stock_prices_log[i]) + 117
- training = weekly_stock_prices_log[i][0:split_point]
- model = {}
- # Try modelling first using p=2, q=1, if that fails use p=1, q=0
- try:
- model = arima_model.ARMA(training["close"], order=(2,1)).fit()
- except:
- model = arima_model.ARMA(training["close"], order=(1,0)).fit()
- #Add the predicted values in a dataframe for ease of further operations.
- daterange = pd.date_range(training.index[0], periods=num_of_predictions, freq = 'W-MON').tolist()
- stock_predictions[i] = pd.DataFrame(columns=["date", "prediction"])
- stock_predictions[i]["date"] = daterange
- stock_predictions[i]["prediction"] = model.predict(start=0, end=num_of_predictions)
- stock_predictions[i].set_index("date", inplace=True)
- # Draw a QQPlot to check if the residuals are evenly distributed
- if count < 5:
- resid = model.resid
- print("For "+i+": ",stats.normaltest(resid))
- qqplot(resid, line='q', fit=True)
- plt.show()
- count += 1
- AttributeError Traceback (most recent call last)
- in
- 1 count = 0
- 2 stock_predictions = {}
- ----> 3 stats.normaltest = {}
- 4 for i in weekly_stock_prices_log:
- 5 # Splitting available data into training for accuracy check using remaining data points
- AttributeError: 'dict' object has no attribute 'normaltest'
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement