<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:blogger='http://schemas.google.com/blogger/2008' xmlns:georss='http://www.georss.org/georss' xmlns:gd="http://schemas.google.com/g/2005" xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-5262984523496383497</id><updated>2026-04-27T16:10:17.063-07:00</updated><category term="Data Analysis"/><category term="Utility Script"/><category term="Download Data"/><category term="Option"/><category term="Strategy Testing Scripts"/><category term="Visualization Script"/><title type='text'>Financial Scripting With FreeMAT/MATLAB</title><subtitle type='html'>-Converting my MATLAB scripts to FreeMAT so that more people can use them</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://financialscriptswithfreemat.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5262984523496383497/posts/default?redirect=false'/><link rel='alternate' type='text/html' href='http://financialscriptswithfreemat.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>EdgeMe</name><uri>http://www.blogger.com/profile/11680180959319239914</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>13</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-5262984523496383497.post-4060412141569134918</id><published>2010-03-01T16:31:00.000-08:00</published><updated>2010-03-01T16:31:08.834-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Visualization Script"/><title type='text'>How to generate a Candlestick chart in FreeMAT or MATLAB</title><content type='html'>The plot below is generated in FreeMAT, it can also be run at MATLAB:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEixJ9iaSyu4fAxzx3_8GtsNPGHHvOMYETRp22KeOQCrAnQNkcSOFNBlHogFphAIaR8DYoPhU5NkuMEmDDaJjSn_VNg1EmZKsTFa6enuYhFustiYJp1DAgH3ppECDT9tO7pDpz5nrdNYLLkc/s1600-h/F.jpg&quot; imageanchor=&quot;1&quot; style=&quot;clear: left; cssfloat: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;370&quot; kt=&quot;true&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEixJ9iaSyu4fAxzx3_8GtsNPGHHvOMYETRp22KeOQCrAnQNkcSOFNBlHogFphAIaR8DYoPhU5NkuMEmDDaJjSn_VNg1EmZKsTFa6enuYhFustiYJp1DAgH3ppECDT9tO7pDpz5nrdNYLLkc/s640/F.jpg&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;content&quot;&gt;
&lt;pre class=&quot;codeinput&quot;&gt;&lt;span class=&quot;keyword&quot;&gt;function&lt;/span&gt; gen_chart(D,O,H,L,C,symbol)
    &lt;span class=&quot;comment&quot;&gt;%&lt;/span&gt;
    &lt;span class=&quot;comment&quot;&gt;% This function generates a candlestick chart for a given O,H,L,C data&lt;/span&gt;
    &lt;span class=&quot;comment&quot;&gt;% D is dates&lt;/span&gt;
    &lt;span class=&quot;comment&quot;&gt;% O is open&lt;/span&gt;
    &lt;span class=&quot;comment&quot;&gt;% H is high&lt;/span&gt;
    &lt;span class=&quot;comment&quot;&gt;% L is low&lt;/span&gt;
    &lt;span class=&quot;comment&quot;&gt;% C is close&lt;/span&gt;
    &lt;span class=&quot;comment&quot;&gt;% symbol&lt;/span&gt;
    &lt;span class=&quot;comment&quot;&gt;%&lt;/span&gt;
    &lt;span class=&quot;comment&quot;&gt;% Example:&lt;/span&gt;
    &lt;span class=&quot;comment&quot;&gt;% [D O H L C V]=get_symbol_data(&#39;F&#39;,150);&lt;/span&gt;
    &lt;span class=&quot;comment&quot;&gt;% gen_chart(D,O,H,L,C,&#39;F&#39;);&lt;/span&gt;
    &lt;span class=&quot;comment&quot;&gt;%&lt;/span&gt;
    &lt;span class=&quot;comment&quot;&gt;%&lt;/span&gt;
    &lt;span class=&quot;comment&quot;&gt;%   Copyright 2010 EdgeMe&lt;/span&gt;
    &lt;span class=&quot;comment&quot;&gt;%   $Revision: 1.0.0.0 $&lt;/span&gt;
    &lt;span class=&quot;comment&quot;&gt;%   EdgeMe, 28-Feb-2010&lt;/span&gt;
    &lt;span class=&quot;comment&quot;&gt;%&lt;/span&gt;
    &lt;span class=&quot;comment&quot;&gt;%&lt;/span&gt;
    &lt;span class=&quot;keyword&quot;&gt;if&lt;/span&gt; nargin&amp;lt;6
        error(&lt;span class=&quot;string&quot;&gt;&#39;Not enough inputs&#39;&lt;/span&gt;);
    &lt;span class=&quot;keyword&quot;&gt;end&lt;/span&gt;



    datapoints=length(D);
    &lt;span class=&quot;comment&quot;&gt;%make sure we have the same length of data&lt;/span&gt;
    &lt;span class=&quot;keyword&quot;&gt;if&lt;/span&gt; length(O) ~=datapoints || length(H) ~=datapoints || length(L) ~=datapoints ||length(C) ~=datapoints
        error(&lt;span class=&quot;string&quot;&gt;&#39;Data must be in the same length&#39;&lt;/span&gt;);
    &lt;span class=&quot;keyword&quot;&gt;end&lt;/span&gt;


    figure;


    hold &lt;span class=&quot;string&quot;&gt;on&lt;/span&gt;;
    &lt;span class=&quot;comment&quot;&gt;%draw low to high lines&lt;/span&gt;
    &lt;span class=&quot;keyword&quot;&gt;for&lt;/span&gt; i=1:datapoints
        plot([i i],[L(i) H(i)],&lt;span class=&quot;string&quot;&gt;&#39;Color&#39;&lt;/span&gt;,&lt;span class=&quot;string&quot;&gt;&#39;k&#39;&lt;/span&gt;);
        &lt;span class=&quot;keyword&quot;&gt;if&lt;/span&gt; C(i)&amp;gt;O(i)
            plot([i i],[O(i) C(i)],&lt;span class=&quot;string&quot;&gt;&#39;linewidth&#39;&lt;/span&gt;,3,&lt;span class=&quot;string&quot;&gt;&#39;color&#39;&lt;/span&gt;,&lt;span class=&quot;string&quot;&gt;&#39;g&#39;&lt;/span&gt;);
        &lt;span class=&quot;keyword&quot;&gt;else&lt;/span&gt;
            plot([i i],[O(i) C(i)],&lt;span class=&quot;string&quot;&gt;&#39;linewidth&#39;&lt;/span&gt;,3,&lt;span class=&quot;string&quot;&gt;&#39;color&#39;&lt;/span&gt;,&lt;span class=&quot;string&quot;&gt;&#39;r&#39;&lt;/span&gt;);
        &lt;span class=&quot;keyword&quot;&gt;end&lt;/span&gt;
    &lt;span class=&quot;keyword&quot;&gt;end&lt;/span&gt;


    title(symbol);
    hold &lt;span class=&quot;string&quot;&gt;off&lt;/span&gt;;
    grid &lt;span class=&quot;string&quot;&gt;on&lt;/span&gt;;

    &lt;span class=&quot;comment&quot;&gt;%&lt;/span&gt;
    xlim([1 datapoints+1]);
    y=get(gca,&lt;span class=&quot;string&quot;&gt;&#39;ylim&#39;&lt;/span&gt;);
    ymin=int16(y(1)-0.5);
    ymax=int16(y(2)+0.5);
    ylim([ymin ymax]);


    XTick=[];
    j=1;
    &lt;span class=&quot;keyword&quot;&gt;for&lt;/span&gt; i=1:10:datapoints
        XTick(j)=i;
        j=j+1;
    &lt;span class=&quot;keyword&quot;&gt;end&lt;/span&gt;

    &lt;span class=&quot;comment&quot;&gt;%Set XTicklabel to an empty string&lt;/span&gt;
    set(gca,&lt;span class=&quot;string&quot;&gt;&#39;XTick&#39;&lt;/span&gt;,XTick,&lt;span class=&quot;string&quot;&gt;&#39;XTickLabel&#39;&lt;/span&gt;,&lt;span class=&quot;string&quot;&gt;&#39;&#39;&lt;/span&gt;)

    &lt;span class=&quot;keyword&quot;&gt;for&lt;/span&gt; i=1:length(XTick)
        &lt;span class=&quot;comment&quot;&gt;% Set the new xTickLabels of Dates&lt;/span&gt;
        hText = text(XTick(i), double(ymin), D{XTick(i)});
        set(hText,&lt;span class=&quot;string&quot;&gt;&#39;Rotation&#39;&lt;/span&gt;,28,&lt;span class=&quot;string&quot;&gt;&#39;HorizontalAlignment&#39;&lt;/span&gt;,&lt;span class=&quot;string&quot;&gt;&#39;right&#39;&lt;/span&gt;);
    &lt;span class=&quot;keyword&quot;&gt;end&lt;/span&gt;

&lt;span class=&quot;keyword&quot;&gt;end&lt;/span&gt;
&lt;/pre&gt;
&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://financialscriptswithfreemat.blogspot.com/feeds/4060412141569134918/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://financialscriptswithfreemat.blogspot.com/2010/03/how-to-generate-candlestick-chart-in.html#comment-form' title='5 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5262984523496383497/posts/default/4060412141569134918'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5262984523496383497/posts/default/4060412141569134918'/><link rel='alternate' type='text/html' href='http://financialscriptswithfreemat.blogspot.com/2010/03/how-to-generate-candlestick-chart-in.html' title='How to generate a Candlestick chart in FreeMAT or MATLAB'/><author><name>EdgeMe</name><uri>http://www.blogger.com/profile/11680180959319239914</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEixJ9iaSyu4fAxzx3_8GtsNPGHHvOMYETRp22KeOQCrAnQNkcSOFNBlHogFphAIaR8DYoPhU5NkuMEmDDaJjSn_VNg1EmZKsTFa6enuYhFustiYJp1DAgH3ppECDT9tO7pDpz5nrdNYLLkc/s72-c/F.jpg" height="72" width="72"/><thr:total>5</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5262984523496383497.post-6990649739563948305</id><published>2010-02-28T08:07:00.001-08:00</published><updated>2010-02-28T08:07:46.674-08:00</updated><title type='text'>Scripts updates</title><content type='html'>Per readers comments, the following two scripts have been updated:&lt;br /&gt;
&lt;br /&gt;
get_symbol_data.m&lt;br /&gt;
adx2.m</content><link rel='replies' type='application/atom+xml' href='http://financialscriptswithfreemat.blogspot.com/feeds/6990649739563948305/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://financialscriptswithfreemat.blogspot.com/2010/02/scripts-updates.html#comment-form' title='7 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5262984523496383497/posts/default/6990649739563948305'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5262984523496383497/posts/default/6990649739563948305'/><link rel='alternate' type='text/html' href='http://financialscriptswithfreemat.blogspot.com/2010/02/scripts-updates.html' title='Scripts updates'/><author><name>EdgeMe</name><uri>http://www.blogger.com/profile/11680180959319239914</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>7</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5262984523496383497.post-6095761589144779903</id><published>2010-02-18T17:10:00.000-08:00</published><updated>2010-02-18T17:10:59.827-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Option"/><title type='text'>Option Pricing Black-Scholes script for MATLAB and FreeMAT</title><content type='html'>&lt;style&gt;
body {
  background-color: white;
  margin:10px;
}

h1 {
  color: #990000; 
  font-size: x-large;
}

h2 {
  color: #990000;
  font-size: medium;
}

/* Make the text shrink to fit narrow windows, but not stretch too far in 
wide windows. */ 
p,h1,h2,div.content div {
  max-width: 600px;
  /* Hack for IE6 */
  width: auto !important; width: 600px;
}

pre.codeinput {
  background: #EEEEEE;
  padding: 10px;
}
@media print {
  pre.codeinput {word-wrap:break-word; width:100%;}
} 

span.keyword {color: #0000FF}
span.comment {color: #228B22}
span.string {color: #A020F0}
span.untermstring {color: #B20000}
span.syscmd {color: #B28C00}

pre.codeoutput {
  color: #666666;
  padding: 10px;
}

pre.error {
  color: red;
}

p.footer {
  text-align: right;
  font-size: xx-small;
  font-weight: lighter;
  font-style: italic;
  color: gray;
}

  
&lt;/style&gt;&lt;br /&gt;
&lt;div class=&quot;content&quot;&gt;
&lt;pre class=&quot;codeinput&quot;&gt;&lt;span class=&quot;keyword&quot;&gt;function&lt;/span&gt; [C, P]= option_bs(S,X,r,sigma,days)
    &lt;span class=&quot;comment&quot;&gt;%&lt;/span&gt;
    &lt;span class=&quot;comment&quot;&gt;%  This function to calculate Call and Put price per Black-Scholes formula.&lt;/span&gt;
    &lt;span class=&quot;comment&quot;&gt;%  This function can be run both at FreeMAT and MATLAB,&lt;/span&gt;
    &lt;span class=&quot;comment&quot;&gt;%  This function should be same as MATLAB&#39;s financial toolbox function&lt;/span&gt;
    &lt;span class=&quot;comment&quot;&gt;%  blsprice.&lt;/span&gt;
    &lt;span class=&quot;comment&quot;&gt;%&lt;/span&gt;
    &lt;span class=&quot;comment&quot;&gt;% C: call price&lt;/span&gt;
    &lt;span class=&quot;comment&quot;&gt;% P: put price&lt;/span&gt;
    &lt;span class=&quot;comment&quot;&gt;% S: stock price at time 0&lt;/span&gt;
    &lt;span class=&quot;comment&quot;&gt;% X:  strike price&lt;/span&gt;
    &lt;span class=&quot;comment&quot;&gt;% r: risk-free interest rate&lt;/span&gt;
    &lt;span class=&quot;comment&quot;&gt;% sigma: volatility of the stock price measured as annual standard deviation&lt;/span&gt;
    &lt;span class=&quot;comment&quot;&gt;% days: numbers of days remaining in the option contract, this will be converted into unit of years.&lt;/span&gt;
    &lt;span class=&quot;comment&quot;&gt;% Black-Scholes formula:&lt;/span&gt;
    &lt;span class=&quot;comment&quot;&gt;%  C = S N(d1) - Xe-rt N(d2)&lt;/span&gt;
    &lt;span class=&quot;comment&quot;&gt;%  P = Xe-rt N(-d2) - S N(-d1)&lt;/span&gt;
    &lt;span class=&quot;comment&quot;&gt;%&lt;/span&gt;

    T=days/365;

    &lt;span class=&quot;comment&quot;&gt;% for call&lt;/span&gt;
    d1 = (log(S/X) + (r + 0.5*sigma^2)*T)/(sigma*sqrt(T));
    d2 = d1 - sigma*sqrt(T);
    N1 = 0.5*(1+erf(d1/sqrt(2)));
    N2 = 0.5*(1+erf(d2/sqrt(2)));

    C = S*N1-X*exp(-r*T)*N2;

    &lt;span class=&quot;comment&quot;&gt;% for put&lt;/span&gt;

    N1 = 0.5*(1+erf(-d1/sqrt(2)));
    N2 = 0.5*(1+erf(-d2/sqrt(2)));

    P = X*exp(-r*T)*N2 - S*N1;
&lt;span class=&quot;keyword&quot;&gt;end&lt;/span&gt;
&lt;/pre&gt;
&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://financialscriptswithfreemat.blogspot.com/feeds/6095761589144779903/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://financialscriptswithfreemat.blogspot.com/2010/02/option-pricing-black-scholes-script-for.html#comment-form' title='4 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5262984523496383497/posts/default/6095761589144779903'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5262984523496383497/posts/default/6095761589144779903'/><link rel='alternate' type='text/html' href='http://financialscriptswithfreemat.blogspot.com/2010/02/option-pricing-black-scholes-script-for.html' title='Option Pricing Black-Scholes script for MATLAB and FreeMAT'/><author><name>EdgeMe</name><uri>http://www.blogger.com/profile/11680180959319239914</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>4</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5262984523496383497.post-1297193805109032953</id><published>2010-02-16T17:26:00.000-08:00</published><updated>2010-02-16T17:26:07.366-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Data Analysis"/><title type='text'>get_hisVolatility.m</title><content type='html'>&lt;style&gt;
body {
  background-color: white;
  margin:10px;
}

h1 {
  color: #990000; 
  font-size: x-large;
}

h2 {
  color: #990000;
  font-size: medium;
}

/* Make the text shrink to fit narrow windows, but not stretch too far in 
wide windows. */ 
p,h1,h2,div.content div {
  max-width: 600px;
  /* Hack for IE6 */
  width: auto !important; width: 600px;
}

pre.codeinput {
  background: #EEEEEE;
  padding: 10px;
}
@media print {
  pre.codeinput {word-wrap:break-word; width:100%;}
} 

span.keyword {color: #0000FF}
span.comment {color: #228B22}
span.string {color: #A020F0}
span.untermstring {color: #B20000}
span.syscmd {color: #B28C00}

pre.codeoutput {
  color: #666666;
  padding: 10px;
}

pre.error {
  color: red;
}

p.footer {
  text-align: right;
  font-size: xx-small;
  font-weight: lighter;
  font-style: italic;
  color: gray;
}

  
&lt;/style&gt;&lt;br /&gt;
&lt;div class=&quot;content&quot;&gt;
&lt;pre class=&quot;codeinput&quot;&gt;&lt;span class=&quot;keyword&quot;&gt;function&lt;/span&gt; vol = get_hisVolatility(closes, N)
&lt;span class=&quot;comment&quot;&gt;%&lt;/span&gt;
&lt;span class=&quot;comment&quot;&gt;%   This script is to calculate the historical&lt;/span&gt;
&lt;span class=&quot;comment&quot;&gt;%   volatility for close prices using N days sliding window&lt;/span&gt;
&lt;span class=&quot;comment&quot;&gt;%   If N is not specified, a default of 20 days will be&lt;/span&gt;
&lt;span class=&quot;comment&quot;&gt;%   used.&lt;/span&gt;
&lt;span class=&quot;comment&quot;&gt;%&lt;/span&gt;
&lt;span class=&quot;comment&quot;&gt;%   Copyright 2010 EdgeMe&lt;/span&gt;
&lt;span class=&quot;comment&quot;&gt;%   EdgeMe, 12-Feb-2010&lt;/span&gt;
&lt;span class=&quot;comment&quot;&gt;%&lt;/span&gt;
&lt;span class=&quot;comment&quot;&gt;%&lt;/span&gt;
&lt;span class=&quot;keyword&quot;&gt;if&lt;/span&gt; nargin==0
    N=20;
&lt;span class=&quot;keyword&quot;&gt;end&lt;/span&gt;

    dataN=numel(closes);
    vol=[];
    &lt;span class=&quot;keyword&quot;&gt;if&lt;/span&gt; dataN&amp;lt;N
      warning (&lt;span class=&quot;string&quot;&gt;&#39;Not enough data&#39;&lt;/span&gt;)
      &lt;span class=&quot;keyword&quot;&gt;return&lt;/span&gt;;
    &lt;span class=&quot;keyword&quot;&gt;end&lt;/span&gt;

    log_change(1)=0;
    &lt;span class=&quot;keyword&quot;&gt;for&lt;/span&gt; i=2:dataN
    log_change(i) = log(closes(i)/closes(i-1));
    &lt;span class=&quot;keyword&quot;&gt;end&lt;/span&gt;

    &lt;span class=&quot;keyword&quot;&gt;for&lt;/span&gt; i=N+1:dataN
    stdev = std(log_change(i-N+1:i));

    &lt;span class=&quot;comment&quot;&gt;% Normalize to annual volatility&lt;/span&gt;
    vol(i)= stdev*sqrt(252);
    &lt;span class=&quot;keyword&quot;&gt;end&lt;/span&gt;

    &lt;span class=&quot;comment&quot;&gt;%fillin the first N days using N+1 vol&lt;/span&gt;
    &lt;span class=&quot;keyword&quot;&gt;for&lt;/span&gt; i=1:N
        vol(i)=vol(N+1);
    &lt;span class=&quot;keyword&quot;&gt;end&lt;/span&gt;

&lt;span class=&quot;keyword&quot;&gt;end&lt;/span&gt;
&lt;/pre&gt;
&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://financialscriptswithfreemat.blogspot.com/feeds/1297193805109032953/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://financialscriptswithfreemat.blogspot.com/2010/02/gethisvolatilitym.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5262984523496383497/posts/default/1297193805109032953'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5262984523496383497/posts/default/1297193805109032953'/><link rel='alternate' type='text/html' href='http://financialscriptswithfreemat.blogspot.com/2010/02/gethisvolatilitym.html' title='get_hisVolatility.m'/><author><name>EdgeMe</name><uri>http://www.blogger.com/profile/11680180959319239914</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5262984523496383497.post-789735862114225490</id><published>2010-02-15T17:12:00.001-08:00</published><updated>2010-02-15T17:12:55.786-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Data Analysis"/><title type='text'>ema.m</title><content type='html'>&lt;style&gt;
body {
  background-color: white;
  margin:10px;
}

h1 {
  color: #990000; 
  font-size: x-large;
}

h2 {
  color: #990000;
  font-size: medium;
}

/* Make the text shrink to fit narrow windows, but not stretch too far in 
wide windows. */ 
p,h1,h2,div.content div {
  max-width: 600px;
  /* Hack for IE6 */
  width: auto !important; width: 600px;
}

pre.codeinput {
  background: #EEEEEE;
  padding: 10px;
}
@media print {
  pre.codeinput {word-wrap:break-word; width:100%;}
} 

span.keyword {color: #0000FF}
span.comment {color: #228B22}
span.string {color: #A020F0}
span.untermstring {color: #B20000}
span.syscmd {color: #B28C00}

pre.codeoutput {
  color: #666666;
  padding: 10px;
}

pre.error {
  color: red;
}

p.footer {
  text-align: right;
  font-size: xx-small;
  font-weight: lighter;
  font-style: italic;
  color: gray;
}

  
&lt;/style&gt;&lt;br /&gt;
&lt;div class=&quot;content&quot;&gt;
&lt;pre class=&quot;codeinput&quot;&gt;&lt;span class=&quot;keyword&quot;&gt;function&lt;/span&gt; dataout = ema(datain,period)
&lt;span class=&quot;comment&quot;&gt;%&lt;/span&gt;
&lt;span class=&quot;comment&quot;&gt;% This function is to get EMA of a given datain and a given period&lt;/span&gt;
&lt;span class=&quot;comment&quot;&gt;%&lt;/span&gt;
&lt;span class=&quot;comment&quot;&gt;%   Copyright 2010 EdgeMe&lt;/span&gt;
&lt;span class=&quot;comment&quot;&gt;%   EdgeMe, 10-Feb-2010&lt;/span&gt;
&lt;span class=&quot;comment&quot;&gt;%&lt;/span&gt;
&lt;span class=&quot;comment&quot;&gt;%&lt;/span&gt;
    f = 2/(period+1);
    N = numel(datain);
    dataout = zeros(N,1);
    dataout(1) = datain(1);
    &lt;span class=&quot;keyword&quot;&gt;for&lt;/span&gt; i=2:N
    dataout(i) = f*(datain(i)-dataout(i-1)) + dataout(i-1);
    &lt;span class=&quot;keyword&quot;&gt;end&lt;/span&gt;

&lt;span class=&quot;keyword&quot;&gt;end&lt;/span&gt;
&lt;/pre&gt;
&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://financialscriptswithfreemat.blogspot.com/feeds/789735862114225490/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://financialscriptswithfreemat.blogspot.com/2010/02/emam.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5262984523496383497/posts/default/789735862114225490'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5262984523496383497/posts/default/789735862114225490'/><link rel='alternate' type='text/html' href='http://financialscriptswithfreemat.blogspot.com/2010/02/emam.html' title='ema.m'/><author><name>EdgeMe</name><uri>http://www.blogger.com/profile/11680180959319239914</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5262984523496383497.post-5911371633236586911</id><published>2010-02-15T16:11:00.000-08:00</published><updated>2010-02-15T16:11:51.149-08:00</updated><title type='text'>How to generate a list of stocks according to your own magic formula – A reader made it working</title><content type='html'>&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Trebuchet MS&#39;, Trebuchet, Verdana, sans-serif; font-size: 13px;&quot;&gt;&lt;a href=&quot;http://yeforex.blogspot.com/2010/02/how-to-generate-list-of-your-own-part.html&quot; style=&quot;color: #9e5205;&quot;&gt;How to generate a list of stocks according to your own magic formula – Part One&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;a href=&quot;http://yeforex.blogspot.com/2010/02/how-to-generate-list-of-your-own-part_13.html&quot; style=&quot;color: #de7008;&quot;&gt;How to generate a list of stocks according to your own magic formula – Part Two&lt;/a&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
After I posted the above article, a reader sent me an email pointed out it requires one more script &quot;split_str_by_comma.m&quot;.&lt;br /&gt;
&lt;br /&gt;
After sending him the script and I also updated the script &quot;get_symbols.m&quot;. Today he sent an email saying that&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;i&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: x-large;&quot;&gt;&quot;&lt;/span&gt;&lt;/i&gt;&lt;/b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;border-collapse: collapse; font-family: arial, sans-serif;&quot;&gt;&lt;b&gt;&lt;i&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: x-large;&quot;&gt;It is working great now. thank you so much...&quot;&lt;/span&gt;&lt;/i&gt;&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;border-collapse: collapse; font-family: arial, sans-serif; font-size: 13px;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;border-collapse: separate; font-family: &#39;Times New Roman&#39;; font-size: medium;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;border-collapse: collapse; font-family: arial, sans-serif; font-size: 13px;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;border-collapse: separate; font-family: &#39;Times New Roman&#39;; font-size: medium;&quot;&gt;Thanks for visiting my blog, and I hope my blog will help others too.&amp;nbsp;&lt;/span&gt;&lt;/span&gt;</content><link rel='replies' type='application/atom+xml' href='http://financialscriptswithfreemat.blogspot.com/feeds/5911371633236586911/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://financialscriptswithfreemat.blogspot.com/2010/02/how-to-generate-list-of-stocks.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5262984523496383497/posts/default/5911371633236586911'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5262984523496383497/posts/default/5911371633236586911'/><link rel='alternate' type='text/html' href='http://financialscriptswithfreemat.blogspot.com/2010/02/how-to-generate-list-of-stocks.html' title='How to generate a list of stocks according to your own magic formula – A reader made it working'/><author><name>EdgeMe</name><uri>http://www.blogger.com/profile/11680180959319239914</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5262984523496383497.post-1114689412737144097</id><published>2010-02-14T20:39:00.001-08:00</published><updated>2010-02-14T20:39:37.913-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Utility Script"/><title type='text'>split_str_by_comma.m</title><content type='html'>&lt;style&gt;
body {
  background-color: white;
  margin:10px;
}

h1 {
  color: #990000; 
  font-size: x-large;
}

h2 {
  color: #990000;
  font-size: medium;
}

/* Make the text shrink to fit narrow windows, but not stretch too far in 
wide windows. */ 
p,h1,h2,div.content div {
  max-width: 600px;
  /* Hack for IE6 */
  width: auto !important; width: 600px;
}

pre.codeinput {
  background: #EEEEEE;
  padding: 10px;
}
@media print {
  pre.codeinput {word-wrap:break-word; width:100%;}
} 

span.keyword {color: #0000FF}
span.comment {color: #228B22}
span.string {color: #A020F0}
span.untermstring {color: #B20000}
span.syscmd {color: #B28C00}

pre.codeoutput {
  color: #666666;
  padding: 10px;
}

pre.error {
  color: red;
}

p.footer {
  text-align: right;
  font-size: xx-small;
  font-weight: lighter;
  font-style: italic;
  color: gray;
}

  
&lt;/style&gt;&lt;br /&gt;
&lt;div class=&quot;content&quot;&gt;
&lt;pre class=&quot;codeinput&quot;&gt;&lt;span class=&quot;keyword&quot;&gt;function&lt;/span&gt; ret_cell_array=split_str_by_comma(str)
&lt;span class=&quot;comment&quot;&gt;%&lt;/span&gt;
&lt;span class=&quot;comment&quot;&gt;% This function is to split a str by comma, return as cell array&lt;/span&gt;
&lt;span class=&quot;comment&quot;&gt;%&lt;/span&gt;
&lt;span class=&quot;comment&quot;&gt;% EXAMPLE:&lt;/span&gt;
&lt;span class=&quot;comment&quot;&gt;% ret_cell_array=split_str_by_comma(&#39;12, 34, 56&#39;);&lt;/span&gt;
&lt;span class=&quot;comment&quot;&gt;% the ret_cell_array should be {&#39;12&#39;,&#39;34&#39;,&#39;56&#39;}&lt;/span&gt;
&lt;span class=&quot;comment&quot;&gt;%&lt;/span&gt;
&lt;span class=&quot;comment&quot;&gt;% If you have MATLAB, you can use ret_cell_array=regexp(str,&#39;,&#39;,&#39;split&#39;) to get job done;&lt;/span&gt;
&lt;span class=&quot;comment&quot;&gt;%&lt;/span&gt;
&lt;span class=&quot;comment&quot;&gt;%   Copyright 2010 EdgeMe&lt;/span&gt;
&lt;span class=&quot;comment&quot;&gt;%   EdgeMe, 10-Feb-2010&lt;/span&gt;
&lt;span class=&quot;comment&quot;&gt;%&lt;/span&gt;
&lt;span class=&quot;comment&quot;&gt;%&lt;/span&gt;

    &lt;span class=&quot;comment&quot;&gt;%find out where are the commas&lt;/span&gt;
    commas=regexp(str,&lt;span class=&quot;string&quot;&gt;&#39;,&#39;&lt;/span&gt;);

    &lt;span class=&quot;comment&quot;&gt;%if no comma, just return the str&lt;/span&gt;
    &lt;span class=&quot;keyword&quot;&gt;if&lt;/span&gt; isempty(commas)
        ret_cell_array={str};
        &lt;span class=&quot;keyword&quot;&gt;return&lt;/span&gt;;
    &lt;span class=&quot;keyword&quot;&gt;else&lt;/span&gt; &lt;span class=&quot;comment&quot;&gt;%we found comma(s)&lt;/span&gt;

        &lt;span class=&quot;comment&quot;&gt;%first comma, also get rid of space&lt;/span&gt;
        ret_cell_array{1}=strrep(str(1:commas(1)-1),&lt;span class=&quot;string&quot;&gt;&#39; &#39;&lt;/span&gt;,&lt;span class=&quot;string&quot;&gt;&#39;&#39;&lt;/span&gt;);

        &lt;span class=&quot;keyword&quot;&gt;for&lt;/span&gt; i=1:numel(commas)-1

            ret_cell_array{end+1}=strrep(str(commas(i)+1:commas(i+1)-1),&lt;span class=&quot;string&quot;&gt;&#39; &#39;&lt;/span&gt;,&lt;span class=&quot;string&quot;&gt;&#39;&#39;&lt;/span&gt;);

        &lt;span class=&quot;keyword&quot;&gt;end&lt;/span&gt;

        &lt;span class=&quot;comment&quot;&gt;%last one&lt;/span&gt;
        &lt;span class=&quot;keyword&quot;&gt;if&lt;/span&gt; length(str)&amp;gt;commas(end)
            ret_cell_array{end+1}=strrep(str(commas(end)+1:length(str)),&lt;span class=&quot;string&quot;&gt;&#39; &#39;&lt;/span&gt;,&lt;span class=&quot;string&quot;&gt;&#39;&#39;&lt;/span&gt;);
        &lt;span class=&quot;keyword&quot;&gt;end&lt;/span&gt;


    &lt;span class=&quot;keyword&quot;&gt;end&lt;/span&gt;


 &lt;span class=&quot;keyword&quot;&gt;end&lt;/span&gt;
&lt;/pre&gt;
&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://financialscriptswithfreemat.blogspot.com/feeds/1114689412737144097/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://financialscriptswithfreemat.blogspot.com/2010/02/splitstrbycommam.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5262984523496383497/posts/default/1114689412737144097'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5262984523496383497/posts/default/1114689412737144097'/><link rel='alternate' type='text/html' href='http://financialscriptswithfreemat.blogspot.com/2010/02/splitstrbycommam.html' title='split_str_by_comma.m'/><author><name>EdgeMe</name><uri>http://www.blogger.com/profile/11680180959319239914</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5262984523496383497.post-5379966835753032099</id><published>2010-02-13T19:17:00.001-08:00</published><updated>2010-02-20T15:56:25.284-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Strategy Testing Scripts"/><title type='text'>Classical Pairs Trading</title><content type='html'>&lt;div&gt;
&lt;div style=&quot;margin: 0pt;&quot;&gt;
&lt;span style=&quot;font-family: &#39;Times New Roman&#39;;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;Classical Pairs Trading&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: &#39;Times New Roman&#39;;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt; Scripts Running in FreeMAT&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin: 0pt;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;margin: 0pt;&quot;&gt;
&lt;br /&gt;&lt;span style=&quot;color: #191919; font-family: Tahoma;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;“&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: &#39;Times New Roman&#39;;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;The &lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: &#39;Times New Roman&#39;;&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-size: small;&quot;&gt;pairs trade&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;span style=&quot;font-family: &#39;Times New Roman&#39;;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt; or &lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: &#39;Times New Roman&#39;;&quot;&gt;&lt;b&gt;&lt;i&gt;&lt;span style=&quot;font-size: small;&quot;&gt;pair trading&lt;/span&gt;&lt;/i&gt;&lt;/b&gt;&lt;/span&gt;&lt;span style=&quot;font-family: &#39;Times New Roman&#39;;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;, also known as market neutral, was developed in the late 1980s by &lt;/span&gt;&lt;/span&gt;&lt;a href=&quot;http://en.wikipedia.org/wiki/Quantitative_analyst&quot;&gt;&lt;span style=&quot;color: #0053d0; font-family: &#39;Times New Roman&#39;;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;quantita&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #0053d0; font-family: &#39;Times New Roman&#39;;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;t&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #0053d0; font-family: &#39;Times New Roman&#39;;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;ive analysts&lt;/span&gt;&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;font-family: &#39;Times New Roman&#39;;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt; and pioneered by &lt;/span&gt;&lt;/span&gt;&lt;a href=&quot;http://en.wikipedia.org/w/index.php?title=Gerald_Bamberger&amp;amp;action=edit&amp;amp;redlink=1&quot;&gt;&lt;span style=&quot;color: #cc2200; font-family: &#39;Times New Roman&#39;;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;Gerald Bamberger&lt;/span&gt;&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;font-family: &#39;Times New Roman&#39;;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt; while at Morgan Stanley. With the help of others at Morgan Stanley at the time, including Nunzio Tartaglia, Bamberger found that certain securities, often competitors in the same sector, were correlated in their day-to-day price movements. When the correlation broke down, i.e. one stock traded up while the other traded down, they would sell the outperforming stock and buy the underperforming one, betting that the &quot;spread&quot; between the two would eventually converge.” –from wikipedia&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin: 0pt;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;margin: 0pt 1.2pt 0pt 0pt;&quot;&gt;
&lt;a href=&quot;http://www.mathworks.com/matlabcentral/fileexchange/authors/21596&quot;&gt;&lt;span style=&quot;color: black; font-family: &#39;Times New Roman&#39;;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;Marcelo P&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: black; font-family: &#39;Times New Roman&#39;;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;e&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: black; font-family: &#39;Times New Roman&#39;;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;rlin&lt;/span&gt;&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;font-family: &#39;Times New Roman&#39;;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt; shared his MATLAB scripts for &lt;/span&gt;&lt;/span&gt;&lt;a href=&quot;http://www.mathworks.com/matlabcentral/fileexchange/13171-classical-pairs-trading-using-matlab&quot;&gt;&lt;span style=&quot;color: #0053d0; font-family: &#39;Times New Roman&#39;;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;Classical Pairs Tra&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #0053d0; font-family: &#39;Times New Roman&#39;;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;d&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #0053d0; font-family: &#39;Times New Roman&#39;;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;ing Using MatLab&lt;/span&gt;&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;font-family: &#39;Times New Roman&#39;;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt; in the MathWorks website. I downloaded his scripts, and tried to run at FreeMAT. &lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: blue; font-family: &#39;Times New Roman&#39;;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;It basically worked without any change.&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: &#39;Times New Roman&#39;;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt; (Two minor errors due to the difference between MATLAB and FreeMAT, but you can run scripts to end to get the final results and a plot.)&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin: 0pt 1.2pt 0pt 0pt;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;margin: 0pt 1.2pt 0pt 0pt;&quot;&gt;
&lt;span style=&quot;font-family: &#39;Times New Roman&#39;;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;Unzip the files you downloaded into a directory. Open the FreeMAT, then c&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: &#39;Times New Roman&#39;;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;hange &lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: &#39;Times New Roman&#39;;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;d&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: &#39;Times New Roman&#39;;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;irectory&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: &#39;Times New Roman&#39;;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt; to the directory where the file “&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: &#39;Times New Roman&#39;;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;Example_Script_Pairs_Trading&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: &#39;Times New Roman&#39;;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;.m” is. Then the FreeMAT command line, type&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin: 0pt 1.2pt 0pt 0pt;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;margin: 0pt 1.2pt 0pt 0pt;&quot;&gt;
&lt;span style=&quot;font-family: Wingdings;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;à&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: &#39;Times New Roman&#39;;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt; Example_Script_Pairs_Trading&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin: 0pt 1.2pt 0pt 0pt;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;margin: 0pt 1.2pt 0pt 0pt;&quot;&gt;
&lt;span style=&quot;font-family: &#39;Times New Roman&#39;;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;Just like that, after a few minutes, you will get plot like this:&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin: 0pt 1.2pt 0pt 0pt;&quot;&gt;
&lt;img alt=&quot;&quot; height=&quot;404&quot; src=&quot;http://docs.google.com/File?id=dgbsrb2z_30cksq6qck_b&quot; style=&quot;border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none;&quot; width=&quot;576&quot; /&gt;&lt;/img&gt;&lt;/div&gt;
&lt;div style=&quot;margin: 0pt 1.2pt 0pt 0pt;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;margin: 0pt 1.2pt 0pt 0pt;&quot;&gt;
&lt;span style=&quot;font-family: &#39;Times New Roman&#39;;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;This is resulted from his sample stock data. &lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: &#39;Times New Roman&#39;;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;He seems also used S&amp;amp;P data to get the results like this:&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin: 0pt 1.2pt 0pt 0pt;&quot;&gt;
&lt;img alt=&quot;&quot; height=&quot;420&quot; src=&quot;http://docs.google.com/File?id=dgbsrb2z_31dqpndrhb_b&quot; style=&quot;border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none;&quot; width=&quot;561&quot; /&gt;&lt;/img&gt;&lt;/div&gt;
&lt;div style=&quot;margin: 0pt 1.2pt 0pt 0pt;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;margin: 0pt 1.2pt 0pt 0pt;&quot;&gt;
&lt;span style=&quot;font-family: &#39;Times New Roman&#39;;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;Since his scripts used his sample data, I will have to modify/add some scripts to make it robust to be used for a set of stocks I choose to test out the pair trading strategy. &lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin: 0pt 1.2pt 0pt 0pt;&quot;&gt;
&lt;span style=&quot;font-family: &#39;Times New Roman&#39;;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;I will keep you posted.&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;br /&gt;</content><link rel='replies' type='application/atom+xml' href='http://financialscriptswithfreemat.blogspot.com/feeds/5379966835753032099/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://financialscriptswithfreemat.blogspot.com/2010/02/classical-pairs-trading.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5262984523496383497/posts/default/5379966835753032099'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5262984523496383497/posts/default/5379966835753032099'/><link rel='alternate' type='text/html' href='http://financialscriptswithfreemat.blogspot.com/2010/02/classical-pairs-trading.html' title='Classical Pairs Trading'/><author><name>EdgeMe</name><uri>http://www.blogger.com/profile/11680180959319239914</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5262984523496383497.post-73431474416878862</id><published>2010-02-13T12:48:00.000-08:00</published><updated>2010-02-13T12:48:24.132-08:00</updated><title type='text'>Scripts for the article below are posted in this blog</title><content type='html'>&lt;a href=&quot;http://yeforex.blogspot.com/2010/02/how-to-generate-list-of-your-own-part.html&quot;&gt;How to generate a list of stocks according to your own magic formula – Part One&lt;/a&gt; &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;a href=&quot;http://yeforex.blogspot.com/2010/02/how-to-generate-list-of-your-own-part_13.html&quot;&gt;How to generate a list of stocks according to your own magic formula – Part Two&lt;/a&gt;</content><link rel='replies' type='application/atom+xml' href='http://financialscriptswithfreemat.blogspot.com/feeds/73431474416878862/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://financialscriptswithfreemat.blogspot.com/2010/02/scripts-for-article-below-are-posted-in.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5262984523496383497/posts/default/73431474416878862'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5262984523496383497/posts/default/73431474416878862'/><link rel='alternate' type='text/html' href='http://financialscriptswithfreemat.blogspot.com/2010/02/scripts-for-article-below-are-posted-in.html' title='Scripts for the article below are posted in this blog'/><author><name>EdgeMe</name><uri>http://www.blogger.com/profile/11680180959319239914</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5262984523496383497.post-4201816154557358928</id><published>2010-02-13T09:07:00.000-08:00</published><updated>2010-02-13T14:16:06.412-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Utility Script"/><title type='text'>save2html.m</title><content type='html'>&lt;style&gt;
body {
  background-color: white;
  margin:10px;
}

h1 {
  color: #990000; 
  font-size: x-large;
}

h2 {
  color: #990000;
  font-size: medium;
}

/* Make the text shrink to fit narrow windows, but not stretch too far in 
wide windows. */ 
p,h1,h2,div.content div {
  max-width: 600px;
  /* Hack for IE6 */
  width: auto !important; width: 600px;
}

pre.codeinput {
  background: #EEEEEE;
  padding: 10px;
}
@media print {
  pre.codeinput {word-wrap:break-word; width:100%;}
} 

span.keyword {color: #0000FF}
span.comment {color: #228B22}
span.string {color: #A020F0}
span.untermstring {color: #B20000}
span.syscmd {color: #B28C00}

pre.codeoutput {
  color: #666666;
  padding: 10px;
}

pre.error {
  color: red;
}

p.footer {
  text-align: right;
  font-size: xx-small;
  font-weight: lighter;
  font-style: italic;
  color: gray;
}

  
&lt;/style&gt;&lt;br /&gt;
&lt;div class=&quot;content&quot;&gt;
&lt;pre class=&quot;codeinput&quot;&gt;&lt;span class=&quot;keyword&quot;&gt;function&lt;/span&gt; save2html(htmlfile,cells,title)
&lt;span class=&quot;comment&quot;&gt;%&lt;/span&gt;
&lt;span class=&quot;comment&quot;&gt;%   This script is to save cells into a table format html file&lt;/span&gt;
&lt;span class=&quot;comment&quot;&gt;%&lt;/span&gt;
&lt;span class=&quot;comment&quot;&gt;%   Copyright 2010 EdgeMe&lt;/span&gt;
&lt;span class=&quot;comment&quot;&gt;%   EdgeMe, 10-Feb-2010&lt;/span&gt;
&lt;span class=&quot;comment&quot;&gt;%&lt;/span&gt;
&lt;span class=&quot;comment&quot;&gt;%&lt;/span&gt;

fid = fopen(htmlfile,&lt;span class=&quot;string&quot;&gt;&#39;w&#39;&lt;/span&gt;);
fprintf(fid,[&lt;span class=&quot;string&quot;&gt;&#39;&amp;lt;table style=&quot;color:black; font-size:20; font-family:Times;&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; border=&quot;1&quot;&amp;gt;&#39;&lt;/span&gt;]);

fprintf(fid,[&lt;span class=&quot;string&quot;&gt;&#39;&amp;lt;title&amp;gt;&#39;&lt;/span&gt;,title,&lt;span class=&quot;string&quot;&gt;&#39;&amp;lt;/title&amp;gt;&#39;&lt;/span&gt;]);

[r c] = size(cells);

&lt;span class=&quot;keyword&quot;&gt;if&lt;/span&gt; r==1 &amp;amp;&amp;amp; c&amp;gt;1 &lt;span class=&quot;comment&quot;&gt;% transpose the cells&lt;/span&gt;
    cells=cells&#39;;
&lt;span class=&quot;keyword&quot;&gt;end&lt;/span&gt;

[r c] = size(cells);

&lt;span class=&quot;keyword&quot;&gt;for&lt;/span&gt; j=1:r; &lt;span class=&quot;comment&quot;&gt;% for each row&lt;/span&gt;

 fprintf(fid,&lt;span class=&quot;string&quot;&gt;&#39;&amp;lt;tr&amp;gt;&#39;&lt;/span&gt;);

 &lt;span class=&quot;keyword&quot;&gt;for&lt;/span&gt; i=1:c; &lt;span class=&quot;comment&quot;&gt;%for each column&lt;/span&gt;

  temp = cells{j,i};
        &lt;span class=&quot;keyword&quot;&gt;if&lt;/span&gt; ~isempty(temp)
       &lt;span class=&quot;keyword&quot;&gt;if&lt;/span&gt; isnumeric(temp) &amp;amp;&amp;amp; ~isnan(temp);
       td = num2str(temp);
        &lt;span class=&quot;keyword&quot;&gt;elseif&lt;/span&gt; ischar(temp)
       td = temp;
             &lt;span class=&quot;keyword&quot;&gt;end&lt;/span&gt;

        &lt;span class=&quot;keyword&quot;&gt;else&lt;/span&gt;
            td = &lt;span class=&quot;string&quot;&gt;&#39;&amp;amp;nbsp;&#39;&lt;/span&gt;;
        &lt;span class=&quot;keyword&quot;&gt;end&lt;/span&gt;

        fprintf(fid,[&lt;span class=&quot;string&quot;&gt;&#39;&amp;lt;td&amp;gt;&#39;&lt;/span&gt;,&lt;span class=&quot;string&quot;&gt;&#39;&amp;lt;a href=&quot;http://www.finviz.com/quote.ashx?t=&#39;&lt;/span&gt;,td,&lt;span class=&quot;string&quot;&gt;&#39;&quot; target=&quot;_blank&quot;&amp;gt;&#39;&lt;/span&gt;,td,&lt;span class=&quot;string&quot;&gt;&#39;&amp;lt;/td&amp;gt;&#39;&lt;/span&gt;]);

 &lt;span class=&quot;keyword&quot;&gt;end&lt;/span&gt;

 fprintf(fid,&lt;span class=&quot;string&quot;&gt;&#39;&amp;lt;/tr&amp;gt;&#39;&lt;/span&gt;);

&lt;span class=&quot;keyword&quot;&gt;end&lt;/span&gt;


fprintf(fid,&lt;span class=&quot;string&quot;&gt;&#39;&amp;lt;/table&amp;gt;&#39;&lt;/span&gt;);
fclose(fid);

&lt;span class=&quot;keyword&quot;&gt;end&lt;/span&gt;
&lt;/pre&gt;
&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://financialscriptswithfreemat.blogspot.com/feeds/4201816154557358928/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://financialscriptswithfreemat.blogspot.com/2010/02/function-save2htmlhtmlfilecellstitle.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5262984523496383497/posts/default/4201816154557358928'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5262984523496383497/posts/default/4201816154557358928'/><link rel='alternate' type='text/html' href='http://financialscriptswithfreemat.blogspot.com/2010/02/function-save2htmlhtmlfilecellstitle.html' title='save2html.m'/><author><name>EdgeMe</name><uri>http://www.blogger.com/profile/11680180959319239914</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5262984523496383497.post-7445993845974415475</id><published>2010-02-13T08:53:00.000-08:00</published><updated>2010-02-14T20:43:18.344-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Utility Script"/><title type='text'>get_symbols.m</title><content type='html'>&lt;style&gt;
body {
  background-color: white;
  margin:10px;
}

h1 {
  color: #990000; 
  font-size: x-large;
}

h2 {
  color: #990000;
  font-size: medium;
}

/* Make the text shrink to fit narrow windows, but not stretch too far in 
wide windows. */ 
p,h1,h2,div.content div {
  max-width: 600px;
  /* Hack for IE6 */
  width: auto !important; width: 600px;
}

pre.codeinput {
  background: #EEEEEE;
  padding: 10px;
}
@media print {
  pre.codeinput {word-wrap:break-word; width:100%;}
} 

span.keyword {color: #0000FF}
span.comment {color: #228B22}
span.string {color: #A020F0}
span.untermstring {color: #B20000}
span.syscmd {color: #B28C00}

pre.codeoutput {
  color: #666666;
  padding: 10px;
}

pre.error {
  color: red;
}

p.footer {
  text-align: right;
  font-size: xx-small;
  font-weight: lighter;
  font-style: italic;
  color: gray;
}

  
&lt;/style&gt;&lt;br /&gt;
&lt;div class=&quot;content&quot;&gt;
&lt;pre class=&quot;codeinput&quot;&gt;&lt;span class=&quot;keyword&quot;&gt;function&lt;/span&gt; symbols=get_symbols(symbolfile)
&lt;span class=&quot;comment&quot;&gt;%&lt;/span&gt;
&lt;span class=&quot;comment&quot;&gt;% This function return all symbols from a symbol file&lt;/span&gt;
&lt;span class=&quot;comment&quot;&gt;% A symbol file is a simple text file contain a stock symbol at each line&lt;/span&gt;
&lt;span class=&quot;comment&quot;&gt;% EXAMPLE:&lt;/span&gt;
&lt;span class=&quot;comment&quot;&gt;% symbols=get_symbols(&#39;all_symbols.txt&#39;);&lt;/span&gt;
&lt;span class=&quot;comment&quot;&gt;%&lt;/span&gt;
&lt;span class=&quot;comment&quot;&gt;% If you have MATLAB, you can just use &quot;importdata(symbolfile)&quot; to get job done.&lt;/span&gt;
&lt;span class=&quot;comment&quot;&gt;% If you run this script in MATLAB, please change fgetline to fgetl&lt;/span&gt;
&lt;span class=&quot;comment&quot;&gt;%&lt;/span&gt;
&lt;span class=&quot;comment&quot;&gt;% 12-Feb-2010, added deblank to make sure no space&lt;/span&gt;
&lt;span class=&quot;comment&quot;&gt;%&lt;/span&gt;
&lt;span class=&quot;comment&quot;&gt;%   Copyright 2010 EdgeMe&lt;/span&gt;
&lt;span class=&quot;comment&quot;&gt;%   EdgeMe, 10-Feb-2010&lt;/span&gt;
&lt;span class=&quot;comment&quot;&gt;%&lt;/span&gt;
&lt;span class=&quot;comment&quot;&gt;%&lt;/span&gt;
    symbols=[];
    symbolpath=&lt;span class=&quot;string&quot;&gt;&#39;c:\relativestrength\list&#39;&lt;/span&gt;;

    datafile=[symbolpath,&lt;span class=&quot;string&quot;&gt;&#39;\&#39;&lt;/span&gt;,symbolfile];

     &lt;span class=&quot;keyword&quot;&gt;if&lt;/span&gt; exist(datafile)&amp;gt;0

         fid = fopen(datafile);
         &lt;span class=&quot;keyword&quot;&gt;while&lt;/span&gt; (~feof(fid))
             temp=fgetline(fid); &lt;span class=&quot;comment&quot;&gt;% if run in the MATLAB, use fgetl(fid)&lt;/span&gt;
             newlinestart= regexp(temp,&lt;span class=&quot;string&quot;&gt;&#39;\n&#39;&lt;/span&gt;) ;&lt;span class=&quot;comment&quot;&gt;%get the line, but the return may contains a empty new line&lt;/span&gt;

             &lt;span class=&quot;keyword&quot;&gt;if&lt;/span&gt; isempty(newlinestart) &lt;span class=&quot;comment&quot;&gt;%means no empty new line&lt;/span&gt;
                    symbols{end+1} =deblank(temp);
             &lt;span class=&quot;keyword&quot;&gt;else&lt;/span&gt;

                    symbols{end+1} =deblank(temp(1:newlinestart-1)); &lt;span class=&quot;comment&quot;&gt;% only save the content without the empty new line&lt;/span&gt;
             &lt;span class=&quot;keyword&quot;&gt;end&lt;/span&gt;
         &lt;span class=&quot;keyword&quot;&gt;end&lt;/span&gt;
     &lt;span class=&quot;keyword&quot;&gt;else&lt;/span&gt;
        warning([&lt;span class=&quot;string&quot;&gt;&#39;Could not find the file &#39;&lt;/span&gt;,symbolfile]);
         &lt;span class=&quot;keyword&quot;&gt;return&lt;/span&gt;;
     &lt;span class=&quot;keyword&quot;&gt;end&lt;/span&gt;

    &lt;span class=&quot;keyword&quot;&gt;end&lt;/span&gt;
&lt;/pre&gt;
&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://financialscriptswithfreemat.blogspot.com/feeds/7445993845974415475/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://financialscriptswithfreemat.blogspot.com/2010/02/getsymbolsm.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5262984523496383497/posts/default/7445993845974415475'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5262984523496383497/posts/default/7445993845974415475'/><link rel='alternate' type='text/html' href='http://financialscriptswithfreemat.blogspot.com/2010/02/getsymbolsm.html' title='get_symbols.m'/><author><name>EdgeMe</name><uri>http://www.blogger.com/profile/11680180959319239914</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5262984523496383497.post-1059135804772151812</id><published>2010-02-13T08:44:00.000-08:00</published><updated>2010-02-28T08:06:36.968-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Download Data"/><title type='text'>get_symbol_data.m</title><content type='html'>&lt;style&gt;
body {
  background-color: white;
  margin:10px;
}

h1 {
  color: #990000; 
  font-size: x-large;
}

h2 {
  color: #990000;
  font-size: medium;
}

/* Make the text shrink to fit narrow windows, but not stretch too far in 
wide windows. */ 
p,h1,h2,div.content div {
  max-width: 600px;
  /* Hack for IE6 */
  width: auto !important; width: 600px;
}

pre.codeinput {
  background: #EEEEEE;
  padding: 10px;
}
@media print {
  pre.codeinput {word-wrap:break-word; width:100%;}
} 

span.keyword {color: #0000FF}
span.comment {color: #228B22}
span.string {color: #A020F0}
span.untermstring {color: #B20000}
span.syscmd {color: #B28C00}

pre.codeoutput {
  color: #666666;
  padding: 10px;
}

pre.error {
  color: red;
}

p.footer {
  text-align: right;
  font-size: xx-small;
  font-weight: lighter;
  font-style: italic;
  color: gray;
}

  
&lt;/style&gt;&lt;br /&gt;
&lt;div class=&quot;content&quot;&gt;
&lt;pre class=&quot;codeinput&quot;&gt;&lt;span class=&quot;keyword&quot;&gt;function&lt;/span&gt; [dates opens highs lows closes volumes]=get_symbol_data(symbol,days)
&lt;span class=&quot;comment&quot;&gt;%&lt;/span&gt;
&lt;span class=&quot;comment&quot;&gt;% This function returns stock data array by input stock file .csv file and number of days&lt;/span&gt;
&lt;span class=&quot;comment&quot;&gt;%&lt;/span&gt;
&lt;span class=&quot;comment&quot;&gt;%&lt;/span&gt;
&lt;span class=&quot;comment&quot;&gt;% If you have MATLAB, you can use &quot;importdata&quot; function to get the job done easily.&lt;/span&gt;
&lt;span class=&quot;comment&quot;&gt;% This script can be run both in MATLAB and in FreeMAT&lt;/span&gt;
&lt;span class=&quot;comment&quot;&gt;% If you run this script in MATLAB, please change fgetline to fgetl&lt;/span&gt;
&lt;span class=&quot;comment&quot;&gt;%&lt;/span&gt;
&lt;span class=&quot;comment&quot;&gt;% 14-feb-2010, notice the zero volume day is in dataset, we have to get rid of these days&lt;/span&gt;
&lt;span class=&quot;comment&quot;&gt;%&lt;/span&gt;
&lt;span class=&quot;comment&quot;&gt;%   Copyright 2010 EdgeMe&lt;/span&gt;
&lt;span class=&quot;comment&quot;&gt;%   EdgeMe, 10-Feb-2010&lt;/span&gt;
&lt;span class=&quot;comment&quot;&gt;%&lt;/span&gt;
&lt;span class=&quot;comment&quot;&gt;%&lt;/span&gt;
dates=[];
    opens=[];
    highs=[];
    closes=[];
    lows=[];
    volumes=[];
    &lt;span class=&quot;comment&quot;&gt;%this is our data file path, change to your if different&lt;/span&gt;
    datapath=&lt;span class=&quot;string&quot;&gt;&#39;c:\relativestrength\temp&#39;&lt;/span&gt;;
    symbolfile=[symbol,&lt;span class=&quot;string&quot;&gt;&#39;.csv&#39;&lt;/span&gt;];
    datafile=[datapath,&lt;span class=&quot;string&quot;&gt;&#39;\&#39;&lt;/span&gt;,symbolfile];

    extradays=10; &lt;span class=&quot;comment&quot;&gt;%some days are holidays, but data file still have entry;&lt;/span&gt;

    &lt;span class=&quot;keyword&quot;&gt;if&lt;/span&gt; exist(datafile)&amp;gt;0
     rawdata=[];
     fid = fopen(datafile);
     d=0;
     &lt;span class=&quot;keyword&quot;&gt;while&lt;/span&gt; (d&amp;lt;days+extradays)
         rawdata{end+1} = fgetline(fid);&lt;span class=&quot;comment&quot;&gt;% if run in the MATLAB, use fgetl(fid)&lt;/span&gt;
         d=d+1;
     &lt;span class=&quot;keyword&quot;&gt;end&lt;/span&gt;
     fclose(fid);
     totaldays=numel(rawdata);

     &lt;span class=&quot;keyword&quot;&gt;for&lt;/span&gt; i=0:totaldays-1
         &lt;span class=&quot;comment&quot;&gt;% since the first data is the latest data, so we treat the oldest data first&lt;/span&gt;
         &lt;span class=&quot;keyword&quot;&gt;if&lt;/span&gt; ~isempty(rawdata{totaldays-i})
         temp=split_str_by_comma(rawdata{totaldays-i});

         &lt;span class=&quot;keyword&quot;&gt;if&lt;/span&gt; isempty(temp)
             &lt;span class=&quot;keyword&quot;&gt;return&lt;/span&gt;;
         &lt;span class=&quot;keyword&quot;&gt;end&lt;/span&gt;
         &lt;span class=&quot;keyword&quot;&gt;if&lt;/span&gt; str2num(temp{6})&amp;gt;0 &lt;span class=&quot;comment&quot;&gt;%make sure we have real data&lt;/span&gt;
         dates{end+1}=temp{1};
         opens(end+1)=str2num(temp{2});
         highs(end+1)=str2num(temp{3});
         lows(end+1)=str2num(temp{4});
         closes(end+1)=str2num(temp{5});
         volumes(end+1)=str2num(temp{6});
         &lt;span class=&quot;keyword&quot;&gt;end&lt;/span&gt;
         &lt;span class=&quot;keyword&quot;&gt;end&lt;/span&gt;
     &lt;span class=&quot;keyword&quot;&gt;end&lt;/span&gt;
     &lt;span class=&quot;keyword&quot;&gt;if&lt;/span&gt; numel(dates)&amp;gt;days
         dates=dates(end-days+1:end);
         opens=opens(end-days+1:end);
         highs=highs(end-days+1:end);
         lows=lows(end-days+1:end);
         closes=closes(end-days+1:end);
         volumes=volumes(end-days+1:end);
     &lt;span class=&quot;keyword&quot;&gt;end&lt;/span&gt;

    &lt;span class=&quot;keyword&quot;&gt;else&lt;/span&gt;
      warning([&lt;span class=&quot;string&quot;&gt;&#39;No data file found for &#39;&lt;/span&gt;,symbol]);
      &lt;span class=&quot;keyword&quot;&gt;return&lt;/span&gt;;
    &lt;span class=&quot;keyword&quot;&gt;end&lt;/span&gt;


&lt;span class=&quot;keyword&quot;&gt;end&lt;/span&gt;
&lt;/pre&gt;
&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://financialscriptswithfreemat.blogspot.com/feeds/1059135804772151812/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://financialscriptswithfreemat.blogspot.com/2010/02/getsymboldatam.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5262984523496383497/posts/default/1059135804772151812'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5262984523496383497/posts/default/1059135804772151812'/><link rel='alternate' type='text/html' href='http://financialscriptswithfreemat.blogspot.com/2010/02/getsymboldatam.html' title='get_symbol_data.m'/><author><name>EdgeMe</name><uri>http://www.blogger.com/profile/11680180959319239914</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5262984523496383497.post-8041175077693397410</id><published>2010-02-13T08:38:00.000-08:00</published><updated>2010-02-13T14:19:05.184-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Data Analysis"/><title type='text'>gen_myList.m</title><content type='html'>&lt;style&gt;
body {
  background-color: white;
  margin:10px;
}

h1 {
  color: #990000; 
  font-size: x-large;
}

h2 {
  color: #990000;
  font-size: medium;
}

/* Make the text shrink to fit narrow windows, but not stretch too far in 
wide windows. */ 
p,h1,h2,div.content div {
  max-width: 600px;
  /* Hack for IE6 */
  width: auto !important; width: 600px;
}

pre.codeinput {
  background: #EEEEEE;
  padding: 10px;
}
@media print {
  pre.codeinput {word-wrap:break-word; width:100%;}
} 

span.keyword {color: #0000FF}
span.comment {color: #228B22}
span.string {color: #A020F0}
span.untermstring {color: #B20000}
span.syscmd {color: #B28C00}

pre.codeoutput {
  color: #666666;
  padding: 10px;
}

pre.error {
  color: red;
}

p.footer {
  text-align: right;
  font-size: xx-small;
  font-weight: lighter;
  font-style: italic;
  color: gray;
}

  
&lt;/style&gt;&lt;br /&gt;
&lt;div class=&quot;content&quot;&gt;
&lt;pre class=&quot;codeinput&quot;&gt;&lt;span class=&quot;comment&quot;&gt;%&lt;/span&gt;
&lt;span class=&quot;comment&quot;&gt;% This script is to generate a watch list according to your magic formula criteria&lt;/span&gt;
&lt;span class=&quot;comment&quot;&gt;%&lt;/span&gt;

&lt;span class=&quot;comment&quot;&gt;% to get list of symbols we want to choose from&lt;/span&gt;
symbols=get_symbols(&lt;span class=&quot;string&quot;&gt;&#39;all_symbols.txt&#39;&lt;/span&gt;);

&lt;span class=&quot;comment&quot;&gt;% initialize the result list&lt;/span&gt;
myList=[];

&lt;span class=&quot;comment&quot;&gt;% now loop thru all symbols&lt;/span&gt;
&lt;span class=&quot;keyword&quot;&gt;for&lt;/span&gt; i=1:numel(symbols)

    &lt;span class=&quot;comment&quot;&gt;% get data for each symbol&lt;/span&gt;
    [dates opens highs lows closes volumes]=get_symbol_data(symbols{i},2);

    &lt;span class=&quot;comment&quot;&gt;% for this example, we will generate a list of stock that move up 2% for the day&lt;/span&gt;
    &lt;span class=&quot;comment&quot;&gt;% so we need only 2 days of data; change the criteria of your own if you wish.&lt;/span&gt;

    &lt;span class=&quot;comment&quot;&gt;% make sure we have data for the symbol&lt;/span&gt;
    &lt;span class=&quot;keyword&quot;&gt;if&lt;/span&gt; (~isempty(closes))
       &lt;span class=&quot;comment&quot;&gt;% now let&#39;s find out if the stock meet our 2% up day&lt;/span&gt;
        &lt;span class=&quot;keyword&quot;&gt;if&lt;/span&gt; (100*(closes(2)-closes(1)))/closes(1) &amp;gt;= 2
        &lt;span class=&quot;comment&quot;&gt;%ok, this one is up 2%&lt;/span&gt;
        &lt;span class=&quot;comment&quot;&gt;% save into the list&lt;/span&gt;
          myList{end+1}=symbols{i};
        &lt;span class=&quot;keyword&quot;&gt;end&lt;/span&gt;
    &lt;span class=&quot;keyword&quot;&gt;end&lt;/span&gt;

&lt;span class=&quot;keyword&quot;&gt;end&lt;/span&gt;

&lt;span class=&quot;comment&quot;&gt;% now we are here, myList should contain all the stock that met our criteria.&lt;/span&gt;
&lt;span class=&quot;comment&quot;&gt;% we can save into a HTML file with a hyperlink to a charting website&lt;/span&gt;
&lt;span class=&quot;keyword&quot;&gt;if&lt;/span&gt; ~isempty(myList) &lt;span class=&quot;comment&quot;&gt;%make sure we have at least one stock that met our criteria to save to a file&lt;/span&gt;
 save2html(&lt;span class=&quot;string&quot;&gt;&#39;myList.html&#39;&lt;/span&gt;,myList,&lt;span class=&quot;string&quot;&gt;&#39;My list per my magic formula&#39;&lt;/span&gt;); &lt;span class=&quot;comment&quot;&gt;% generate a HTML file&lt;/span&gt;
 disp(&lt;span class=&quot;string&quot;&gt;&#39;Your magic stock list is generated in myList.html&#39;&lt;/span&gt;);
&lt;span class=&quot;keyword&quot;&gt;else&lt;/span&gt;
 disp(&lt;span class=&quot;string&quot;&gt;&#39;Sorry, No stock met your magic formula&#39;&lt;/span&gt;);
&lt;span class=&quot;keyword&quot;&gt;end&lt;/span&gt;
&lt;/pre&gt;
&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://financialscriptswithfreemat.blogspot.com/feeds/8041175077693397410/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://financialscriptswithfreemat.blogspot.com/2010/02/genmylistm.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5262984523496383497/posts/default/8041175077693397410'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5262984523496383497/posts/default/8041175077693397410'/><link rel='alternate' type='text/html' href='http://financialscriptswithfreemat.blogspot.com/2010/02/genmylistm.html' title='gen_myList.m'/><author><name>EdgeMe</name><uri>http://www.blogger.com/profile/11680180959319239914</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry></feed>