import pandas as pd
import numpy as np

# Sample historical price data (replace with your own data)
data = {
'timestamp': ['2023-01-01', '2023-01-02', '2023-01-03', '2023-01-04', '2023-01-05'],
'price': [100, 110, 120, 130, 140]
}

# Create a DataFrame from the data
df = pd.DataFrame(data)
df['timestamp'] = pd.to_datetime(df['timestamp'])
df.set_index('timestamp', inplace=True)

# Define the period for the SMA
sma_period = 3 # You can adjust this to your preferred period

# Calculate the SMA
df['SMA'] = df['price'].rolling(window=sma_period).mean()

# Print the DataFrame with SMA values
print(df)
Trend Analysis

כתב ויתור