prediction

I have tried to figure out why my code doesnt work the correct way. I want to compare prediction market with current bid. when i tried with my simple test.csv to test it, it doesnt give me correct answer, I dont get any errors, but when i cout in accumulate method i can see it doesnt work there.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
  int MerkelBot::predictMarketPrice(){
  int prediction = 0;
  for (std::string const& p : orderBook.getKnownProducts()){
    std::cout << "Product: " << p << std::endl;
    std::vector<OrderBookEntry> entries = 
   orderBook.getOrders(OrderBookType::ask, 
                                                            p, currentTime);

  double sum = accumulate(entries.cbegin(), entries.cend(), 0.0, [](double sum, 
  const OrderBookEntry &bookEntry){
    cout<< "call here"<< endl;
    return sum + bookEntry.price;
  });
  prediction =  sum / entries.size();
  std::cout << "Price Prediction is: " << prediction << std::endl;
  }
  return prediction;
}
are you sure that getOrders worked?
what did the cout statement tell you that you see it isn't working? If you cout price there, do you see your data from the CSV? Did you try your debugger, to see what it is doing?

and, is it worth it? some of the stl algorithms are more toy than useful IMHO.
double sum{0.0};
for(auto &a : entries) sum+=a.price;
Last edited on
Slightly re-formatted:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
int MerkelBot::predictMarketPrice() {
	int prediction = 0;
	for (std::string const& p : orderBook.getKnownProducts()) {
		std::cout << "Product: " << p << std::endl;

		std::vector<OrderBookEntry> entries = orderBook.getOrders(OrderBookType::ask, p, currentTime);

		double sum = accumulate(entries.cbegin(), entries.cend(), 0.0, [](double sum, const OrderBookEntry& bookEntry) {
			cout << "call here" << endl;
			return sum + bookEntry.price;
		});

		prediction = sum / entries.size();
		std::cout << "Price Prediction is: " << prediction << std::endl;
	}

	return prediction;
}


Before accumulate, how many elements for entries?
3540 entries
Topic archived. No new replies allowed.