/
fcb.py
67 lines (51 loc) · 2.23 KB
/
fcb.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
from decimal import Decimal
from typing import Iterable, Optional, TypeVar
from stock_indicators._cslib import CsIndicator
from stock_indicators._cstypes import List as CsList
from stock_indicators._cstypes import Decimal as CsDecimal
from stock_indicators._cstypes import to_pydecimal
from stock_indicators.indicators.common.helpers import RemoveWarmupMixin
from stock_indicators.indicators.common.results import IndicatorResults, ResultBase
from stock_indicators.indicators.common.quote import Quote
def get_fcb(quotes: Iterable[Quote], window_span: int = 2):
"""Get FCB calculated.
Fractal Chaos Bands (FCB) outline high and low price channels
to depict broad less-chaotic price movements.
FCB is a channelized depiction of Williams Fractals.
Parameters:
`quotes` : Iterable[Quote]
Historical price quotes.
`window_span` : int, defaults 2
Number of span periods in the evaluation window.
Returns:
`FCBResults[FCBResult]`
FCBResults is list of FCBResult with providing useful helper methods.
See more:
- [FCB Reference](https://python.stockindicators.dev/indicators/Fcb/#content)
- [Helper Methods](https://python.stockindicators.dev/utilities/#content)
"""
results = CsIndicator.GetFcb[Quote](CsList(Quote, quotes), window_span)
return FCBResults(results, FCBResult)
class FCBResult(ResultBase):
"""
A wrapper class for a single unit of Fractal Chaos Bands (FCB) results.
"""
@property
def upper_band(self) -> Optional[Decimal]:
return to_pydecimal(self._csdata.UpperBand)
@upper_band.setter
def upper_band(self, value):
self._csdata.UpperBand = CsDecimal(value)
@property
def lower_band(self) -> Optional[Decimal]:
return to_pydecimal(self._csdata.LowerBand)
@lower_band.setter
def lower_band(self, value):
self._csdata.LowerBand = CsDecimal(value)
_T = TypeVar("_T", bound=FCBResult)
class FCBResults(RemoveWarmupMixin, IndicatorResults[_T]):
"""
A wrapper class for the list of Fractal Chaos Bands (FCB) results.
It is exactly same with built-in `list` except for that it provides
some useful helper methods written in CSharp implementation.
"""