84 - Spark RDD - Custom StockPositionAccumulator code demo

Опубликовано: 29 Сентябрь 2024
на канале: Rishi Srivastava
272
7

‪@backstreetbrogrammer‬

--------------------------------------------------------------------------------
Chapter 16 - Spark RDD - Custom StockPositionAccumulator code demo
--------------------------------------------------------------------------------

In this code demo, we will build our custom stock position and profit accumulator based on realtime intraday trades.

For buy trades, position += traded quantity, profit -= notional

For sell trades, position -= traded quantity, profit += notional

(notional = traded quantity * executed price)


We can create our own accumulators by subclassing AccumulatorV2.

The AccumulatorV2 abstract class has several methods which one has to override:

- reset() for resetting the accumulator to zero
- add() for adding another value into the accumulator
- merge() for merging another same-type accumulator into this one, etc.

Other methods that must be overridden are contained in the API documentation:

https://spark.apache.org/docs/latest/...


Github: https://github.com/backstreetbrogramm...

- Apache Spark for Java Developers Playlist:    • Apache Spark for Java Developers  
- Upgrade to Java 21 Playlist:    • Upgrade to Java 21  
- Top Java Coding Interview Problems Playlist:    • Top Java Coding Interview Problems  
- Java Serialization Playlist:    • Java Serialization  
- Dynamic Programming Playlist:    • Dynamic Programming  

#java #javadevelopers #javaprogramming #apachespark #spark