# How to fit dated stock market data with non-linear model fit?

I am new to Mathematica and I am currently doing a project on predicting stock market trends using log-periodic power law. I am trying to fit stock market data to the following equation. y(t) = A + B (tc − t)^z + C (tc − t)^z*cos (ω log (tc − t) + Φ) https://www2.math.su.se/matstat/reports/serieb/2009/rep7/report.pdf Page 5

nlm = NonlinearModelFit[Data,A + B (tc - t)^z + (c (tc - t)^z)*(Cos (\[Omega]*Log (tc - t) +[Phi])), {A, B, tc, z,c, \[Omega], \[Phi]}, t]


"Data" is a dated stock market data for Dow Jones Index Average I am not sure exactly why this did not work. I figure it should be something to do with the data being dated and I am not sure how to handle dated data.

This is the Output I got

NonlinearModelFit::nrlnum: The function value {-16007.8+1. (1. -1. DateObject[{<<6>>},Instant,Gregorian,8.])^1.+1. Cos (1. +1. Log (1. -1. DateObject[<<4>>])) (1. -1. DateObject[{<<6>>},Instant,Gregorian,8.])^1.,-15913.6+1. (1. -1. DateObject[{<<6>>},Instant,Gregorian,8.])^1.+1. Cos (1. +1. Log (1. -1. DateObject[<<4>>])) (1. -1. DateObject[{<<6>>},Instant,Gregorian,8.])^1.,-15888.8+1. (1. -1. DateObject[{<<6>>},Instant,Gregorian,8.])^1.+1. Cos (1. +1. Log (1. -1. DateObject[<<4>>])) (1. -1. DateObject[{<<6>>},Instant,Gregorian,8.])^1.,<<46>>,-15793.1+1. (1. -1. DateObject[{<<6>>},Instant,Gregorian,8.])^1.+1. Cos (1. +1. Log (1. -1. DateObject[<<4>>])) (1. -1. DateObject[{<<6>>},Instant,Gregorian,8.])^1.,<<1255>>} is not a list of real numbers with dimensions {1305} at {A,B,tc,z,c,[Omega],[Phi]} = {1.,1.,1.,1.,1.,1.,1.}.

Edit One error I realized. I used the wrong brackets. New Input

nlm = NonlinearModelFit[Data,  A + B[tc - t]^z + [c[tc - t]^z]*[Cos[\[Omega]*Log[tc - t] + \[Phi]]], {A, B, tc,z, c, \[Omega], \[Phi]}, t]


But the output was Syntax::sntxb: Expression cannot begin with "[c[tc-t]^z][Cos[[Omega]Log[tc-t]+[Phi]]]". Not exactly sure what was wrong.

Any help is appreciated.

• Welcome to Mathematica.SE! I suggest the following: 1) As you receive help, try to give it too, by answering questions in your area of expertise. 2) Take the tour and check the faqs! 3) When you see good questions and answers, vote them up by clicking the gray triangles, because the credibility of the system is based on the reputation gained by users sharing their knowledge. Also, please remember to accept the answer, if any, that solves your problem, by clicking the checkmark sign! – Dunlop Dec 1 '18 at 5:44
• You have to be careful about your use of square brackets and round brackets! Square brackets define functions, i.e. B[tc-t] implies B is a function (which I think is not what you want try: A + B (tc - t)^z + (c (tc - t)^z)*(Cos[\[Omega]*Log[tc - t] + \[Phi]) – Dunlop Dec 1 '18 at 5:46

Here is something to try. Compute fits for a range of estimated tc dates and see which is the best fit.

data = FinancialData["^DJI", "1980-01-01"];
(* convert to OLE day values *)
DateDifference[{1901, 1, 0}, date]] + 366;
data2 = data;
data2[[All, 1]] = toOAdate /@ data2[[All, 1]];
(* estimate start date of crash (Fitch downgrade of Countrywide) *)
`