python: stock market fractals vs log-normal distribution

Discussion in 'App Development' started by rs2000, Apr 7, 2017.

  1. rs2000

    rs2000

    Hi All,

    I am working on a project and need your help with a module.
    I have daily stock prices for Index for last 10 years. The question goes like

    Considering last 10 year daily price movements of NASDAQ, write a program to check whether fractal geometrics could have better predicted stock market movements than log-normal distribution assumption. Explain your findings with suitable graphs.


    Please could you recommend on how to implement fractals for stock market prediction and how can I compare this with the forecast of lognormal distribution. Its a bit of open ended question and I am lost here.
    The programming language I use is Python but right not I am stuck on how to tackle this question. a bit lost.....what shall I show here

    Many Thanks for your help
     
  2. xandman

    xandman

    You just isolate the source of returns.

    If lognormal, buy and sell the stock market for the same durations. The degree of skewness for the distribution of returns will prove it is lognormal. Essentially, a baseline for your fractal experiment.

    If fractal, buy and hold for different durations. I would expect the fractal dimension to be time.

    There might be a more practical way of finding fractal patterns in stock charts. This may require that you identify specific patterns to trade in varying time frames using technical analysis.

    If it is for school, may I get a copy of the finished study and code? I am looking for elementary material on the subject. Additionally, you can write a cool blog about that.
     
    tommcginnis likes this.
  3. rs2000

    rs2000

    I am more than happy to share the code but please help me out with this. I need little more detauls on what you mean.

    1. so I have daily returns of the last 10 years. I take log of these returns. I calculate the mean & standard deviation of these returns
    2. Then I generate random numbers from a normal distribution with same mean and standard deviation as above
    3. I try to compare the two distributions (1& 2) above to see if these fit well or are similar. This would tell me how well the lognormal distribution would have predicted the returns?

    4. the way we have been tau ght briefly about the fractals is through Hurst which is given below


    Please see the attached code too. I can implement this for the stock returns to show that the data has a trend and the OLS r-square is high. but how can I graphically and conceptually say that this is better or worst that lognormal distribution? does this make sense , shall I try somethign else?

    -----------------------------------------------------------------------------------------
    The Hurst Exponent is used for checking if the time series are predictable.

    Fractal Dimension = 2 – Hurst exponent

    Hurst Exponent takes values between 0 and 1.

    There are three possible situations:

    1. Fractal Dimension of 1.50 (Hurst = 0.50) – indicates a random walk process, there is no long memory and the time series is hard to predict its future evolution
    2. Fractal Dimension > 1.50 (Hurst<0.50) – anti-persistent behavior.
    3. Fractal Dimension <1.50 hurst="">0.50) – Trend behavior.
    We want to calculate fractal dimension and Hurst exponent for Microsoft stock return.


    ------------------------------------------------------------------------------------




    112.png 113.png
     
  4. xandman

    xandman

    1,2,3: Yes. I didn't think about random numbers. That is a good baseline. Very scientific/professional.

    4:

    The Hurst Exponent is a more statistically rigorous measure of what you have defined as fractal dimensions. I am not sure how Hurst Exponent works without being specific on what a tradeable pattern is but I think it is just a measure of autocorrelation.

    What I presented may not be appropriate for a statistics class and may be considered outright voodoo. For a Finance/CS course, it is an interesting concept.

    RE Fractals for Traders: There are common technical chart patterns or price action behavior that people view as predictive regardless of time frame. And we do see it in various time frames regardless of instrument. This is what makes us view markets as fractal in nature. I don't have the vocabulary for the type of autocorrelation that would make a pattern. It is not so linear and a lot more deliberate.

    If you are up to the task of building some pattern matching algorithms and using a few of the commonly recognized technical formations, then you may have something novel...for a traditional Finance or CS class.
     
    tommcginnis likes this.
  5. tommcginnis

    tommcginnis

    E(u) = 0??
    Remember that Mr.s Durbin and Watson are slapping your study around a bit.
    Get your "I.I.D." in order before you cure anything else.
     
  6. rs2000

    rs2000

    Its a python course and I am jst lookign for a basic implementation fractals. Please give me a simple idea of how this can be implemented and compared to lognormal distribution forecaste. I am stuck here and cant implement something.....many thanks
     
  7. Simples

    Simples

    This is a bit inaccurate wording actually. Using the Fractal Dimension Index (FDI), which is basically the same numbers just in a different range, you can measure how "trendy" the data is vs how "noisy" the data is. Ie. a sinus curve is 100% predictable, but could be measured as "noisy", since it's definately not "trendy", except if you limit the lookback period to be less than each wavelength / 2.

    Not sure if there are better words for this, but you could say FDI measures "trend or congestion persistence", ie. wether the time series tend to persist in trends or in congestion over the lookback period. However, the predictability of this is a big assumption.

    So FDI depends heavily on chosen lookback period and resolution (time frame) of the time series. It's another tool in the toolbox, but not directly profitable by itself. Ie. by the time you measure a trend beyond doubt, it may already be too late to jump in on it. A starting trend may require wide stops etc. However, it is very useful to know that market data usually range from congestion areas to trends and back again, and this is in a way predictable behaviour, albeit non-directional.

    Trade Station code:
    http://traders.com/documentation/FEEDbk_docs/2007/04/TradersTips/TradersTips.html#tradestation2

    Multicharts code:
    https://futures.io/download/multicharts/1102-download.html?view

    I've seen some other code floating on the net on this too, but can't seem to find it now. Usually helps to search for some trading concepts + "trading" + "code" or "formula".

    Hope this helps some.
     
    Last edited: Apr 8, 2017
  8. What python course is this...??