avion23 / tastyworksTaxes

calculates the yearly taxes for a tastyworks export
MIT License
3 stars 0 forks source link

legacy.py DATE error #1

Open flanello opened 5 days ago

flanello commented 5 days ago

Hello,

first, thanks for the convert script. Unfortunately, I get the error below.

My csv file looks like this: Date/Time,Transaction Code,Transaction Subcode,Symbol,Buy/Sell,Open/Close,Quantity,Expiration Date,Strike,Call/Put,Price,Fees,Amount,Description,Account Reference 12/29/2022 9:08 PM,Trade,Sell to Open,XLE,Sell,Open,1,02/10/2023,83,C,6.75,1.142,675,Sold 1 XLE 02/10/23 Call 83.00 @ 6.75,Individual...00

Traceback (most recent call last): File "C:\Users\micha\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\pandas\core\indexes\base.py", line 3805, in get_loc return self._engine.get_loc(casted_key) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "index.pyx", line 167, in pandas._libs.index.IndexEngine.get_loc File "index.pyx", line 196, in pandas._libs.index.IndexEngine.get_loc File "pandas\_libs\hashtable_class_helper.pxi", line 7081, in pandas._libs.hashtable.PyObjectHashTable.get_item File "pandas\_libs\hashtable_class_helper.pxi", line 7089, in pandas._libs.hashtable.PyObjectHashTable.get_item KeyError: 'Date'

The above exception was the direct cause of the following exception:

Traceback (most recent call last): File "legacy.py", line 168, in main() File "legacy.py", line 164, in main convert_csv(args.input_file, args.output_file) File "legacy.py", line 143, in convert_csv converted_df = convert_to_legacy_format(df) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "legacy.py", line 95, in convert_to_legacy_format legacy_df['Date/Time'] = df['Date'].apply(parse_date) ~~^^^^^^^^ File "C:\Users\micha\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\pandas\core\frame.py", line 4102, in getitem indexer = self.columns.get_loc(key) ^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\micha\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\pandas\core\indexes\base.py", line 3812, in get_loc raise KeyError(key) from err KeyError: 'Date'

avion23 commented 5 days ago

Hello flanello,

it tells you that it can't find the "Date" column.

It is trying to convert the new format to the legacy format. The legacy format is the one you were able to download before ~March 2024 and is accepted by this software and tastyworks-pnl.

If you look here you can see how the columns are being mapped:

NEW_TO_LEGACY_MAPPING: Dict[str, str] = {
    'Date': 'Date/Time',
    'Type': 'Transaction Code',
    'Sub Type': 'Transaction Subcode',
    'Symbol': 'Symbol',
    'Expiration Date': 'Expiration Date',
    'Strike Price': 'Strike',
    'Call or Put': 'Call/Put',
    'Average Price': 'Price',
    'Fees': 'Fees',
    'Value': 'Amount',
    'Description': 'Description',
    'Quantity': 'Quantity'
}

Which shows you in the left column how the columns in the new format are expected.

Are you absolutely sure that you downloaded the file as is in the recent days? This looks like legacy format to me

flanello commented 4 days ago

Thanks for the information. No, I´m not sure that I downladed the file in the recent days, it could be probably a legacy format. Anyhow, it is recommended to download the file from the website or the desktop application?

avion23 commented 4 days ago

If it is already in legacy format then you don't need the script. The script is a workaround because tastyworks discontinued the old format.

It should be readable by this software.

I only used the website and don't expect the desktop application to deliver different results.

If you have problems running the software you could give me an (anonymized) snippet and I'll try to run it for you

flanello commented 3 days ago

I have found out that the - in %-I in .strftime("%m/%d/%Y %-I:%M %p") does not work on my system. When I change it to .strftime("%m/%d/%Y %I:%M %p"), the script runs.

avion23 commented 3 days ago

Thanks for pointing that out. I removed the "-I" which is unsupported on windows.

Now the date format has a leading zero which shouldn't (TM) be a problem for any python software.

Were you able to run your transactions through the software?