Results 1 to 9 of 9
  1. #1
    ppcash is offline Novice
    Windows 7 64bit Access 2016
    Join Date
    Jan 2022
    Posts
    3

    calculate an exponential moving average


    Greetings to all, I would like to know how I can calculate an exponential moving average, I am new to Access and I only know the basics. Thanks

  2. #2
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Office 365
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,979
    Welcome to the forum. Nothing like starting with something 'easy' to do!

    Suggest you give further explanation and examples in order to help members help you!
    Colin, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I don't know, I keep quiet!
    If I don't know that I don't know, I don't know whether to answer

  3. #3
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,803
    You're asking for a formula? Available via Google but you'd need to calculate or also store the SMA and retrieve it from a table. Problem with that is that the general consensus is to not store calculated values. Not my area of expertise, but if the SMA is fixed, might be OK to do that. If it will ever fluctuate, then should not store.

    You're asking how you'd do this in Access? Then we have to assume you have all the data to plug in the equation. I'd probably take the vba approach although someone might eventually figure out how to plug the formula into a query. Problem I'd have with that is that it would all have to be on one line - that would be complicated and difficult to troubleshoot IMO.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  4. #4
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,430
    Suggest you provide some example data so responders have something to work with.

    In principle it is not difficult to achieve - a simple moving average over say 10 days with no breaks would be something like

    Code:
    SELECT A.FK, A.Date, Sum(B.price)/10 AS SMA
    FROM myTable A inner join myTable B ON  A.FK=B.FK AND B.Date>=A.Date-10 and B.Date<=A.Date
    GROUP BY A.FK, A.Date
    ORDER BY A.FK, A.Date
    Obviously if this is share trading and there are no prices for the weekend so the calculation will be off - which is why we need to understand the context and the data

    To covert this to a EMA you need to adjust for the smoothing factor (2 here) for today and yesterday

    Code:
    SELECT A.FK, A.Date, (A.Price*2/11) + (sum(B.price)/10*(1-(2/11)) AS EMA
    FROM myTable A inner join myTable B ON  A.FK=B.FK AND B.Date>=A.Date-11 and B.Date<A.Date
    GROUP BY A.FK, A.Date
    ORDER BY A.FK, A.Date
    Not checked if the code is working as required, but just to give you an idea - join the same table to itself with non standard joins

  5. #5
    orange's Avatar
    orange is offline Moderator
    Windows 10 Office 365
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,726

  6. #6
    ppcash is offline Novice
    Windows 7 64bit Access 2016
    Join Date
    Jan 2022
    Posts
    3

    The example

    Quote Originally Posted by Ajax View Post
    Suggest you provide some example data so responders have something to work with.

    In principle it is not difficult to achieve - a simple moving average over say 10 days with no breaks would be something like

    Code:
    SELECT A.FK, A.Date, Sum(B.price)/10 AS SMA
    FROM myTable A inner join myTable B ON  A.FK=B.FK AND B.Date>=A.Date-10 and B.Date<=A.Date
    GROUP BY A.FK, A.Date
    ORDER BY A.FK, A.Date
    Obviously if this is share trading and there are no prices for the weekend so the calculation will be off - which is why we need to understand the context and the data

    To covert this to a EMA you need to adjust for the smoothing factor (2 here) for today and yesterday

    Code:
    SELECT A.FK, A.Date, (A.Price*2/11) + (sum(B.price)/10*(1-(2/11)) AS EMA
    FROM myTable A inner join myTable B ON  A.FK=B.FK AND B.Date>=A.Date-11 and B.Date<A.Date
    GROUP BY A.FK, A.Date
    ORDER BY A.FK, A.Date
    Not checked if the code is working as required, but just to give you an idea - join the same table to itself with non standard joins

    My formula:
    24/03/2019 Leverage 14/3 to 23/03
    25/03/2019 price (25/03)*(2/(1+ema 12))+(previous price (24/03)*(1-2/(1+ema 12)))
    Attached Files Attached Files

  7. #7
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,430
    don't understand your formula, why previous price? surely it is the average of the previous 12 prices

  8. #8
    ppcash is offline Novice
    Windows 7 64bit Access 2016
    Join Date
    Jan 2022
    Posts
    3
    Calculate ema 12 periods:
    First step: calculate the average from day 1 to 12
    Second step: closing price of day 13 x multiplier + EMA (previous day, in this case the average of step 1) x (1-multiplier)

  9. #9
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,430
    put some numbers to it from your example data, since as you have described it that is the example I provided

Please reply to this thread with any new information or opinions.

Similar Threads

  1. query to calculate a 20 moving average
    By Bob M in forum Queries
    Replies: 2
    Last Post: 02-13-2020, 06:20 AM
  2. Moving average calculation
    By Secue in forum Access
    Replies: 1
    Last Post: 08-13-2013, 01:28 PM
  3. Calculate the Average
    By Jerseynjphillypa in forum Queries
    Replies: 1
    Last Post: 06-18-2012, 03:26 PM
  4. Calculate average in a query
    By srbooth in forum Queries
    Replies: 1
    Last Post: 02-20-2010, 09:41 AM
  5. Select query for Exponential Moving Average.
    By krishna79 in forum Queries
    Replies: 0
    Last Post: 01-22-2009, 05:52 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums