Unknown model· unknown
from NVIDIA HelpSteer3 Preference
Utilizing python, can you give examples of both a systematic trading strategy, and a…
- User
Utilizing python, can you give examples of both a systematic trading strategy, and a discretionary one?
- Assistant
- Systematic Trading Strategy Example: Moving Average Crossover
pythonimport pandas as pd import numpy as np from pandas_datareader import data as pdr import yfinance as yf yf.pdr_override() def moving_average_crossover(data, short_window, long_window): short_ema = data['Close'].ewm(span=short_window, adjust=False).mean() long_ema = data['Close'].ewm(span=long_window, adjust=False).mean() crossover_signal = np.where(short_ema > long_ema, 1, 0) return crossover_signal # Download historical stock data stock_data = pdr.get_data_yahoo('AAPL', start='2020-01-01', end='2023-01-01') stock_data['Signal'] = moving_average_crossover(stock_data, short_window=20, long_window=50) stock_data['Position'] = stock_data['Signal'].diff() print(stock_data[['Close', 'Signal', 'Position']].tail())- Discretionary Trading Strategy Example: Fundamental Analysis
pythonimport pandas as pd import yfinance as yf def fundamental_analysis(stock_symbol): stock_data = yf.Ticker(stock_symbol).info # Perform fundamental analysis based on financial ratios, earnings, etc. # This is a simplified example, in practice, you would need to fetch and analyze financial statements. if stock_data['trailingPE'] < 15 and stock_data['priceToSales'] < 2: return 'BUY' elif stock_data['trailingPE'] > 30: return 'SELL' else: return 'HOLD' # Example usage of the fundamental analysis strategy stock_symbol = 'AAPL' recommendation = fundamental_analysis(stock_symbol) print(f"Fundamental Analysis Recommendation for {stock_symbol}: {recommendation}")
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.