Back to Community
Is it possible... to recreat this RBF Model.. to predict price in Quantopian...?

Still relatively new here.. in Quantopian not really familiar what command lines to use.. any help from the community... is greatly appreciated thanks... https://www.youtube.com/watch?v=SSu00IRRraY&t=304s

import csv
import numpy as np
from sklearn.svm import SVR
import matplotlib.pyplot as plt

plt.switch_backend('newbackend')

dates = []
prices = []

def get_data(filename):
with open(filename, 'r') as csvfile:
csvFileReader = csv.reader(csvfile)
next(csvFileReader) # skipping column names
for row in csvFileReader:
dates.append(int(row[0].split('-')[0]))
prices.append(float(row[1]))
return

def predict_price(dates, prices, x):
dates = np.reshape(dates,(len(dates), 1)) # converting to matrix of n X 1

svr_lin = SVR(kernel= 'linear', C= 1e3)  
svr_poly = SVR(kernel= 'poly', C= 1e3, degree= 2)  
svr_rbf = SVR(kernel= 'rbf', C= 1e3, gamma= 0.1) # defining the support vector regression models  
svr_rbf.fit(dates, prices) # fitting the data points in the models  
svr_lin.fit(dates, prices)  
svr_poly.fit(dates, prices)

plt.scatter(dates, prices, color= 'black', label= 'Data') # plotting the initial datapoints  
plt.plot(dates, svr_rbf.predict(dates), color= 'red', label= 'RBF model') # plotting the line made by the RBF kernel  
plt.plot(dates,svr_lin.predict(dates), color= 'green', label= 'Linear model') # plotting the line made by linear kernel  
plt.plot(dates,svr_poly.predict(dates), color= 'blue', label= 'Polynomial model') # plotting the line made by polynomial kernel  
plt.xlabel('Date')  
plt.ylabel('Price')  
plt.title('Support Vector Regression')  
plt.legend()  
plt.show()

return svr_rbf.predict(x)[0], svr_lin.predict(x)[0], svr_poly.predict(x)[0]

get_data('aapl.csv') # calling get_data method by passing the csv file to it

print "Dates- ", dates

print "Prices- ", prices

predicted_price = predict_price(dates, prices, 29)

1 response

It looks like you should be able to recreate that example using Quantopian.

First off, you want to do this in the research environment. Do the "Introduction to Research" lecture.

Then, you want to replace that get_data function with the Quantopian get_pricing function.

From there, it looks like it should mostly work. If you get stuck, share your work so far as an attached notebook.

Disclaimer

The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by Quantopian. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. No information contained herein should be regarded as a suggestion to engage in or refrain from any investment-related course of action as none of Quantopian nor any of its affiliates is undertaking to provide investment advice, act as an adviser to any plan or entity subject to the Employee Retirement Income Security Act of 1974, as amended, individual retirement account or individual retirement annuity, or give advice in a fiduciary capacity with respect to the materials presented herein. If you are an individual retirement or other investor, contact your financial advisor or other fiduciary unrelated to Quantopian about whether any given investment idea, strategy, product or service described herein may be appropriate for your circumstances. All investments involve risk, including loss of principal. Quantopian makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances.