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

Update average price in ValueBarAggregator when using bars #1927

Merged
merged 1 commit into from
Sep 11, 2024

Conversation

faysou
Copy link
Collaborator

@faysou faysou commented Sep 11, 2024

Pull Request

Modified price value to average of high low close instead of open high low close in the ValueBarAggregator when using bars as source data.
This is to avoid having the close value being used a second time in the next open value, also similarly to the VWAP price.

Type of change

  • New feature (non-breaking change which adds functionality)

How has this change been tested?

Tests have been updated to reflect the new formula.

Such syntax needed to be used in order to compare decimal numbers because of dividing by 3.

expected = Decimal("40001.11")
assert (
   aggregator.get_cumulative_value().quantize(expected, rounding=ROUND_HALF_UP) == expected
)

@@ -14,6 +14,7 @@
# -------------------------------------------------------------------------------------------------

from datetime import timedelta
from decimal import ROUND_HALF_UP
Copy link
Member

@cjdsellers cjdsellers Sep 11, 2024

Choose a reason for hiding this comment

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

I'm interested to know the thinking behind ROUND_HALF_UP vs the standard ROUND_HALF_EVEN?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I didn't even know ROUND_HALF_EVEN existed, I just asked an LLM for helping me solve the the rounding problem. I guess I used something that worked int his case and was rounding correctly.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Related https://gerrytan.wordpress.com/2014/02/25/whats-the-deal-with-half-up-and-half-even-rounding/ although it doesn't matter in this case as it's for a test, you can change to half even if you want in another commit so people can do by analogy in the future.

@cjdsellers cjdsellers merged commit 7f825ff into nautechsystems:develop Sep 11, 2024
13 checks passed
@faysou faysou deleted the value_bar_agg branch October 7, 2024 18:27
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