Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Loss some exit signals by using SignalFactory. #612

Open
eromoe opened this issue Jun 21, 2023 · 2 comments
Open

Loss some exit signals by using SignalFactory. #612

eromoe opened this issue Jun 21, 2023 · 2 comments

Comments

@eromoe
Copy link

eromoe commented Jun 21, 2023

I want to generate an exit signal exact n tick after an entry .

Test below code

import numpy as np
import pandas as pd
import vectorbt as vbt
from numba import njit

@njit
def choice_func_nb(from_i, to_i, col, n):
    if from_i + n - 1 < to_i:
        return np.array([from_i + n - 1], dtype=np.int_)
    return np.empty(0, dtype=np.int_)  # no index

ExitAfter = vbt.SignalFactory(
    short_name="exit_after",
    mode="chain", 
    param_names=["n"]
).from_choice_func(exit_choice_func=choice_func_nb, exit_settings=dict(pass_params=["n"]))


entries = pd.DataFrame(np.tile([True, False, True, False, True, False, False], 3).reshape(3, -1).T, columns=list('abc'))
ExitAfter.run(entries, n=[2]).exits

I found output is


a | b | c
-- | -- | --
False | False | False
False | False | False
True | True | True
False | False | False
False | False | False   # here I expect all True 
False | False | False
True | True | True

What I expect result is same as entries.shift(2).fillna(False)

a | b | c
-- | -- | --
False | False | False
False | False | False
True | True | True
False | False | False
True | True | True
False | False | False
True | True | True

I want to see what happen and use vscode to debug, but the breakpoints doesn't stop in vbt.SignalFactory.__init__ and vbt.SignalFactory.run , I can't figure it out so ask for help here.

@polakowo
Copy link
Owner

Exit signals are generated strictly between each pair of entries, there's no option in community version to change this (again, this was redesigned in pro). But you can create your own numba function that does the generation part and wrap it with indicator factory.

@eromoe
Copy link
Author

eromoe commented Jun 27, 2023

Thank you for clarify

Exit signals are generated strictly between each pair of entries

Since entries are

	a	b	c
-- | -- | --
0	True	True	True              # entry 1
1	False	False	False
2	True	True	True               # entry 2
3	False	False	False
4	True	True	True               # entry 3
5	False	False	False
6	False	False	False

produce exits

a | b | c
-- | -- | --
False | False | False
False | False | False
True | True | True           # exit 1
False | False | False
False | False | False   
False | False | False
True | True | True           # exit 2

Here exit 1 is overlaped with entry 2, it is not betweeen entry 1 and entry 2 , and exit 2 isn't between two entry.
I can't get the machenism.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants