예제 #1
0
def GetStockPrediction(csvfile,ticker,inifile,litemode=False):
	### MAKE HISTORY GRAPH.
	hstg = 30 # number of days 

	# Define files and filetypes
	ext = ".pdf"
	ModZ =[str(stocksfolder+ticker+".HighLowClose" + ext), #0
				str(stocksfolder+ticker+".ChangeVolume"+ext),   #1
				str(stocksfolder+ticker+".ChangePoint"+ext),    #2
				# str(stocksfolder+ticker+".ChangePointTrends"+ext),#3
				str(stocksfolder+ticker+".evaluate_prediction"+ext),#4
				str(stocksfolder+ticker+".TrendsA"+ext),#5
				str(stocksfolder+ticker+".Naive" + str(hstg) + ext)]
				#6
	StockFiles=[str(stocksfolder+ticker+".HighLowClose" + ext), #0
				str(stocksfolder+ticker+".ChangeVolume"+ext),   #1
				str(stocksfolder+ticker+".ChangePoint"+ext),    #2
				str(stocksfolder+ticker+".ChangePointTrends"+ext),#3
				str(stocksfolder+ticker+".evaluate_prediction"+ext),#4
				str(stocksfolder+ticker+".TrendsA"+ext),#5
				str(stocksfolder+ticker+".Naive" + str(hstg) + ext),#6
				# ACTUAL MACHINE LEARNING BEGINS
				str(stocksfolder+ticker+".linear_regression_01"+ext)]#7

	# print(csvfile)

	# df = pd.read_csv(csvfile)
	


	## START ANALSYS.
	
	Months = str((today - datetime.timedelta(days=hstg)).date())
	### Stocker is initialized and will retrieve the entire stock's data as it is read in the file.
	stock = Stocker(ticker=ticker, 
		exchange='CSV',
		csv_repository='stocks')
	print(stock.stock.head())
	plt.clf()

	### plot_stock will plot the stock's (High, Low, Close) recent history. see 'hstg' for number of days

	stock.plot_stock(start_date = str(Months),
		stats = ['high', 'low', 'close'],
		plot_type='hlc',
		filename=StockFiles[0])
	plt.clf()

	### plot_stock will plot the Stock's (Daily Change, Volume) recent history. see 'hstg' for number of days

	stock.plot_stock(start_date = str(Months) ,
		stats = ['Daily Change', 'volume'], 
		plot_type='pct',
		filename=StockFiles[1])
	plt.clf()

	stock.changepoint_date_analysis(filename=StockFiles[2])
	plt.clf()

	# stock.buy_and_hold(start_date=str(Months),nshares=1,filename=str(stocksfolder+ticker+".PredictedBuyHold"+ext)) # This function is broken.
	# plt.clf()

	stock.evaluate_prediction(start_date=str(Months),nshares=1,filename=StockFiles[4])
	plt.clf()

	## START BASIC PREDICTIONS BASED ON ANALYSIS
	model, model_data = stock.create_prophet_model()
	model.plot_components(model_data)
	plt.savefig(StockFiles[5])
	plt.clf()

	stock.predict_future(days=hstg,filename=StockFiles[6])
	plt.clf()

	# START MORE ADVANCED PREDICTONS BASED ON DEEP LEARNING.
	if litemode:
		pass
	else:
		### changepoint_date_analysis is looking through historical data of the past 3 years to find the optimal time to buy or sell a stock.
		print(inifile)
		search_terms = inifile["STOCK PROFILE"]["search_terms"]
		# print(search_terms)
		bountylist = search_terms.split(",")
		# print(bountylist)
		stock.changepoint_date_analysis(search=bountylist,filename=StockFiles[3])
		plt.clf()
		# LINEAR REGRESSION 01
		stock.Stocker_linear_regression(days=hstg, filename=StockFiles[7])
		plt.clf()

	## Merge files into a pdf.
	
	if litemode:
		ModZ = ModZ; print(ModZ)
	else:
		ModZ = StockFiles[:]; print(ModZ)
		# thelimit = len(ModZ)
	
	Merge_PDFS(ModZ,reportsfolder+ticker+"._REPORT.PDF")
