【问题标题】:Using Talib in AlgoTrader with Esper在 AlgoTrader 中使用 Talib 和 Esper
【发布时间】:2014-02-22 05:03:36
【问题描述】:

我已经安装了 AlgoTrader 的开源版本

https://code.google.com/p/algo-trader/

我正在使用 Talib 库开发新策略“stochF”。

http://ta-lib.org/

我能够从 AlgoTrader 运行移动平均线示例。

移动平均线的默认值为

insert into Indicator
select stat1.average - stat2.average as value
from Tick(security.isin = underlayingIsin).win:length(movLengthFast).stat:uni(currentValueDouble) as stat1, 
Tick(security.isin = underlayingIsin).win:length(movLengthSlow).stat:uni(currentValueDouble) as stat2
where stat2.datapoints = movLengthSlow;

但这不使用 Talib 库,仅使用 Esper 完成。

为了使移动平均线与 talib 一起使用,我使用以下代码:

// Moving Average using of esper built in functions
@Name('MOVING_AVERAGE')
insert into Indicator
select talib("movingAverage", currentValueDouble, movLengthFast, "Sma") - talib("movingAverage", currentValueDouble, movLengthSlow, "Sma") as value
from Tick(security.isin = underlayingIsin);

其中 Indicator 是一个变量,用于存储 select talib("arguments") 的结果,而 Tick 是正在使用的数据。

我一直在尝试查找有关 talib 的文档,但不幸的是,我发现可用的文档很少。我一直在用的是关于Python的https://cryptotrader.org/talib

当我尝试像那样运行 stochF 时

插入指标 选择 talib("stochF", 2.0, 3.0, 1.0, 3, 2, "Sma") 作为值 来自 Tick(security.isin = underlayingIsin);

我收到以下错误

1989-12-31 23:00:00,000 DEBUG RuleServiceImpl initialized service provider: BASE 
1989-12-31 23:00:00,000 DEBUG RuleServiceImpl deployed module market-data on service provider: BASE 
1989-12-31 23:00:00,000 DEBUG RuleServiceImpl deployed module current-values on service provider: BASE 
1989-12-31 23:00:00,000 DEBUG RuleServiceImpl deployed module trades on service provider: BASE 
1989-12-31 23:00:00,000 DEBUG RuleServiceImpl deployed module portfolio on service provider: BASE 
1989-12-31 23:00:00,000 DEBUG RuleServiceImpl deployed module performance on service provider: BASE 
1989-12-31 23:00:00,000 DEBUG RuleServiceImpl deployed module algo on service provider: BASE 
1989-12-31 23:00:00,000 DEBUG RuleServiceImpl deployed module ib-market-data on service provider: BASE 
1989-12-31 23:00:00,000 DEBUG RuleServiceImpl deployed module ib-trades on service provider: BASE 
1989-12-31 23:00:00,000 DEBUG RuleServiceImpl initialized service provider: MOV 
Exception in thread "main" com.algoTrader.service.SimulationServiceException: Error performing 'SimulationService.simulateWithCurrentParams()' --> com.algoTrader.service.SimulationServiceException: Error performing 'SimulationService.runByUnderlayings()' --> com.algoTrader.service.RuleServiceException: Error performing 'RuleService.deployAllModules(String strategyName)' --> com.algoTrader.service.RuleServiceException: Error performing 'RuleService.deployModule(String strategyName, String moduleName)' --> com.espertech.esper.client.deploy.DeploymentActionException: Deployment failed in module 'movMain' in module url 'module-mov-main.epl' in expression '//select talib("movingAverage", currentValueDouble...(1293 chars)' : Error validating expression: Failed to resolve property 'indicator.value' to a stream or nested property in a stream [//select talib("movingAverage", currentValueDouble, movLengthFast, "Sma") - talib("movingAverage", currentValueDouble, movLengthSlow, "Sma") as value


//select values.fastk, values.fastd
//from Indicator(values != null);


//first string in algo second in talib enum
//select talib("movingAverage", currentValueDouble, movLengthFast, "Ema") - talib("movingAverage", currentValueDouble, movLengthSlow, "Ema") as value
//select talib("trix", currentValueDouble, movLengthFast 10) as values
//select talib("atr", 3.0, 1.0, 2.0, 10) as value



//insert into Indicator
//select stat1.average - stat2.average as value
//from Tick(security.isin = underlayingIsin).win:length(movLengthFast).stat:uni(currentValueDouble) as stat1, 
//Tick(security.isin = underlayingIsin).win:length(movLengthSlow).stat:uni(currentValueDouble) as stat2
//where stat2.datapoints = movLengthSlow;

@Name('OPEN_POSITION')
@Subscriber(className='com.algoTrader.service.mov.MovServiceImpl$OpenPositionSubscriber')
select
engineStrategy.name as strategyName, 
indexTick.security.id as underlayingid,
indexTick.currentValue as underlayingSpot
from pattern [every (indexTick=Tick(security.isin=underlayingIsin) -> indicator=Indicator)]
where indicator.value > 0
and prior(1, indicator.value) <= 0]
    at com.algoTrader.service.SimulationServiceBase.simulateWithCurrentParams(SimulationServiceBase.java:246)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:309)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:183)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)
    at org.springframework.orm.hibernate3.HibernateInterceptor.invoke(HibernateInterceptor.java:111)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
    at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:110)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
    at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202)
    at com.sun.proxy.$Proxy15.simulateWithCurrentParams(Unknown Source)
    at com.algoTrader.starter.SimulationStarter.main(SimulationStarter.java:29)
