Code Monkey home page Code Monkey logo

Comments (7)

joshuaulrich avatar joshuaulrich commented on August 23, 2024

Closing as duplicate of #1. If you truly believe the calculation in the 3 references provided in ?DPO are incorrect, please provide some evidence of the correct calculation.

from ttr.

FrancisHChen avatar FrancisHChen commented on August 23, 2024

I think the way TTR does is wrong. You didn't look at the details I provided.

The reference shows: DPO = Close - (Moving Average ((n/2)+1) days ago)

But what TTR does is using Moving Average ((n/2)+1) days in future!!!

from ttr.

joshuaulrich avatar joshuaulrich commented on August 23, 2024

I did look at the details you provided, and they're not the correct way to calculate the DPO indicator. Since you agree that all the references are correct, I'll quote some sections of the StockCharts reference.

Here they talk about the "displaced" moving average, which "centers" the moving average. Centered moving averages look into the future, by definition.

Displaced Moving Average
The moving average displacement actually centers the moving average. Consider a 20-day simple moving average offset 11 days to the left. There are 10 days in front of the moving average, 1 day at the moving average and 9 days behind the moving average. In reality, this moving average is in the middle of its look-back period. Roughly half the prices used in the calculation are to the right and half are to the left.

They also explicitly say it is not designed for momentum signals because the displaced (centered) moving average is set in the past.

Using DPO
Even though this indicator looks like a classic oscillator, it is not designed for momentum signals. The displaced moving average is set in the past and this is why the DPO is shown in the past.

Then they explicitly say that what you suggest defeats the purpose of the DPO indicator.

To Shift or not to Shift
It is possible to displace the Detrended Price Oscillator (DPO) with a horizontal shift to the right. If DPO is set at 20, then an 11 period shift is needed to place it in line with the most recent price. This displacement number comes from the formula at the top (20/2 + 1) = 11. While shifting may seem like a good idea, it really defeats the purpose of this indicator, which is to identify cycles.

from ttr.

FrancisHChen avatar FrancisHChen commented on August 23, 2024

I see. Thanks! But now I think the three refereces are all different with each other. Totally confused.

  1. https://www.metastock.com/customer/resources/taaz/?c=3&p=48
    Formula: DPO = Close - (Moving Average ((n/2)+1) days ago)

  2. http://www.fmlabs.com/reference/default.htm?url=DPO.htm
    Formula: DPO[i] = Close[i-1] - Mean(Close[i-n:i])

  3. http://stockcharts.com/school/doku.php?id=chart_school:technical_indicators:detrended_price_osci
    displace MA n/2+1 days in the middle of close

I think the third way is only useful for visualization, otherwise it does not make sense technically.

from ttr.

joshuaulrich avatar joshuaulrich commented on August 23, 2024

Yes, the references are confusing. I should probably remove the MetaStock and FM Labs references, since they aren't internally consistent. The chart on the MetaStock page suggests a centered MA is used, but that is not clear from the text. The FM Labs text says, "Note that the calculation shifts the results (shift = term / 2 + 1) periods, so the last shift periods will be zero." The only way the last "shift" periods are zero are if you use a centered MA. But there's nothing in the formula that suggests the MA is centered.

from ttr.

FrancisHChen avatar FrancisHChen commented on August 23, 2024

Thanks for your reply.

I searched google scholar, and found out most papers (even though very few) used the first way (curent price - moving average n/2+1 days ago), which is based on this paper:

Achelis, S. B. (2001). Technical Analysis from A to Z. New York: McGraw Hill.
http://freetradingdownloads.com/Technical%20Analysis%20from%20A%20to%20Z.pdf

cited 589 times.

The displacement way is very likely from this book:

Di Lorenzo, Renato. Basic Technical Analysis of Financial Markets: A Modern Approach. Springer Science & Business Media, 2013.

I looked at the origin. It says:

**15.7 Detrended Price Oscillator**
The detrended price oscillator is basically a SMA, i.e., a simple moving average,
materially shifted back along the time axis to eliminate the delay, just like a centered
average already seen in the first part of this treatise.

Therefore one needs to decide in advance how many bars (n) the cycles of the
security that we are considering can last, then he may materially take back along
the time axis the SMA of n/2+1 bars.

Obviously enough, we will not have any indication in the last part of the graph,
as it is evident from Fig. 15.24.

Some peaks have been highlighted, i.e., those perfectly matching both in the
oscillator chart and in the price chart, but… the last part, as said, does not report
any indication at all, and this makes such an oscillator not suitable for the construction
of a trading system whatsoever.

This explaination is almost the same as: http://stockcharts.com/school/doku.php?id=chart_school:technical_indicators:detrended_price_osci

Let's review this from StockCharts:

While shifting may seem like a good idea, it really defeats the purpose of this indicator, which is to identify cycles.

This DPO can be calculated by any n period and shift to past. If I can look into future, any cycle can be identified. Look at the e.g. figure for Nasdaq 100 ETF (QQQQ). Cycles in the past are perfect, but it ends with displaced SMA. Then there is no indication that whether recent prices are in a cycle or not. So it is not an technical indicator but more like a visualization tool.

Overall, I still doubt the effectiveness of this method.

from ttr.

joshuaulrich avatar joshuaulrich commented on August 23, 2024

Re-opening so I remember to update the documentation.

from ttr.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.