/
vwma.py
55 lines (41 loc) · 1.82 KB
/
vwma.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
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_vwma(quotes: Iterable[Quote], lookback_periods: int):
"""Get VWMA calculated.
Volume Weighted Moving Average (VWMA) is the volume adjusted average price
over a lookback window.
Parameters:
`quotes` : Iterable[Quote]
Historical price quotes.
`lookback_periods` : int
Number of periods in the lookback window.
Returns:
`VWMAResults[VWMAResult]`
VWMAResults is list of VWMAResult with providing useful helper methods.
See more:
- [VWMA Reference](https://python.stockindicators.dev/indicators/Vwma/#content)
- [Helper Methods](https://python.stockindicators.dev/utilities/#content)
"""
results = CsIndicator.GetVwma[Quote](CsList(Quote, quotes), lookback_periods)
return VWMAResults(results, VWMAResult)
class VWMAResult(ResultBase):
"""
A wrapper class for a single unit of Volume Weighted Moving Average (VWMA) results.
"""
@property
def vwma(self) -> Optional[float]:
return self._csdata.Vwma
@vwma.setter
def vwma(self, value):
self._csdata.Vwma = value
_T = TypeVar("_T", bound=VWMAResult)
class VWMAResults(CondenseMixin, RemoveWarmupMixin, IndicatorResults[_T]):
"""
A wrapper class for the list of Volume Weighted Moving Average (VWMA) results.
It is exactly same with built-in `list` except for that it provides
some useful helper methods written in CSharp implementation.
"""