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

Add Example to Writing Algorithms / Universes / Futures #2055

Merged
merged 4 commits into from
Feb 4, 2025

Conversation

LouisSzeto
Copy link
Collaborator

Description

Add Example to Writing Algorithms / Universes / Futures

Related Issue

Motivation and Context

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • Refactor (non-breaking change which improves implementation)
  • New feature (non-breaking change which adds functionality)
  • Non-functional change (xml comments/documentation/etc)

Checklist:

  • My code follows the code style of this project.
  • I have read the CONTRIBUTING document.
  • My branch follows the naming convention bug-<issue#>-<description> or feature-<issue#>-<description>

dataMappingMode: DataMappingMode.OpenInterest
);
// To reduce the transaction cost needed for rolling over contracts, we only filter the ones expiring on quarter ends.
_future.SetFilter(futureFilterUniverse =&gt; futureFilterUniverse.ExpirationCycle(new int[] { 3, 6, 9, 12 }));
Copy link
Member

Choose a reason for hiding this comment

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

Since you are trading Mapped, the filter doesn't matter. If we replace 3, 6, 9, 12 for 4, 7, 10, 11, the results are the same. In fact, we trade less if we don't use DataMappingMode.OpenInterest because the contract with the highest OI can change more than once during the quarter.

dataMappingMode: DataMappingMode.OpenInterest
);
// Select the contracts expiring within a week since they have the highest liquidity.
_future.SetFilter(futureFilterUniverse =&gt; futureFilterUniverse.Expiration(0, 7));
Copy link
Member

Choose a reason for hiding this comment

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

Same as the previous algorithm.

Copy link
Member

@AlexCatarino AlexCatarino left a comment

Choose a reason for hiding this comment

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

Please review to not use Mapped and SetFilter. it makes more sense to change the first one, and use Slice.FuturesChains. For the second, remove SetFilter.

Also, keep an eye out for invalid orders.

@LouisSzeto
Copy link
Collaborator Author

Please review to not use Mapped and SetFilter. it makes more sense to change the first one, and use Slice.FuturesChains. For the second, remove SetFilter.

Also, keep an eye out for invalid orders.

I think I shall keep SetFilter? Since the page is for Future universes

@AlexCatarino
Copy link
Member

For the Bollinger Band example, we can trade the Mapped contract without adding the SetFilter. Or we can add SetFilter but add a comment saying it is unnecessary since we will trade the Mapped contract.

@LouisSzeto
Copy link
Collaborator Author

For the Bollinger Band example, we can trade the Mapped contract without adding the SetFilter. Or we can add SetFilter but add a comment saying it is unnecessary since we will trade the Mapped contract.

I modified the example to check from the FutureChain, now it should limit to 7-day expiring contracts.

@AlexCatarino AlexCatarino merged commit 1446853 into master Feb 4, 2025
@AlexCatarino AlexCatarino deleted the refactor-futures-universe-example branch February 4, 2025 23:59
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

Successfully merging this pull request may close these issues.

2 participants