Skip to content

External data along with trades #425

Answered by limx0
OnlyC asked this question in Q&A
Aug 31, 2021 · 2 comments · 2 replies
Discussion options

You must be logged in to vote

Hey @OnlyC - it's actually much simpler than that - nautilus has first class support for "custom data".

Simply create a Data subclass to represent your data in your project:

class OpenInterest(Data):
    def __init__(self, value, ts_event=0, ts_init=0):
        super().__init__(ts_event, ts_init)
        self.value = value

Then in your backtest code - add a parsing function that creates these objects from your raw csv data:

def load_open_interest(filename):
    data = []
    for _, row in  pd.read_csv(filename).iterrows():
        data.append(
            OpenInterest(value=row['open_interest'], timestamp=row['timestamp'])
        )
    return data

Then, you can simply add this data to …

Replies: 2 comments 2 replies

Comment options

You must be logged in to vote
1 reply
@limx0
Comment options

limx0 Sep 1, 2021
Collaborator

Answer selected by cjdsellers
Comment options

You must be logged in to vote
1 reply
@cjdsellers
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
question Further information is requested
3 participants