-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refacto: Base streaming module, use it for fs2
- Loading branch information
Clark Andrianasolo
committed
Jun 21, 2023
1 parent
4173d09
commit 617e15b
Showing
14 changed files
with
110 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 2 additions & 1 deletion
3
...scala/io/clarktsiory/ta/fs2/package.scala → .../clarktsiory/ta/streams/fs2/package.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 0 additions & 39 deletions
39
lib/talib-fs2/shared/src/main/scala/io/clarktsiory/ta/fs2/BufferedIndicator.scala
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...io/clarktsiory/ta/fs2/OHLCSignalOps.scala → ...tsiory/ta/streams/fs2/OHLCSignalOps.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package io.clarktsiory.ta.fs2 | ||
package io.clarktsiory.ta.streams.fs2 | ||
|
||
import fs2.Stream | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 69 additions & 0 deletions
69
lib/talib-streams/shared/src/main/scala/io/clarktsiory/ta/streams/BufferedIndicator.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package io.clarktsiory.ta.streams | ||
import scala.collection.mutable.ListBuffer | ||
|
||
import io.clarktsiory.signals.ScalarSignal | ||
import io.clarktsiory.ta.Indicator | ||
import io.clarktsiory.ta.Indicator.* | ||
|
||
/** | ||
* Type-class that encodes buffering needs according to the indicator computation properties. | ||
* Most indicators will need to buffer past values in order to output more accurate results on current values. | ||
* @tparam A the indicator type | ||
*/ | ||
trait BufferedIndicator[A <: Indicator]: | ||
/** | ||
* Defines the max number of periods that need to be buffered. | ||
* If the value is static, it may influence the precision of computations. | ||
* If the value is 0 or purely depends on the indicator parameters, it means that the indicator computation should | ||
* always be deterministic and computation is always fundamentally accurate (e.g. the mean of _n_ values). | ||
*/ | ||
def bufferSize(indicator: A): Int | ||
|
||
/** | ||
* Defines the min number of periods that yield a computation result (e.g. _n_ for the indicator that is mean of the | ||
* _n_ latest values). | ||
*/ | ||
def minComputationSize(indicator: A): Int | ||
|
||
/** | ||
* The type of the buffer used to store past values. It allows buffer manipulation with a pre-defined number of | ||
* operations through the extension methods. | ||
* It should always be an opaque type, to avoid accidental buffer manipulation apart from the extension methods. | ||
*/ | ||
type SignalBuffer | ||
|
||
/** | ||
* @return An empty buffer than can be further manipulated with the extension methods. | ||
*/ | ||
def emptyBuffer(): SignalBuffer | ||
|
||
extension (buffer: SignalBuffer) | ||
def added(value: ScalarSignal): SignalBuffer | ||
def dropped(n: Int): SignalBuffer | ||
def takeRight(n: Int): SignalBuffer | ||
def size: Int | ||
def toArray: Array[ScalarSignal] | ||
end extension | ||
end BufferedIndicator | ||
|
||
/** | ||
* Partial implementation of the BufferedIndicator type-class for MACD, using known properties of the indicator, and | ||
* a heuristic for the buffer size. | ||
*/ | ||
abstract private[streams] class MACDBufferedIndicator extends BufferedIndicator[MACD]: | ||
override def bufferSize(macd: MACD): Int = 1_000 | ||
override def minComputationSize(macd: MACD): Int = macd.slow + macd.signalPeriod - 1 | ||
end MACDBufferedIndicator | ||
|
||
/** | ||
* Partial implementation of the BufferedIndicator type-class for RSI, using known properties of the indicator, and | ||
* a heuristic for the buffer size. | ||
*/ | ||
abstract private[streams] class RSIBufferedIndicator extends BufferedIndicator[RSI]: | ||
override def bufferSize(rsi: Indicator.RSI): Int = 500 | ||
override def minComputationSize(rsi: RSI): Int = rsi.timeperiod + 1 | ||
end RSIBufferedIndicator | ||
|
||
object BufferedIndicator: | ||
def apply[A <: Indicator](using BufferedIndicator[A]): BufferedIndicator[A] = summon | ||
end BufferedIndicator |
2 changes: 1 addition & 1 deletion
2
...ory/ta/fs2/MutableBufferedIndicator.scala → ...ta/streams/MutableBufferedIndicator.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package io.clarktsiory.ta.fs2 | ||
package io.clarktsiory.ta.streams | ||
|
||
import scala.collection.mutable.ListBuffer | ||
|
||
|