# Introduction

The ORATS Backtest API is organized around REST. You can use our Backtest API to submit an option strategy to backtest going back 2007. ORATS has the most advanced backtesting engine in the industry. You can create complex option strategies that includes multi-leg, delta hedging, frequency of trades, adjustments, entry filters, and exit targets.

# Authentication

All requests must be sent with a valid Authorization header with your private token.

Get your API token here (opens new window).

If you need help with your token, email us at support@orats.com.

# Workflow

  1. Backtest by submitting JSON Payload with a POST request using endpoint https://api.orats.io/backtest/submit.

  2. Request the status of the backtest by POST or GET request using endpoint https://api.orats.io/backtest/status.

  3. If the status of the backtest is completed, you can request for the results using https://api.orats.io/backtest/results.

Alternatively, instead of polling the status of the backtest, you can set a callback url in the JSON payload data you send when you submit a backtest. The backtester will attempt to do a POST request to your callback url after the test is finished. See Setting a CallBack URL.

# Workflow Example

# Submit a Backtest using curl

curl -d "@IBM_LongCallBasic.json" -H "Authorization: your-private-token" -X POST "https://api.orats.io/backtest/submit"

# Payload Example (IBM_LongCallBasic.json file)

{
	"general": {
		"startDate": "2007-01-03",
		"endDate": "2019-04-16",
		"symbols": [{
			"symbol": "IBM",
			"weight": null,
			"signals": null
		}]
	},
	"entry": {
		"options": [{
			"ratio": 1,
			"optionType": "call",
			"leg": 1,
			"opening": {
				"dte": {
					"target": 40,
					"min": 30,
					"max": 50
				},
				"strikeSelection": {
					"type": "absDelta",
					"value": {
						"target": 0.35,
						"min": 0.25,
						"max": 0.45
					}
				}
			}
		}]
	}
}

# Response

{ 
	"backtestId" : "hxo70n0kz9v2p0sg", 
	"status": "success"
}

# Request Status of our Backtest

curl -H "Authorization: your-private-token" -X GET "https://api.orats.io/backtest/status?backtestId=hxo70n0kz9v2p0sg"

# Status Response

{
	"backtestId": "hxo70n0kz9v2p0sg",
	"status": "completed",
	"executionTime": 1.49,
	"totalWaitTime": 9.92
}

# Get Backtest Results in CSV Format

We can request for the results when the status of our backtest is completed.

curl -H "Authorization: your-private-token" -L "https://api.orats.io/backtest/results?backtestId=hxo70n0kz9v2p0sg" --output "LongCallBasicResults.zip"

Response will be a zip file.

In the zip file you will find a CSV version of the backtest results that includes 
StrategyStats.csv, StrategyTrades.csv, StrategyReturns.csv, StrategySummary, 
StockStats.csv, StockReturns.csv, and StockSummary.

We will go over the details of the results in the Results Definitions section.

# Get Backtest Results in JSON Format

You can get the results in JSON format.

curl -H "Authorization: your-private-token" -L "https://api.orats.io/backtest/results?backtestId=hxo70n0kz9v2p0sg&format=json"

Example Response

