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

Pairs Trading #104

Open
arunavo4 opened this issue Jul 13, 2020 · 11 comments
Open

Pairs Trading #104

arunavo4 opened this issue Jul 13, 2020 · 11 comments
Labels
enhancement New feature or request question Not a bug, but a FAQ entry

Comments

@arunavo4
Copy link

So currently the Library can only support a single instrument. I would like to extend it for pairs Trading (Two instruments) Buying one selling other.

Any advice will be helpful.

@arunavo4
Copy link
Author

@kernc any ideas?

@kernc kernc changed the title Guide to Extend the Library for Pairs Trading Pairs Trading Jul 15, 2020
@kernc kernc added the question Not a bug, but a FAQ entry label Jul 15, 2020
@kernc
Copy link
Owner

kernc commented Jul 15, 2020

Most simply, until #20 is properly addressed, you could prepare the data beforehand.

Assuming you always enter trades on the two instruments in parallel (buy one, sell the other), this is equivalent to buying instrument1 / instrument2. Even when you long-trade spot EUR/USD forex instrument, you're actually buying EUR currency and selling a corresponding amount of USD. 👍

Thus, you can prepare your data (assuming the two instruments' data frames have the same, appropriately named columns):

data = df_instrument1 / df_instrument2

@arunavo4
Copy link
Author

Yes, I had Initially thought about this approach but this highly restricts the kind of algo that can be developed. If I come across a solution .. I will add a PR

@kernc
Copy link
Owner

kernc commented Jul 15, 2020

Besides always entering trades on the two instruments simultaneously (buying one–selling the other, or vice versa), how does it restrict it?

@arunavo4
Copy link
Author

arunavo4 commented Jul 15, 2020

its not about just making trades. Its about the analysis that you want to perform it indicators or other things. That would be restricted. with the data already a ratio.

@kernc
Copy link
Owner

kernc commented Jul 15, 2020

Note, the passed in data can contain additional columns you require (e.g. instrument1_Close, instrument2_Close, ...), and they can be referred to by your strategy in any way you need them ...

@arunavo4
Copy link
Author

yes true that is possible, yea this definitely solves the issue to some extent. but still, how can we accurately calculate the stats?

@kernc
Copy link
Owner

kernc commented Jul 15, 2020

You're trying to buy low and sell high just like usual. I think the stats will be fine as-is? 🤔

Maybe account for double the spread/commission as you're simulating entering trades on two separate instruments.

@arunavo4
Copy link
Author

I will try and let you know how it goes and If I face issues I will put it up here.

@alenpavlovich
Copy link

Any updates on the following?

@Lexus2016
Copy link

Lexus2016 commented May 22, 2023

Hello.

I will also add my voice for the implementation of work with several assets.

Arguments:

  1. Pair trading is possible between more than 2 cointegrated pairs.
  2. It would be convenient to get a portfolio in the base currency at once, regardless of pairs (in the spread we get the financial result in invented mathematical frills).
  3. To get the result separately for each side of the pair and for the full portfolio of pairs.
  4. Competing libraries have it: https://vectorbt.pro/tutorials/pairs-trading/

Goblincomet pushed a commit to Goblincomet/forex-trading-backtest that referenced this issue Jul 5, 2023
@kernc kernc added top-choice enhancement New feature or request and removed top-choice labels Feb 19, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request question Not a bug, but a FAQ entry
Projects
None yet
Development

No branches or pull requests

4 participants