Back test for option

hi all
option contains PUT and CALL

how to do back test for both

for call it will be buy after that i will sell it

but for put how to do it ( if i buy contract in put how use back test to find out the profit )

also is there back test for hedge ( like if i buy two contract call and put )

as example if i use RSI and place CALL when rsi < 30 and i close the contract when rsi >50
and I place PUT contract when rsi >70 and close the contract when the rsi < 40
how to code the back test for both call and put

it is like forex selling or buying pair (usdjpy)

thank you

Do you actually have option price data, or are you trying to simulate option trades by using the underlying instrument? If you have option data, then buying a Put is no different than buying a Call... it's just a different symbol in your database. In both cases, you profit when the exit (sell) price is higher than the entry (buy) price.

thank you for your reply
how to treat sell contract as buy contract in the back test

if i use PUT and the market goes down i should have profit ( + not - in the back test report)

i do not have option price data

i have daily price only

i want to test the indicators
thank you

Speaking from experience, I will tell you that it is extremely difficult to accurately simulate option trading without having actual option price data. To answer your question, you can simply use Short and Cover instead of Buy and Sell if you want your trade to profit when the price declines.

1 Like
_SECTION_BEGIN("test sell for proift");

SetOption("InitialEquity",100000);
SetOption("MaxOpenPositions",Optimize("MaxOpen",10,10,30,5));
SetOption("MinShares",100);
RoundLotSize = 100;
SetOption("CommissionMode",1);	
SetOption("CommissionAmount",0.2);
SetTradeDelays( 0,0,0,0);


rsi14 = RSI(14);

Buy = Cross( rsi14, 20);
sell = Cross( rsi14, 70);

Short = Sell;
Cover = Buy;

_SECTION_END();

if you can help my write full back test system for me and for other

you got my idea

the idea is

buy ( CALL) contract ( or ( stock )) rsi < 20 and exit when rsi > 50

sell (PUT) contract ( or ( stock )) rsi > 70 and exit when rsi < 50

the idea is to test the instrument or strategy base on buy the stock or sell the stock

for your world above
( Speaking from experience, I will tell you that it is extremely difficult to accurately simulate option trading without having actual option price data.)

option will need many factors ( delta ,gamma , expiration date , and so on)

but when you know the direction of the stock you can place PUT or CALL

thank you for your help

and waiting for your code

is what I wrote correct

The little bit of code you posted doesn’t match your written description of your rules, so i would say that no, your code is not "correct". Writing a backtest for options trading is a complex task that's quite specific to your rules, so it's not something that I'm going to post on the forum. I suggest you do your best to implement it yourself or pay someone to help you, then post back here if you get stuck on specific problems.

There is no way to backtest a strategy if you don't have data prices for the traded instruments. Backtesting requires historical data. If you can't afford it, try to create an artificial ticker for the option you intend to trade, using an option pricing model (see for instance Black&Scholes for a start). You need one per option strike/maturity. Once you have it, you can backtest as usual. If your system is based on the price of the underlying and not the option price, use Foreign() to access the underlying eg

// decision-making part based on underlying NOT derivative
// use rules in first post
underlying = "...."; // underlying instrument of your option
R = RSIa(Foreign(underlying, "C"));
BUY = Cross(R, 30);
SELL = Cross(50, R);
// etc as usual

Good luck.
PS: don't expect realistic results as option pricing is more sophisticated than B&S in the real world.

1 Like

Guys, thanks for your comments
Interactive Broker Company with Margin
You can buy Apple, and when the stock goes up, you sell it, and here you make a profit

on the other side
You sell the Apple stock, and when the stock drops, you get rid of it, and here you make a profit

And I don't mean the option to be specific
But like currency speculation, you buy and sell
Same process with stocks
for example
When the RSI reaches 30, you buy the stock and get rid of it at 60
And the reverse process
When the indicator reaches the level of 70, a sale will take place and get rid of it at the level of 40

That's all the matter
If you need a paid programmer, what's the point of buying the Ami broker program?
What is the point of the forum?
On the other hand, developers who are capable of the Ami Broker program benefit from the free ideas on this forum, especially if they are not well versed in mathematics.

and I am a user of Ami broker but not programmers .

and please help to write the code or let it go and topic will close 3 months after the last reply

Thanks

This topic was automatically closed 100 days after the last reply. New replies are no longer allowed.