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

Minimum Profit Optimization #19

Merged
merged 61 commits into from Dec 9, 2020
Merged

Minimum Profit Optimization #19

merged 61 commits into from Dec 9, 2020

Conversation

Stochastic-Adventure
Copy link

@Stochastic-Adventure Stochastic-Adventure commented Nov 17, 2020

Description

Implementations in this module are based on the following papers:

  • Lin, Y.-X., McCrae, M., and Gulati, C. (2006). Loss protection in pairs trading through minimum profit bounds: A cointegration approach.Journal of Applied Mathematics and Decision Sciences, 2006(1):1–14.
  • Puspaningrum, H., Lin, Y.-X., and Gulati, C. M. (2010).  Finding the optimal pre-set boundaries for pairs trading strategy based on cointegration technique. Journal of  Statistical  Theory and Practice, 4(3):391–419.

Implemented features are:

  • Simulate AR(1) processes in batch
  • Simulate cointegrated time series pairs in batch
  • Calculate cointegration coefficient based on either Engle-Granger or Johansen test
  • Fit the AR(1) coefficient of cointegration error
  • Calculate optimal preset upper-bound and minimal total profit for cointegrated pairs trading strategy

Dependency:

  • arbitrage_lab.cointegration_approach

Type of change

  • New feature (non-breaking change which adds functionality)
  • This change requires a documentation update

How Has This Been Tested?

This unit tests file was created to test the added functions:

  • test\test_minimum_profit_simulation.py
  • test\test_minimum_profit.py

Test Configuration:

  • Windows 10
  • PyCharm

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published in downstream modules

Description
Implementations in this module are based on the following paper:
Lin, Y.-X., McCrae, M., and Gulati, C. (2006). Loss protection in pairs trading through minimum profit bounds: A cointegration approach.Journal of Applied Mathematics and Decision Sciences, 2006(1):1–14.
Puspaningrum, H., Lin, Y.-X., and Gulati, C. M. (2010).  Finding the optimal pre-set boundaries for pairs trading strategy based on cointegration technique. Journal of  Statistical  Theory and Practice, 4(3):391–419.

Implemented features are:

Simulate AR(1) processes in batch
Simulate cointegrated time series pairs in batch
Calculate cointegration coefficient based on either Engle-Granger or Johansen test
Fit the AR(1) coefficient of cointegration error
Calculate optimal preset upper-bound and minimal total profit for cointegrated pairs trading strategy
Trade the strategy based on the optimal parameters
Dependency:

mlfinlab.statistical_arbitrage
Type of change
 New feature (non-breaking change which adds functionality)
 This change requires a documentation update
How Has This Been Tested?
This unit tests file was created to test the added functions:

 test\test_minimum_profit.py
Test Configuration:

Windows 10
PyCharm
Checklist:
 My code follows the style guidelines of this project
 I have performed a self-review of my own code
 I have commented my code, particularly in hard-to-understand areas
 I have made corresponding changes to the documentation
 My changes generate no new warnings
 I have added tests that prove my fix is effective or that my feature works
 New and existing unit tests pass locally with my changes
 Any dependent changes have been merged and published in downstream modules
@PanPip PanPip self-requested a review November 18, 2020 14:44
@PanPip PanPip added documentation Improvements or additions to documentation enhancement New feature or request labels Nov 18, 2020
Copy link
Contributor

@PanPip PanPip left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I see that the file structure should be changed in this PR.

Will first fix it.

minimum_profit/MinimumProfit.py Outdated Show resolved Hide resolved
Copy link
Contributor

@PanPip PanPip left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code quality has improved greatly! 👍

Left a few comments for now.

Will get back to review after the stand-up call.

Copy link
Contributor

@PanPip PanPip left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Finished the initial review.

Really like the unit tests. Great work! 🙂

Will help a bit with small code fixes.

arbitragelab/util/split_dataset.py Outdated Show resolved Hide resolved
tests/test_minimum_profit.py Outdated Show resolved Hide resolved
tests/test_minimum_profit.py Outdated Show resolved Hide resolved
tests/test_minimum_profit.py Outdated Show resolved Hide resolved
Copy link
Contributor

@PanPip PanPip left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The theoretical part of the docs is good. We might want to add a bit more details on the trading process, optimization steps, and how the MTP behaves on the empirical data (sent you a pdf with notes).

I'm still looking for a way to remove the Return type section in the new sphinx docs.

docs/source/cointegration_approach/minimum_profit.rst Outdated Show resolved Hide resolved
docs/source/cointegration_approach/minimum_profit.rst Outdated Show resolved Hide resolved
Added trading simulation class. Added tqdm progress bar for optimization. Added plot function for cointegration simulation. Changed name for simulation class.
Copy link
Contributor

@PanPip PanPip left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work on improving the build times for this PR! Approving it. 👍

Made small changes to docs and code.

Ready for review @Jackal08.

@PanPip
Copy link
Contributor

PanPip commented Nov 27, 2020

@Stochastic-Adventure Also, please remember to update the changelog.

@PanPip PanPip requested a review from Jackal08 November 27, 2020 21:12
Copy link
Member

@Jackal08 Jackal08 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Fix all license link
  • You need to update the changelog

tests/test_minimum_profit.py Outdated Show resolved Hide resolved
@PanPip PanPip merged commit ff02659 into develop Dec 9, 2020
@PanPip PanPip deleted the minimum_profit branch December 9, 2020 14:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants