Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Urgent Help for Matlab code

Status
Not open for further replies.

chrisnonso

Newbie level 4
Joined
Dec 4, 2010
Messages
6
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,374
Hello everyone,

I am currently writing a trading algorithm on matlab and I have encountered a road block. This is really urgent as it is my project due on Wed. and I need to graduate on the 16th of this month. So urgent inputs and contribution will be greatly appreciated. Thanks in advance. Ok I have done the regression for my input data, I have set a threshold on the residual error so that I can do the time series segmentation. When I go to plot my data (i.e. the input Y and the estimated Y input) I get only the last interval of my segmentation. I am trying to fix this problem but so far no solution. My matlab code is shown below please review and help if you can to point out my error. Thanks again.

Y = price;
THR = 100; %Threshold
Residue_Errors = zeros(1,117000);
AngleB0 = zeros(1,117000);
AngleB1 = zeros(1,117000);
anchor = 1;
for N = 100:length(Y)
time = (anchor:N);
X = (time)';
P = Y(anchor:N);
if (length(P) >= 100)
B = [ones(size(X,1),1),X]\P; % Gives the Intercept and slope
B0 = B(1,:);
B1 = B(2,:);
P_hat = B0 + B1*X; % Computes the predicted values of price given the intercept and slope
e = P - P_hat;
ResSqr = e.^2;
AngleB0(N) = B0;
AngleB1(N) = B1;
TotalResSqr = sum(ResSqr);
Residue_Errors(N) = TotalResSqr;
if Residue_Errors(N) > THR
anchor = N;
end
end
end
%time = (0:N-1);
%X = time';
%P = Y(1:N);
figure(1)
plot(X,P,X,P_hat,'r');title('Regression of Price and Price Hat Versus Time');xlabel('Time (N Samples)');ylabel('Price ($)')
figure(2)
plot(Residue_Errors);title('N Samples Vs. Residue Errors');xlabel('N Samples');ylabel('Residue Errors')
figure(3)
plot(AngleB0);title('Intercept B0 Angles Versus N Samples');xlabel('N Samples');ylabel('Intercept B0')
figure(4)
plot(AngleB1);title('Coefficient B1 Angles Versus N Samples');xlabel('N Samples');ylabel('Coefficient B1')
 

you've stored B0 and B1 in "AngleB0" and "AngleB1". you can reconstruct P_hat from these values.

likewise for P and X, you can reconstruct them outside of the loop.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top