<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Implied Volatility &#8211; The Financial Hacker</title>
	<atom:link href="https://financial-hacker.com/tag/implied-volatility/feed/" rel="self" type="application/rss+xml" />
	<link>https://financial-hacker.com</link>
	<description>A new view on algorithmic trading</description>
	<lastBuildDate>Tue, 12 Jul 2022 10:26:22 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	

<image>
	<url>https://financial-hacker.com/wp-content/uploads/2017/07/cropped-mask-32x32.jpg</url>
	<title>Implied Volatility &#8211; The Financial Hacker</title>
	<link>https://financial-hacker.com</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>Algorithmic Options Trading 1</title>
		<link>https://financial-hacker.com/algorithmic-options-trading/</link>
					<comments>https://financial-hacker.com/algorithmic-options-trading/#comments</comments>
		
		<dc:creator><![CDATA[jcl]]></dc:creator>
		<pubDate>Thu, 26 Jan 2017 12:22:22 +0000</pubDate>
				<category><![CDATA[Introductory]]></category>
		<category><![CDATA[System Development]]></category>
		<category><![CDATA[Black-Scholes Formula]]></category>
		<category><![CDATA[Call]]></category>
		<category><![CDATA[Implied Volatility]]></category>
		<category><![CDATA[Options]]></category>
		<category><![CDATA[Put]]></category>
		<category><![CDATA[SPY]]></category>
		<guid isPermaLink="false">http://www.financial-hacker.com/?p=2198</guid>

					<description><![CDATA[Despite the many interesting features of options, private traders rarely take advantage of them (of course I&#8217;m talking here of serious options, not binary options). Maybe options are unpopular due to their reputation of being complex. Or because they are unsupported by most trading software. Or due to the price tags of the few options &#8230; <a href="https://financial-hacker.com/algorithmic-options-trading/" class="more-link">Continue reading<span class="screen-reader-text"> "Algorithmic Options Trading 1"</span></a>]]></description>
										<content:encoded><![CDATA[<p>Despite the many interesting features of options, private traders rarely take advantage of them (of course I&#8217;m talking here of serious options, not <a href="http://www.financial-hacker.com/binary-options-scam-or-opportunity/" target="_blank" rel="noopener noreferrer">binary options</a>). Maybe options are unpopular due to their reputation of being <strong>complex</strong>. Or because they are unsupported by most trading software. Or due to the <strong>price tags</strong> of the few options trading tools and of the historical data that you need for algorithmic trading. Whatever &#8211; we recently did several programming contracts for algorithmic options trading systems, and I was surprised that even simple systems seemed to produce <strong>relatively consistent profit</strong>. Especially selling options appears more lucrative than trading &#8216;conventional&#8217; instruments. This article is the first one of a mini-series about earning money with algorithmic options trading.  <span id="more-2198"></span></p>
<h3>Options 101</h3>
<p>Options are explained on many websites and in many trading books, so here&#8217;s just a quick overview. An option is a contract that gives its owner the right to buy (<strong>call</strong> option) or sell (<strong>put</strong> option) a financial asset (the <strong>underlying</strong>) at a fixed price (the <strong>strike</strong> price) at or before a fixed date (the <strong>expiry</strong> date). If you sell short (<strong>write</strong>) an option, you&#8217;re taking the other side of the trade. So you can enter a position in 4 different ways: buy a call, buy a put, sell short a call, sell short a put. And this with all possible combinations of strike prices and expiry dates.</p>
<p>The <strong>premium</strong> is the price that you pay or collect for buying or selling an option. It is far less than the price of the underlying stock. Major option markets are usually liquid, so you can anytime buy, write, or sell an option with any reasonable strike price and expiry date. If the current underlying price (the <strong>spot</strong> price) of a call option lies above the strike price, the option is <strong>in the money</strong>; otherwise it&#8217;s <strong>out of the money</strong>. The opposite is true for put options. In-the-money is good for the buyer and bad for the seller. Options in the money can be <strong>exercised</strong> and are then exchanged for the underlying at the strike price. The difference of spot and strike is the buyer&#8217;s profit and the seller&#8217;s loss. <strong>American</strong> style options can be exercised anytime, <strong>European</strong> style options only at expiration.</p>
<p>Out-of-the-money options can not be exercised, at least not at a profit. But they are not worthless, since they have still a chance to walk into the money before expiration. The <strong>value</strong> of an option depends on that chance, and can be calculated for European options from spot price, strike, expiry, riskless yield rate, dividend rate, and underlying volatility with the famous <a href="https://www.investopedia.com/terms/b/blackscholes.asp" target="_blank" rel="noopener noreferrer"><strong>Black-Scholes formula</strong></a>. This value is the basis of the option <strong>premium</strong>. The real premium might deviate slightly dependent on supply, demand, and belief in the underlying&#8217;s future price.</p>
<p>By reversing the formula with an approximation process, the volatility can be calculated from the real premium. This <strong>implied volatility</strong> is how the market expects the underlying to fluctuate in the next time. The partial derivatives of the option value are the <a href="https://en.wikipedia.org/wiki/Greeks_(finance)" target="_blank" rel="noopener noreferrer"><strong>Greeks</strong></a> (Delta, Vega &#8211; don&#8217;t know what Greek letter that&#8217;s supposed to be &#8211; and Theta). They determine in which direction, and how strong, the value will change when a market parameter changes.</p>
<p>That&#8217;s all basic info needed for trading options. By the way, it&#8217;s interesting to compare the performances of strategies from trading books. While the forex or stock trading systems described in those books are <a href="http://www.financial-hacker.com/seventeen-popular-trade-strategies-that-i-dont-really-understand/" target="_blank" rel="noopener noreferrer">mostly bunk</a> and lose already in a simple backtest, it is not so with option systems. They often win in backtests. And this even though apparently almost no book author has really backtested his system. Are options trading book authors just more intelligent than other trading book authors? Maybe, but we&#8217;ll see that there is an alternative explanation.</p>
<h3>Why trading options at all?</h3>
<p>They are more complex and more difficult to trade, and you need a Nobel prize winning formula to calculate a value that otherwise would simply be a difference of entry and exit price. Despite all this, options offer many wonderful advantages over other financial instruments:</p>
<ul style="list-style-type: square;">
<li><strong>High leverage.</strong> With $100 you can buy only a few shares, but options of several hundred shares.</li>
<li><strong>Controlled risk.</strong> A short position in a stock can wipe your account; positions in options can be clever combined to limit the risk in any desired way. And unlike a stop loss it&#8217;s a real risk limit.</li>
<li><strong>Additional dimensions.</strong> Stock profits just depend on rising or falling prices. Option profits can be achieved with rising volatility, falling volatility, prices moving in a range, out of a range, or almost any other imaginable price behavior.</li>
<li><strong>Fire and forget.</strong> Options expire, so you don&#8217;t need an algorithm for closing them (unless you want to sell or exercise them on special conditions). And you pay no exit commission for an expired option.</li>
<li><b>Seller advantage.</b> Due to the premium, options can still produce a profit to their seller even if the underlying moves in the wrong direction.</li>
</ul>
<p>Hacker ethics requires that you not just claim something, but prove it. For getting familiar with options, let&#8217;s put the last claim, the seller advantage, to the test:</p>
<pre class="prettyprint">void run() 
{
	BarPeriod = 1440;
	assetList("assetsIB");
	assetHistory("SPY",FROM_YAHOO|UNADJUSTED);
	asset("SPY");
	if(is(INITRUN)) dataLoad(1,"SPY_Options.t8",9);

	Multiplier = 100;
	contractUpdate("SPY",1,CALL|PUT);	
	int Type = ifelse(random() &gt; 0,CALL,PUT);
	contract(Type,30,priceClose());
	static int LastExpiry = 0;
	if(ContractType &amp;&amp; LastExpiry != ContractExpiry) {
		enterShort();
		LastExpiry = ContractExpiry;
	}
}</pre>
<p>This is a very simple option trading system. It randomly writes call or put options and keeps the positions open until they expire. Due to the put/call randomness it is trend agnostic. Before looking into code details, just run it in [Test] mode a couple times (you&#8217;ll need <a href="http://www.financial-hacker.com/hackers-tools-zorro-and-r/" target="_blank" rel="noopener noreferrer">Zorro</a> version 1.53 or above). You&#8217;ll notice that the result is different any time, but it is more often positive than negative, even though commission is subtracted from the profit. A typical outcome:</p>
<p><a href="http://www.financial-hacker.com/wp-content/uploads/2017/03/OptionsSellRandom_SPY.png"><img fetchpriority="high" decoding="async" class="alignnone wp-image-2270 size-full" src="http://www.financial-hacker.com/wp-content/uploads/2017/03/OptionsSellRandom_SPY.png" width="649" height="401" srcset="https://financial-hacker.com/wp-content/uploads/2017/03/OptionsSellRandom_SPY.png 649w, https://financial-hacker.com/wp-content/uploads/2017/03/OptionsSellRandom_SPY-300x185.png 300w" sizes="(max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 984px) 61vw, (max-width: 1362px) 45vw, 600px" /></a></p>
<p>You can see that most trades win, but when they lose, they lose big. Now reverse the strategy and buy the options instead of selling them: Replace <strong>enterShort()</strong> by <strong>enterLong()</strong>. Run it again a couple times (the script needs about 3 seconds for a backtest). You will now see that the result is more often negative &#8211; in fact almost any time.</p>
<p>It seems that options, at least the tested SPY contracts, indeed favor the seller. This is somewhat similar to the <a href="http://www.financial-hacker.com/get-rich-slowly/" target="_blank" rel="noopener noreferrer">positive expectancy</a> of long positions in stocks, ETFs, or index futures, but the options seller advantage is stronger and independent of the market direction. It might explain a large part of the positive results of option systems in trading books. Why are there then option buyers at all? Options are often purchased not for profit, but as an insurance against unfavorable price trends of the underlying. And why is the seller advantage not arbitraged away by the market sharks? Maybe because there&#8217;s yet not much algorithmic trading with options, and because there are anyway <a href="http://www.financial-hacker.com/build-better-strategies/" target="_blank" rel="noopener noreferrer">more whales than sharks</a> in the financial markets.</p>
<h3>Functions for options</h3>
<p>We can see that options trading and backtesting requires a couple more functions than just trading the underlying. Without options, the same random trading system would be reduced to this short script:</p>
<pre class="prettyprint">void run() 
{
	BarPeriod = 1440;
	assetList("assetsIB");
	assetHistory("SPY",FROM_YAHOO);
	asset("SPY");

	if(random() &gt; 0)
		enterLong();
	else
		enterShort();
}</pre>
<p>Options require (at least) three additional functions:</p>
<ul style="list-style-type: square;">
<li><strong>dataLoad(1,&#8221;SPY_Options.t8&#8243;,9)</strong> loads historical options data from the file <strong>&#8220;SPY_Options.t8&#8221;</strong> into a data set. Options data includes not only the ask and bid prices, but also the strike price, the expiration date, the type &#8211; put or call, American or European &#8211; of any option, and some rarely used additional data such as the open interest. Unlike historical price data, options data is usually expensive. You can purchase it from vendors such as <a href="http://www.ivolatility.com/" target="_blank" rel="noopener noreferrer">iVolatility</a>. But there&#8217;s an alternative way to get it for free, which I&#8217;ll describe below.</li>
<li><strong>contractUpdate(&#8220;SPY&#8221;,1,CALL|PUT)</strong> loads the current <strong>option chain</strong>. In backtest mode it&#8217;s loaded from the above data set, in live trading mode it&#8217;s loaded from the broker. The option chain is a list of all available option contracts of the selected underlying, with all available strike prices and all expiration dates. If you open it manually in the IB trading platform, it looks like this:</li>
</ul>
<p><a href="http://www.financial-hacker.com/wp-content/uploads/2017/03/optionchain.png"><img decoding="async" class="alignnone wp-image-2257 size-full" src="http://www.financial-hacker.com/wp-content/uploads/2017/03/optionchain.png" width="743" height="582" srcset="https://financial-hacker.com/wp-content/uploads/2017/03/optionchain.png 743w, https://financial-hacker.com/wp-content/uploads/2017/03/optionchain-300x235.png 300w" sizes="(max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 984px) 61vw, (max-width: 1362px) 45vw, 600px" /></a></p>
<p>The center column lists different strike prices and expiry dates, the right and left parts are the ask and bid prices and order book sizes for their assigned call (left) and put options (right). The prices are per share; an option contract always covers a certain number of shares, normally 100. So you can see in the list above that you&#8217;ll collect $15 premium when you write a SPY call option expiring next week (Feb 03, 2017) with a $230 strike price. If SPY won&#8217;t rise above $230 until that date, the $15 are your profit. If it rised to $230 and 10 cents and the option is exercised (happens automatically when it expires in the money), you still keep $5. But if it suddenly soared to $300 (maybe Trump announced 100-ft. walls all around the US, all paid by himself), you have to bear a $6985 loss.</p>
<p>The image displays 54 contracts, but this is only a small part of the option chain, since there are many more expiry dates and strike prices available. The SPY option chain can contain up to 10,000 different options. They all are downloaded to the PC with the above <strong>contractUpdate</strong> function, which can thus take a couple seconds to complete<strong>.</strong></p>
<ul style="list-style-type: square;">
<li><strong>contract(Type,30,priceClose())</strong> selects a particular option from the previously downloaded option chain. The type (<strong>PUT</strong> or <strong>CALL</strong>), the days until expiration (<strong>30</strong>), and the strike (<strong>priceClose()</strong> is the current price of the underlying) are enough information to select the best fitting option. Note that for getting correct strike prices in the backtest, we downloaded the underlying price data with the <strong>UNADJUSTED</strong> flag. Strike prices are always unadjusted.</li>
</ul>
<p>Once a contract is selected, the next <strong>enterLong()</strong> or <strong>enterShort()</strong> buys or sells the option at market. The <strong>if()</strong> clause checks that the contract is available and its expiry date is different to the previous one (for ensuring that only different contracts are traded). Entry, stop, or profit limits would work as usual, they now only apply to the option value, the premium, instead of the underlying price. The backtest assumes that when an option is exercised or expires in the money, the underlying is immediately sold, and the profit is booked into the buyer&#8217;s account and deducted from the seller&#8217;s account. If the option expires out of the money, the position just vanishes. So we don&#8217;t care about exiting positions in this strategy. Apart from those differences, trading options works just as trading any other financial instrument.</p>
<h3>Backtesting option strategies</h3>
<p>Here&#8217;s an easy way to get rich. Open an IB account and run a software that records the options chains and contract prices in one-minute intervals. That&#8217;s what some data vendors did in the last 5 years, and now they are dear selling their data treasures. Although you can easily pay several thousand dollars for a few year&#8217;s option chains of major stocks, I am not sure who really owns the copyright of this data &#8211; the vendor, the broker, the exchange, or the market participants? This might be a legal grey area. Anyway, you need historical data for developing options strategies, otherwise you could not backtest them.</p>
<p>Here&#8217;s a method to get it for free and without any legal issues:</p>
<pre class="prettyprint">#include &lt;contract.c&gt;

string Code = "SPY"; 
string FileName = "History\\SPY_Options.t8";
var StrikeMax[3] = { 5,25,100 }; // strike ranges
var StrikeStep[3] = { 1,5,10 }; // strike step widths
int DaysMax = 180;  // max contract life in days
var BidAskSpread = 2.5; // bid/ask spread in percent
var Dividend = 2.0; // annual dividend in percent
int Type = 0; // or EUROPEAN, or FUTURE 

/////////////////////////////////////////////////////////

CONTRACT* c;
int N = 0;

void run() 
{
	BarPeriod = 1440;
	StartDate = 2011;
	EndDate = 2017;
	LookBack = 21;
	assetList("AssetsIB");
	assetHistory(Code,FROM_YAHOO|UNADJUSTED);
	asset(Code);
	if(is(INITRUN)) {
		initRQL();
		int MaxContractsPerDay = 2*(1+2*(StrikeMax[0]/StrikeStep[0] + StrikeMax[1]/StrikeStep[1] + StrikeMax[2]/StrikeStep[2])) * (1+DaysMax/7);
		int TotalContracts = (1+EndDate-StartDate)*252*MaxContractsPerDay;
		printf("\nAllocating %d Contracts",TotalContracts);
		c = (CONTRACT*)dataNew(1,TotalContracts,9);
		N = 0;
	}

	vars Close = series(priceClose());
	var HistVolOV = VolatilityOV(20);
	var Unl = Close[0];
	var Interest = yield();

	if(!is(LOOKBACK)) {
		var Strike;
		int i, Days = 1;
		while((dow()+Days)%7 != FRIDAY) Days++;
		for(; Days &lt;= DaysMax; Days += 7)
		for(Strike = max(10,round(Unl-StrikeMax[2],StrikeStep[2])); Strike &lt;= Unl+StrikeMax[2]; Strike)
		for(i = 0; i &lt; 2; i++)
		{
			c-&gt;time = wdate();
			c-&gt;fUnl = Unl;
			c-&gt;fStrike = Strike;
			c-&gt;Type = Type | ifelse(i,PUT,CALL);
			c-&gt;Expiry = ymd(c-&gt;time+Days);
			c-&gt;fBid = contractVal(c,Unl,HistVolOV,0.01*Dividend,0.01*Interest);
			if(c-&gt;fBid &lt; 0.01) continue; // probably no liquidity
			c-&gt;fAsk = (1.0+BidAskSpread/100)*c-&gt;fBid;

			if(abs(Unl-Strike) &lt; StrikeMax[0]) Strike += StrikeStep[0];
			else if(abs(Unl-Strike) &lt; StrikeMax[1]) Strike += StrikeStep[1];
			else Strike += StrikeStep[2];
			N++; c++;
		}
	}
	
	if(is(EXITRUN)) {
		printf("\nSaving %d Records",N);
		dataSort(1);	// reverse the entry order
		dataSave(1,FileName,0,N);
		printf("\nOk!");
	}
}
</pre>
<p>This script is a bit longer than the usual Zorro scripts that I post here, so I won&#8217;t explain it in detail. It generates artificial option chains for any day from 2011-2017, and stores them in a historical data file. The option prices are calculated from the underlying price, the volatility, the current risk free interest rate, and the dividend rate of the underlying. It uses three ranges of strike prices, and expiry dates at any Friday of the next 180 days. You need <a href="http://www.financial-hacker.com/hackers-tools-zorro-and-r/" target="_blank" rel="noopener noreferrer">R</a> installed for running it, and also the <a href="https://cran.r-project.org/web/packages/RQuantLib/RQuantLib.pdf" target="_blank" rel="noopener noreferrer">RQuantlib</a> package for calculating option values. All functions are described in the Zorro manual. The <strong>yield()</strong> function returns the current yield rate of US treasury bills, and <strong>contractVal()</strong> calculates the premium by solving a differential equation with all option parameters. The source code of both functions can be found in the <strong>contract.c</strong> include file.</p>
<p>Due to the slow differential equation solver and the huge number of options, the script needs several hours to complete. Here&#8217;s a comparison of the generated data with real SPY options data:</p>
<p><a href="http://www.financial-hacker.com/wp-content/uploads/2017/03/OptionsTest7_SPY.png"><img decoding="async" class="alignnone wp-image-2278 size-full" src="http://www.financial-hacker.com/wp-content/uploads/2017/03/OptionsTest7_SPY.png" width="1099" height="568" srcset="https://financial-hacker.com/wp-content/uploads/2017/03/OptionsTest7_SPY.png 1099w, https://financial-hacker.com/wp-content/uploads/2017/03/OptionsTest7_SPY-300x155.png 300w, https://financial-hacker.com/wp-content/uploads/2017/03/OptionsTest7_SPY-768x397.png 768w, https://financial-hacker.com/wp-content/uploads/2017/03/OptionsTest7_SPY-1024x529.png 1024w" sizes="(max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 1362px) 62vw, 840px" /></a></p>
<p>The blue line are the artificial option prices, the black line are the real prices purchased from an options data vendor, both for 3-weeks SPY contracts with 10 points spot-strike distance. You can see that the prices match quite well. There are some tiny differences that might be partially random, partially caused by anomalies in supply and demand. For strategies that exploit those anomalies &#8211; that includes all strategies based on implied volatility &#8211; you&#8217;ll need real historical options prices. For option strategies that exploit only price or volatility changes of the underlying, the artificial data will most likely do. See, reading this article up to the end already saved you a couple thousand dollars.</p>
<h3>Conclusion</h3>
<ul style="list-style-type: square;">
<li>Options and option combinations can be used to create artificial financial instruments with very interesting properties.</li>
<li>Option strategies, especially options selling, are more likely to be profitable than other strategies.</li>
<li>Algorithmic option strategies are a bit, but not much more complex than strategies with other financial instruments.</li>
</ul>
<p>I&#8217;ve included all scripts in the 2017 script repository, and also a historical data set with the yield rates (otherwise you needed the Quandl bridge or Zorro S for downloading them). You&#8217;ll need Zorro 1.53 or above, which is currently available under the &#8220;Beta&#8221; link of the Zorro download page. The error message from the free Zorro version about the not supported Quandl bridge can be ignored, due to the included yield rates the script will run nevertheless.</p>
<p>In the next article we&#8217;ll look more closely into option values and into methods to combine options for limiting risk or trading arbitrary price ranges. Those combinations with funny names like &#8220;Iron Condor&#8221; or &#8220;Butterfly&#8221; are often referred to as option strategies, but they are not &#8211; they are just artificial financial instruments. How you trade them is up to the real strategy. Some simple, but consistently profitable option strategies will be the topic of the third article of this mini-series.</p>
<p style="text-align: right;"><a href="http://www.financial-hacker.com/algorithmic-options-trading-2/"><strong>=&gt; Part 2</strong></a></p>
]]></content:encoded>
					
					<wfw:commentRss>https://financial-hacker.com/algorithmic-options-trading/feed/</wfw:commentRss>
			<slash:comments>57</slash:comments>
		
		
			</item>
	</channel>
</rss>