예제 #2
0
                       end_date='2002-01-03',
                       nshares=100)

# In[38]:

f = open('msft6.txt', 'w')
f.write(
    str(
        microsoft.buy_and_hold(start_date='1999-01-05',
                               end_date='2002-01-03',
                               nshares=100)))
f.close()

# In[39]:

microsoft.changepoint_date_analysis()

# In[40]:

f = open('msft7.txt', 'w')
f.write(str(microsoft.changepoint_date_analysis()))
f.close()

# In[41]:

model, future = microsoft.create_prophet_model(days=30)

# In[42]:

f = open('msft8.txt', 'w')
f.write(str(microsoft.create_prophet_model(days=30)))
예제 #3
0
from stocker import Stocker
import matplotlib.pyplot as plt

microsoft = Stocker(ticker='MSFT')

stock_history = microsoft.stock
# microsoft.plot_stock(start_date='2001-01-05', end_date='2002-02-05', stats=["Adj. Close"], plot_type="basic")
# microsoft.buy_and_hold(start_date='2001-01-05', end_date='2002-02-05', nshares=200)

model, model_data = microsoft.create_prophet_model()

model.plot_components(model_data)
plt.show()
print(microsoft.weekly_seasonality)
microsoft.weekly_seasonality = True
print(microsoft.weekly_seasonality)

model, model_data = microsoft.create_prophet_model(days=0)
model.plot_components(model_data)
plt.show()
microsoft.weekly_seasonality = False
microsoft.changepoint_date_analysis()
model, future = microsoft.create_prophet_model(days=180)
예제 #4
0
microsoft = Stocker('MSFT')

stock_history = microsoft.stock
stock_history.head()
microsoft.plot_stock()

microsoft.plot_stock(start_date = '2000-01-03', end_date = '2018-01-16', stats ['Daily Change', 'Adj.Volume'], plot_type='pct')

microsoft.buy_and_hold(start_date = '1986-03-13', end_date='2018-01-16', nshares=100)

model, model_data = microsoft.create_prophet_model()
model.plot_components(model_data)
plt.show()

print(micorsoft.weekly_seasonality)
microsoft.weekly_seasonality = True
print(microsoft.weekly_seasonality)

#only shows data in the first 80% of data
microsoft.changepoint_date_analysis()

#This will need to add a library of search terms related to the stocks information
microsoft.changepoint_date_analysis(search = 'Microsoft profit')
microsoft.changepoint_date_analysis(search = 'Microsoft Office')

#Future predictions
model, future = microsoft.create_prophet_model(days=180)

microsoft.evaluate_prediction()
예제 #5
0
britishmidland.buy_and_hold(start_date='1999-01-05', end_date='2002-01-03', nshares=100)


# In[17]:


f = open('./BMI/bmi6.txt','w')
f.write(str(britishmidland.buy_and_hold(start_date='1999-01-05', end_date='2002-01-03', nshares=100)))
f.close()


# In[18]:


britishmidland.changepoint_date_analysis()


# In[19]:


f = open('./BMI/bmi7.txt','w')
f.write(str(britishmidland.changepoint_date_analysis()))
f.close()


# In[20]:


model, future = britishmidland.create_prophet_model(days=30)
예제 #6
0
def stockChangePoint():
    print(
        "enter the code for the company you want to check the predictions of:")
    companyCode = input()
    st = Stocker(companyCode)
    st.changepoint_date_analysis()
예제 #7
0
get_ipython().system('pip install quandl')
get_ipython().system('pip install fbprophet')
get_ipython().system('pip install pytrends')

from stocker import Stocker
import quandl
quandl.ApiConfig.api_key = 'AsJgrNdvc_MbnWxwNB4V'
import matplotlib.pyplot as plt

ms = Stocker('MSFT')

ms.plot_stock()
ms.changepoint_date_analysis()
ms.buy_and_hold(start_date='2017-09-01', end_date='2018-03-01', nshares=100)
model, future = ms.create_prophet_model(days=180)