Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save hendrawd/07088cc387b240124b229973f412bde9 to your computer and use it in GitHub Desktop.
Save hendrawd/07088cc387b240124b229973f412bde9 to your computer and use it in GitHub Desktop.
BukaReksaAnnualPercentageFrom3MonthsCalculator.kt
fun main(args: Array<String>) {
println("This program will calculate annual interest of BukaReksa based on 3 months price")
println("Input start price")
val startPrice = readLine()!!.toDouble()
println("Input end price")
val endPrice = readLine()!!.toDouble()
println("Annual interest is ${calculateAnnualInterest(startPrice, endPrice)}")
}
/**
* Calculate Annual interest based on start price and end price after 3 months period
*/
private fun calculateAnnualInterest(startPrice: Double, endPrice: Double): String {
val percent = (endPrice - startPrice) / startPrice * 100 * 4
// both below method return the same result
// return "${DecimalFormat("#.#####").format(percent)}%"
return "${String.format("%.5f", percent)}%"
}
// hasil cek annual interest di tanggal 25 Desember 2017
// pasar uang
// 6.17311 CIMB-PRINCIPAL Bukareksa Pasar Uang
// 6.77242% Reksa Dana Syariah Mandiri Bukareksa Pasar Uang
// pendapatan tetap
// 9.96690% CIMB-Principal Total Return Bond Fund
// 20.08363% Syailendra Fixed Income Fund
// 12.30109% Mandiri Investa Dana Syariah
// campuran
// 15.95017% Kresna Flexima
// 2.05082% Cipta Syariah Balance
// saham
// 18.34288% BNP Paribas Pesona - masih terlalu fluktuatif grafiknya
// -7.40085% BNP Paribas Pesona Syariah
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment