Backtesting Code for Algorithmic Trading Strategy

버전 1.0.0.0 (395 KB) 작성자: Moeti Ncube
Code to Backtest trading strategy
다운로드 수: 5K
업데이트 날짜: 2010/12/17

라이선스 보기

%Author: Moeti Ncube
%This is code that can be used to backtest a trading strategy. The example strategy used was partially used in the development of a medium-frequency algorithmic trading strategy; this is a some of the backtesting coding we use to analyze tick data.

This code can be used to backtest a trading strategy for a time series that has the price vector in the first column and trading indicator in
second column. I will be using NG futures contracts for trading and will track pnl in terms of ticks (NG trades in ticks, so .001 ticks on ICE would be about $70/contract, $10/contract on NYMEX)

Over 17 days this strategy on this dataset would make about $1060 on NYMEX, or $7427 on ICE.

Data is stored in the first column and a (proprietery) indicator, that basically tracks the speed of market, is stored in second column.

%This code can be adjusted to incorporate another dataset/indicator as long as it assumes the basic strategy outline I will describe here. This is actually a simplification of my real strategy. For example, my real Buy/Sell indicator updates to be vt=max(v1,....vt-1) whereas here I make it static.

%Buy/Sell Indicator:
Whenever the indicator is less than value "v1", you buy one contract at the current price in market. Whenever indicater is greater than value "v1' you sell one contract at
current price in market.

%Profit Target:
%If the weighted average long/short position is "pt" ticks in the money you close out your position, make "pt" and strategy starts over from current price/ind.

%Stop Loss:
If the weighted average long/short position is "st" ticks out of the money, your strategy depends on you double down indicator "dd", If dd=0, you take the loss the first time this happens and strategy starts over. If dd=1, you add 1 contract to your long/short postion and obtain a new weighted average long/short price. Now, If your new long/short position becomes "pt" ticks in the money you double your profit to "2*pt", however if it becomes "st" ticks out of the money, you double your losses to "2*st"; Unless dd=2, in which once again you would buy another contract for potential "3*pt" gain or "3*st" loss.

%val(d,:) (matrix)
Here I use intraday data from 17 days in the market, val provides output from each day of the [pnl,percent profitability, sharpe ratio, number of trades]

%dtrades{d}
Here I track the profit or loss realized on each trade on a given day 'd'

인용 양식

Moeti Ncube (2024). Backtesting Code for Algorithmic Trading Strategy (https://www.mathworks.com/matlabcentral/fileexchange/29762-backtesting-code-for-algorithmic-trading-strategy), MATLAB Central File Exchange. 검색됨 .

MATLAB 릴리스 호환 정보
개발 환경: R2009b
모든 릴리스와 호환
플랫폼 호환성
Windows macOS Linux
카테고리
Help CenterMATLAB Answers에서 Transaction Cost Analysis에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!
버전 게시됨 릴리스 정보
1.0.0.0