<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 Plots
Opening vs Closing
blue - opening
red - closing
Step1:  Historical opening, closing, high, low
- opening - yellow
- closing - red
- high - blue
- low - green
Step2:  Volume vs Average Volume
Step3:  Convert the data collected into numpy arrays
Step4:  Stack the data
Reshape (sample_size, #_of_features
Step5:  Need today's data for the features selected
Step6:  Collect today's data int a numpy array
Step7:  Scikit-learn
- Import svm
- fit
- predict
<ASSISTANT_TASK:>
Python Code:
%matplotlib inline
x_axis = np.arange(0+1, len(historical)+1)
plt.plot(x_axis, historical_opening, 'b', x_axis, historical_closing, 'r')
plt.xlabel('Day')
plt.ylabel('Price ($)')
#plt.figure(figsize=(20,10))
plt.title("Stock price:  Opening vs Closing")
plt.show();
Explanation: Plots
Opening vs Closing
blue - opening
red - closing
End of explanation
plt.plot(x_axis, historical_high, 'b', x_axis, historical_low, 'g', x_axis, historical_opening, 'y', x_axis, historical_closing, 'r')
plt.xlabel('Day')
plt.ylabel('Price ($)')
#plt.figure(figsize=(20,10))
plt.show();
Explanation: Historical opening, closing, high, low
- opening - yellow
- closing - red
- high - blue
- low - green
End of explanation
plt.plot(x_axis,historical_volume, 'g', x_axis, average_volume, 'b')
plt.xlabel('Day')
plt.ylabel('Volume')
plt.show()
Explanation: Volume vs Average Volume
End of explanation
opening =  np.array(historical_opening)
volume = np.array(historical_volume)
high = np.array(historical_high)
low = np.array(historical_low)
avg_vol = np.array(average_volume)
closing = np.array(historical_closing)
Explanation: Convert the data collected into numpy arrays
End of explanation
data = np.vstack((opening, high, low, volume, avg_vol))
shape1, shape2 = data.shape
data = data.reshape(shape2, shape1)
data.shape
Explanation: Stack the data
Reshape (sample_size, #_of_features
End of explanation
opening_price = company.get_open()
todays_volume = company.get_volume()
high = company.get_days_high()
low = company.get_days_low()
avg_volume = average_volume[0]
print opening_price
print todays_volume
print high
print low
print avg_volume
#target_pre = np.asarray(closing)
#target = np.vstack(target_pre)
Explanation: Need today's data for the features selected
End of explanation
today =np.array((opening_price, high, low, todays_volume, avg_volume))
Explanation: Collect today's data int a numpy array
End of explanation
from sklearn import svm
clf = svm.SVR(gamma=0.00001, C=29000)
#Fit takes in data (#_samples X #_of_features array), and target(closing - 1 X #_of_Sample_size array)
fit = clf.fit(data[:-10],closing[:-10])
predict = clf.predict(today)
graph = clf.fit(data, closing).predict(data)
date = company.get_trade_datetime()
name = cn.find_name(ticker)
print name, "[" , ticker, "]"  #get company name using the ticker symbol
print "\nPredicted [closing] price for ", date[:10], ": $", predict[0]
company.refresh()
#change = (company.get_price() - company.get_open())/company.get_open()
#print change
print "current price $", company.get_price()
#print "% change today ", 
print data[:,0].shape
print closing.shape
print graph
plt.scatter(data[:,0], closing, c='k', label='data')
plt.hold('on')
plt.plot(data[:,0],graph, c='g', label = 'Linear')
plt.ylabel('target')
plt.xlabel('data')
plt.show()
Explanation: Scikit-learn
- Import svm
- fit
- predict
End of explanation
<END_TASK>