Tradelib is Open Source

Tradelib is my framework which I have been using for backtesting and signal generation in my futures trading. My feeling is that it might be useful to others, and I have decided to open source it.

Unfortunately, I don’t have the time at the moment to open source any strategy implemented with it, and I am also too lazy to provide a step-by-step guide for it. If you have an interesting strategy which you don’t mind sharing with the rest of the world, let me know, and I may consider implementing it and adding it to the repository as an illustrative example.

Comments

  1. Tom says:

    Hi..thanks so much for sharing

    I don’t know Java but hope you can explain a few things about how you are approach aligning data series together. For example when you are testing a portfolio of securities that have different start and ends dates, how are you currently aligning them so that they feed in to your backtester correctly? Are you using some sort of time series library in Java or are you writing one yourself? I know R and in R its simply done with merge or cbind which is very convenient.

    I am currently choosing to write one myself in a complied language but am stuck on this part.

    Thanks.
    Tom

    1. quintuitive says:

      It’s a framework, so you can code it anyway you want. What I do is to select the daily bars from the database ordering by datetime. Thus, they arrive sorted in the engine.

      1. osssman says:

        I was wondering how the speed is when you query the database for data. Are you doing so for each day during the backtest or are you importing all the data into memory before backtest from DB and then processing them day by day?

        1. quintuitive says:

          The back tests are sufficiently fast for my needs. I don’t remember seeing a back test taking more than a few seconds.

          The current implementation is to get the data for all instruments in a single query and the retrieval of the data drives the back test. This way filtering the data based on interesting instruments, start/end date, and similar operations uses the database query engine.

          In fact, writing all the backtest data to the database (PnL, trade stats, etc) is typically what dominates the execution time.

  2. singer says:

    Thanks for open sourcing your framework. Since the framework supports futures, perhaps a good strategy to illustrate many uses cases is a simple long/short futures strategy combining something like the following signals: cross-sectional momentum, time series momentum, and carry.

    – Rank each market in the universe by 12-month returns scaled by 3 month close to close volatility. There would be a weight in each market between 1 and -1 by computing the z-score of the cross-sectional return ranks. Scale weights by volatility.
    – Assign a 1 or -1 weight to each market of the sign of the past 3 month return is positive or negative, again having some weight in each market. Equal Volatility scaling.
    – Rank each market by annualized carry: [ln(PriceNear) – ln(PriceFar)] * 365 / (daysToMaturityFar – daysToMaturityNear). The z-score of the ranks is the signal. Weights scaled by volatility.
    – Average the 3 scaled weights for long/short positions in every market. Optionally choose only the top n markets with strongest signal absolute values.
    – Each market is a futures contract with some roll strategy. Forward panama would work fine with open interest switch should work fine for many markets.

    That’d be a pretty straightforward futures strategy with info from the cross section, term structure, etc. Slightly fancier enhancements would be portfolio level volatility targeting using info from the correlation matrix (or rescaling all positions after estimating portfolio vol form, say past 3 month portfolio return vol).

    1. quintuitive says:

      Thanks for sharing. Looking at it, there are a few things I’d likely change even if I decide to give it a try. The annualized carry for instance – I am using continues contracts for signals.

      My plan in terms of data for the examples was to use a few (4 to 8) markets, and provide the series for late 90s for instance. This is to avoid issues with the data providers. However, this strategy would require a much wider basket – otherwise the ranking is not that meaningful.

Leave a Reply