/
awesome.py
66 lines (49 loc) · 2.25 KB
/
awesome.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
from typing import Iterable, Optional, TypeVar
from stock_indicators._cslib import CsIndicator
from stock_indicators._cstypes import List as CsList
from stock_indicators.indicators.common.helpers import CondenseMixin, RemoveWarmupMixin
from stock_indicators.indicators.common.results import IndicatorResults, ResultBase
from stock_indicators.indicators.common.quote import Quote
def get_awesome(quotes: Iterable[Quote], fast_periods: int = 5, slow_periods: int = 34):
"""Get Awesome Oscillator calculated.
Awesome Oscillator (aka Super AO) is a measure of the gap
between a fast and slow period modified moving average.
Parameters:
`quotes` : Iterable[Quote]
Historical price quotes.
`fast_periods` : int, defaults 5
Number of periods in the Fast moving average.
`slow_periods` : int, defaults 34
Number of periods in the Slow moving average.
Returns:
`AwesomeResults[AwesomeResult]`
AwesomeResults is list of AwesomeResult with providing useful helper methods.
See more:
- [Awesome Oscillator Reference](https://python.stockindicators.dev/indicators/Awesome/#content)
- [Helper Methods](https://python.stockindicators.dev/utilities/#content)
"""
awesome_results = CsIndicator.GetAwesome[Quote](CsList(Quote, quotes), fast_periods, slow_periods)
return AwesomeResults(awesome_results, AwesomeResult)
class AwesomeResult(ResultBase):
"""
A wrapper class for a single unit of Awesome Oscillator results.
"""
@property
def oscillator(self) -> Optional[float]:
return self._csdata.Oscillator
@oscillator.setter
def oscillator(self, value):
self._csdata.Oscillator = value
@property
def normalized(self) -> Optional[float]:
return self._csdata.Normalized
@normalized.setter
def normalized(self, value):
self._csdata.Normalized = value
_T = TypeVar("_T", bound=AwesomeResult)
class AwesomeResults(CondenseMixin, RemoveWarmupMixin, IndicatorResults[_T]):
"""
A wrapper class for the list of Awesome Oscillator (aka Super AO) results.
It is exactly same with built-in `list` except for that it provides
some useful helper methods written in C# implementation.
"""