// cpp_engine/src/simd_alpha_calculator.cpp #include "../include/simd_alpha_calculator.hpp" #include #include std::vector SIMDAlphaCalculator::calculate_ofi_vectorized( const std::vector& bid_prices, const std::vector& bid_sizes, const std::vector& ask_prices, const std::vector& ask_sizes ) { size_t n = bid_prices.size(); std::vector ofi(n, 0.0); if (n < 2) return ofi; for (size_t t = 1; t < n; ++t) { double delta_e_bid = 0.0; if (bid_prices[t] > bid_prices[t - 1]) { delta_e_bid = bid_sizes[t]; } else if (bid_prices[t] == bid_prices[t - 1]) { delta_e_bid = bid_sizes[t] - bid_sizes[t - 1]; } else { delta_e_bid = -bid_sizes[t - 1]; } double delta_e_ask = 0.0; if (ask_prices[t] < ask_prices[t - 1]) { delta_e_ask = ask_sizes[t]; } else if (ask_prices[t] == ask_prices[t - 1]) { delta_e_ask = ask_sizes[t] - ask_sizes[t - 1]; } else { delta_e_ask = -ask_sizes[t - 1]; } ofi[t] = delta_e_bid - delta_e_ask; } return ofi; } std::vector SIMDAlphaCalculator::calculate_microprice_velocity( const std::vector& mid_prices, const std::vector& ofi_signals, size_t window ) { size_t n = mid_prices.size(); std::vector velocity(n, 0.0); if (n <= window) return velocity; for (size_t i = window; i < n; ++i) { double price_change = mid_prices[i] - mid_prices[i - window]; double ofi_sum = 0.0; for (size_t j = i - window; j <= i; ++j) { ofi_sum += ofi_signals[j]; } velocity[i] = price_change * 0.7 + (ofi_sum / window) * 0.3; } return velocity; } double SIMDAlphaCalculator::calculate_vpin_toxicity( const std::vector& trade_volumes, const std::vector& price_changes, size_t bucket_size ) { size_t n = trade_volumes.size(); if (n == 0) return 0.0; double buy_vol = 0.0; double sell_vol = 0.0; double total_vol = 0.0; for (size_t i = 0; i < n; ++i) { double v = trade_volumes[i]; total_vol += v; if (price_changes[i] >= 0) { buy_vol += v; } else { sell_vol += v; } } return total_vol > 0.0 ? std::abs(buy_vol - sell_vol) / total_vol : 0.0; }