|
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/
|