Repository: jerry81333/StockProdiction Branch: master Commit: e9054f2eeb0f Files: 9 Total size: 21.2 KB Directory structure: gitextract_f3d5p1ip/ ├── .gitattributes ├── .gitignore ├── GYN.json ├── IASP520_ARMA_V1.01.py ├── IASP520_SVM.py ├── IASP520_SVM_V2.py ├── IASP520_SVM_V2_With_Polarity_Json.py ├── NQN.json └── README.md ================================================ FILE CONTENTS ================================================ ================================================ FILE: .gitattributes ================================================ # Auto detect text files and perform LF normalization * text=auto # Custom for Visual Studio *.cs diff=csharp # Standard to msysgit *.doc diff=astextplain *.DOC diff=astextplain *.docx diff=astextplain *.DOCX diff=astextplain *.dot diff=astextplain *.DOT diff=astextplain *.pdf diff=astextplain *.PDF diff=astextplain *.rtf diff=astextplain *.RTF diff=astextplain ================================================ FILE: .gitignore ================================================ IASP520 Project(1).docx Re_ Final Project.zip Re_ Final Project/GetNewsPolarity.py Re_ Final Project/GYN.json Re_ Final Project/IASP520_SVM_V2_With_Polarity.py Re_ Final Project/IASP520_SVM_V2_With_Polarity_Json.py Re_ Final Project/NQN.json Re_ Final Project/scoreSentiment.R Re_ Final Project/scoreSentimentYahooNews.R Re_ Final Project/Write_Polarity_To_File.py Re_ Final Project/__pycache__/GetNewsPolarity.cpython-35.pyc Data Mining Stock_V1.02.pptx IASP520 Project.docx ================================================ FILE: GYN.json ================================================ {"2015-01-27": {"Polarity": 0.8888888888888888, "Date": "2015-01-27", "Epoch": "1422334800"}, "2015-02-13": {"Polarity": -0.3333333333333333, "Date": "2015-02-13", "Epoch": "1423803600"}, "2015-03-19": {"Polarity": 1.0, "Date": "2015-03-19", "Epoch": "1426737600"}, "2015-04-21": {"Polarity": 1.0, "Date": "2015-04-21", "Epoch": "1429588800"}, "2015-05-27": {"Polarity": 1.0, "Date": "2015-05-27", "Epoch": "1432699200"}, "2015-06-18": {"Polarity": 1.0, "Date": "2015-06-18", "Epoch": "1434600000"}, "2015-07-09": {"Polarity": 1.0, "Date": "2015-07-09", "Epoch": "1436414400"}, "2015-07-17": {"Polarity": 1.0, "Date": "2015-07-17", "Epoch": "1437105600"}, "2015-07-27": {"Polarity": 0.4, "Date": "2015-07-27", "Epoch": "1437969600"}, "2015-07-31": {"Polarity": 1.0, "Date": "2015-07-31", "Epoch": "1438315200"}, "2015-09-02": {"Polarity": 1.0, "Date": "2015-09-02", "Epoch": "1441166400"}, "2015-10-20": {"Polarity": 1.0, "Date": "2015-10-20", "Epoch": "1445313600"}, "2015-11-23": {"Polarity": 1.0, "Date": "2015-11-23", "Epoch": "1448254800"}, "2015-12-16": {"Polarity": 0.2, "Date": "2015-12-16", "Epoch": "1450242000"}, "2016-01-07": {"Polarity": -1.0, "Date": "2016-01-07", "Epoch": "1452142800"}, "2016-02-01": {"Polarity": 0.0, "Date": "2016-02-01", "Epoch": "1454302800"}, "2016-02-02": {"Polarity": 1.0, "Date": "2016-02-02", "Epoch": "1454389200"}, "2016-02-03": {"Polarity": -0.16666666666666666, "Date": "2016-02-03", "Epoch": "1454475600"}, "2016-02-10": {"Polarity": 0.42857142857142855, "Date": "2016-02-10", "Epoch": "1455080400"}, "2016-02-18": {"Polarity": 0.0, "Date": "2016-02-18", "Epoch": "1455771600"}, "2016-04-27": {"Polarity": 0.4, "Date": "2016-04-27", "Epoch": "1461729600"}, "2016-05-05": {"Polarity": 0.2222222222222222, "Date": "2016-05-05", "Epoch": "1462420800"}, "2016-05-16": {"Polarity": 1.0, "Date": "2016-05-16", "Epoch": "1463371200"}, "2016-05-20": {"Polarity": 0.6666666666666666, "Date": "2016-05-20", "Epoch": "1463716800"}, "2016-05-25": {"Polarity": 1.0, "Date": "2016-05-25", "Epoch": "1464148800"}, "2016-05-31": {"Polarity": 1.0, "Date": "2016-05-31", "Epoch": "1464667200"}, "2016-06-07": {"Polarity": 0.6, "Date": "2016-06-07", "Epoch": "1465272000"}, "2016-06-08": {"Polarity": 1.0, "Date": "2016-06-08", "Epoch": "1465358400"}, "2016-06-09": {"Polarity": 0.3333333333333333, "Date": "2016-06-09", "Epoch": "1465444800"}, "2016-07-05": {"Polarity": 1.0, "Date": "2016-07-05", "Epoch": "1467691200"}, "2016-07-07": {"Polarity": 1.0, "Date": "2016-07-07", "Epoch": "1467864000"}, "2016-07-18": {"Polarity": 0.3137254901960784, "Date": "2016-07-18", "Epoch": "1468814400"}, "2016-07-19": {"Polarity": 1.0, "Date": "2016-07-19", "Epoch": "1468900800"}, "2016-07-22": {"Polarity": 1.0, "Date": "2016-07-22", "Epoch": "1469160000"}, "2016-07-25": {"Polarity": 0.6723809523809524, "Date": "2016-07-25", "Epoch": "1469419200"}, "2016-08-08": {"Polarity": 0.0, "Date": "2016-08-08", "Epoch": "1470628800"}, "2016-08-26": {"Polarity": 1.0, "Date": "2016-08-26", "Epoch": "1472184000"}, "2016-08-31": {"Polarity": 1.0, "Date": "2016-08-31", "Epoch": "1472616000"}, "2016-09-22": {"Polarity": 0.14285714285714285, "Date": "2016-09-22", "Epoch": "1474516800"}, "2016-09-23": {"Polarity": -0.3333333333333333, "Date": "2016-09-23", "Epoch": "1474603200"}, "2016-10-06": {"Polarity": 1.0, "Date": "2016-10-06", "Epoch": "1475726400"}, "2016-10-18": {"Polarity": 0.14285714285714285, "Date": "2016-10-18", "Epoch": "1476763200"}, "2016-10-19": {"Polarity": 0.14285714285714285, "Date": "2016-10-19", "Epoch": "1476849600"}, "2016-10-27": {"Polarity": 0.14285714285714285, "Date": "2016-10-27", "Epoch": "1477540800"}, "2016-11-22": {"Polarity": 0.5384615384615384, "Date": "2016-11-22", "Epoch": "1479790800"}, "2016-11-26": {"Polarity": 0.5172413793103449, "Date": "2016-11-26", "Epoch": "1480136400"}, "2016-11-29": {"Polarity": -0.16013071895424838, "Date": "2016-11-29", "Epoch": "1480395600"}, "2016-11-30": {"Polarity": 0.3076923076923077, "Date": "2016-11-30", "Epoch": "1480482000"}, "2016-12-02": {"Polarity": 0.125, "Date": "2016-12-02", "Epoch": "1480654800"}, "2016-12-05": {"Polarity": 0.41435185185185186, "Date": "2016-12-05", "Epoch": "1480914000"}, "2016-12-08": {"Polarity": 0.6153846153846154, "Date": "2016-12-08", "Epoch": "1481173200"}, "2016-12-09": {"Polarity": 0.4495726495726496, "Date": "2016-12-09", "Epoch": "1481259600"}, "2016-12-11": {"Polarity": 0.0, "Date": "2016-12-11", "Epoch": "1481432400"}, "2016-12-12": {"Polarity": 0.5454406704406705, "Date": "2016-12-12", "Epoch": "1481518800"}, "2016-12-14": {"Polarity": 0.32844490453186104, "Date": "2016-12-14", "Epoch": "1481691600"}, "2016-12-15": {"Polarity": 0.26835749954655724, "Date": "2016-12-15", "Epoch": "1481778000"}, "2016-12-17": {"Polarity": 0.46338743802957916, "Date": "2016-12-17", "Epoch": "1481950800"}, "2016-12-18": {"Polarity": 0.6180405242905243, "Date": "2016-12-18", "Epoch": "1482037200"}} ================================================ FILE: IASP520_ARMA_V1.01.py ================================================ from yahoo_finance import Share from pandas import Series,DataFrame import pandas as pd import numpy as np import matplotlib.pyplot as plt from sklearn import svm import statsmodels.api as sm from statsmodels.graphics.api import qqplot import statsmodels.tsa.stattools as ts from scipy import stats import pywt yaho = Share('YHOO') #choose stock, YAHOO, GOLD startday='2015-11-1' #choose first day endday='2016-12-15' #choose end day #train = 15 #How many data for train, 9 is the least. #draw fig=plt.figure() ax1=fig.add_subplot(711) ax2=fig.add_subplot(712) ax3=fig.add_subplot(713) ax4=fig.add_subplot(714) ax5=fig.add_subplot(715) ax6=fig.add_subplot(716) ax7=fig.add_subplot(717) #Data processing StockDate = DataFrame(yaho.get_historical(startday, endday)) StockDate.index = StockDate.Date StockDate = DataFrame.sort_index(StockDate) #sort test = DataFrame(yaho.get_historical(startday, '2016-12-1')) test.index = test.Date test = DataFrame.sort_index(test) test = test['Close'] test=test.astype(float) test.plot(ax=ax5) #L=len(StockDate) #total_predict_data=L-train ''' #draw Data = StockDate.drop(['Date','Symbol','Adj_Close'],axis=1) Data=Data.astype(float) ax=Data.plot(secondary_y=['Volume']) ax.set_ylabel('Value') ax.right_ax.set_ylabel('Volume') plt.grid(True) plt.show() #Create more data value = pd.Series(Data['Open']-Data['Close'],index=Data.index) #Data['DOP'] = value #Difference between Open and Close #Data['DHL'] = Data['High']-Data['Low'] #Difference between High and Low value[value>=0]=0 #0 means fall value[value<0]=1 #1 means rise print(value) ''' #ARIMA Close_original = StockDate['Close'] Close_original=Close_original.astype(float) #Close.plot() close=pywt.dwt(Close_original, 'db4') #DB4,Wavelet decomposition Close_db4=pd.Series(close[0]) Close_db4=Close_db4-14 Close_db4.index = pd.Index(sm.tsa.datetools.dates_from_range('2001','2145')) #aa=Close.diff(3) #draw #aa.plot(ax=ax4) Close_db4.plot(ax=ax2) Close=Close_db4.diff(4) #stationary time series Close=Close[4:] print("Augmented Dickey-Fuller test:",ts.adfuller(Close,4)) #Augmented Dickey-Fuller test Close.plot(ax=ax3) Close_original.plot(ax=ax1) sm.graphics.tsa.plot_acf(Close,lags=40,ax=ax6) #ARIMA,q sm.graphics.tsa.plot_pacf(Close,lags=40,ax=ax7) #ARIMA,p #print(Close) Arma = sm.tsa.ARMA(Close,order=(9,3)).fit(disp=-1, method='mle') print(Arma.aic,Arma.bic,Arma.hqic) #predict Arma_stock=Arma.predict() Arma_stock.plot(ax=ax3) predict_stock = Arma.predict('2137','2148',dynamic=True) predict_stock.plot(ax=ax3) #reduce diff() L=len(Arma_stock) i=0 while i=0]=0 #0 means fall value[value<0]=1 #1 means rise print(value) #Data['Value']=value correct = 0 train_original=train i=0 ''' #Classical classification, normal way Data_train=Data[0:L-20] value_train = value[0:L-20] Data_predict=Data[L-20:L] value_real = value[L-20:L] print(Data_predict) classifier = svm.SVC() classifier.fit(Data_train,value_train) value_predict=classifier.predict(Data_predict) print("value_real = ",value_predict) while i<19: print("value_real = ",value_real[i]) if(value_real[i]==int(value_predict[i])): correct=correct+1 i+=1 print("Correct = ",correct/19*100,"%") ''' #loop training,15 days data for train while train=0]=1 #0 means rise value[value<0]=0 #1 means fall Data=Data.dropna(how='any') del(Data['Open']) del(Data['Close']) del(Data['High']) del(Data['Low']) #print(Data) print(type(Data)) #Data['Value']=value correct = 0 train_original=train i=0 L=len(Data) ''' #Classical classification, normal way Data_train=Data[0:L-20] value_train = value[0:L-20] Data_predict=Data[L-20:L] value_real = value[L-20:L] print(Data_predict) classifier = svm.SVC() classifier.fit(Data_train,value_train) value_predict=classifier.predict(Data_predict) print("value_real = ",value_predict) while i<19: print("value_real = ",value_real[i]) if(value_real[i]==int(value_predict[i])): correct=correct+1 i+=1 print("Correct = ",correct/19*100,"%") ''' #loop training,15 days data for train print(L) while train=0]=1 #0 means rise value[value<0]=0 #1 means fall Data=Data.dropna(how='any') del(Data['Open']) del(Data['Close']) del(Data['High']) del(Data['Low']) #print(Data) print(type(Data)) #Data['Value']=value correct = 0 train_original=train i=0 L=len(Data) ''' #Classical classification, normal way Data_train=Data[0:L-20] value_train = value[0:L-20] Data_predict=Data[L-20:L] value_real = value[L-20:L] print(Data_predict) classifier = svm.SVC() classifier.fit(Data_train,value_train) value_predict=classifier.predict(Data_predict) print("value_real = ",value_predict) while i<19: print("value_real = ",value_real[i]) if(value_real[i]==int(value_predict[i])): correct=correct+1 i+=1 print("Correct = ",correct/19*100,"%") ''' #loop training,15 days data for train print(L) while train