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

cookies - Yii2 Advanced - Share session between frontend and mainsite (duplicate of frontend for www) -

angular - password and confirm password field validation angular2 reactive forms -

php - Permission denied. Laravel linux server -