-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPricingEngine.cpp
More file actions
41 lines (35 loc) · 1.27 KB
/
PricingEngine.cpp
File metadata and controls
41 lines (35 loc) · 1.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#include "PricingEngine.h"
#include <limits>
#include <algorithm>
#include "PriceFeed.h"
#include "OrderBook.h"
#include <iostream>
PricingEngine::PricingEngine(PriceFeed& pf, OrderBook& ob)
: priceFeed(pf), orderBook(ob) {}
void PricingEngine::calculatePricing() {
std::string symbol = "EUR/USD"; // placeholder — you can loop over symbols later
double midPrice = calculateMidPrice(symbol);
std::cout << "Mid price for " << symbol << " is: " << midPrice << std::endl;
}
double PricingEngine::getBestBid(const std::string& symbol) const {
double bestBid = 0.0;
for (const auto& order : orderBook.getBuyOrders(symbol)) {
bestBid = std::max(bestBid, order.getPrice());
}
return bestBid;
}
double PricingEngine::getBestAsk(const std::string& symbol) const {
double bestAsk = std::numeric_limits<double>::max();
for (const auto& order : orderBook.getSellOrders(symbol)) {
bestAsk = std::min(bestAsk, order.getPrice());
}
return (bestAsk == std::numeric_limits<double>::max()) ? 0.0 : bestAsk;
}
double PricingEngine::calculateMidPrice(const std::string& symbol) const {
double bid = getBestBid(symbol);
double ask = getBestAsk(symbol);
if (bid > 0.0 && ask > 0.0) {
return (bid + ask) / 2.0;
}
return 0.0;
}