Example #1
0
File: wallet.go Project: vadimg/fpd
func main() {
	// Buy price of the security: $136.02
	buyPrice := fpd.New(13602000, -5)

	// Sell price of the security: $137.699
	sellPrice := fpd.New(13769900, -5)

	// Volume traded: 0.01
	volume := fpd.New(1000000, -8)

	// Trade fee percentage: 0.6%
	feePer := fpd.New(6, -3)

	buyCost := buyPrice.Mul(volume)
	buyFee := buyPrice.Mul(volume).Mul(feePer)
	sellRevenue := sellPrice.Mul(volume)
	sellFee := sellPrice.Mul(volume).Mul(feePer)

	// Initall account balance: $2.00000
	balance := fpd.New(200000, -5)

	balance = balance.Sub(buyCost)
	balance = balance.Sub(buyFee)
	balance = balance.Add(sellRevenue)
	balance = balance.Sub(sellFee)

	// Final balance
	fmt.Println(balance.FormattedString())
	// Did this trade turn into profit? :)
}
Example #2
0
File: div.go Project: vadimg/fpd
func main() {
	// 166.004
	a := fpd.New(18275499, -6)

	// 1.006
	b := fpd.New(1, -1)
	c := a.Div(b)
	d := c.Mul(fpd.New(100, 0))

	fmt.Println(c.FormattedString())
	fmt.Println(d.FormattedString())
}