huseinzol05 / Stock-Prediction-Models

Gathers machine learning and deep learning models for Stock forecasting including trading bots and simulations
Apache License 2.0
7.96k stars 2.81k forks source link

ABCD Strategy seems to use future knowledge #61

Open nlothian opened 4 years ago

nlothian commented 4 years ago
    ma = pd.Series(trend).rolling(ma).mean().values
    x = []
    for a in range(ma.shape[0]):
        for b in range(a, ma.shape[0], skip_loop):
            for c in range(b, ma.shape[0], skip_loop):
                for d in range(c, ma.shape[0], skip_loop):
                    if ma[b] > ma[a] and \
                    (ma[c] < ma[b] and ma[c] > ma[a]) \
                    and ma[d] > ma[b]:
                        x.append([a,b,c,d])

This is pretty dense code so I'm probably wrong here, but it looks to me like this takes values derived from the (backwards) moving average (which fine), but it loops forward over the time period (which isn't).

The easiest way to see this is to pass in different length datasets. The trading strategies should be identical up to the end of the shortest strategy. However, they diverge significantly before this.

In this example, I pass in 60 days vs 80 days of data, and the trading strategy diverges after 8 days

image

image

ansev-0 commented 4 years ago

Looking over the code the abcd strategy seems to look for trends in forms of s the problem is that the decision on a point i should be based only on the result when d = i (in the code). This is simply not true. This code precisely eliminates the biggest failures that this method would have, that is, forecasting a sale and having had to buy or vice versa