-
Notifications
You must be signed in to change notification settings - Fork 134
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add xirr and other details in gain page
- Loading branch information
1 parent
51ee391
commit 572cc14
Showing
8 changed files
with
120 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package service | ||
|
||
import ( | ||
"github.com/ChizhovVadim/xirr" | ||
"github.com/ananthakumaran/paisa/internal/model/posting" | ||
"github.com/samber/lo" | ||
"gorm.io/gorm" | ||
"time" | ||
) | ||
|
||
func XIRR(db *gorm.DB, ps []posting.Posting) float64 { | ||
today := time.Now() | ||
marketAmount := lo.Reduce(ps, func(acc float64, p posting.Posting, _ int) float64 { return acc + p.MarketAmount }, 0.0) | ||
payments := lo.Reverse(lo.Map(ps, func(p posting.Posting, _ int) xirr.Payment { | ||
if IsInterest(db, p) { | ||
return xirr.Payment{Date: p.Date, Amount: 0} | ||
} else { | ||
return xirr.Payment{Date: p.Date, Amount: -p.Amount} | ||
} | ||
})) | ||
payments = append(payments, xirr.Payment{Date: today, Amount: marketAmount}) | ||
returns, err := xirr.XIRR(payments) | ||
if err != nil { | ||
return 0 | ||
} | ||
|
||
return (returns - 1) * 100 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters