量化投资均线简化、长均线的保护机制

1、内容简介


294-可以交流、咨询、答疑

2、内容说明

3、仿真分析

clc
close all
clear
data = load('baidu3.txt');
day_real = data(:,1);
day = 1:length(day_real);
price = data(:,2);
figure
plot(day,price)
xlabel 日
ylabel 调整后的收盘价
% 均线简化
a = 7;% 模型参数
num = floor(length(day_real)/a);%+(rem(length(day_real),a)~=0)*1;
day_new = 1:num;
% price(length(day_real)+1:a*num) = 0;
price = price(1:a*num);
price_new = reshape(price,a,num);
price_mean = mean(price_new);
figure
plot(day_new,price_mean)
xlabel 日
ylabel 调整后的收盘价
title 均线简化后结果
% 过滤微小波动
B = 2;% 模型参考参数
price_filter = zeros(1,num);
[pks1,locs1] = findpeaks(price_mean);
[pks2,locs2] = findpeaks(-price_mean);pks2 = -pks2;
figure
plot(day_new,price_mean)
xlabel 日
ylabel 调整后的收盘价
title 找到对应的极值点
hold on
scatter(locs1,pks1,'r*')
hold on
scatter(locs2,pks2,'r*')
hold off

for i = 1:length(pks1)
    if abs(price_mean(locs1(i)-1)-price_mean(locs1(i)))< B
        price_mean(locs1(i)-1) = price_mean(locs1(i));
    end
    if abs(price_mean(locs1(i)+1)-price_mean(locs1(i)))< B
        price_mean(locs1(i)+1) = price_mean(locs1(i));
    end
end

for i = 1:length(pks2)
    if abs(price_mean(locs2(i)-1)-price_mean(locs2(i)))< B
        price_mean(locs2(i)-1) = price_mean(locs2(i));
    end
    if abs(price_mean(locs2(i)+1)-price_mean(locs2(i)))< B
        price_mean(locs2(i)+1) = price_mean(locs2(i));
    end
end
figure
plot(day_new,price_mean)
xlabel 日
ylabel 调整后的收盘价
title 过滤微小波动

% 高低点比较策略,高低点突破策略,长波的保护机制长均线的保护机制。

k=0.5;
t1 = locs1(4):day_new(end);
y1 = (t1-locs1(4))*k+pks1(4);

t2 = locs2(3):day_new(end);
y2 = (t2-locs2(3))*k+pks2(3);

figure
plot(day_new,price_mean)
hold on
plot(t1,y1,'r',t2,y2,'r')
hold off
xlabel 日
ylabel 调整后的收盘价

 

4、参考论文

量化投资策略与技术.pdf

猜你喜欢

转载自blog.csdn.net/qingfengxd1/article/details/125173607
今日推荐