ncortines / morgan-stanley-pl Goto Github PK
View Code? Open in Web Editor NEWLicense: MIT License
License: MIT License
The script Throws Error:
fetching data...
VM231:254 please ignore the "GET https://api.nbp.pl/api/exchangerates/rates/a/usd/YYYY-MM-DD/?format=json 404 (Not Found - Brak danych)" errors logged on the console by the browser - THEY ARE EXPECTED
(anonymous) @ VM231:254
(anonymous) @ VM231:270
undefined
VM231:269 ups!, TypeError: Cannot read property 'filter' of undefined
When there is no data from Morgan Stanley provided for the range of dates defined in Filter:
const PERIOD_START = '2016-01-01'
const PERIOD_END = '2016-31-12'
You can check this by going: MorganStanley (www) -> Activity (tab) -> Change Date (link) -> Previous Year (option)
Solution:
This issue is track changes in the PIT form(s)
Some user has reported these changes in form PIT-38
p.36 -> p.35
p.37 -> p.36
Sale records with txApiType
equal to "ISOT" are ignored.
They should be treated as any other sale records for tax reporting purposes.
When a sale originates from a limited order, a wrong date is used for the sale. The date when the order was placed is used. The actual sale date should be used instead.
Currently withdrawals from cash account cause the script to fail.
Need to fix the script to ignore cash withdrawals.
I know that for 2018 we no longer have to pay income tax for stock vesting (capital gains tax after selling), but what about dividends?
I mean - the difference between US (15%) and Poland (19%) that resulted in the laughably small tax in most cases (couple gr for starters). I think the new law about vesting doesn't say anything in that regard.
In order to avoid third-party libraries, services, CORS, etc., the currency exchange rates need to be hardcoded inside the script
Moreover npb.pl's API does not support CORS
To resolve this limitation the best solution would be to deploy a local service on the client machine which would fetch the rates on the fly
The main script would still be executed from the Console as it is now but, instead of having a set currency exchange rates hardcoded, it would be able to fetch any exchange rate on demand via REST on http://localhost:{port-number}/{currency-date}
For convenience, this service could be distributed as a NPM package
A less transparent and expensive solution would involve hosting this service
The Releases value is always 0.
This seems to be due to an internal API change.
In the output csv file, the following label is wrong as of 2018:
total profit pln (PIT/ZG p, 31):
Instead it should say:
total profit pln (PIT/ZG p, 32):
This issue was introduced with the fix for #5
As the transaction type was changed from "Release" to "Release Shared" the script does not calculate correctly income in situations when there are shares which are withheld to cover the tax. In that case "Release" means all shares, and "Release Shared" means net shares released after taxation. I think (not sure about that) for tax purpose we need the full amount which is "Release", not "Release Shared".
It seems like new tax law changes are being introduced in 2019.
From now on, the tax calculation will be simplified since we will only pay for shares sold in a given year (we will not longer pay for the fact we got them).
Questions to be answered:
The script seems to handle dates for dividends improperly in my case, but works ok for share releases.
I have the following dividends for 2017:
However, they are being reported by the script as:
This results in the exchange rates being checked for improper days, which results in wrong PLN amounts.
What is more, the JSON from morgan stanley seems to be ok, e.g. for the second one:
{
"salePrice": "$61.1626",
"uniqueRowId": "2",
(...)
"transTypeForUIRef": "Dividend Reinvested",
"orderDate": "01/01/1900",
(...)
"tradeDate": "07/18/2017",
(...)
"transactionType": "Dividend Reinvested",
"uniqueProductType": "RESTRICTED_STOCK",
"segmentIdAvailable": true
},
For some reason, some people don't have "Release" records, only "Released Shared" records. I guess most people have both records generated when releases are vested.
Since both records seem to have the same date and value, it is safe to default to use "Released Shared" instead of "Release" records
By default, the script goes up to 3 days back on time to find the exchange rate.
However, in 2017 there was 3 days period (easter) in which there were no exchange rates published.
Solution is to change 3
to 4
for the retry count.
The service base URL has recently changed from https://stockplan.morganstanley.com to https://atwork.morganstanley.com.
Turns out the old base URL was hardcoded in one place, so let's fixed that.
The script currently says:
total dividend 19% tax pln (PIT-36 p. 387)
total dividend 15% (*) tax withhold (PIT-36 p. 389)
I believe it should say 413 and 415 respectively, right now (but I'm just guessing based on some discussion and screenshots from last year and matching the fields on that screenshot so better double-check these field numbers yourself)
Hi @ncortines I tried running the script for 2020 tax year, and I had to change boolean compounds order at the beginning of processSaleDetails
to:
const saleDateString = sale.withdrawalDate || sale.order.uniqueFillDate
return getExchangeRate(new Date(saleDateString))
.then(sellExchangeRate => {
const longTermCostTransactions = (sale.costBasis && sale.costBasis.longTerm && sale.costBasis.longTerm.rows) || []
const shortTermCostTransactions = (sale.costBasis && sale.costBasis.shortTerm && sale.costBasis.shortTerm.rows) || []
because sale.order
arrived undefined, and so did sale.costBasis
. Not sure why.
Also, I'm getting Uncaught (in promise) TypeError: can't convert undefined to object
in stringifyList
. The stringified data
is as follows:
0: "sales summary:"
"1.0.date": "2020-08-06"
"1.0.settlement date": "2020-08-10"
"1.0.quantity": "0.00"
"1.0.exchange rate": "3.71"
"1.0.earnings usd": "0.00"
"1.0.earnings pln": "0.00"
"1.0.cost pln": "0.00"
"1.0.fees usd": "50.05"
"1.0.fees pln": "185.90"
"1.0.cost + fees pln": "185.90"
2: "total earnings pln (PIT-38 p. 22): 0.00"
3: "total earnings cost (with fees) pln (PIT-38 p. 23): 666.66"
4: "total profit pln (PIT/ZG p. 32): -666.66"
5: "breakdown of sale from 2020-08-06:"
7: "dividends summary:"
"8.0.date": "2020-07-22"
"8.0.exchange rate": "3.88"
"8.0.amount usd": "66.66"
"8.0.amount pln": "66.66"
9: "total dividend earnings pln: 66.66"
10: "total dividend 19% tax pln (PIT-38 p. 45): 66.66"
11: "total dividend 15% (*) tax withhold (PIT-38 p. 46): 66.66"
12: "(*) Assuming you filled in W-8BEN. Otherwise adjust this number"
I changed some sensitive data to "666"/"66", but what's also interesting is that the "total profit pln" field has a negative value.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.