Forum Applications Trading Strategies (Algo Quant)
news in AlgoQuant
-
jose123456789Participant 2014-12-10 at 2:04 pm
Hello: I am interested in using algo quant to backtest strategies: 1 purely based on news 2 based on news and technical indicators. In 1 I have an stream of sentiment every minute from some initial date to some final date . If the accumulated sentiment is positive before the open for AAPL I buy at the open and sell at the close. I want to start with something easy like this so I get used to algo quant for news and then to make things more complex. What could be the best way to start with this. Is there a demo that could guide me? I have seen most of the demos illustrating technical strategies. In this case the news-stream is an series of floating values and i also need the eod data from yahoo (to buy at the open and sell at the close once the sentiment triggers an order). Thanks for any help t start.
-
RyuParticipant 2014-12-11 at 1:02 pm
Hi,
Here are some concepts you need to have. First, algoquant simulator is nothing but an elaborated for-loop. It continues to feed “data” into a strategy for simulation. This example shows that the “data” to feed in are in DepthCaches, which are the prices. http://redmine.numericalmethod.com/projects/public/repository/svn-algoquant/entry/demo/src/main/java/com/numericalmethod/algoquant/model/signal/crossover/demo/DemoSMA2_010.java
Second, a strategy is nothing but a collection of event handlers. In this example, the strategy simply handles event from depth updates (namely price updates) from the simulator. http://redmine.numericalmethod.com/projects/public/repository/svn-algoquant/entry/core/src/main/java/com/numericalmethod/algoquant/model/signal/technical/crossover/sma2/SMA2Crossover.java
To achieve what you want to do, you will therefore want to
1. create a new event type, e.g., MyNews 2. create a new event handler type, e.g., MyNewsHandler 3. feed the news into the simulator 4. write a strategy than implement the handler MyNewsHandler
The idea is exactly the same as what we have done for prices as in technical indicators. Now, I admit that there will be some programming and understanding of the code involved. That’s why we open up the source code so the users can modify in however they want, hence the maximal flexibility.
Hope this helps.
-
jose123456789Participant 2015-08-25 at 9:58 pm
Hello thanks for the response,
I am coming back to the problem of adding another event type, NEWS.
The dataset could have the form:
date1, sentiment11,sentiment21,sentiment31 … date2, sentiment21,sentiment22,sentiment23 …
etc
I want to apply the same machinery as for prices: strategies with rtechnical indicators:
If acumulated sentiment greater than some threshold then buy (sell) the stock etc…
I see that basically I have to follow the same ideas developed for the type Depth and create another type MyNews as suggested above.
I see that I have to repeat the process that was done for the type Depth. I have to define NewsCaches (DepthCahes) NewsCacheFactorybyMap(DepthCaheFactorybyMap)
etc…
Is there an easier way to do it or I have to follow the same logic as for Depth and repeat simjilar classes?
when I pass the information to the simulator, can I pass simultanelously?:
.withDepthUpdates(depthCaches) .withNonDepthUpdates(newsCaches) .withNonDepthUpdates(Timer)
thanks
I
-
Ken YiuParticipant 2015-08-27 at 6:21 am
hi jose123456789,
Let me answer your questions one by one: > Is there an easier way to do it or I have to follow the same logic as for Depth and repeat simjilar classes? DepthCaches may be too comprehensive to duplicate. You may refer to TimerEvent as a simpler example. Basically, you just need to: 1. create a new event type by extending Event class (e.g., NewsEvent) and its corresponding handler by extending StrategyHandler (e.g., NewsHandler). 2. add an entry in a ChannelMessageHandlerFactories (similar to that for TimerEvent). After that, your strategy can implement NewsHandler, and your simulator can accept NewsEvent by calling
.withNonDepthUpdates(newsCaches)where newsCache is just a SequentialCache (it’s not necessary to create a new class NewsCache, but it’s up to you if you want to add features to that type of cache).
> can I pass simultanelously? .withDepthUpdates(depthCaches) .withNonDepthUpdates(newsCaches) .withNonDepthUpdates(Timer)
YES.
hope this help.
-
jose123456789Participant 2015-08-27 at 11:01 pm
Thanks for the help: I have two more: 1 Lets suppose I have one minute data but I want my strategy (simple moving average crossover, for example) to run from 10:am- 16:00, for everyday in the back testing period.
This means I want a warm up period of 30 minutes. I also want the strategy to end at 16:00: The moving average crossover strategy starts fresh everyday and ends the same day.
Is there an easy way to do it? I was thinking in using the timer in such a way that i select one minute instants from 10:00 am to 16:00 pm as firing events.
Is this the correct way to do it?.
2
In the simple Tutorial Strategy that comes as example with Algoquant ,
I created the dummy dataset that can be produced with the the BloomberFactory(just to get used to and play with algoquant)
BloombergTickDataCacheFactory data = new BloombergTickDataCacheFactory(outDir); SequentialCache loadedCache = data.newInstance(product, interval);and I apply it to the stategy DepthCaches depthCaches = new DepthCaches(product, loadedCache); // construct an instance of the strategy to simulate Strategy strategy = new TutorialStrategy(product) etc…
I get NAN results:
Since the cross over moving average strategy needs the bid and ask (buy at the ask and sell at the bid).
Why did you did not create the bid and ask (as in depth) for the class BloombergTickData
It sems you can define a type only.
The class BloombergTickDataCacheFactory creates a new instance(…) and it is not smart enough to figure out only one type was created and therefore the results return NAN
wehen I change the isntruction buffer.put(tick.time(), new Depth(product, bid, ask))
to buffer.put(tick.time(), new Depth(product, bid, 3.1416)); I could also put buffer.put(tick.time(), new Depth(product, bid, bid));
The strategy runs and plots sometihng that is ok.
I was wondering what could be the easiest way to transform BloombergTickData to a proper Depth?
(StockEOD (data from Yahoo) was transformed to Depth without problem)
thanks, ja
-
Ken YiuParticipant 2015-08-28 at 9:15 am
1. You are right. The simple way to do trading within a period of time each day is using Timers. The timers are in fact part of your strategy logic.
2. That depends on your strategy requirements. If a single price mimicking both bid and ask does not matter, you could use
new Depth(product, price, price)or justnew Depth(product, price)which will give you a Depth instance with both bid and ask of the same value. In fact, StockEOD from Yahoo give only one close price (no bid/ask), and the code creates the corresponding Depth instance withnew Depth(product, price).However, if your strategy treats bid and ask differently, the presence of bid/ask before the strategy making decision must be checked.
-
Ken YiuParticipant 2015-08-28 at 9:19 am
One more thing on Timer. Timer is also a tool for triggering a strategy to close its positions, e.g., before market close for a day trading strategy.