tag:infinitekind.tenderapp.com,2009-01-14:/discussions/problems/60477-a-python-script-to-setup-fifo-cost-basisInfinite Kind: Discussion 2020-07-27T17:30:22Ztag:infinitekind.tenderapp.com,2009-01-14:Comment/482553722020-04-20T10:23:08Z2020-04-20T10:23:08ZA Python Script to Setup FIFO Cost Basis<div><p>Hi Don,</p>
<p>I'm sorry to say that we don't expose a nice API for this yet, but you can update the stored cost basis by storing the allocated buys manually by setting the "cost_basis" parameter on each sell transaction:</p>
<pre>
<code>String buys = "";
for( buy : buyAllocations) {
buys += buy.txnID + ":" + buy.allocatedUnits +";";
}
sellTxn.setParameter("cost_basis", buys);</code>
</pre>
<p>the txnID should be the UUID for the buy transaction and the allocatedUnits is the long value of the number of units allocated in the buy, so if a security has 4 decimal places then 40000 would be four shares.</p>
<p>Thanks!<br>
Sean</p>
<p>--<br>
Sean Reilly<br>
Developer, The Infinite Kind<br>
<a href="https://infinitekind.com">https://infinitekind.com</a></p></div>Sean Reillytag:infinitekind.tenderapp.com,2009-01-14:Comment/482553722020-04-20T18:15:10Z2020-04-20T18:15:11ZA Python Script to Setup FIFO Cost Basis<div><p>Thank you Sean!<br>
I think this gives me what I need. I'll let you know if I get it to work or run into more problems.</p>
<p>Thanks;<br>
Don</p></div>Dontag:infinitekind.tenderapp.com,2009-01-14:Comment/482553722020-04-21T20:44:17Z2020-04-21T20:44:20ZA Python Script to Setup FIFO Cost Basis<div><p>OK; I've got a script working that changes the cost basis for specified securities from Average Cost to FIFO Lot Matching including identifying the buy lots for each sale transaction. It's still a bit crude and it only works with securities with 4 decimal places but it meets my needs. I'm attaching it here in case it might help others. Use it at your own risk.</p>
<p>Thanks again Sean for your help!</p>
<p>Don</p></div>Dontag:infinitekind.tenderapp.com,2009-01-14:Comment/482553722020-04-27T17:26:46Z2020-04-27T17:26:48ZA Python Script to Setup FIFO Cost Basis<div><p>Here is an updated version of the script that includes a couple bug fixes.</p>
<p>Don</p></div>Don