t=25
x1=Array_jan_13{t}.Volume;
y1=Array_jan_13{t}.Price;
line1 = 2500*ones(1, length(x1));
x_inter=intersectPoints_jan_13{t}.x0;
y_inter=intersectPoints_jan_13{t}.y0;
hFig = figure
plot(x1, y1, 'r-', 'LineWidth', 2)
hold on
plot(x1, line1, 'b', 'LineWidth', 2);
hold on
plot(x_inter,y_inter,'r.','markersize',18)
n=50000
x1_new=linspace(x1(1),x_inter,n);
y1_new=interp1(x1,y1,x1_new);
line_fine1 = 2500*ones(1, length(x1_new));
hFig = figure
plot(x1_new, y1_new, 'r-', 'LineWidth', 2)
hold on
plot(x1_new, line_fine1, 'b', 'LineWidth', 2);
hold on
plot(x_inter,y_inter,'r.','markersize',18)
indexLeft = find(y1_new < 2500, 1, 'first');
xline(x1_new(indexLeft), 'Color', 'm', 'LineWidth', 2);
xline(x1_new(end), 'Color', 'y', 'LineWidth', 2);
x_area=x1_new(indexLeft : end);
y_area=line_fine1(indexLeft : end)-y1_new(indexLeft : end);
area_Loss_up = trapz(x_area, y_area)
area_Loss2_up = sum(y_area) * abs(x1_new(2) - x1_new(1))
t=25
x2=Array_jan_13_s{t}.Volume_s;
y2=Array_jan_13_s{t}.Price_s;
line2 = 2500*ones(1, length(x2));
x_inter=intersectPoints_jan_13{t}.x0
y_inter=intersectPoints_jan_13{t}.y0
hFig = figure
plot(x2, y2, 'r-', 'LineWidth', 2)
hold on
plot(x2, line2, 'b', 'LineWidth', 2);
hold on
plot(x_inter,y_inter,'r.','markersize',18)
n=50000;
x2_new=linspace(x_inter, x2(end),n);
y2_new=interp1(x2,y2,x2_new);
line_fine2 = 2500*ones(1, length(x2_new));
hFig = figure
plot(x2_new, y2_new, 'r-', 'LineWidth', 2)
hold on
plot(x2_new, line_fine2, 'b', 'LineWidth', 2);
hold on
plot(x_inter,y_inter,'r.','markersize',18)
indexLeft = find(y2_new < 2500, 1, 'last');
xline(x2_new(indexLeft), 'Color', 'm', 'LineWidth', 2);
xline(x2_new(1), 'Color', 'y', 'LineWidth', 2);
x_area_s=x2_new(1 : indexLeft);
y_area_s=line_fine2(1 : indexLeft)-y2_new(1 : indexLeft);
area_Loss_s_up = trapz(x_area_s, y_area_s)
area_Loss2_s_up= sum(y_area_s) * abs(x2_new(2) - x2_new(1))
Total_area_up=area_Loss_up+area_Loss_s_up
Total_area2_up=area_Loss2_up+area_Loss2_s_up
Best Answer