http://mikemcl.github.io/decimal.js/
// 解决javascript语言数据计算时的精度问题
function main() {
var x = -1.2
var a = Decimal.abs(x)
var b = new Decimal(x).abs()
Log(a.equals(b)) // true
var y = 2.2
var sum = Decimal.add(x, y)
Log(sum.equals(new Decimal(x).plus(y))) // true
}
function main() {
var sum = _.reduce([1, 2, 3], function(memo, num){return memo + num}, 0)
Log(sum)
}
function main(){
var records = exchange.GetRecords()
// 打印所有指标数据,在发明者量化交易平台上,JavaScript语言的策略已经集成了talib库
Log(talib.MACD(records))
Log(talib.MACD(records, 12, 26, 9))
}
动态加载JavaScript库 如果需要使用其它第三方JavaScript库,可以使用以下方式动态加载:
function main() {
// via. https://cdnjs.com/libraries
eval(HttpQuery("https://cdnjs.cloudflare.com/ajax/libs/mathjs/13.2.0/math.min.js"))
Log(math.round(math.e, 3)) // 2.718
Log(math.atan2(3, -3) / math.pi) // 0.75
Log(math.log(10000, 10)) // 4
Log(math.sqrt(-4)) // {"mathjs":"Complex","re":0,"im":2}
}