How to fit complicated non-linear curve

171 Views Asked by At

I am currently working on a model in my free time to see if I can predict the stock market. My methodology is that I first want to take the data and subtract out the function:

$Value(x)=A\left(1+\frac{B*x}{Volume(x)}\right)^{Volume(x)}+C$

Where A, B and C are constants. How do you go about fitting a curve with constants tucked in a non-linear fashion? Specifically, assuming you have the data for what $Values(x)$ and $Volume(x)$ are, what is the method to fit this curve?

Note: I understand that $e^x$ is equal to $\left(1+\frac{x}{n}\right)^n$ as $n$ goes to infinity. I am trying to see what happens when you don't assume that the stock is traded at infinite intervals since the noted function describes interest traded continuously.

1

There are 1 best solutions below

4
On BEST ANSWER

Forgetting the stock market, suppose that you have $n$ data points $(x_i,y_i,z_i)$ and you want to fit the model $$z=A\left(1+\frac {B\, x} y \right)^y+C$$ in the least square sense.

Suppose that you give $B$ an arbitrary value. For this value, define $$t_i=\left(1+\frac {B \,x_i} {y_i} \right)^{y_i}$$ making the model $$z=A t+C$$ which is more than simple and a very basic linear regression gives the sum of squares $SSQ$ which is a function of $B$.

Try different values of $B$ and plot $SSQ$ as a function of it until you notice a minimum. At this point, you have at least consistent estimates of the parameters and you can start a full nonlinear regression.

If this works for the stock market, please let me know.

For illustration purposes, I took the following data set $$\left( \begin{array}{ccc} x & y & z \\ 1 & 0.10 & 249 \\ 2 & 0.10 & 252 \\ 3 & 0.10 & 255 \\ 4 & 0.20 & 259 \\ 5 & 0.30 & 264 \\ 6 & 0.40 & 272 \\ 7 & 0.70 & 281 \\ 8 & 0.90 & 293 \\ 9 & 1.30 & 307 \\ 10 & 1.80 & 325 \end{array} \right)$$ and applied the method proposed above. For the area of interest, the results of the first step are $$\left( \begin{array}{cccc} B & SSQ & A & C \\ 0.10 & 24.7654 & 65.0836 & 178.329 \\ 0.11 & 16.9369 & 58.1372 & 185.946 \\ 0.12 & 11.7504 & 52.3874 & 192.321 \\ 0.13 & 8.82305 & 47.5551 & 197.738 \\ 0.14 & 7.83916 & 43.4414 & 202.402 \\ 0.15 & 8.53552 & 39.9007 & 206.461 \\ 0.16 & 10.6906 & 36.8239 & 210.027 \\ 0.17 & 14.1165 & 34.1279 & 213.187 \\ 0.18 & 18.6525 & 31.7481 & 216.007 \\ 0.19 & 24.1604 & 29.6337 & 218.540 \\ 0.20 & 30.5204 & 27.7441 & 220.829 \end{array} \right)$$ So, as estimates for the nonlinear regression are $A=43.44$, $B=0.14$, $C=202.40$. The final result is $$z=43.2065 \left(1+\frac{0.14062 \,x}{y}\right)^y+202.67$$ which would produce for the predicted $z$'s $$\{249.842,252.063,253.639,259.136,264.73,270.686,282.558,292.311,307.23,324.805\}$$