Domanda

I have installed the open source version of AlgoTrader

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

and I am working on developing new strategy 'stochF' using the Talib library.

http://ta-lib.org/

I was able to run the moving average example from AlgoTrader.

The default values for the moving average are

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;

but this is not using the Talib library and is done only with Esper.

To make the moving average work with talib I use the following code:

// 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);

Where Indicator is a variable to store the result from select talib("arguments") and Tick is the data that is using.

I have been trying to find a documentation about talib and unfortunatelly I found that there is very little available. The one that I have been using is about Python https://cryptotrader.org/talib

When I try to run the stochF like that

insert into Indicator select talib("stochF", 2.0, 3.0, 1.0, 3, 2, "Sma") as values from Tick(security.isin = underlayingIsin);

I get the following error

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

I have tried to run different Indicators for example

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

The Average True Range is running but there are no trades because it only show the range from the lowest to the highest points.

If anyone has any expirience with Talib or/and Esper and strategy development I would very much appriciate any information, links, books because I have been stuck on this for a few days and I can not find any useful things to do. Thank you very much. I would really like to develop a strategy with Talib/Esper in AlgoTrader and run it in backtest mode.

Regards

Nema

È stato utile?

Soluzione

Have a look at the AlgoTrader GenericTALibFunction javadoc

Also, try re-writing your statement like this:

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))];

Hope this helps

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top