(f)
| 28 | return series.rolling(window=window_size).apply(lambda x: x.iloc[-1] - x.iloc[0], raw=False).shift(-(window_size - 1)) |
| 29 | |
| 30 | def process_file(f): |
| 31 | df = pd.read_csv(f) |
| 32 | |
| 33 | best_ask_price = df.ASKp1 / 10000 |
| 34 | best_bid_price = df.BIDp1 / 10000 |
| 35 | local_mids = (best_ask_price + best_bid_price) / 2 |
| 36 | local_spreads = best_ask_price - best_bid_price |
| 37 | volatility_10 = np.std(calculate_log_returns(local_mids, 10)) |
| 38 | volatility_50 = np.std(calculate_log_returns(local_mids, 50)) |
| 39 | volatility_100 = np.std(calculate_log_returns(local_mids, 100)) |
| 40 | levels_ask_side = ((df.ASKp10 / 10000 - df.ASKp1 / 10000) / 0.01).tolist() |
| 41 | levels_bid_side = ((df.BIDp1 / 10000 - df.BIDp10 / 10000) / 0.01).tolist() |
| 42 | df['seconds'] = pd.to_datetime(df['seconds']) |
| 43 | secs = df['seconds'].astype(int) / 10**9 |
| 44 | |
| 45 | seconds_in_horizon_10 = optimized_rolling_diff(secs, 10).dropna().tolist() |
| 46 | seconds_in_horizon_50 = optimized_rolling_diff(secs, 50).dropna().tolist() |
| 47 | seconds_in_horizon_100 = optimized_rolling_diff(secs, 100).dropna().tolist() |
| 48 | |
| 49 | print(f"Finished {f}.") |
| 50 | return { |
| 51 | 'Mids': local_mids.tolist(), |
| 52 | 'Spreads': local_spreads.tolist(), |
| 53 | 'Best_Ask_Volume': df.ASKs1.tolist(), |
| 54 | 'Best_Bid_Volume': df.BIDs1.tolist(), |
| 55 | 'Volatility_10': [volatility_10], |
| 56 | 'Volatility_50': [volatility_50], |
| 57 | 'Volatility_100': [volatility_100], |
| 58 | 'Levels_Ask_Side': levels_ask_side, |
| 59 | 'Levels_Bid_Side': levels_bid_side, |
| 60 | 'Seconds_Horizon_10': seconds_in_horizon_10, |
| 61 | 'Seconds_Horizon_50': seconds_in_horizon_50, |
| 62 | 'Seconds_Horizon_100': seconds_in_horizon_100 |
| 63 | } |
| 64 | |
| 65 | def process_stock_files(file_list): |
| 66 | stock_data = { |
no test coverage detected