Path: news.mathworks.com!newsfeed-00.mathworks.com!newsfeed2.dallas1.level3.net!news.level3.com!postnews.google.com!m20g2000vbp.googlegroups.com!not-for-mail
From: independent analyst <indstockanalyst@gmail.com>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Help executing function
Date: Mon, 16 Nov 2009 18:48:26 -0800 (PST)
Organization: http://groups.google.com
Lines: 45
Message-ID: <ce149fff-3c27-4b6e-90bf-6e3d42c27270@m20g2000vbp.googlegroups.com>
References: <hcnstm$fp3$1@fred.mathworks.com>
NNTP-Posting-Host: 71.224.41.135
Mime-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
X-Trace: posting.google.com 1258426106 4613 127.0.0.1 (17 Nov 2009 02:48:26 GMT)
X-Complaints-To: groups-abuse@google.com
NNTP-Posting-Date: Tue, 17 Nov 2009 02:48:26 +0000 (UTC)
Complaints-To: groups-abuse@google.com
Injection-Info: m20g2000vbp.googlegroups.com; posting-host=71.224.41.135; 
	posting-account=mLuC8QoAAACH4Izv43eZrClapTOy1ndb
User-Agent: G2/1.0
X-HTTP-UserAgent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.1.5) 
	Gecko/20091102 Firefox/3.5.5,gzip(gfe),gzip(gfe)
Xref: news.mathworks.com comp.soft-sys.matlab:585652


On Nov 2, 7:19 pm, "michael DeFelice" <mike198...@yahoo.com> wrote:
> I need to write a function that buys astockat the max and sells at the minimum points.  Assume I use all my money to buy astockand that I could buy fractions of astock.  This is as far as I could get.  I was wondering how I would actually go about buying and selling thestocknow.
>
> %Lets find the critical points, where we may want to purchase thestock
> rowloc=[];
> locationsize = 1;
> for i = 1:(i)
>     if y(i) < y(i+1)
>         rowloc(locationsize)=1;
>     else
>         rowloc(locationsize)=0;
>     end
> locationsize = locationsize+1;
> end
> rowloc(locationsize)=0;
> %Now that we have found where we may want to buy thestock, lets see where
> %we may want to sell thestock
> rowloc2=[];
> locationsize=1;
> for i = 1:(i)
>     if y(i) > y(i+1)
>         rowloc2(locationsize)=1;
>     else
>         rowloc2(locationsize)= 0;
>     end
> locationsize = locationsize+1;
> end
> rowloc2(locationsize)=0;
> %We have found the critical points of thestock, but we need to know what
> %the value of thestockis at the critical point.
> for x = 1:i+1
> newvec(x) = y(x);
> end
> buystock = newvec.*rowloc;
> sellstock = newvec.*rowloc2;
> %This creates a matrix of the values.
> totals = [buystock ; sellstock]
> %Now lets use this information to buy and sell thestock

If you're interested in more analysis, try the technical analysis
toolbox:
http://www.offbeatanalytics.com/