{
	"strategy": {
		"trades": [{
			"date": "2007-01-09",
			"ticker": "IBM",
			"leg": 1,
			"ratio": 1,
			"optionType": "call",
			"year": 2007,
			"month": 2,
			"strike": 105,
			"dTE": 40,
			"tradeOptPx": 0.938,
			"delta": 0.25,
			"entryStockPx": 100.07,
			"ivr": "",
			"exitDate": "2007-02-16",
			"exitStockPx": 98.99,
			"exitOptionPx": 0,
			"expirDate": "2007-02-16",
			"expirPx": 98.99,
			"profit": -94.8,
			"tradeType": "opening"
		}, {
			"date": "2007-02-16",
			"ticker": "IBM",
			"leg": 1,
			"ratio": 1,
			"optionType": "call",
			"year": 2007,
			"month": 3,
			"strike": 100,
			"dTE": 30,
			"tradeOptPx": 1.188,
			"delta": 0.44,
			"entryStockPx": 98.99,
			"ivr": "",
			"exitDate": "2007-03-16",
			"exitStockPx": 93.25,
			"exitOptionPx": 0,
			"expirDate": "2007-03-16",
			"expirPx": 93.25,
			"profit": -119.8,
			"tradeType": "opening"
		}, 
		...
		],
		"returns": [{
			"date": "2007-01-09",
			"return": -9.9930048965724e-5,
			"delta": 0.25,
			"stockPx": 75.18776,
			"totalProfit": 0,
			"totalTrades": 1
		}, {
			"date": "2007-01-10",
			"return": -0.002748076346557409,
			"delta": 0.202636,
			"stockPx": 74.30116,
			"totalProfit": -27.499999999999993,
			"totalTrades": 1
		}, {
			"date": "2007-01-11",
			"return": -0.0013790346757269914,
			"delta": 0.168502,
			"stockPx": 74.12084,
			"totalProfit": -13.8,
			"totalTrades": 1
		}, 
		...
		],
		"stats": {
			"summary": {
				"annReturn": -2.78,
				"annSharpe": -0.67,
				"maxDrawDownPct": 33.05,
				"drawDownDays": 3795,
				"pnlDollarPerTradeAvg": -39.72,
				"pnlDollarPerDayAvg": -1.08,
				"pnlPctPerTradeAvg": -0.19,
				"pnlPctPerDayAvg": -0.52,
				"strategyWinRate": 26.55,
				"daysInTradeAvg": 37,
				"totalTrades": 113,
				"totalDollarProfits": -4488.5,
				"totalPctProfits": -18.991305083670056,
				"avgCreditReceived": 209.15,
				"percentOfTimeInMarket": 96.93396226415094
			},
			"monthly": [{
				"year": 2007,
				"Jan": -0.92,
				"Feb": -1.17,
				"Mar": -0.09,
				"Apr": -1.71,
				"May": 1.15,
				"Jun": -2.87,
				"Jul": 4.15,
				"Aug": -0.47,
				"Sep": -0.62,
				"Oct": -0.98,
				"Nov": -3.11,
				"Dec": -0.94,
				"annReturn": -7.57,
				"annSharpe": -1.31
			}, {
				"year": 2008,
				"Jan": 0.36,
				"Feb": 0.76,
				"Mar": 1.37,
				"Apr": 2.63,
				"May": 2.47,
				"Jun": -5.94,
				"Jul": 3.18,
				"Aug": -2.06,
				"Sep": -1,
				"Oct": -2.51,
				"Nov": 0.45,
				"Dec": -3,
				"annReturn": -3.27,
				"annSharpe": -0.53
			},
			...
			]
		}
	},
	"stock": {
		"returns": [{
			"date": "2007-01-03",
			"return": 0,
			"stockPx": 73.08397
		}, {
			"date": "2007-01-04",
			"return": "0.0105551",
			"stockPx": 73.86538
		}, {
			"date": "2007-01-05",
			"return": "-0.0090530",
			"stockPx": 73.19668
		}, 
		...
		],
		"stats": {
			"summary": {
				"annReturn": 7.23,
				"annSharpe": 0.33,
				"maxDrawDownPct": 40.64,
				"drawDownDays": 119
			},
			"monthly": [{
				"year": 2007,
				"Jan": 2.03,
				"Feb": -6.08,
				"Mar": 1.49,
				"Apr": 8.28,
				"May": 4.7,
				"Jun": -1.16,
				"Jul": 5.23,
				"Aug": 5.84,
				"Sep": 1.01,
				"Oct": -1.26,
				"Nov": -8.96,
				"Dec": 2.92,
				"annReturn": 14.03,
				"annSharpe": 0.76
			}, {
				"year": 2008,
				"Jan": -0.37,
				"Feb": 6.8,
				"Mar": 1.26,
				"Apr": 4.89,
				"May": 7.53,
				"Jun": -8.61,
				"Jul": 7.89,
				"Aug": -4.49,
				"Sep": -3.39,
				"Oct": -21.07,
				"Nov": -11.17,
				"Dec": 3.93,
				"annReturn": -16.8,
				"annSharpe": -0.71
			},
			...
			]
		}
	}
}