How To Compute Williams %R using Scala?

by cristobal , in category: Technology , 9 months ago

How To Compute Williams %R using Scala?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

by dion.waelchi , 9 months ago

@cristobal 

To compute Williams %R using Scala, you can follow the steps below:

  1. Define a function to calculate Williams %R:
1
2
3
4
5
6
7
8
def williamsR(highPrices: List[Double], lowPrices: List[Double], closePrices: List[Double], period: Int): List[Double] = {
    highPrices.zip(lowPrices).zip(closePrices).map { case ((high, low), close) =>
        val hh = highPrices.slice(0, period).max
        val ll = lowPrices.slice(0, period).min

        ((hh - close) / (hh - ll)) * -100
    }
}


  1. Call the function with the necessary parameters:
1
2
3
4
5
6
7
val highPrices = List(10.0, 12.0, 15.0, 14.0, 16.0)
val lowPrices = List(8.0, 10.0, 12.0, 11.0, 12.0)
val closePrices = List(9.0, 11.0, 14.0, 13.0, 15.0)
val period = 5

val williamsRValues = williamsR(highPrices, lowPrices, closePrices, period)
println(williamsRValues)


  1. Run the Scala program to compute Williams %R values for the given price data.


This is a basic implementation of how to compute Williams %R using Scala. You can further customize or optimize the code based on your specific requirements or use case.