Basic Backtest Function for Matlab

[pnl,pnlvector, sh]= backtestlongAmount(data,signal,buyprice,delay,amount$$);

This is a very basic function for backtesting a strategy in Matlab.
All you need is a vector with 1s for Buy, -1's for Sell and 0's for Hold.

To use it we need
1. A vector of prices,i.e. SPY close prices
2. Signal: A vector of  1 for BUY, -1 for SELL and 0 for HOLD
3. Buyprice: A vector of Close prices if we buy at close or Open prices if we buy at Open
4. Delay: 0 if we buy "Today" - 1 if we buy tomorrow. So to Buy Tomorrow on Open:
backtestlongAmount(data,signal,open,1,amount$$);
4. Amount :i.e., 100,000

backtestlongAmount.m

Please report any bugs or inaccuracies you find. Improvements are welcome.

This article was updated on

Related post

QUANTtrader -The Logical-Invest investment software for building and backtesting rules-based strategies

Quanttrader Logical Invest's swiss army knife

Investment software to easily create and backtest a rules-based investment strategy

QUANTtrader is a swiss-made software tool used to develop, backtest and implement rules-based strategies. It was initially developed by Frank Grossmann as his personal investment software. After having sold two companies, Frank trades for a living and his software reflects this. QuantTrader is available from Logical-Invest.com for a monthly license.

Quanttrader Logical Invest investment Software demo

Since it is built by a trader and long-time  investor rather than by a  developer. QuantTrader's main strength is in building medium to long term investment portfolios that are diverse, adaptive and can control risk. All this without writing a single line of code.