robcarver17 / python-uk-trading-tax-calculator

Automatically exported from code.google.com/p/python-uk-trading-tax-calculator
29 stars 32 forks source link

Assertion Error #2

Closed emretezel closed 2 years ago

emretezel commented 2 years ago

Hi Rob,

This is a great tool. Would the code work if I only get the Activity Statement for the tax fiscal year, or do I need to get the reports going back to account opening?

I am getting the following assertion error, any help greatly appreciated.

/Users/emre/opt/anaconda3/bin/python "/Applications/PyCharm CE.app/Contents/plugins/python-ce/helpers/pydev/pydevd.py" --multiproc --qt-support=auto --client 127.0.0.1 --port 53976 --file /Users/emre/opt/python-uk-trading-tax-calculator/example.py Connected to pydev debugger (build 212.4746.96) /Users/emre/opt/python-uk-trading-tax-calculator/calculatetax.py:82: SyntaxWarning: "is not" with a literal. Did you mean "!="? if reportfile is not "the screen": /Users/emre/opt/python-uk-trading-tax-calculator/taxcalctradegroup.py:38: SyntaxWarning: "is" with a literal. Did you mean "=="? assert closingtrade.tradetype is "Close" Getting trades from /Users/emre/opt/python-uk-trading-tax-calculator/U1004320_20210405_20210405.htm Report will be written to TaxReport.txt Getting fx data Matching trades Traceback (most recent call last): File "/Applications/PyCharm CE.app/Contents/plugins/python-ce/helpers/pydev/pydevd.py", line 1483, in _exec pydev_imports.execfile(file, globals, locals) # execute the script File "/Applications/PyCharm CE.app/Contents/plugins/python-ce/helpers/pydev/_pydev_imps/_pydev_execfile.py", line 18, in execfile exec(compile(contents+"\n", file, 'exec'), glob, loc) File "/Users/emre/opt/python-uk-trading-tax-calculator/example.py", line 99, in taxcalc_dict=calculatetax(all_trades, CGTCalc=CGTCalc, reportfile=reportfile, File "/Users/emre/opt/python-uk-trading-tax-calculator/calculatetax.py", line 70, in calculatetax taxcalc_dict.allocate_dict_trades(CGTCalc) File "/Users/emre/opt/python-uk-trading-tax-calculator/taxcalcdict.py", line 44, in allocate_dict_trades [taxelement.allocate_trades(CGTcalc) for taxelement in self.values()] File "/Users/emre/opt/python-uk-trading-tax-calculator/taxcalcdict.py", line 44, in [taxelement.allocate_trades(CGTcalc) for taxelement in self.values()] File "/Users/emre/opt/python-uk-trading-tax-calculator/taxcalcdict.py", line 204, in allocate_trades taxcalcgroup=self.matchingforgroup(earliest_closing_trade, CGTcalc) File "/Users/emre/opt/python-uk-trading-tax-calculator/taxcalcdict.py", line 297, in matchingforgroup popped_trades=self.unmatched._proportionate_pop_idx(tradeidxlist, taxcalcgroup.count_unmatched()) File "/Users/emre/opt/python-uk-trading-tax-calculator/tradelist.py", line 419, in _proportionate_pop_idx assert abs(totaltopop - popped_trades.final_position())<THRESHOLD AssertionError python-BaseException

Process finished with exit code 1

emretezel commented 2 years ago

Screenshot 2022-02-15 at 23 47 58

Something going wrong trying to match open/close trades on the following Forex trades, likely a bug in next 30 days code

emretezel commented 2 years ago

I found the problem, the THRESHOLD in tradelist file is not small enough, best to set it much smaller.