(1)收盘价曲线图,并求收盘价序列的最大值、最小值、均值及标准差;
(2)对数收益率曲线图,并求收益率序列的最大值、最小值、均值及标准差;
(3)概率密度分布图。
要用到什么函数?
编写出一个符合题意的编码
(1)收盘价曲线图,并求收盘价序列的最大值、最小值、均值及标准差;
(2)对数收益率曲线图,并求收益率序列的最大值、最小值、均值及标准差;
(3)概率密度分布图。
要用到什么函数?
编写出一个符合题意的编码
clc,clear,close all; %清屏
%%数据准备
data = [11084.2841
11051.6971
10379.2832
10206.6385
10652.9044
10628.9202
11021.4353
11046.3827
10809.8794
10765.6253
10912.7421
11109.4784
11094.8694
11159.7910
11093.3739
11230.1589
11208.0750
11250.0602
];
date = ["2022-04-21"
"2022-04-22"
"2022-04-25"
"2022-04-26"
"2022-04-27"
"2022-04-28"
"2022-04-29"
"2022-05-05"
"2022-05-06"
"2022-05-09"
"2022-05-10"
"2022-05-11"
"2022-05-12"
"2022-05-13"
"2022-05-16"
"2022-05-17"
"2022-05-18"
"2022-05-19"
];
save data data
save date date
datenn = datenum(date,'yyyy-mm-dd');
%%收盘价
figure(1)
plot(datenn,data,'--gs',...
'LineWidth',2,...
'MarkerSize',10,...
'MarkerEdgeColor','b',...
'MarkerFaceColor',[0.5,0.5,0.5])
set(gca,'XTick',datenn(1):datenn(end),'XTickLabelRotation',30);
datetick('x','yyyy-mm-dd','keepticks')
grid on
title("收盘价曲线图")
%%求最值、均值、标准差
max1 = max(data);
indx1 = find(data==max1);
disp("收盘价序列的最大值:"+date(indx1,1)+','+num2str(max1))
min1 = min(data);
indx2 = find(data==min1);
disp("收盘价序列的最小值:"+date(indx2,1)+','+num2str(min1))
mm = mean(data);
disp("均值:"+num2str(mm))
ss = std(data);
disp("标准差:"+num2str(ss))
%%对数收益
lg_data = zeros(18,1);
lg_data(1,1) = log(1);
for i = 2:length(data)
lg_data(i,1) = log(data(i,1)/data(i-1,1));
end
save lg_data lg_data
figure(2)
plot(datenn,lg_data,'--gs',...
'LineWidth',2,...
'MarkerSize',10,...
'MarkerEdgeColor','r',...
'MarkerFaceColor',[0.5,0,0])
set(gca,'XTick',datenn(1):datenn(end),'XTickLabelRotation',30);
datetick('x','yyyy-mm-dd','keepticks')
grid on
title("对数收益曲线图")
%%求最值、均值、标准差
max2 = max(lg_data);
indx12 = find(lg_data==max2);
disp("对数收益序列的最大值:"+date(indx12,1)+','+num2str(max2))
min2 = min(lg_data);
indx22 = find(lg_data==min2);
disp("对数收益序列的最小值:"+date(indx22,1)+','+num2str(min2))
mm1 = mean(lg_data);
disp("对数收益均值:"+num2str(mm1))
ss1 = std(lg_data);
disp("对数收益标准差:"+num2str(ss1))