[hist_date, hist_high, hist_low, hist_open, hist_close, hist_vol] =get_hist_stock_data('AAPL','2012'); data=hist_close; [lead,lag]=movavg(data,5,20,'e'); s=zeros(size(data)); s(lead<=lag)=-1; s(lead>lag)=1; r=[0;s(1:end-1).*diff(data)]; R=cumsum(r); % ax(1) = subplot(2,1,1); % plot([data,lead,lag]); grid on % legend('Close','Lead','Lag','Location','Best') % title(['Data, Lead and Lag MA']) % ax(2) = subplot(2,1,2); % plot([s*50,cumsum(r)]); grid on % legend('signal long and short','Cumulative Return','Location','Best') % linkaxes(ax,'x') rsi=rsindex(data,14) s1=zeros(size(data)); s1(rsi>75)=-1; s1(rsi<25)=1; r1=[0;s1(1:end-1).*diff(data)]; R1=cumsum(r); ax(1) = subplot(2,1,1); plot([data]); grid on legend('Close','Location','Best') title(['Close']) ax(2) = subplot(2,1,2); plot([s1*25,R1]); grid on legend('RSI Signal long short,no action','Cumulative Return','Location','Best') linkaxes(ax,'x')

No comments:
Post a Comment