Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Cannot reuse same history list with different slices on different indicators

See original GitHub issue

Hello I’m trying your library (thanks for the effort so far) and I’ve found a bug regarding the usage of the quotes to generate different indicators using the same set of historical quotes but taking a different slice of them

Debug was hard on my side, so I took a look at your code and I see that your model classes have an internal Index that you use and I think that’s the problem.

Suppose I get historical data from my POCO classes and convert them to your Quote model suppose I’ve a list List<Quote> history of 100 Quotes

Now if I call

Indicator.GetBollingerBands(history.TakeLast(20), 20);
Indicator.GetRsi(history.TakeLast(14), 14);

I get a System.ArgumentOutOfRangeException: 'Index was out of range. Must be non-negative and less than the size of the collection.'

I think the problem is that if I reuse Quote objects taking a different slice of the array, the bugs pops out because there is the Index field inconsistence inside your model classes

This means that historical quotes cannot be reused this way but I must always use the same set and I think it’s not good because of performance (I’m not interested in applying indicators on the whole historical set in my scenario


Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:19 (18 by maintainers)

github_iconTop GitHub Comments

MithrilMancommented, Nov 15, 2020

Okay, I’ll check that scenario. I had a unit test to check for corruption and thought I had fixed it. As a side note, I already have a plan (AB#763) to review and probably remove the use of Index internally. I just need to see if I can reasonably do that without causing other problems.

For now, I’d avoid trying to mess with history after it’s composed and used or just use that helper RemoveIndex. There’s really not much of a performance improvement to do this micro-resizing between uses. It’s not how I had intended in the design. I get that you’re trying to hyper-optimize, but simply using TakeLast is probably a higher performance hit than the benefit from doing it.

I’m actually appending RemoveIndex() wherever I pass Data, Takelast is not a performance hit at all because prevent to compute lot of data in indicators I’m actually monitoring real time 50+ symbols and my history buffer is 288 elements (1 day with 5 min candles) there are indicators that I can use by just feeding them with a subset of items, e.g. if I’m interested only in current RoC value, I can feed Roc indicator with 14+1 samples on a loopback of 14, saving 288-15 computation of that indices (that I’ve to do multiple times per second on all symbols)

DaveSkendercommented, Nov 11, 2020

I’ve added a fix to recompose the index if it detects a bad starting value.

I’m also adding an undocumented history.RemoveIndex() extension that will allow a user to remove the internal index from a previously utilized or cleaned history. With this fix, you would not need this extension; however, I’m adding it in case there are unidentified reasons for a user to need to remove the internal indexing.

This fix was implemented in version 1.0.6

Read more comments on GitHub >

github_iconTop Results From Across the Web

PEP 204 - Range Literals: Getting closure - Python discussion
This proposal is over two decades old and wanted to reuse slice syntax standalone to generate a list the same as the old...
Read more >
When a value of a sliced list "copy" is overwritten ...
As is said in the comments, the slice is a copy of the original list. It currently (when the values are same) refers...
Read more >
TikZ and pgf
The pgf package, where “pgf” is supposed to mean “portable graphics format” (or “pretty, good, functional” if you prefer...), is a package for...
Read more >
The RDF Data Cube Vocabulary
Within the Data Cube vocabulary we allow arbitrary dimensionality slices and do not give different names to particular types of slice.
Read more >
Agarose Gel FAQs
You can reuse your agarose gel a few different ways: ... Even if you're trying to preserve a sliced gel for future extraction,...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Post

No results found

github_iconTop Related Hashnode Post

No results found