import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
plt.style.use ('fivethirtyeight')
pd.set_option("display.max_rows", 1000)
# Import yfinance package
import yfinance as yf
# Set the start and end date
start_date = '2010-01-02'
end_date = '2020-01-01'
cash = 10000
# Set the ticker
ticker = 'SPY'
# Get the data
df = yf.download(ticker, start_date, end_date)
# Print rows
df.head()
def SMA10(data, period=10, column='Close'):
return data [column].rolling(window=period).mean()
def SMA30(data, period=30, column='Close'):
return data [column].rolling(window=period).mean()
# Set strategie
def strategy(df):
buy = []
sell = []
flag = 0
buy_price = 0
for i in range(0, len(df)):
if df['SMA10'] > df['SMA30'] and flag == 0:
buy.append(df['Close'])
sell.append(np.nan)
buy_price = df['Close']
flag = 1
elif df['SMA10'] < df['SMA30'] and flag == 1:
sell.append(df['Close'])
buy.append(np.nan)
buy_price = 0
flag = 0
else:
sell.append(np.nan)
buy.append(np.nan)
return (buy, sell)
Hallo, kann mir jemand helfen, diese Strategi zu testen, zum Beispiel, wir haben cash=10.000 , kaufen Aktien - so viel , wie es Geld reicht, dann entsteht Portfolio, wenn SMA10<SMA30 wir verkaufen Aktien, alle die wir haben, und somit verdienen Geld.
Danke im Voraus.
Moving average strategy
Wurde schon mal https://forum-raspberrypi.de/forum/thre ... g-average/ diskutiert.
- __blackjack__
- User
- Beiträge: 13111
- Registriert: Samstag 2. Juni 2018, 10:21
- Wohnort: 127.0.0.1
- Kontaktdaten:
Dort sogar in zwei Themen. Hier nämlich auch noch mal: https://forum-raspberrypi.de/forum/thre ... tID=510598
Und das wurde durch die gleiche Frage wie hier ergänzt.
Und das wurde durch die gleiche Frage wie hier ergänzt.
„All religions are the same: religion is basically guilt, with different holidays.” — Cathy Ladman