import pandas as pd
import numpy as np
import matplotlib.pyplot as plt

# Örnek veri seti oluşturma (Bu kısmı kendi veri setinize göre düzenleyebilirsiniz)
dates = pd.date_range('2023-01-01', periods=100)
prices = np.random.rand(100) * 100
data = pd.DataFrame({'Date': dates, 'Close': prices})
data.set_index('Date', inplace=True)

# Hareketli ortalamaları hesaplama
short_window = 20
long_window = 50

data['SMA20'] = data['Close'].rolling(window=short_window, min_periods=1).mean()
data['SMA50'] = data['Close'].rolling(window=long_window, min_periods=1).mean()

# Al-sat sinyalleri oluşturma
data['Signal'] = 0.0
data['Signal'][short_window:] = np.where(data['SMA20'][short_window:] > data['SMA50'][short_window:], 1.0, 0.0)
data['Position'] = data['Signal'].diff()

# Al-sat noktalarını belirleme
buy_signals = data[data['Position'] == 1]
sell_signals = data[data['Position'] == -1]

# Veriyi görselleştirme
plt.figure(figsize=(14, 7))
plt.plot(data['Close'], label='Fiyat', alpha=0.5)
plt.plot(data['SMA20'], label='20 Günlük SMA', alpha=0.75)
plt.plot(data['SMA50'], label='50 Günlük SMA', alpha=0.75)
plt.scatter(buy_signals.index, buy_signals['Close'], label='Al', marker='^', color='g', alpha=1)
plt.scatter(sell_signals.index, sell_signals['Close'], label='Sat', marker='v', color='r', alpha=1)
plt.title('Basit Hareketli Ortalama Kesişim Stratejisi')
plt.xlabel('Tarih')
plt.ylabel('Fiyat')
plt.legend()
plt.show()
Parallel Channel

คำจำกัดสิทธิ์ความรับผิดชอบ