ewma python
时间: 2023-10-18 10:30:43 浏览: 216
EWMA stands for Exponentially Weighted Moving Average. It is a statistical calculation used to smooth out a time series by giving more weight to recent data points while decreasing the weight of older data points. In Python, you can calculate EWMA using the pandas library.
Here's an example of how to calculate EWMA in Python:
```python
import pandas as pd
# Create a sample time series data
data = [10, 12, 15, 20, 18, 22, 25]
# Convert the data into a pandas Series
ts = pd.Series(data)
# Calculate EWMA with a span of 3
ewma = ts.ewm(span=3).mean()
# Print the EWMA values
print(ewma)
```
In this example, we create a sample time series data and convert it into a pandas Series. Then, we use the `ewm` function with the `span` parameter set to 3 to calculate the EWMA. Finally, we print the EWMA values.
Note that you can adjust the `span` parameter to control the weight given to recent data points. Smaller values of `span` give more weight to recent data, while larger values give more weight to older data.
阅读全文