【股价预测】基于matlab SVM股票价格预测【含Matlab源码 180期】

380 阅读1分钟

一、简介

支持向量机(Support Vector Machine)是Cortes和Vapnik于1995年首先提出的,它在解决小样本、非线性及高维模式识别中表现出许多特有的优势,并能够推广应用到函数拟合等其他机器学习问题中。
1 数学部分
1.1 二维空间
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
2 算法部分
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

二、源代码

clear;
clc;

%load financial data of the stock price of Apple company
%The data is from Nov 18 1982-Nov 18 2012
%The data contains six collums:Open, High, Low, Close, Volume, Adj Close
sh = dlmread('yahoo.csv');
%The data needs to flip because the data is from latest to earliest.
sh = flipdim(sh,1);

%extract data
[m,n] = size(sh);
ts = sh(2:m,1);
tsx = sh(1:m-1,:);
original = ts(length(sh)*0.7+1:end,:);

% Draw the original graphic of the stock price
figure;
plot(ts,'LineWidth',1);
title('Yahoo Stock Price(1996.4.12-2012.11.16) before mapping','FontSize',12);
grid on;

fprintf('Plot the stock price before mapping.\n');
fprintf('Program paused. Press enter to continue.\n');
pause;

%data preprocessing
ts = ts';
tsx = tsx';

% mapminmax is an mapping function in matlab
%Use mapminmax to do mapping
[TS,TSps] = mapminmax(ts);
% The scale of the data from 1 to 2
TSps.ymin = 1;
TSps.ymax = 2;
%normalization
[TS,TSps] = mapminmax(ts,TSps);

% plot the graphic of the stock price after mapping
figure;
plot(TS,'LineWidth',1);
title('Yahoo Stock price after mapping','FontSize',12);
grid on;

fprintf('\nPlot the stock price after mapping.\n');
fprintf('Program paused. Press enter to continue.\n');
pause;


% Transpose the data in order to meet the requirement of libsvm
fprintf('\n Initializing.......\n');
TS = TS';

[TSX,TSXps] = mapminmax(tsx);
TSXps.ymin = 1;
TSXps.ymax = 2;
[TSX,TSXps] = mapminmax(tsx,TSXps);
TSX = TSX';

三、运行结果

在这里插入图片描述

四、备注

版本:2014a