Caused by: com.espertech.esper.client.deploy.DeploymentItemException: Error validating expression: Failed to resolve property 'indicator.value' to a stream or nested property in a stream [//select talib("movingAverage", currentValueDouble, movLengthFast, "Sma") - talib("movingAverage", currentValueDouble, movLengthSlow, "Sma") as value


//select values.fastk, values.fastd
//from Indicator(values != null);


//first string in algo second in talib enum
//select talib("movingAverage", currentValueDouble, movLengthFast, "Ema") - talib("movingAverage", currentValueDouble, movLengthSlow, "Ema") as value
//select talib("trix", currentValueDouble, movLengthFast 10) as values
//select talib("atr", 3.0, 1.0, 2.0, 10) as value



//insert into Indicator
//select stat1.average - stat2.average as value
//from Tick(security.isin = underlayingIsin).win:length(movLengthFast).stat:uni(currentValueDouble) as stat1, 
//Tick(security.isin = underlayingIsin).win:length(movLengthSlow).stat:uni(currentValueDouble) as stat2
//where stat2.datapoints = movLengthSlow;

@Name('OPEN_POSITION')
@Subscriber(className='com.algoTrader.service.mov.MovServiceImpl$OpenPositionSubscriber')
select
engineStrategy.name as strategyName, 
indexTick.security.id as underlayingid,
indexTick.currentValue as underlayingSpot
from pattern [every (indexTick=Tick(security.isin=underlayingIsin) -> indicator=Indicator)]
where indicator.value > 0
and prior(1, indicator.value) <= 0]
    at com.espertech.esper.core.deploy.EPDeploymentAdminImpl.deployInternal(EPDeploymentAdminImpl.java:181)
    at com.espertech.esper.core.deploy.EPDeploymentAdminImpl.deploy(EPDeploymentAdminImpl.java:97)
    at com.algoTrader.service.RuleServiceImpl.handleDeployModule(RuleServiceImpl.java:180)
    at com.algoTrader.service.RuleServiceBase.deployModule(RuleServiceBase.java:281)
    at com.algoTrader.service.RuleServiceImpl.handleDeployAllModules(RuleServiceImpl.java:196)
    at com.algoTrader.service.RuleServiceBase.deployAllModules(RuleServiceBase.java:314)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:309)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:183)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)
    at org.springframework.orm.hibernate3.HibernateInterceptor.invoke(HibernateInterceptor.java:111)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
    at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:110)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
    at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202)
    at com.sun.proxy.$Proxy17.deployAllModules(Unknown Source)
    at com.algoTrader.service.SimulationServiceImpl.handleRunByUnderlayings(SimulationServiceImpl.java:140)
    at com.algoTrader.service.SimulationServiceBase.runByUnderlayings(SimulationServiceBase.java:216)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:309)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:183)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)
    at org.springframework.orm.hibernate3.HibernateInterceptor.invoke(HibernateInterceptor.java:111)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
    at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:110)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
    at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202)
    at com.sun.proxy.$Proxy15.runByUnderlayings(Unknown Source)
    at com.algoTrader.service.SimulationServiceImpl.handleSimulateWithCurrentParams(SimulationServiceImpl.java:183)
    at com.algoTrader.service.SimulationServiceBase.simulateWithCurrentParams(SimulationServiceBase.java:242)
    ... 14 more

例如,我尝试运行不同的指标

select talib("atr", 3.0, 1.0, 2.0, 10) as value

平均真实范围正在运行,但没有交易,因为它只显示从最低点到最高点的范围。

如果有人对 Talib 或/和 Esper 以及战略开发有任何经验,我会非常感谢任何信息、链接、书籍,因为我已经在这方面停留了几天,我找不到任何有用的事情要做。非常感谢。我真的很想在 AlgoTrader 中使用 Talib/Esper 开发一个策略并在回测模式下运行它。

问候

尼玛

【问题讨论】:

    标签: java python eclipse algorithm esper


    【解决方案1】:

    看看AlgoTrader GenericTALibFunction javadoc

    另外,试着像这样重写你的陈述:

    select
    engineStrategy.name as strategyName, 
    indexTick.security.id as underlayingid,
    indexTick.currentValue as underlayingSpot
    from pattern [every (indexTick=Tick(security.isin=underlayingIsin) -> indicator=Indicator(indicator.value > 0, prior(1, indicator.value) <= 0))];
    

    希望对你有帮助

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-02-24
      • 2014-02-12
      • 1970-01-01
      • 2020-03-24
      • 2014-02-12
      • 1970-01-01
      • 1970-01-01
      • 2022-06-27
      相关资源
      最近更新 更多