Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4025568
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T10:51:47+00:00 2026-05-20T10:51:47+00:00

I am learning to use R. I have an interest in pulling stock data

  • 0

I am learning to use R. I have an interest in pulling stock data and calculating various technical indicators on the stock data. My test benchmark is Google Finance. That is, I check my results with GF’s results.

While trying to implement some sort of MACD analysis, I have noticed a couple of things. These are probably my misinterpretation of the documentation. I have tried many variations and I cannot get agreement with Google Finance’s numbers in some cases.

library(quantmod) gives me MACD(), which returns columns macd and signal.

library(fTrading) gives me cdsTA() and cdoTA(), which return cdsTA and cdoTA respectively.

My test stock is IBM, and hopefully this link will pull up a chart with prices, volume, slow stochastics and MACD with histogram.

http://www.google.com//finance?chdnp=1&chdd=1&chds=1&chdv=1&chvs=Linear&chdeh=0&chfdeh=0&chdet=1298224745682&chddm=46920&chddi=86400&chls=CandleStick&q=NYSE:IBM&ntsp=0

Loading up IBM’s price data into R and generating the values of the 3 functions above for the values 8, 17, 9 and for MACD() I set percent=FALSE gives me the following output.

MACD(close, 8, 17, 9, maType="EMA", percent=FALSE)
cdsTA(close, lag1 = 8, lag2 = 17, lag3 = 9)
cdoTA(close, lag1 = 8, lag2 = 17, lag3 = 9)

      date     close     macd   signal      cdsTA      cdoTA
2011-02-07    164.17 3.187365 3.208984   3.208984 -0.7673435
2011-02-08    166.05 3.246812 3.216549   3.216549 -0.7996041
2011-02-09    164.65 3.052187 3.183677   3.183677 -1.0496306
2011-02-10    164.09 2.780047 3.102951   3.102951 -1.3332292
2011-02-11    163.85 2.496591 2.981679   2.981679 -1.5867962
2011-02-14    163.22 2.168977 2.819138   2.819138 -1.8408138
2011-02-15    162.84 1.846701 2.624651   2.624651 -2.0507546
2011-02-16    163.40 1.640518 2.427824   2.427824 -2.1262626
2011-02-17    164.24 1.550798 2.252419   2.252419 -2.0854783
2011-02-18    164.84 1.517145 2.105364   2.105364 -1.9968608

If you refer to the google finance chart above, the columns cdsTA and macd are identical and agree closely with Google’s EMA figures. MACD()‘s value for macd al also pretty close to GF’s. And so I get

macd – signal = divergence.

However, cdoTA is way off. What am I doing wrong?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T10:51:48+00:00Added an answer on May 20, 2026 at 10:51 am

    You’re not doing anything wrong. The cdoTA code doesn’t pass lag1 or lag2 to cdsTA, so it just uses the default values of 12 and 26.

    > cdoTA
    function (x, lag1 = 12, lag2 = 26, lag3 = 9) 
    {
        cdo = macdTA(x, lag1 = lag1, lag2 = lag2) -
               cdsTA(x, lag3 = lag3)                 # no lag1 or lag2, so...
        if (is.timeSeries(x)) 
            colnames(cdo) <- "CDO"
        cdo
    }
    > args(cdsTA)                                    # default arg values are used
    function (x, lag1 = 12, lag2 = 26, lag3 = 9) 
    NULL
    

    You can define your own function CDOTA:

    CDOTA <- function (x, lag1 = 12, lag2 = 26, lag3 = 9) {
        cdo = macdTA(x, lag1 = lag1, lag2 = lag2) -
               cdsTA(x, lag1 = lag1, lag2 = lag2, lag3 = lag3)
        if (is.timeSeries(x)) 
            colnames(cdo) <- "CDO"
        cdo
    }
    

    Or just do the subtraction yourself with the results from TTR::MACD.

    require(quantmod)
    getSymbols("IBM", source="google")
    ibm <- merge(Cl(IBM), MACD(Cl(IBM), 8, 17, 9, "EMA", FALSE))
    ibm$macdOsc <- ibm$macd - ibm$signal
    tail(ibm)
    #            IBM.Close      macd   signal    macdOsc
    # 2011-02-15    162.84 1.8361263 2.643950 -0.8078238
    # 2011-02-16    163.40 1.6248017 2.440120 -0.8153187
    # 2011-02-17    164.24 1.5319154 2.258479 -0.7265640
    # 2011-02-18    164.84 1.4965394 2.106091 -0.6095520
    # 2011-02-22    161.95 1.1140192 1.907677 -0.7936578
    # 2011-02-23    160.18 0.6253874 1.651219 -1.0258316
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been learning to use Emacs for a little while now. So far
I am learning how to use NUnit. I have my main project in it's
I am interested in using/learning RoR in a project where I have to use
I am still learning to use MVVM and Prism and have some general questions:
I am learning to use LabVIEW as part of my honours project, and was
I am learning to use polymorphism in C#, but cannot figure out this one.
I am learning to use the Dvorak keyboad layout, but I am not good
I'm learning how to use Greasemonkey, and was wondering what the @namespace metadata id
Where is a good place to get started learning how to use jQuery? It
So in my simple learning website, I use the built in ASP.NET authentication system.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.