Forum Discussion

chrisB13's avatar
chrisB13
Frequent Visitor
7 years ago
Solved

Historical Stock Data Concept

Hi Everyone,   I am currently working on building out a Historical Stock Market analysis.  Currently I am pulling in a parametered function that brings in the entire history of each of the symbo...
  • Mariusz's avatar
    7 years ago

    Hi chrisB13,

    Please see the below.

    4 Day Moving Avg =
    VAR __maxDateInCurrentSelection =
        MAX ( TickerList[Date] )
    VAR __top4DaysWithValues =
        TOPN (
            4,
            FILTER ( ALL ( TickerList ), TickerList[Date] <= __maxDateInCurrentSelection  ),
            TickerList[Date], DESC
        )
    RETURN
        AVERAGEX ( __top4DaysWithValues , TickerList[Close_Price] )

     

    Hope this helps.
    Mariusz




  • Mariusz's avatar
    Mariusz
    7 years ago

    Hi chrisB13 ,

    Try the below and let me know if it performs any better.

    4 Day Simple Moving Avg = 
    VAR d = MAX(TickerList[Date])
    VAR t = TOPN(
        4, 
        FILTER(
            ALL(TickerList[Date]),
            TickerList[Date] <= d), 
        TickerList[Date], 
        DESC
    )
    RETURN 
    AVERAGEX(t, CALCULATE(SUM(TickerList[Close_Price])))

    Hope this helps
    Mariusz