-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPriceMap.cpp
More file actions
47 lines (45 loc) · 1.51 KB
/
Copy pathPriceMap.cpp
File metadata and controls
47 lines (45 loc) · 1.51 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
42
43
44
45
46
47
#include "PriceMap.h"
#include "readData.h"
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <cmath>
#include <string>
#include <fstream>
#include <vector>
using namespace std;
using namespace fre;
typedef map<string, map<string, double>> Map;
namespace fre{
PriceMap PriceMap::randomSelect(int n){
Group subgroup = group.randomSelect(n);
PriceMap subMap;
vector<Stock> sList = subgroup.getStockList();
for(int i = 0; i < n; i++){
subMap.addStock(sList[i]);
subMap.setPM(sList[i].getTicker(),getPrice(sList[i].getTicker()));
}
return subMap;
}
PriceMap PriceMap::createReturnMap(){
PriceMap returnMap;
vector<Stock> sList = getStockList();
for(int i = 0; i < sList.size(); i++){
Stock temp = sList[i];
string ticker = temp.getTicker();
returnMap.addStock(temp);
map<string, double> price = getPrice(ticker);
map<string, double> ret;
double pricePrevious = price.begin()-> second;
for(map<string,double>::iterator itr = next(price.begin()); itr!=price.end(); itr++){
string date = itr -> first;
double pricePresent = itr -> second;
ret[date] = (pricePresent - pricePrevious)/(pricePrevious);
pricePrevious = pricePresent;
}
returnMap.group.addStock(temp);
returnMap.setPM(ticker,ret);
}
return returnMap;
}
}