-
Notifications
You must be signed in to change notification settings - Fork 34
/
dynamic.py
57 lines (42 loc) · 1.9 KB
/
dynamic.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
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
from stock_indicators.indicators.common.results import IndicatorResults, ResultBase
from stock_indicators.indicators.common.quote import Quote
def get_dynamic(quotes: Iterable[Quote], lookback_periods: int, k_factor: float = 0.6):
"""Get McGinley Dynamic calculated.
McGinley Dynamic is a more responsive variant of exponential moving average.
Parameters:
`quotes` : Iterable[Quote]
Historical price quotes.
`lookback_periods` : int
Number of periods in the lookback window.
`k_factor` : float, defaults 0.6
Range adjustment factor.
Returns:
`DynamicResults[DynamicResult]`
DynamicResults is list of DynamicResult with providing useful helper methods.
See more:
- [McGinley Dynamic Reference](https://python.stockindicators.dev/indicators/Dynamic/#content)
- [Helper Methods](https://python.stockindicators.dev/utilities/#content)
"""
results = CsIndicator.GetDynamic[Quote](CsList(Quote, quotes), lookback_periods, k_factor)
return DynamicResults(results, DynamicResult)
class DynamicResult(ResultBase):
"""
A wrapper class for a single unit of McGinley Dynamic results.
"""
@property
def dynamic(self) -> Optional[float]:
return self._csdata.Dynamic
@dynamic.setter
def dynamic(self, value):
self._csdata.Dynamic = value
_T = TypeVar("_T", bound=DynamicResult)
class DynamicResults(CondenseMixin, IndicatorResults[_T]):
"""
A wrapper class for the list of McGinley Dynamic results.
It is exactly same with built-in `list` except for that it provides
some useful helper methods written in CSharp implementation.
"""