import pandas as pd NAME_LIST = ["aapl1", "amgn1", "ba1", "dis1", "intc1", "ko1", "mcd1", "msft1", "trv1", "v1"] for file in NAME_LIST: file_path = 'PredictionData\\' + file + '_hybrid_model_data.csv' data = pd.read_csv(file_path) lookback_period = 14 data['Highest_High'] = data['high'].rolling(window=lookback_period).max() data['Lowest_Low'] = data['low'].rolling(window=lookback_period).min() data['Williams_%R'] = (data['Highest_High'] - data['close']) / (data['Highest_High'] - data['Lowest_Low']) * (-100) data = data.drop(columns=['Highest_High', 'Lowest_Low']) print(file + ": ") print(data[['date', 'close', 'Williams_%R']].tail()) # 显示最后几行数据 output_file_path = 'HybridWillmsData\\' + file + '_data_with_WilliamsR.csv' data.to_csv(output_file_path, index=False)