fbpx

How to build historical database for backtesting with Yahoo market data, Matlab, and free MYSQL. Apple (AAPL) is example

(Last Updated On: November 23, 2011)

How to build historical database for backtesting with Yahoo market data, Matlab, and free MYSQL. Apple (AAPL) is example

Here is a little basic Matlab M file script I build to fetch the latest stock symbol data for AAPL

How to build historical database for backtesting with Yahoo market data, Matlab, and free MYSQL. Apple (AAPL) is example

With Yahoo fetch market data:

javaaddpath(‘C:\Program Files (x86)\MySQL\MySQL Connector J\mysql-connector-java-5.1.15-bin.jar’)

clc; clear all;

Connect = yahoo;
k = {‘AAPL’};
data = fetch(Connect, k)
close(Connect)

% connection parameteres

host = ‘localhost’;

user = ‘root’;

password = ‘hello7560362’;

%dbName = ‘test’;
dbName = ‘stocks’;

% JDBC parameters 

jdbcString = sprintf(‘jdbc:mysql://%s/%s’, host, dbName);

jdbcDriver = ‘com.mysql.jdbc.Driver’;

% Create the database connection object

conn = database(dbName, user , password, jdbcDriver, jdbcString);

if isconnection(conn) % check to make sure that we successfully connected 

%qry = sprintf(‘SELECT * from test’);
%qry = sprintf(‘SELECT * from stock_eod’);
qry = sprintf(‘insert stock_eod (hist_date, hist_high, hist_low, hist_open, hist_close, hist_vol) values (now(),%f,%f,%f,%f,%d) ‘,data.High,data.Low,data.

Open,data.Last,data.Volume); 

rs = fetch(exec(conn, qry)); 

rsdata = get(rs, ‘Data’);

end

close(conn)

 

Like this post? You can learn more quant secrets by registering for our newsletter. We send out frequent announcement and discoveries.

NOTE I now post my TRADING ALERTS into my personal FACEBOOK ACCOUNT and TWITTER. Don't worry as I don't post stupid cat videos or what I eat!
Don't miss out!
Get my TRADE LIKE A BOSS 2 PDF Books

You will received instantly the download links.

Invalid email address
Give it a try. You can unsubscribe at any time.

NOTE!

Check NEW site on stock forex and ETF analysis and automation

Scroll to Top