• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

Math question

Miramonti

Lifer
Here's a math problem I need to learn how to figure out. It's less important that I know the specific answer as much as it is that I learn how to approach it and solve it with a program I'm using. Unfortunately my math background is extremely limited to say the least.

Given the datapoints below, I need to predict when and where these curves will intersect. The x-axis (1,2…9) is time, where a datapoint for each curve occurs every 90 minutes.

curve1 curve2
1) 1.1045 1.02410
2) 1.1100 1.03270
3) 1.1146 1.04110
4) 1.1185 1.04951
5) 1.1215 1.05782
6) 1.1238 1.06603
7) 1.1256 1.07399
8) 1.1269 1.08142
9) 1.1275 1.08830

Here is a picture of these curves graphed, basically a stock chart paired down to shows these only. The area of these points is circled.

sample_intersect.png


I understand calculating intersect of straight lines by taking the slope of each but I am clueless how to account for acceleration and deceleration.

UPDATE 7/21:

For now I'm going with the following equation for each line (explained how I got to it later in the thread.)

curve 1: a+b-.5cx²+.5cx
curve 2: d+e-.5fx²+.5fx (same as curve 1 but different variable letters except X.)

Here's a graph of curve 1 (green...thick line is original, thin is forecasted curve), and curve 2 (Red...thick is original, thin is 'forecasted' curve.

sample_intersect3.png


And now I'm hoping someone can help me solve for X. In the pic, X=11, but I want to solve for X to determine when in the future these 'forecasted' curves will meet. They clearly aren't perfect because visually they appear to meet approx. 6 periods before the original curves meet, instead of 11.

So the equation to solve for x would be:

a+b-.5cx²+.5cx = d+e-.5fx²+.5fx

Mathway.com's answer is:

sample_intersect_mathway1.gif


Is this is correct? I tried plugging it in but didn't get a good result. I'd also love to know the steps that someone goes thru to solve for X here, which at this point is a bit beyond me. (Btw, since X is always time looking into the future, it will always be >0)
 
Last edited:
Well you have to make a decision on how you want to model your curve (aka linear, 2nd/3rd/4th order polynomial, exponential). This is kind of a crap shoot since you're trying to model stocks based on price history I'm guessing?

Then just calculate the best fit (ala excel) and then solve for intersection.
 
First, let epsillon < 0...

😛

Anyway, TuxDave seems to have hit it spot on. With the limited data points that you have, it is best to know for what purpose the data models...
 
Well you have to make a decision on how you want to model your curve (aka linear, 2nd/3rd/4th order polynomial, exponential). This is kind of a crap shoot since you're trying to model stocks based on price history I'm guessing?

Then just calculate the best fit (ala excel) and then solve for intersection.

These curves are created based off of stock prices but I don't have the time on the fly to fit anything realtime and basically need to apply one approach and stick to it. They deal with rate of change in a shorter period compared to rate of change of stock movement in a longer period.

If I could take it to 2nd order, which I'm assuming is one degree further than linear [aka linear acceleration?], that would be cool but I have no idea if I can get there.

The time distance between the x-axis datapoints will vary (ie this is 90 minutes, it could be 1 minute, 390 minutes, all the above...) but I want to keep consistent the amount of datapoints used for the prediction, and I'll adjust the time periods based on volatility. Either case, this isn't going to be Nasa work. 😛

Back to your answer...I have no idea really how to create a polynomial equation for your solution. What would a linear or 2nd order solution look like for this series?
 
Last edited:
Perhaps you want quadratic interpolation? It only interpolates and you can't say anything about how the lines will behave outside of the data points.

http://www.youtube.com/watch?v=ifS8LL3qT2g&feature=channel

I don't know if I want to interpolate as much as extrapolate. I'm also guessing that I'll need to stick to linear at this point...extrapolating the acceleration of both lines and calculating where and when they will intersect.
 
Just use excel to make the curve. Is your issue that you don't know how to? If you make a scatter plot, just right click one of the data points and add a trendline. Also be sure to click the display formula (or something) checkbox.
 
Just use excel to make the curve. Is your issue that you don't know how to? If you make a scatter plot, just right click one of the data points and add a trendline. Also be sure to click the display formula (or something) checkbox.

