diff --git a/.gitignore b/.gitignore index 1f5aac2..7716b5d 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,6 @@ venv/ tax-reports tax-reports.old +# Ignore other files +*.pyc +.DS_Store diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..f9d949b --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,11 @@ +{ + "python.testing.unittestArgs": [ + "-v", + "-s", + "./tests", + "-p", + "*_test.py" + ], + "python.testing.unittestEnabled": true, + "python.testing.pytestEnabled": false +} \ No newline at end of file diff --git a/tastytradehelper.py b/tastytradehelper.py new file mode 100644 index 0000000..6a383d0 --- /dev/null +++ b/tastytradehelper.py @@ -0,0 +1,19 @@ +class TastytradeHelper: + CASH_SETTLED_SYMBOLS = ["SPXW", "SPX", "VIXW"] + + """ + Helper class for Tastytrade data processing. + """ + @staticmethod + def is_symbol_cash_settled(symbol: str) -> bool: + """ + Check if the given symbol is cash settled. + + Args: + symbol (str): The symbol to check. + + Returns: + bool: True if the symbol is cash settled, False otherwise. + """ + core_symbol = symbol.split()[0] + return any(core_symbol.startswith(prefix) for prefix in TastytradeHelper.CASH_SETTLED_SYMBOLS) \ No newline at end of file diff --git a/tests/tastytradehelper_test.py b/tests/tastytradehelper_test.py new file mode 100644 index 0000000..8dda64f --- /dev/null +++ b/tests/tastytradehelper_test.py @@ -0,0 +1,17 @@ +import os +import unittest + +from tastytradehelper import TastytradeHelper + +class TastytradeHelperTests(unittest.TestCase): + def setUp(self): + pass + + def test_is_cash_settled(self): + # Test with basic cash settled symbols + self.assertTrue(TastytradeHelper.is_symbol_cash_settled("SPX")) + self.assertTrue(TastytradeHelper.is_symbol_cash_settled("VIXW")) + # Test with cash settled option symbol + self.assertTrue(TastytradeHelper.is_symbol_cash_settled("SPXW 240919C05710000")) + # Test with non-cash settled symbol AAPL + self.assertFalse(TastytradeHelper.is_symbol_cash_settled("AAPL")) \ No newline at end of file diff --git a/tw-pnl.py b/tw-pnl.py index d972883..f6f57b1 100755 --- a/tw-pnl.py +++ b/tw-pnl.py @@ -37,6 +37,7 @@ import math import datetime as pydatetime import pandas +from tastytradehelper import TastytradeHelper convert_currency: bool = True @@ -1112,11 +1113,11 @@ def check(all_wk, output_summary, output_csv, output_excel, tax_output, show, ve ratio = int(ratio) #print(symbol, quantity, oldquantity, ratio) fifos_split(fifos, symbol, ratio) - elif tcode == 'Receive Deliver' and tsubcode in ('Exercise', 'Assignment') and symbol == 'SPX': + elif tcode == 'Receive Deliver' and tsubcode in ('Exercise', 'Assignment') and TastytradeHelper.is_symbol_cash_settled(symbol): # SPX Options already have a "Cash Settled Exercise/Assignment" tsubcode that handels all # trade relevant data. So we just delete this Exercise/Assignment line altogether. # XXX Add a check there is no relevant transaction data included here. - pass + continue else: asset = symbol if not isnan(expire):