-
-
Save ejektaflex/4fee26c0fc849b8419b30aa9ffb4071f to your computer and use it in GitHub Desktop.
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
fun main(args: Array<String>) { | |
val data = StockHelper.data("src/main/kotlin/data/STOCK.json")!! | |
// Basic example of where I would use it, creating a map of dates and changes for each day | |
// I'd then probably further display this on a chart. | |
val dailyChanges = data.map { it.date to it.change } | |
// ... Displaying of chart here | |
} |
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
[ | |
{ | |
"date": "2018/01/10", | |
"close": 0.25, | |
"volume": 500000, | |
"open": 0.5, | |
"high": 0.5, | |
"low": 0.25 | |
} | |
] |
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
import com.beust.klaxon.Klaxon | |
import java.io.File | |
object StockHelper { | |
data class StockEntry( | |
val date: String, | |
val close: Double, | |
val volume: Int, | |
val open: Double, | |
val high: Double, | |
val low: Double | |
) { | |
val change: Double | |
get() = close - open | |
val movement: Double | |
get() = high - low | |
} | |
fun data(loc: String): ArrayList<StockEntry>? { | |
return ArrayList(Klaxon().parseArray<StockEntry>(File(loc).inputStream())) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment