Skip to content

Multiple assets, multiple trade signals per asset #171

Answered by polakowo
Sanjan611 asked this question in Q&A
Discussion options

You must be logged in to vote

@Sanjan611 here's an example:

import pandas as pd
import vectorbt as vbt

price = pd.DataFrame({
    'p1': [1, 2, 3, 4],
    'p2': [5, 6, 7, 8]
})
price.columns.name = 'asset'
entries = pd.DataFrame({
    'en1': [True, False, False, False],
    'en2': [False, True, False, False],
    'en3': [False, False, True, False],
    'en4': [False, False, False, True]
})
entries.columns.name = 'entries'
exits = pd.DataFrame({
    'ex1': [False, False, False, True],
    'ex2': [False, False, False, True],
    'ex3': [False, False, False, True],
    'ex4': [False, False, False, True]
})
exits.columns.name = 'exits'
entries = entries.vbt.stack_index(pd.Index(['p1', 'p1', 'p2', 'p2'], name='asset'))
exits 

Replies: 1 comment 7 replies

Comment options

You must be logged in to vote
7 replies
@polakowo
Comment options

@forLinDre
Comment options

@polakowo
Comment options

@forLinDre
Comment options

@polakowo
Comment options

Answer selected by Sanjan611
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
4 participants