|
Percentile function very slow
#486781
10/06/22 10:16
10/06/22 10:16
|
Joined: Jul 2022
Posts: 4 Velika Gorica
MislavSag
OP
Guest
|
OP
Guest
Joined: Jul 2022
Posts: 4
Velika Gorica
|
Hi,
I am new to Zorro. I have donwloaded minute data from IB for few symbols and start experimenting.
Here is my first sample script:
``` function run() // at any bar { // Setup StartDate = 20200101; EndDate = 20200201; BarPeriod = 1; LookBack = 4800; // Universe assetList("AssetsIB");
// trading strategy while(asset(loop("AMZN", "AXP"))){ // help ts // The priceO, priceH, priceL, priceC functions can be also used under the names priceOpen, priceHigh, priceLow, priceClose. vars close = series(priceC()); vars close_returns = series(ROCP(close, 4800 - 1)); // calculate percentile var percentile_upper = Percentile(close_returns, 4800, 0.99); //var percentile_lower = Percentile(close_returns, CLOSE_WINDOW_SIZE, 0.01); /* // get above and belowe returns if any if(priceC(0) > percentile_upper){ var above = price(0) - percentile_upper; } */ } }
``` The code works, but it is pretty slow. I have set only one month for backtest period, but it takes more than 5 minutes for just 2 symbols (I have stopped execution after 5 minutes so I don't know how long it takes in the end ).
Is the problem in my code or is just Percentile function so slow?
|
|
|
Re: Percentile function very slow
[Re: MislavSag]
#486791
10/07/22 13:22
10/07/22 13:22
|
Joined: Feb 2017
Posts: 1,718 Chicago
AndrewAMD
Serious User
|
Serious User
Joined: Feb 2017
Posts: 1,718
Chicago
|
How is Percentile quicksorting without using its own mutable buffer? Is it actually making changes to the input buffer?
EDIT: Or maybe Percentile has its own static mutabable buffer but only resizes it when necessary. That would make sense.
Last edited by AndrewAMD; 10/07/22 13:44.
|
|
|
Re: Percentile function very slow
[Re: jcl]
#486795
10/11/22 09:17
10/11/22 09:17
|
Joined: Aug 2022
Posts: 65
alun
Junior Member
|
Junior Member
Joined: Aug 2022
Posts: 65
|
If the array is already sorted on a previous step can we just insert the next element at the right place and remove the previous (FIFO) one? I believe that would make it O(N) in the worst case instead of O(N*log(N)) as with quick sorting from scratch. Maybe appending to the sorted array and then sorting it again would be of a similar. Other ideas - see if could implement something like: http://hdrhistogram.org/which sacrifices precision for performance
|
|
|
|