@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:
spark.apache.org/docs/latest/...
Github: github.com/backstreetbrogramm...
- Apache Spark for Java Developers Playlist: • Apache Spark for Java ...
- Upgrade to Java 21 Playlist: • Upgrade to Java 21
- Top Java Coding Interview Problems Playlist: • Top Java Coding Interv...
- Java Serialization Playlist: • Java Serialization
- Dynamic Programming Playlist: • Dynamic Programming
#java #javadevelopers #javaprogramming #apachespark #spark
Негізгі бет Ғылым және технология 84 - Spark RDD - Custom StockPositionAccumulator code demo
Пікірлер: 10