Thread Subject: Help executing function

Subject: Help executing function

From: michael DeFelice

Date: 3 Nov, 2009 00:19:02

Message: 1 of 2

I need to write a function that buys a stock at the max and sells at the minimum points. Assume I use all my money to buy a stock and that I could buy fractions of a stock. This is as far as I could get. I was wondering how I would actually go about buying and selling the stock now.

%Lets find the critical points, where we may want to purchase the stock
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 the stock, lets see where
%we may want to sell the stock
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 the stock, but we need to know what
%the value of the stock is 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 the stock


    
    

Subject: Help executing function

From: independent analyst

Date: 17 Nov, 2009 02:48:26

Message: 2 of 2

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/

Tags for this Thread

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

rssFeed for this Thread
 

MATLAB Central Terms of Use

NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Terms prior to use.

Contact us at files@mathworks.com