I have the datapoints and curves, I just want to project them based on their accelerating or decelerating properties, and use the projection of two curves to predict when they will intersect and at what value (/edit: if they will intersect that is...sometimes they won't.)
 
Last edited:
I have the datapoints and curves, I just want to project them based on it's accelerating or decelerating properties, and use the projection of two curves to predict when they will intersect and at what value (/edit: if they will intersect that is...sometimes they won't.)

This kind of stuff is very hard to predict. This stuff and numerical methods to find very crude solutions is taught in a financial math class I think.
 
I have the datapoints and curves, I just want to project it based on it's properties, and use the projection of two curves to predict when they will intersect and at what value (/edit: if they will intersect that is...sometimes they won't.)

If you have the curves, all you do is set formula 1 = formula 2 and use algebra to solve for the x (time) value where they are equal, then substitute x into either of the the formulas to find the y (price) value

If you don't want to do the math by hand a TI-89 is always great, but there are websites like http://www.mathway.com/ that do it all for you. In this case the subject is algebra, and the subtopic (on the second page after you enter a formula) is find the x and y intercepts
 
If you have the curves, all you do is set formula 1 = formula 2 and use algebra to solve for the x (time) value where they are equal, then substitute x into either of the the formulas to find the y (price) value

If you don't want to do the math by hand a TI-89 is always great, but there are websites like http://www.mathway.com/ that do it all for you. In this case the subject is algebra, and the subtopic (on the second page after you enter a formula) is find the x and y intercepts

I will be putting the formula into my program to calculate frequently and apply elsewhere. I understand what you mean using algebra, but I have to account for acceleration in a formula for each curve which I need help on.
 
If you have the curves, all you do is set formula 1 = formula 2 and use algebra to solve for the x (time) value where they are equal, then substitute x into either of the the formulas to find the y (price) value

Yup. It seems to me that solving for the intersection is the easy part. It's finding the correct equation to fit the data that is the hard part (and what everyone's posts were hitting on). [edit: And also why some people on Wall Street get paid million dollar bonuses and others don't. I think it's as much an "art" than a "science" at this point in time, and whoever gets it the closest makes megabucks, while the others go bankrupt; in other words, there isn't a set "correct" answer to this question.]

I am no mathematician, but I would say that you have to make a choice whether you actually want to account for "acceleration or deceleration" at all and just approximate with a linear model, because once you starting accounting for "acceleration" you have to make some assumptions about how the acceleration is behaving, hence all of the other posters' comments about 2nd, 3rd order polynomial, etc.

Given that you only have a portion of the curve, you cannot really know the true behavior of the curve unless you are told that you can assume it behaves a certain way. You could go through a whole number of different possibilities and see which one fits your given data the best, but you still would not know with 100&#37; certainty whether the curve actually behaves in that manner outside of the data range you have been given.

If you want it quick and dirty, just assume linearity and do a linear regression for the short-term data. I'm sure there are lots of algorithms out there that are almost copy-and-pasteable for linear regression. It should be "close enough" if you don't need to extrapolate very far.

Otherwise, you're going to have to just make certain assumptions (after all, you don't REALLY know what is going on here). Heck, the behavior may actually be cyclical and you would want to find some sort of sinusoidal (sine or cosine) equation to fit to the data. You may have to adjust the equation if the stocks are trending up or down over time, however, but based on the graphs you have, you can't say much about that.

I think the whole point of this exercise is in what process you go through in analyzing the stock behavior and the decisions you make in how you decide to model it.

Sorry, I'm no mathematician nor financial whiz so I can't really help you there. Good luck. Post count +1, I guess. :\
 
Last edited:
What do you mean by acceleration? Do you mean the changing slope? The curve already captures that, that's the point of second and nth order curves.
 
Even if the acceleration is assumed linear?

Like I said in my other post, this is a decision you are going to have to make (if you haven't been told anything else).

Also, what do you mean by linear acceleration? If you have been told you can assume constant acceleration, then you can look up an equation that will fit a 2nd order polynomial (aka a parabola) to your data. I don't remember anymore, but if the acceleration changes but is linear, then you might need a 3rd order polynomial.

But if you don't know anything for certain, then heck, it could be doing something like this:

image0022.gif


Your program is only going to put out an approximation or best guess as to what is going to happen, as you are extrapolating without any real information as to whether the stocks are going to continue behaving the way they appear to be in the data range you are given. The more correct assumptions you can make about the stock behavior, the more correct your prediction will be, but in the end, it's still going to be a guess as you cannot know ahead of time whether your assumptions are truly correct.

If you you know anything about these stocks so you can make some sort of informed guess as to how they should "usually" behave, I would work from there.

Lacking that, you're going to have to have your program fit multiple types of lines [edit: should be curves, not lines] to the data and see which one fits the best (don't know the exact terminology for this. might be R squared or something that you would use, in which case the highest R squared value is best). However, you said you won't have the time to do that most likely.

