sql server 2014 - Calculate stock trading position for buy and take profit in ms sql -


i'm developing trading diary. there many positions having multiple buy , take profit transactions. here's sample:

  • the initial position size 50 @20 usd
  • one week later, sell 15 @22 usd
  • another 2 weeks later sell again 15 @23 usd
  • one week later, pullback comes price buy 25 @21 usd
  • one week later, sell again 20 @23 usd
  • another 4 weeks later sell 25 shares @25 usd

one business rule following: actual p/l calculation, "last buy point" must used long have shares in place.

in case, can deduct 2 x 15 shares (330 usd + 345 usd) initial 50 shares (1k usd). after buying 25 shares (after pullback), first have deduct 20 remaining shares (460 usd) initial position (50 shares 1k usd). last sell point of 25 shares (625 usd) have use second buy point of 25 shares @21 usd (525 usd).

any appreciated.

krgds sascha


Comments

Popular posts from this blog

php - Permission denied. Laravel linux server -

google bigquery - Delta between query execution time and Java query call to finish -

python - Pandas two dataframes multiplication? -