2
$\begingroup$

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.

$\endgroup$
  • 1
    $\begingroup$ 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! $\endgroup$ – Dunlop Dec 1 '18 at 5:44
  • $\begingroup$ 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]) $\endgroup$ – Dunlop Dec 1 '18 at 5:46
1
$\begingroup$

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 *)
toOAdate[date_] := QuantityMagnitude[
    DateDifference[{1901, 1, 0}, date]] + 366;
data2 = data;
data2[[All, 1]] = toOAdate /@ data2[[All, 1]];
(* estimate start date of crash (Fitch downgrade of Countrywide) *)
tc = toOAdate["2007-08-16"];
(* select for t < tc so Log[tc - t] stays valid *)
data3 = Select[data2, First[#] < tc &];
(* compute with tc - t as tcminust *)
data3[[All, 1]] = data3[[All, 1]] /. x_Integer :> tc - x;
nlm = NonlinearModelFit[data3,
   a + b (tcminust)^z + c (tcminust)^z Cos[\[Omega] Log[tcminust] + \[Phi]],
   {a, b, z, c, \[Omega], \[Phi]}, tcminust, MaxIterations -> 1000];
nlm["BestFit"]
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.