Question: Is there any open-source project/library, which can act as a "local exchange" for agents (algorithms), running on the same computer?

Clarification: by "local exchange" I mean, that the agents, who have the accounts on this exchange are "algorithms", running on the same computer. That is, in this question I don't speak about creation of any exchange market for other people or companies to trade on.

To clarify I will provide a couple of use-cases and a set desirable features. In what follows, the Exchange library stays for the hypothetical library I want to find.

Use-case 1: trading system

Imagine, that you have 4 algorithms, which could manage a certain amount of money on stock exchange market and (hopefully) generating some profit. Say you have 4000 Tögrögs and you want to reduce risks by diversification: you want to give 1000 Tögrögs to each algorithm, so if one fails, the most you can loose is 1000 Tögrögs.

Imagine, you have a stock exchange broker and you opened one account with it. You don't want to open 3 more accounts (e.g. because this would be too expensive for you). Instead, you want each of 4 algorithms to have a virtual account in the Exchange library, so they could send their orders to the Exchange library, and the library would 1. check if the account contains enough money; 2. if it does, forward the orders to the exchange market; 3. cancel the buying and selling orders between the accounts, when possible.

I started by saying, that the purpose of this scheme is diversification. However, there are 3 additional benefits:

  1. Providing a unified interface to the trading algorithms: of course, you need to deal with API of the broker to submit the trades. But in the scheme above, you need to do it once by writing a gateway for the Exchange library, instead of thinking about API while implementing each of 4 algorithms.
  2. Local cancellation of orders allows for otherwise impossible trades. Imagine, for example, that algorithm A wants to pay 10.00 Tögrögs for one stock WWD of the corporation "Worldwide". However the broker has a commission of 0.10 Tögrögs, so the Exchange library obtains an order and puts the BUY order at 9.90 Tögrögs (so if the order is matched, the total amount paid will be 10.00 = 9.90 + 0.10 commission). However it puts a BUY order at the price 10.00 to the "local" market. Later on, while order was not matched, algorithm B decides to sell 1 stock WWD at 9.95. Given commission, the SELL order could be sent to the broker only at 10.05 or higher, but the order can be locally cancelled with the order of algorithm A immediately.
  3. Trades of otherwise untradeable pairs. Imagine, algorithm A decides, that one stock of WWD is worth 25 Lunar Dollars, but it is traded only in Tögrögs (with a current price of 10.00). While you don't have access to any gateway, that could exchange Tögrögs to lunar dollars, algorithm D has 30 Lunar Dollars and is happy to exchange them to 10 Tögrögs. This trade was submitted to the Exchange library, but couldn't be forwarded anywhere. Given that algorithm A decides to exchange 1 stock of WWD to 10 Tögrögs, and then exchange 10 Tögrögs to 30 Lunar Dollars by matching D's order, generating an (assumed) profit of 5 Lunar Dollars.

Use-case 2: economic hypothesis testing

Imagine, you want to observe a phenomena, that if agents follow a certain strategy, market goes through 30-year cycles. You decide to model it on your computer. You implement a simplistic model, in which there are 7 types of goods and 10000 agents, which can buy, sell, produce and consume them. What you need is a marketplace, where buyers and sellers can meet. You could use the Exchange library as such a marketplace and have 10000 accounts for the agents and no external gateways. You could then run the experiment, plot the prices and check, if the phenomena can be observed.

Desirable features

  1. Two interfaces. The library should have an interface for interaction with agents (accounts), as well as an interface for interaction with external world (gateways). There should be a possibility to have multiple accounts and multiple gateways.
  2. Local exchange. The Exchange library should implement local "marketplace", where agents could exchange goods/stocks/currencies.
  3. Flexibility of gateways. E.g. if API's of two brokers allow automatic transfer of stocks between them, there should be a way to add this procedure as a gateway.
  4. Scalability. There should be a simple way to write the algorithms for the agents in C++, as it allows for efficient complex processing of Gigabytes of data. On the other hand, one should be able to implement simple agents with small amount of code.
  5. Linux. One should be able to run the programs, written using the Exchange library on Linux, because both servers and computers, used for heavy computations, use Linux.
  6. Reliability. E.g. while a transaction can fail for objective reasons, it should never happen twice. Some transactions (e.g. transfer of funds between brokers) could take as long as a week, so the fact, that a transaction is ongoing, shouldn't prevent us from shutting down the application and starting it later on with the same state. There should be a way to recover from crashes.
  7. Async/efficiency. E.g. while waiting for a response from one gateway, the library shouldn't become unresponsive or slow down processing of unrelated transactions.

Extended question: It feels to me, that this is a very natural library to write. That's why I'm asking if anyone have done at least something similar. It feels I'm inventing a bicycle, and there even if this wasn't implemented yet, there are at least things I could start with and add my own code on top. If not, I would like to know, why, because this would probably mean, that people think differently, than I am, and may be I'm missing something. So the extended question is:

Is there something similar to the library I've described above, and if there isn't, then why?

  • $\begingroup$ I have not heard and cannot imagine such open source library exists. You would need to write it yourself which is not particularly complex, given the rather simplistic requirements you outlined. $\endgroup$
    – Matt Wolf
    Jan 17, 2014 at 2:09

1 Answer 1


There is the Hudson C++ trading simulation library on google code. Hudson is free and open-source under the GNU GPL v3. It also contains functionality for computing statistics and tools for integration with your trading strategy implementation.

From the website

Hudson calculates various statistics, including compound annualized growth rate, % winners/losers, realized drawdown, position excursion analysis, month-to-month returns, Sharpe ratio and geometric standard deviation of monthly returns. The report statistics are easily extensible by inheriting from the Report class and adding your own calculation based on recorded transactions and historical data. The trader API supports backtesting of any custom long/short trading strategy, such as portfolio backtesting of multiple symbols, pairs-trading and spread-trading strategies. For a spread trading example, check the January trader (JanTrader). This class implements a trading strategy analyzing the seasonal microcap effect that occurs around the end of the year. The Asset Allocator example (AATrader) evaluates the performance of 5 asset classes (World Equities, SP500, Commodities, US Bonds and REIT) on a monthly basis and make allocation decisions based on each index SMA.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.