mirror of
https://github.com/wassname/pandas-ta.git
synced 2026-08-11 11:22:48 +08:00
DEP removed mp property ENH new last_run, time_range and to_utc properties
This commit is contained in:
@@ -424,6 +424,13 @@ df.ta.cores
|
||||
df.ta.datetime_ordered
|
||||
```
|
||||
|
||||
## **last_run**
|
||||
|
||||
```python
|
||||
# Returns the time Pandas TA was last run as a string.
|
||||
df.ta.last_run
|
||||
```
|
||||
|
||||
## **reverse**
|
||||
|
||||
```python
|
||||
@@ -448,6 +455,25 @@ bothhl2 = df.ta.hl2(prefix="pre", suffix="post")
|
||||
print(bothhl2.name) # "pre_HL2_post"
|
||||
```
|
||||
|
||||
## **time_range**
|
||||
|
||||
```python
|
||||
# Returns the time range of the DataFrame as a float.
|
||||
# By default, it returns the time in "years"
|
||||
df.ta.time_range
|
||||
|
||||
# Available time_ranges include: "years", "months", "weeks", "days", "hours", "minutes". "seconds"
|
||||
df.ta.time_range = "days"
|
||||
df.ta.time_range # prints DataFrame time in "days" as float
|
||||
```
|
||||
|
||||
## **to_utc**
|
||||
|
||||
```python
|
||||
# Sets the DataFrame index to UTC format.
|
||||
df.ta.to_utc
|
||||
```
|
||||
|
||||
<br/><br/>
|
||||
|
||||
# **Indicators** (_by Category_)
|
||||
@@ -687,7 +713,7 @@ result = ta.cagr(df.close)
|
||||
* **Moving Average Choices**: dema, ema, fwma, hma, linreg, midpoint, pwma, rma, sinwma, sma, swma, t3, tema, trima, vidya, wma, zlma.
|
||||
* An _experimental_ and independent __Watchlist__ Class located in the [Examples](https://github.com/twopirllc/pandas-ta/tree/master/examples/watchlist.py) Directory that can be used in conjunction with the new __Strategy__ Class.
|
||||
* _Linear Regression_ (**linear_regression**) is a new utility method for Simple Linear Regression using _Numpy_ or _Scikit Learn_'s implementation.
|
||||
* Added utility/convience function, ```to_utc```, to convert the DataFrame index to UTC. See: ```help(ta.to_utc)```
|
||||
* Added utility/convience function, ```to_utc```, to convert the DataFrame index to UTC. See: ```help(ta.to_utc)``` **Now** as a Pandas TA DataFrame Property to easily convert the DataFrame index to UTC.
|
||||
|
||||
<br />
|
||||
|
||||
|
||||
+21
-23
@@ -50,8 +50,8 @@ class Strategy:
|
||||
ta: List = field(default_factory=list) # Required.
|
||||
# Helpful. More descriptive version or notes or w/e.
|
||||
description: str = "TA Description"
|
||||
# Optional. May change type later to datetime
|
||||
created: str = datetime.now().strftime("%m/%d/%Y, %H:%M:%S")
|
||||
# Optional. Gets Exchange Time and Local Time execution time
|
||||
created: str = get_time(to_string=True)
|
||||
|
||||
def __post_init__(self):
|
||||
has_name = True
|
||||
@@ -234,8 +234,8 @@ class AnalysisIndicators(BasePandasObject):
|
||||
|
||||
_adjusted = None
|
||||
_cores = cpu_count()
|
||||
_mp = False
|
||||
_time_range = "years"
|
||||
_last_run = get_time(to_string=True)
|
||||
|
||||
# DataFrame Behavioral Methods
|
||||
def __call__(
|
||||
@@ -253,6 +253,7 @@ class AnalysisIndicators(BasePandasObject):
|
||||
|
||||
# Run the indicator
|
||||
result = fn(**kwargs) # = getattr(self, kind)(**kwargs)
|
||||
self._last_run = get_time(to_string=True) # Save when it completed it's run
|
||||
|
||||
if timed:
|
||||
result.timed = final_time(stime)
|
||||
@@ -294,17 +295,9 @@ class AnalysisIndicators(BasePandasObject):
|
||||
self._cores = cpus
|
||||
|
||||
@property
|
||||
def mp(self) -> bool:
|
||||
"""property: df.ta.mp"""
|
||||
return self._mp
|
||||
|
||||
@mp.setter
|
||||
def mp(self, value: bool) -> None:
|
||||
"""property: df.ta.mp = False (Default)"""
|
||||
if value is not None and isinstance(value, bool):
|
||||
self._mp = value
|
||||
else:
|
||||
self._mp = False
|
||||
def last_run(self) -> str:
|
||||
"""Returns the time when the DataFrame was last run."""
|
||||
return self._last_run
|
||||
|
||||
# Public Get DataFrame Properties
|
||||
@property
|
||||
@@ -326,18 +319,23 @@ class AnalysisIndicators(BasePandasObject):
|
||||
return self._df.iloc[::-1]
|
||||
|
||||
@property
|
||||
def time_range(self) -> str:
|
||||
""""""
|
||||
def time_range(self) -> float:
|
||||
"""Returns the time ranges of the DataFrame as a float. Default is in "years". help(ta.toal_time)"""
|
||||
return total_time(self._df, self._time_range)
|
||||
|
||||
@time_range.setter
|
||||
def time_range(self, value: str) -> None:
|
||||
"""property: df.ta.mp = False (Default)"""
|
||||
"""property: df.ta.time_range = "years" (Default)"""
|
||||
if value is not None and isinstance(value, str):
|
||||
self._time_range = value
|
||||
else:
|
||||
self._time_range = "years"
|
||||
|
||||
@property
|
||||
def to_utc(self) -> None:
|
||||
"""Sets the DataFrame index to UTC format"""
|
||||
self._df = to_utc(self._df)
|
||||
|
||||
@property
|
||||
def version(self) -> str:
|
||||
"""Returns the version."""
|
||||
@@ -540,9 +538,10 @@ class AnalysisIndicators(BasePandasObject):
|
||||
"categories",
|
||||
"cores",
|
||||
"datetime_ordered",
|
||||
"mp",
|
||||
"last_run",
|
||||
"reverse",
|
||||
"time_range",
|
||||
"to_utc",
|
||||
"version",
|
||||
]
|
||||
|
||||
@@ -671,7 +670,7 @@ class AnalysisIndicators(BasePandasObject):
|
||||
# Some magic to optimize chunksize for speed based on total ta indicators
|
||||
_chunksize = mp_chunksize - 1 if mp_chunksize > _total_ta else int(npLog10(_total_ta)) + 1
|
||||
if verbose:
|
||||
print(f"[i] Multiprocessing: {_chunksize} chunks over {cpu_count()} cores for {_total_ta} indicators.")
|
||||
print(f"[i] Multiprocessing {_total_ta} indicators with {_chunksize} chunks over {self.cores}/{cpu_count()} cpus.")
|
||||
|
||||
results = None
|
||||
if mode["custom"]:
|
||||
@@ -697,6 +696,7 @@ class AnalysisIndicators(BasePandasObject):
|
||||
|
||||
pool.close()
|
||||
pool.join()
|
||||
self._last_run = get_time(to_string=True)
|
||||
|
||||
else:
|
||||
# Without multiprocessing:
|
||||
@@ -718,14 +718,12 @@ class AnalysisIndicators(BasePandasObject):
|
||||
# DataFrame
|
||||
[self._post_process(r, **kwargs) for r in results]
|
||||
|
||||
if timed:
|
||||
ftime = final_time(stime)
|
||||
|
||||
if verbose:
|
||||
print(f"[i] Total indicators: {len(ta)}")
|
||||
print(f"[i] Columns added: {len(self._df.columns) - initial_column_count}")
|
||||
print(f"[i] Last Run: {self._last_run}")
|
||||
if timed:
|
||||
print(f"[i] Runtime: {ftime}")
|
||||
print(f"[i] Runtime: {final_time(stime)}")
|
||||
|
||||
# Public DataFrame Methods: Indicators and Utilities
|
||||
# Candles
|
||||
|
||||
@@ -19,10 +19,6 @@ def df_dates(df: DataFrame, dates: Tuple[str, list] = None) -> DataFrame:
|
||||
|
||||
def df_month_to_date(df: DataFrame) -> DataFrame:
|
||||
"""Yields the Month-to-Date (MTD) DataFrame"""
|
||||
# if df.empty: print("[X] Month-to-Date not in range"); return
|
||||
# print(df.shape)
|
||||
# print(type(df))
|
||||
# print(df)
|
||||
return df[df.index >= Timestamp.now().strftime("%Y-%m-01")]
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user