[edit 2: lacking any hard info on what the stock behavior is, however, I'd stay with lower order polynomial fits, as higher orders or sinusoidal curves imply you know that the stock is going to alternate between increasing and decreasing a certain number of times (or infinitely). The safest bet is to assume it behaves like a line or maybe a parabola.
 
Last edited:
Just fit the data with a second order polynomial. That will give you a constant acceleration/deceleration figure. For your purposes, that is all you need. I would not use anything else, because you then need to figure in either nonconstant accelerating factors, or zero accelerating factors.

You don't want to interpolate on this type of thing.
 
Like I said in my other post, this is a decision you are going to have to make (if you haven't been told anything else).

Also, what do you mean by linear acceleration? If you have been told you can assume constant acceleration, then you can look up an equation that will fit a 2nd order polynomial (aka a parabola) to your data. I don't remember anymore, but if the acceleration changes but is linear, then you might need a 3rd order polynomial...

Oh, btw, did I mention my math background is extremely limited...😉 I'm looking up '2nd order polynomials' right now to see what's involved and if it's something that I can do.

Up to this point, I've looked at things from a simple algebraic perspective. Here's an example, using the data of the first curve (green):

1) 1.1045
2) 1.1100, difference .0055,
3) 1.1146, difference .0046, change in diff: -.0009
4) 1.1185, difference .0039, change in diff: -.0007
5) 1.1215, difference .0030, change in diff: -.0009
6) 1.1238, difference .0023, change in diff: -.0007
7) 1.1256, difference .0018, change in diff: -.0005
8) 1.1269, difference .0013, change in diff: -.0005
9) 1.1275, difference .0006, change in diff: -.0007

What this says to me is that, for example, the third datapoint was .0046 more than the second, which was a -.0009 less increase over the previous number's increment...and so on. Given these datapoints, these consecutive numbers increase on average at a rate of -.0007 each datapoint. So for example, the next point will be 1.1274 (reversing the line), and the following will be 1.267, 1.253, 1.232, 1.204.... (if I'm adding this correctly.)

(granted I mentioned having had algebra, creating this formula algebraically to calculate 10 datapoints out is unfortunately even a bit vague.)
 
Last edited:
Oh, btw, did I mention my math background is extremely limited...😉 I'm looking up '2nd order polynomials' right now to see what's involved and if it's something that I can do.

Up to this point, I've looked at things from a simple algebraic perspective. Here's an example, using the data of the first curve (green):

1) 1.1045
2) 1.1100, difference .0055,
3) 1.1146, difference .0046, change in diff: -.0009
4) 1.1185, difference .0039, change in diff: -.0007
5) 1.1215, difference .0030, change in diff: -.0009
6) 1.1238, difference .0023, change in diff: -.0007
7) 1.1256, difference .0018, change in diff: -.0005
8) 1.1269, difference .0013, change in diff: -.0005
9) 1.1275, difference .0006, change in diff: -.0007

What this says to me is that, for example, the third datapoint was .0046 more than the second, which was a -.0009 less increase over the previous number's increment...and so on. Given these datapoints, these consecutive numbers increase on average at a rate of -.0007 each datapoint. So for example, the next point will be 1.1274 (reversing the line), and the following will be 1.267, 1.253, 1.232, 1.204.... (if I'm adding this correctly.)

(granted I mentioned having had algebra, creating this formula algebraically to calculate 10 datapoints out is unfortunately even a bit vague.)

I think you're over-thinking this. You not going to be able to come up with a formula by hand. You need to use a fitting algorithm, or write one yourself (not recommended).
 
How come you're working on this if your math background is limited? Hope it's not your job at a financial business (though with all those failed banks, it would explain some things) 😛

