question-mark
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.

How to configure SelectHasData() ?

See original GitHub issue

Hello,

Some of my price series start with abnormal values and it causes backtest bias, data looks like this :

timestamp
2017-05-20 00:00:00+00:00         NaN
2017-05-21 00:00:00+00:00         NaN
2017-05-22 00:00:00+00:00         NaN
2017-05-23 00:00:00+00:00    100000.0 # abnormal value here
2017-05-24 00:00:00+00:00    00006.54
2017-05-25 00:00:00+00:00    00006.33
2017-05-26 00:00:00+00:00    00006.13
2017-05-27 00:00:00+00:00    00006.24

How can I configure SelectHasData() to wait for at least 2 periods after NaN ? so that selection will starts the 2017-05-25.

I have tried SelectHasData(pd.DateOffset(days=2), min_count=2) or just SelectHasData(pd.DateOffset(days=2) but it doesn’t work as expected and I still have the same problem. What am’I missing here ?

Thank you,

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:6

github_iconTop GitHub Comments

2reactions
HedgeShotcommented, Jul 26, 2018

I have seen a few issues with SelectHasData() but what you are describing seems to work for me.

Here is my algo

testalgo = bt.Strategy('test', 
                [bt.algos.RunDaily(),
                 bt.algos.SelectHasData(pd.DateOffset(days=2), min_count=2),
                 PrintSelector(), 
                 bt.algos.WeighEqually(),
                 bt.algos.Rebalance()])

PrintSelector is just printing target.now and target.temp['selected'].

My data frame as NaN values on the first three dates (2007-05-07, 2007-05-08, 2007-05-09) and values from 2007-05-10 on. I expected to have tickers in target.temp['selected']on 2007-05-11, nothing before.

My console shows:

2007-05-07 00:00:00
[]
#######
2007-05-08 00:00:00
[]
#######
2007-05-09 00:00:00
[]
#######
2007-05-10 00:00:00
[]
#######
2007-05-11 00:00:00
['SPY', 'VNQ', 'RWO', 'GLD']

So it is avoiding NaN’s entries + the first date. What I discovered running this little example is that on every subsequent Monday, target.temp['selected'] is empty… This is clearly an issue. It should offset by business days or integer position to avoid the problem.

Hope this helps.

1reaction
HedgeShotcommented, Jul 27, 2018

The code looks indeed like what Jordan said. Algo is a class of the bt package.

Read more comments on GitHub >

github_iconTop Results From Across the Web

The Fluent API HasData Method - Learn Entity Framework Core
When the HasData method is used, EF Core will automatically generate SET IDENTITY INSERT ON for the relevant table, and the set it...
Read more >
Seeding data with .HasData() #12464 - dotnet/efcore - GitHub
HasData() method but this is what I am currently experiencing. I have the two basic classes created from the EFCore tutorial on Microsoft's...
Read more >
Data Points - Deep Dive into EF Core HasData Seeding
A couple things to pay attention to here: First, I'm explicitly setting the key property, MagazineId. Second, I'm not supplying the Publisher string....
Read more >
Entity Framework Core - Migration HasData method not ...
class Source { // Nullable to allow both using the DEFAULT and inserting SourceType.Email public SourceType? Type {get;set;} }.
Read more >
Migrations and Seed Data With Entity Framework Core
NET Core Web API program and learn how to create a full ... This file has two methods conveniently named Up() and Down...
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 Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found