资源加载中... loading...

内置库

发明者量化交易平台内置集成了一些常用库。

TA指标库

发明者量化的TA指标库优化了常用指标算法,支持JavaScriptPythonC++语言的策略调用。 开源TA库代码发明者量化交易平台API手册

function main(){
    // records的长度,当数据长度不足指标函数的参数计算要求时将返回无效值
    var records = exchange.GetRecords()
    var macd = TA.MACD(records)
    var atr = TA.ATR(records, 14)
    
    // 打印出最后一组指标值
    Log(macd[0][records.length-1], macd[1][records.length-1], macd[2][records.length-1])
    Log(atr[atr.length-1])
}
def main():
    r = exchange.GetRecords()
    macd = TA.MACD(r)
    atr = TA.ATR(r, 14)
    Log(macd[0][-1], macd[1][-1], macd[2][-1])
    Log(atr[-1])
void main() {
    auto r = exchange.GetRecords();
    auto macd = TA.MACD(r);
    auto atr = TA.ATR(r, 14);
    Log(macd[0][macd[0].size() - 1], macd[1][macd[1].size() - 1], macd[2][macd[2].size() - 1]);
    Log(atr[atr.size() - 1]);
}

talib指标库

以下是CCI指标调用范例代码,更多的talib指标函数可以查阅发明者量化交易平台API手册

function main() {
    var records = exchange.GetRecords()
    var cci = talib.CCI(records, 14)
    Log(cci)
}
# Python需要单独安装talib库
import talib
def main():
    records = exchange.GetRecords()
    # 14这个参数可以缺省
    cci = talib.CCI(records.High, records.Low, records.Close, 14)   
    Log(cci)
void main() {
    auto records = exchange.GetRecords();
    auto cci = talib.CCI(records, 14);
    Log(cci);
}

JavaScript库

  • 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    
    }
    
  • http://underscorejs.org/

    function main() {
      var sum = _.reduce([1, 2, 3], function(memo, num){return memo + num}, 0)
      Log(sum)
    }
    
  • http://ta-lib.org/

    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}
    }
    

C++库

  • https://nlohmann.github.io/json/

    void main() {
      json table = R"({"type": "table", "title": "持仓信息", "cols": ["列1", "列2"], "rows": [["abc", "def"], ["ABC", "support color #ff0000"]]})"_json;
      LogStatus("`" + table.dump() + "`");
      LogStatus("第一行消息\n`" + table.dump() + "`\n第三行消息");
      json arr = R"([])"_json;
      arr.push_back(table);
      arr.push_back(table);
      LogStatus("`" + arr.dump() + "`");
    
    
      table = R"({
          "type" : "table", 
          "title" : "持仓操作", 
          "cols" : ["列1", "列2", "Action"], 
          "rows" : [
              ["abc", "def", {"type": "button", "cmd": "coverAll", "name": "平仓"}]
          ] 
      })"_json;
      LogStatus("`" + table.dump() + "`", "\n`" + R"({"type": "button", "cmd": "coverAll", "name": "平仓"})"_json.dump() + "`");
    }
    
Web3 扩展API接口