news in AlgoQuant

  • This topic is empty.
Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
  • #2967

    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.



    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.

    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.

    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.


    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 …


    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)


    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?:





    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


    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?


    hope this help.


    Thanks for the help:
    I have two more:
    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?.


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

    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)



    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 just
    new 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 with new 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.


    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.

Viewing 7 posts - 1 through 7 (of 7 total)
  • You must be logged in to reply to this topic.