Skip to content

Commit b1c1361

Browse files
author
gg
committed
fix delete row if zero
1 parent cb9aea4 commit b1c1361

File tree

3 files changed

+36
-21
lines changed

3 files changed

+36
-21
lines changed

src/CVaRHistorical.cpp

+12-7
Original file line numberDiff line numberDiff line change
@@ -54,16 +54,21 @@ double CVaRHistorical(priceData rawPrices, weightData weights, double alphatest)
5454
}
5555

5656
// Remove missing values to compute trailling returns
57-
// Asynchornous time series. Shift to the next value
5857
Mat prices;
5958
prices.resize(m,Vec(0));
6059

61-
for(size_t i = 0;i < _prices.size();++i){
62-
for(size_t j = 0;j < _prices[i].size();++j){
63-
if(!((_prices[i][j] == 99999) || (_prices[i][j] == 0)))
64-
prices[i].push_back(_prices[i][j]);
65-
}
66-
}
60+
bool goodrow = true;
61+
for(size_t j = 0;j < _prices[0].size();++j){
62+
for(size_t i = 0;i < _prices.size();++i){
63+
if((_prices[i][j] == 99999) || (_prices[i][j] == 0))
64+
goodrow = false;
65+
}
66+
if (goodrow)
67+
for(size_t i = 0;i < _prices.size();++i){
68+
prices[i].push_back(_prices[i][j]);
69+
}
70+
goodrow = true;
71+
}
6772
unsigned int windowsize = prices[0].size()-2;
6873
std::shared_ptr<ComputeReturn> cr(new ComputeReturn(prices,1,windowsize,true));
6974

src/CVaRMonteCarlo.cpp

+12-7
Original file line numberDiff line numberDiff line change
@@ -54,16 +54,21 @@ double CVaRMonteCarlo(priceData rawPrices, weightData weights, double alphatest)
5454
}
5555

5656
// Remove missing values to compute trailling returns
57-
// Asynchornous time series. Shift to the next value
5857
Mat prices;
5958
prices.resize(m,Vec(0));
6059

61-
for(size_t i = 0;i < _prices.size();++i){
62-
for(size_t j = 0;j < _prices[i].size();++j){
63-
if(!((_prices[i][j] == 99999) || (_prices[i][j] == 0)))
64-
prices[i].push_back(_prices[i][j]);
65-
}
66-
}
60+
bool goodrow = true;
61+
for(size_t j = 0;j < _prices[0].size();++j){
62+
for(size_t i = 0;i < _prices.size();++i){
63+
if((_prices[i][j] == 99999) || (_prices[i][j] == 0))
64+
goodrow = false;
65+
}
66+
if (goodrow)
67+
for(size_t i = 0;i < _prices.size();++i){
68+
prices[i].push_back(_prices[i][j]);
69+
}
70+
goodrow = true;
71+
}
6772
unsigned int windowsize = prices[0].size()-2;
6873
std::shared_ptr<ComputeReturn> cr(new ComputeReturn(prices,1,windowsize,true));
6974

src/CVaRVarianceCovariance.cpp

+12-7
Original file line numberDiff line numberDiff line change
@@ -54,16 +54,21 @@ double CVaRVarianceCovariance(priceData rawPrices, weightData weights, double al
5454
}
5555

5656
// Remove missing values to compute trailling returns
57-
// Asynchornous time series. Shift to the next value
5857
Mat prices;
5958
prices.resize(m,Vec(0));
6059

61-
for(size_t i = 0;i < _prices.size();++i){
62-
for(size_t j = 0;j < _prices[i].size();++j){
63-
if(!((_prices[i][j] == 99999) || (_prices[i][j] == 0)))
64-
prices[i].push_back(_prices[i][j]);
65-
}
66-
}
60+
bool goodrow = true;
61+
for(size_t j = 0;j < _prices[0].size();++j){
62+
for(size_t i = 0;i < _prices.size();++i){
63+
if((_prices[i][j] == 99999) || (_prices[i][j] == 0))
64+
goodrow = false;
65+
}
66+
if (goodrow)
67+
for(size_t i = 0;i < _prices.size();++i){
68+
prices[i].push_back(_prices[i][j]);
69+
}
70+
goodrow = true;
71+
}
6772
unsigned int windowsize = prices[0].size()-2;
6873
std::shared_ptr<ComputeReturn> cr(new ComputeReturn(prices,1,windowsize,true));
6974

0 commit comments

Comments
 (0)