Closed drsramd closed 3 years ago
Your post is all garbled up. I cannot decipher anything from it. What visitor are you using? What is your input data?
Return visitor, input data below "DataFrame"; output (garbled?) as produced by dataframe.write function
What column of the input data are you passing to the return (open, high, low, close)? Can I see your source code snippet?
But in general the return visitor result is a vector of length one less than the input column. So the first item is not in the result vector.
output data below "return visitor (log policy, roll = 1)";
ReturnVisitor
So, what is happening is -- as I said above -- the return result vector length is one less than the input. When you load the result into the data frame with nan_policy::pad_with_nans
, it pads the input with nan to make it the same length as the index column. That's why you see a nan at the end.
I was going to change the return result to have a nan at the beginning so it would have the same length as input
I made the change in master
ok great think that would be more similar to the behavior of pandas; what about other visitors with a roll?
thanks a lot for your help;
Can you tell me exactly what visitor? In general, all roll visitors should start with NaN as the first roll items.
I have up to now tried garman klass and return; both resulted in nan in the last item not the first;
return is now fixed
in case of Garman Klass
, the result vector should be the same length as the input vectors. and the first roll-count
items in the result should be NaN. That's what I get from my end. Can you double check?
// GK with roll 1 (daily), annualization factor 252 trading days
GarmanKlassVolVisitor<double, std::string> gk_visitor(1, 252);
ohlc_df.single_act_visit<double, double, double, double>("low", "high", "open", "close", gk_visitor);
std::vector<double> gk_vol = gk_visitor.get_result();
ohlc_df.load_column("gkvol", std::move(gk_vol), nan_policy::pad_with_nans);
input
INDEX:53:
Output
INDEX:53:
is correct, I misspoke
YangZhangVolVisitor<double, std::string> yz_visitor(1, 252);
ohlc_df.single_act_visit<double, double, double, double>("low", "high", "open", "close", yz_visitor);
std::vector<double> yz_vol = yz_visitor.get_result();
ohlc_df.load_column("yzvol", std::move(yz_vol), nan_policy::pad_with_nans);
with input
INDEX:54:
yzvol: 54
INDEX:54:
has the somewhat surprising outcome of all nans
INDEX:54:
YangZhangVolVisitor
with roll_count == 1 won't work. There are calculations in that visitor that divides by (roll_count - 1).
I will put an assert there for roll_count > 1
I added the following to YangZhangVolVisitor
assert(roll_count > 1);
Thanks so much, that was a complete brain freeze on my behalf, sorry to have bothered you with that but thanks again for your patience and guidance;
DataFrame
INDEX:33::0,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,
timestamp:33:<N/A>:2021-Jun-01 13:30:00,2021-Jun-02 13:30:00,2021-Jun-03 13:30:00,2021-Jun-04 13:30:00,2021-Jun-07 13:30:00,2021-Jun-08 13:30:00,2021-Jun-09 20:00:03,2021-Jun-10 20:00:00,2021-Jun-11 20:00:00,2021-Jun-14 20:00:00,2021-Jun-15 20:00:00,2021-Jun-16 20:00:00,2021-Jun-17 20:00:01,2021-Jun-18 20:00:04,2021-Jun-21 20:00:00,2021-Jun-22 20:00:00,2021-Jun-23 13:30:00,2021-Jun-24 13:30:00,2021-Jun-25 20:00:04,2021-Jun-28 20:00:00,2021-Jun-29 20:00:01,2021-Jun-30 20:00:03,2021-Jul-01 20:00:00,2021-Jul-02 20:00:00,2021-Jul-06 20:00:01,2021-Jul-07 20:00:00,2021-Jul-08 20:00:00,2021-Jul-09 20:00:00,2021-Jul-12 20:00:00,2021-Jul-13 13:30:00,2021-Jul-14 13:30:00,2021-Jul-15 20:00:00,2021-Jul-16 20:00:00,
open:33::422.57,420.37,417.85,420.75,422.59,423.11,423.18,422.96,424.2,424.43,425.42,424.63,424.63,417.09,416.8,420.85,423.19,424.89,425.9,427.17,427.88,427.21,428.87,431.67,433.78,433.66,428.78,432.53,435.43,436.24,437.4,434.81,436.01,
high:33::422.72,421.23,419.99,422.92,422.78,423.21,423.26,424.62,424.43,425.37,425.46,424.84,423,417.828,421.06,424,424.05,425.55,427.094,427.64,428.56,428.76,430.6,434.1,434,434.76,431.73,435.81,437.35,437.84,437.92,435.53,436.05,
low:33::419.2,419.29,416.28,418.84,421.19,420.32,421.41,421.56,422.82,423.1,423.54,419.92,419.32,414.7,415.93,420.08,422.51,424.62,425.55,425.89,427.13,427.18,428.8,430.522,430.01,431.51,427.52,430.714,434.97,435.31,434.91,432.72,430.92,
close:33::422.57,420.37,417.85,420.75,422.59,423.11,423.18,422.96,424.2,424.43,425.42,424.63,424.63,417.09,416.8,420.85,423.19,424.89,425.9,427.17,427.88,427.21,428.87,431.67,433.78,433.66,428.78,432.53,435.43,436.24,437.4,434.81,436.01,
volume:33::54216600,49097100,58138800,55910700,51450000,47077600,47096348,50866337,45406077,42033990,51403156,79709612,86675738,114990989,72644868,57147732,49445400,45049400,55742186,49651109,34946598,64471992,53206239,57457221,68148765,63357716,96997650,74749998,44097385,52911300,64039100,54401485,75484551,
return visitor (log policy, roll = 1) INDEX:33::0,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,
timestamp:33:<N/A>:2021-Jun-01 13:30:00,2021-Jun-02 13:30:00,2021-Jun-03 13:30:00,2021-Jun-04 13:30:00,2021-Jun-07 13:30:00,2021-Jun-08 13:30:00,2021-Jun-09 20:00:03,2021-Jun-10 20:00:00,2021-Jun-11 20:00:00,2021-Jun-14 20:00:00,2021-Jun-15 20:00:00,2021-Jun-16 20:00:00,2021-Jun-17 20:00:01,2021-Jun-18 20:00:04,2021-Jun-21 20:00:00,2021-Jun-22 20:00:00,2021-Jun-23 13:30:00,2021-Jun-24 13:30:00,2021-Jun-25 20:00:04,2021-Jun-28 20:00:00,2021-Jun-29 20:00:01,2021-Jun-30 20:00:03,2021-Jul-01 20:00:00,2021-Jul-02 20:00:00,2021-Jul-06 20:00:01,2021-Jul-07 20:00:00,2021-Jul-08 20:00:00,2021-Jul-09 20:00:00,2021-Jul-12 20:00:00,2021-Jul-13 13:30:00,2021-Jul-14 13:30:00,2021-Jul-15 20:00:00,2021-Jul-16 20:00:00,
return:33::-0.00521987,-0.00601273,0.0069163,0.0043636,0.00122972,0.000165447,-0.000520013,0.00292748,0.000542005,0.00232987,-0.00185873,0,-0.0179162,-0.000695555,0.00967003,0.00554477,0.00400909,0.00237422,0.00297753,0.0016607,-0.00156712,0.00387816,0.00650761,0.00487605,-0.000276665,-0.0113169,0.00870772,0.00668235,0.0018585,0.00265557,-0.00593895,0.00275605,nan,
nan should be at index 0;
same issue with a couple of other visitors I have tried