Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,6 @@
venv/
tax-reports
tax-reports.old
# Ignore other files
*.pyc
.DS_Store
11 changes: 11 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"python.testing.unittestArgs": [
"-v",
"-s",
"./tests",
"-p",
"*_test.py"
],
"python.testing.unittestEnabled": true,
"python.testing.pytestEnabled": false
}
19 changes: 19 additions & 0 deletions tastytradehelper.py
Original file line number Diff line number Diff line change
@@ -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)
17 changes: 17 additions & 0 deletions tests/tastytradehelper_test.py
Original file line number Diff line number Diff line change
@@ -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"))
5 changes: 3 additions & 2 deletions tw-pnl.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import math
import datetime as pydatetime
import pandas
from tastytradehelper import TastytradeHelper

convert_currency: bool = True

Expand Down Expand Up @@ -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):
Expand Down