If you want decent results, you'll have to do some research first. It's hard to say what model would be the best without good domain knowledge. Without knowing anything else, for stock data, I'd go with an autoregressive model of some order, they are well suited for general time series. And unless it's for academic purposes, you should use some sort of stats package, instead of computing stuff by hand. There are some free ones, like 'R', and it has AR fitting included, as well as a vast number of other stuff.
 
I think you're over-thinking this. You not going to be able to come up with a formula by hand. You need to use a fitting algorithm, or write one yourself (not recommended).

I thought this was my ghetto-math approach. 😀

How come you're working on this if your math background is limited? Hope it's not your job at a financial business (though with all those failed banks, it would explain some things) 😛

If you want decent results, you'll have to do some research first. It's hard to say what model would be the best without good domain knowledge. Without knowing anything else, for stock data, I'd go with an autoregressive model of some order, they are well suited for general time series. And unless it's for academic purposes, you should use some sort of stats package, instead of computing stuff by hand. There are some free ones, like 'R', and it has AR fitting included, as well as a vast number of other stuff.

It's my job but work for myself, so don't put your money in your mattress yet...if you haven't already. 😉
 
Like I said in my other post, this is a decision you are going to have to make (if you haven't been told anything else).

Also, what do you mean by linear acceleration? If you have been told you can assume constant acceleration, then you can look up an equation that will fit a 2nd order polynomial (aka a parabola) to your data. I don't remember anymore, but if the acceleration changes but is linear, then you might need a 3rd order polynomial.

But if you don't know anything for certain, then heck, it could be doing something like this:

image0022.gif


Your program is only going to put out an approximation or best guess as to what is going to happen, as you are extrapolating without any real information as to whether the stocks are going to continue behaving the way they appear to be in the data range you are given. The more correct assumptions you can make about the stock behavior, the more correct your prediction will be, but in the end, it's still going to be a guess as you cannot know ahead of time whether your assumptions are truly correct.

If you you know anything about these stocks so you can make some sort of informed guess as to how they should "usually" behave, I would work from there.

Lacking that, you're going to have to have your program fit multiple types of lines [edit: should be curves, not lines] to the data and see which one fits the best (don't know the exact terminology for this. might be R squared or something that you would use, in which case the highest R squared value is best). However, you said you won't have the time to do that most likely.

[edit 2: lacking any hard info on what the stock behavior is, however, I'd stay with lower order polynomial fits, as higher orders or sinusoidal curves imply you know that the stock is going to alternate between increasing and decreasing a certain number of times (or infinitely). The safest bet is to assume it behaves like a line or maybe a parabola.

A few more thoughts, after I've had some sleep.

First of all, thanks for your thoughts put into this. I've been trying to advance my math skills with khanacademy.org, but altho the vids are usually only 10 minutes, it takes a lot longer to grasp the content.

The curves will always vary to some degree due to the infinite variability of the stock market, but what's more important to me is the relationships of the curves that I've created, which are far more predictable.

They are based on the same raw data but with different time periods and smoothing, etc., which is why I'm primarily focused on intersection points and values based on each curves properties. The curves oscillate around "1", which significant narrows it's possibilities as compared to using linear regression to fit raw trade data that can go in either direction at any time.

That said, I will look up polynomial and parabola equations to see what can be applied, so that in the least I can learn more about them and perhaps relationship differences in the curves I use.
 
If you have the curves, all you do is set formula 1 = formula 2 and use algebra to solve for the x (time) value where they are equal, then substitute x into either of the the formulas to find the y (price) value

If you don't want to do the math by hand a TI-89 is always great, but there are websites like http://www.mathway.com/ that do it all for you. In this case the subject is algebra, and the subtopic (on the second page after you enter a formula) is find the x and y intercepts

Very cool site, altho haven't been able to get it to work for this problem ...how to I input the x and y points into the formula box so that it will understand what they are? (/edit: maybe there's a misunderstanding, I have the datapoints that make the curve, but not a formula for each curve.)
 
Last edited:
Very cool site, altho haven't been able to get it to work for this problem ...how to I input the x and y points into the formula box so that it will understand what they are? (/edit: maybe there's a misunderstanding, I have the datapoints that make the curve, but not a formula for each curve.)

You need the formulas before it can do anything for you. It looks like a lot of us are agreeing that modeling each curve as a second order polynomial should work. As I have mentioned before, excel does this.
 
Back
Top