vendredi 2 juillet 2021

Initialise vector size within a map

In my header file, I have a map field:

std::map<std::string, std::vector<double>> priceSMA;

I know the length of the vector, which is 50. How do I go about setting the size of this vector?

If the field was a vector on it's own, It's simple to set the size. But since it's nested within a map I'm lost.

The below throws a syntax error for the vector length:

priceSMA = std::map<std::string, std::vector<double>(50)>();

Any help is appreciated

EDIT

For further clarification, the prceSMA key will be populated with a currency identifier, e.g. "USD". The vector is to store the last 50 values of this currency, where each value has a certain timestamp. Once the first 50 values are populated, when we jump to the next timestamp all the current values in the vector shift over by one value, and populate the last (50th) item in the vector with the new value from the current timestamp.

Prior to the shift, I calculate the average of the 50 values in the vector and store this somewhere else.

The idea is to get a simple moving average over a certain time period.

Aucun commentaire:

Enregistrer un commentaire