-
Notifications
You must be signed in to change notification settings - Fork 108
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 ofx support for treasury T-Bill #187
Conversation
zhou13
commented
Feb 6, 2023
•
edited
Loading
edited
- Add ofx support for treasury T-Bill
- Workaround the issues that Fidelity OFX shows the units of treasuries 100x larger.
5bbb45c
to
def67a9
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@zhou13, thank you for identifying a real gap in ofx.py
and closing it.
beancount_import/source/ofx.py
Outdated
@@ -785,6 +786,10 @@ def get_security(unique_id: str) -> Optional[str]: | |||
return None | |||
sec = securities_map[unique_id] | |||
ticker = sec.ticker | |||
# Treasury bill and bond start with 912 | |||
if ticker.startswith("912"): | |||
# Append "T" to make it a valid ticker |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Was this meant to be prepend rather than "append"?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, fixed.
@@ -785,6 +786,10 @@ def get_security(unique_id: str) -> Optional[str]: | |||
return None | |||
sec = securities_map[unique_id] | |||
ticker = sec.ticker | |||
# Treasury bill and bond start with 912 | |||
if ticker.startswith("912"): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is the ticker of a bond always the same as its CUSIP?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is at least for Fidelity's Ofx. I don't have other OFX so I am not sure about it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can verify this is also true for vanguard treasury.
Pytest runs fine locally, not sure what happens. Also the balance change make a lot of changes to the existing tests. |
That's exactly what happens. We need to figure out if the changes are correct or not. Here is the OFX specification that describes the meaning of each field in detail. For
Meanwhile for There are two ways out: either we modify the amount, or the price. There are a number of ofx test files where
But it's not difficult to fix them, and it would result in a PR that is more general and more robust, in my opinion. We're really close here. Are you willing to get it over the finish line? |
Do you know how to reproduce the CI error locally? Currently running
on my branch give me no error (only warnings). |
Maybe you have a local file that that you forgot to check in? |
Here's a sample error:
It indicates that you changed the price, but did not modify the expected output file. Please double-check that the new price is actually correct. |
Here is what I just did:
It passes all the test. The change |
Yeah it is strange. I don't understand why the file in the PR is different from the one in the test. If nothing changes, then I suggest you revert the |
@Zburatorul I think this PR is ready to go. Previously I missed a test, which is why it fails. I checked |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A few questions
testdata/source/ofx/test_vanguard_roth_ira_matching/training_examples.json
Outdated
Show resolved
Hide resolved
@Zburatorul I have been using this branch for a while for Fidelity Treasury bill and it works well for me. I also add tolerance to workaround buggy rounding of the |
Thank you for the contribution @zhou13! |
@@ -797,6 +833,10 @@ def get_security(unique_id: str) -> Optional[str]: | |||
return None | |||
sec = securities_map[unique_id] | |||
ticker = sec.ticker | |||
# Treasury bill and bond start with 912 | |||
if ticker.startswith("912"): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FYI, this will crash if the ticker is None
, rather than printing a helpful error message as it used to.