Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Discover millions of ebooks, audiobooks, and so much more with a free trial

Only $11.99/month after trial. Cancel anytime.

Options and Derivatives Programming in C++20: Algorithms and Programming Techniques for the Financial Industry
Options and Derivatives Programming in C++20: Algorithms and Programming Techniques for the Financial Industry
Options and Derivatives Programming in C++20: Algorithms and Programming Techniques for the Financial Industry
Ebook564 pages4 hours

Options and Derivatives Programming in C++20: Algorithms and Programming Techniques for the Financial Industry

Rating: 0 out of 5 stars

()

Read preview

About this ebook

Master the features of C++ that are frequently used to write financial software for options and derivatives, including the STL, templates, functional programming, and numerical libraries. This book also covers new features introduced in C++20 and other recent standard releases: modules, concepts, spaceship operators, and smart pointers. 

You will explore how-to examples covering all the major tools and concepts used to build working solutions for quantitative finance. These include advanced C++ concepts as well as the basic building libraries used by modern C++ developers, such as the STL and Boost, while also leveraging knowledge of object-oriented and template-based programming.  Options and Derivatives Programming in C++ provides a great value for readers who are trying to use their current programming knowledge in order to become proficient in the style of programming used in large banks, hedge funds, and other investment institutions. The topics covered in the book are introduced in a logical and structured way and even novice programmers will be able to absorb the most important topics and competencies. 

This book is written with the goal of reaching readers who need a concise, algorithms-based book, providing basic information through well-targeted examples and ready-to-use solutions. You will be able to directly apply the concepts and sample code to some of the most common problems faced in the analysis of options and derivative contracts.

What You Will Learn

  • Discover how C++ is used in the development of solutions for options and derivatives trading in the financial industry 
  • Grasp the fundamental problems in options and derivatives trading
  • Converse intelligently about credit default swaps, Forex derivatives, and more
  • Implement valuation models and trading strategies
  • Build pricing algorithms around the Black-Sholesmodel, and also using the binomial and differential equations methods
  • Run quantitative finance algorithms using linear algebra techniques
  • Recognize and apply the most common design patterns used in options trading

Who This Book Is For

Professional developers who have some experience with the C++ language and would like to leverage that knowledge into financial software development. 

 


LanguageEnglish
PublisherApress
Release dateOct 27, 2020
ISBN9781484263150
Options and Derivatives Programming in C++20: Algorithms and Programming Techniques for the Financial Industry

Related to Options and Derivatives Programming in C++20

Related ebooks

Computers For You

View More

Related articles

Reviews for Options and Derivatives Programming in C++20

Rating: 0 out of 5 stars
0 ratings

0 ratings0 reviews

What did you think?

Tap to rate

Review must be at least 10 words

    Book preview

    Options and Derivatives Programming in C++20 - Carlos Oliveira

    © Carlos Oliveira 2020

    C. OliveiraOptions and Derivatives Programming in C++20https://doi.org/10.1007/978-1-4842-6315-0_1

    1. Options Concepts

    Carlos Oliveira¹ 

    (1)

    Seattle, WA, USA

    In the last few decades, software development has become an integral part of the financial and investment industry. Advances in trading infrastructure, as well as the need for increased volume and liquidity, have prompted financial institutions to adopt computational techniques as part of their day-to-day operations. This means that there are many opportunities for computer scientists specializing in the design and development of automated strategies for trading and analyzing stocks, options, and other financial derivatives.

    Options are among the several investment vehicles that are currently traded using automated methods, as you will learn in the following chapters. Given the mathematical structure and properties of options and related derivatives, it is possible to explore their features in a controlled way, which is ideal for the application of computational algorithms. In this book, I present many of the computational techniques currently used to develop strategies in order to trade options and other derivatives.

    An option is a standard financial contract that derives its value from an underlying asset such as common stock, foreign currency, a basket of stocks, or a commodity. Options can be used to pursue multiple economic objectives, such as hedging against large variations on the underlying asset, or speculating on the future price of a stock. This chapter presents the basic concepts of options, along with supporting definitions. These concepts will be used in the next few chapters to describe algorithms and strategies with their implementation in C++20. In this chapter, I also give an overview of the use of C++ in the financial industry and how options can be modeled using this language.

    The following concepts are explored in the next sections:

    Basic definitions: You will learn fundamental definitions about option contracts and how they are used in the investment industry.

    Fundamental option strategies: Due to their flexibility, options can be combined in a surprisingly large number of investment strategies. You will learn about some of the most common option strategies and how to model them using C++.

    Option Greeks: One of the advantages of options investing is that it promotes a very analytical view of financial decisions. Each option is defined by a set of mathematical quantities called Greeks, which reflect the properties of an option contracts at each moment in time.

    Delta hedging: One of the ways to use options is to create a hedge for some other underlying asset positions. This is called delta hedging, and it is widely used in the financial industry. You will see how this investment technique works and how it can be modeled using C++.

    Basic Definitions

    Let’s start with an overview of concepts and programming problems presented by options in the financial industry. Options are specialized trading instruments and therefore require their users to be familiar with a number of details about their operation. In this section, I introduce some basic definitions about options and their associated ideas. Before starting, take a quick look at Table 1-1 for a summary of the most commonly used concepts. These concepts are defined in more detail in the remaining parts of this section.

    Table 1-1

    Basic Concepts in Options Trading

    Options can be classified according to several criteria. The features of these options determine every aspect of how they can be used, such as the quantity of underlying assets, the strike price, and the expiration, among others. There are two main types of option contracts: calls and puts. A call is a standard contract that gives its owner the right (but not the obligation) to buy an underlying instrument at a particular price. Similarly, a put is a standard contract that gives its owner the right (but not the obligation) to sell an underlying instrument at a predetermined price.

    The strike price is the price at which the option can be exercised (i.e., the underlying can be bought or sold). For example, a call for IBM stock with strike $100 gives its owner the right to buy IBM stock at the price of $100. If the current price of IBM is greater than $100, the owner of such an option has the right to buy the stock at a price that is lower than the current price, which means that the call has a higher value as the value of IBM stock increases. This situation is exemplified in Figure 1-1. If the current price is lower than $100 at expiration, then the value of the option is zero, since there is no profit in exercising the contract. Clearly, the profit/loss calculation will depend on the price originally paid for the option and the final price at expiration.

    ../images/371837_2_En_1_Chapter/371837_2_En_1_Fig1_HTML.jpg

    Figure 1-1

    Profit chart for a call option

    As you have seen in this example, if you buy a call option your possible gain is unlimited, while your losses are limited to the value originally paid. This is advantageous when you’re trying to limit losses in a particular investment scenario. As long as you are okay with losing a limited amount of money paid for the option, you can profit from the unlimited upside potential of a call (if the underlying grows in price). Put options don’t have unlimited profit potential since the maximum gain happens when the underlying price is zero. However, they still benefit from the well-defined, limited loss vs. the possible large gains that can be incurred.

    Expiration: The expiration is the moment when the option contracts ends its validity and a final value exchange can be performed. Each option will have a particular, predefined expiration. For example, certain index-based options expire in the morning of the third Friday of the month. Most stock-based options expire in practice at the end of the third Friday of the month (although they will frequently list the Saturday as the formal expiration day). More recently, several weekly-based option contracts have been made available for some of the most traded stocks and indices. And finally, a few highly liquid trading instruments (such as S&P index funds) have expirations twice a week. Each option contracts makes it clear when expiration is due, and investors need to plan accordingly on what to do before expiration date.

    Settlement: The settlement is the agreed-on result of the option transaction at expiration, the specific time when the option contracts expires. The particular details of settlement depend on the type of underlying asset. For example, options on common stock settle at expiration day, when the owner of the option needs to decide to sell (for puts) or buy (for calls) a certain quantity of stock. For index-based options, the settlement is normally performed directly in cash, determined as the cash equivalent for a certain number of units of the index. Some options on futures may require the settlement on the underlying commodity, such as grain, oil, or sugar. Investors need to be aware of the requirement settlement for different option contracts. Trading brokerages will typically let investors know about the steps required to settle the options they’re currently holding.

    Selling options: An investor can buy or sell a call option. When doing so, it is important to understand the difference between these two scenarios. For option buyers, the goal is to profit from the possible increase (in the case of calls) or decrease (in the case of puts) in value for the underlying. For option sellers, on the other hand, the goal is to profit from the lack of movement (increase for calls or decrease for puts). So, for example, if you sell calls against a stock, the intent is to profit in the case that the stock decreases in price or stays at a price lower than the strike price. If you sell a put option, the goal is to profit when the stock increases in price or stays higher than the strike price until expiration.

    Option exercise: An option contracts can be used to buy or sell the underlying asset as dictated by the contract specification. This process of using the option to trade the underlying asset is called option exercising . If the option is a call, you can exercise it and buy the underlying asset at the specified price. If the option is a put, you can use the option to sell the underlying asset at the previously specified price. The price at which the option is exercised is defined by the contract. For example, a call option for AAPL stock with a $100 strike allows its owner to buy the stock for the strike price, independent of the current price of AAPL.

    Exercise style: Option contracts can have different exercise styles based on when exercising is allowed. There are two main types:

    American options: Can be exercised at any time until expiration. That is, the owner of the option can decide to exercise it at any moment, as long as the option has not expired.

    European options: Can be exercised only upon expiration date. This style is more common for contracts that are settled directly on cash, such as index-based options.

    An option is defined as a derivative of an underlying instrument. The underlying instrument is the asset whose price is used as the basic value for an option contracts. There is no fixed restriction on the type of asset used as the underlying for an option contracts, but in practice options tend to be defined based on openly traded securities. Examples of securities that can be used as the underlying asset for commonly traded option contracts include the following:

    Common stock: Probably the most common way to use options is to trade call or put options on common stock. In this way, you can profit largely from price changes in stocks of well-known public companies such as Apple, IBM, Walmart, and Ford.

    Indices: An index, such as the Dow Industrials or the NASDAQ 100, can be used as the underlying for an option contracts. Options based on indices are traditionally settled on cash (as explained earlier), and each unit of value corresponds to multiples of the current index value.

    Currencies: A currency, usually traded using Forex platforms, can also be used as the underlying for option contracts. Common currency pairs involving the US dollar, euro, Japanese yen, and Swiss franc are traded 24 hours a day. The related options are traded on lots of currencies, which are defined according to the relative prices of the target currencies. Expiration varies similarly to stock options.

    Commodities: Options can also be written on commodities contracts. A commodity is a common product that can be traded in large quantities, including agricultural products such as corn, coffee, and sugar; fuels such as gasoline and crude oil; and even index-based underlying assets such as the S&P 500. Options can be used to trade such commodities and trading exchanges now offer options for many of the commodity types.

    Futures: These are contracts for the future delivery of a particular asset. Many of the commodity types discussed previously are traded using future contracts, including gasoline, crude oil, sugar, coffee, and other products. The structure of future contracts is defined to simplify the trade of products that will only be available within a due period, such as next fall, for example.

    ETFs (exchange-traded funds) and ETN (exchange-traded notes): More recently, an increasing number of funds have started to trade using the same rules applicable to common stocks in standard exchanges. Such funds are responsible for maintaining a basket of assets, and their shares are traded daily on exchanges. Examples of well-known ETFs include funds that hold components of the S&P 500, sectors of the economy, and even commodities and currency.

    Options trading has traditionally been done on stock exchanges, just like other forms of stock and future trading. One of the most prominent options exchange is the Chicago Board Options Exchange (CBOE). Many other exchanges provide support and liquidity for the trading of options for many of the instruments listed here.

    The techniques described in this book are useful for options with any of these underlying instruments. Therefore, you don’t need to worry if the algorithms are applied to stock options or the futures options, as long as you consider the peculiarities of these different contracts, such as their expiration and exercise.

    Options can also be classified according to the relation between the strike price and the price of the underlying asset. There are three cases that are typically considered:

    An option is said to be out of the money(OTM) when the strike price is above the current price of the underlying asset for call options, or when the strike price is below the current price of the underlying asset for put options.

    An option is said to be at the money (ATM) when the strike price is close to the current price of the underlying asset.

    An option is said to be in the money (ITM) when the strike price is below the current price of the underlying asset, for call options, or when the strike price is above the current price of the underlying asset, for put options.

    Notice that OTM options are cheaper than a similar ATM option, since the OTM options (being away from the current price of the underlying) have a lower chance of profit than ATM options. Similarly, ATM options are cheaper than ITM options, because ATM options have less probability of making money than ITM options. Also notice that, when considering the relation between strike price and underlying price, the option price generally reflects the probability that the option will generate any profit.

    A related concept is the intrinsic value of an option. The intrinsic value is the part of the value of an option that can be derived from the difference between strike price and the price of the underlying asset. For example, consider an ITM call option for a particular stock with a strike of $100. Assume that the current price for that stock is $102. Therefore, the price of the option must include the $2 difference between the strike and the price of the underlying, since the holder of a call option can exercise it and have an immediate value of $2. Similarly, ITM put options have intrinsic value when the current price of the underlying is below the strike price, using the same reasoning.

    The break-even price is the price of the underlying on expiration at which the owner of an option will start to make a profit. The break-even price has to include not only the potential profit derived from an increase in intrinsic value but also the cost paid for the option. Therefore, for an investor to make a profit on a call option at expiration, the price of the underlying asset has to rise above the strike plus any cost paid for the option (and similarly it has to drop below the strike minus the option cost for put options). For example, if an $100 MSFT call option has a cost of $1, then the investor will have a net profit at expiration only when the price of MSFT rises above $101 (and this without considering transaction costs).

    As part of the larger picture of investing, options have assumed an important role due to their flexibility and their profit potential. As a result, new programming problems introduced by the use of options and related derivatives have come to the forefront of the investment industry, including banks, hedge funds, and other financial institutions. As you will see in the next section, C++ is the ideal language to create efficient and elegant solutions to the programming problems occurring with options- and derivatives-based investing.

    Option Greeks

    One of the characteristics of financial derivatives is the use of derived quantitative measures that can be essential in the analysis and pricing of the product. In the case of options, a few important quantitative metrics are called Greeks, because most of these measures are referred to by Greek letters. These Greek quantities correspond to the variation of option price with respect to one or more variables, such as time, volatility, or underlying price.

    The most well-known option Greek is delta . The delta of an option is defined as the amount of change in the price of an option when the underlying changes by one unit. Therefore, delta represents a rate of change of the option in relation to the change in the underlying, and it is essential to understand price variation in options. Consider, for example, an option for IBM stock that expires in 30 days. The strike price is $100, and the stock is currently trading at $100. Suppose that the price of the stock increases by $1. It is interesting to calculate the expected change in the option price. It turns out that when the underlying price is close to the strike price, the delta of a call option is close to 0.5. One can also think of this in terms of probabilities of the option getting in the money, in which case this means that the value of the option is equality probable to go up or down by the same quantity. Therefore, it makes sense that the change per unit of price will be just half of the change in the underlying asset.

    The value of delta increases as the option becomes more and more in the money. In that case, the delta gets close to one, since each dollar of change will have a larger impact in the intrinsic value of the option. Conversely, the value of delta decreases as the option becomes more and more out of the money. In that case, delta gets closer to zero, since each dollar of change will have less impact on the value of an option that is out of the money.

    The second option Greek is called gamma , and it is also related to delta. The gamma of an option is described as the rate of change of delta with a unit change in price of the underlying. As you have seen, delta changes in different ways when the option is in the money, out of the money, or at the money. But the rate of change of delta will also vary depending on other factors. For example, delta will change more quickly if the option is close to expiration, because there is so little time for a movement to happen. To see why this happens, consider the delta for an option that is 30 days before expiration and for a second option that is just one day before expiration. Delta is also dependent on time, because an option closer to expiration has less probability of change. As a result, the delta will move from zero to one more slowly if there are 30 days to go, because there is still plenty of time left for other changes. But an option with only one day left to expiration will have a delta quickly moving from close to zero to near one, since there is no time left for future changes. This is described by saying that the first option has lower gamma than the second option. Other factors such as volatility can also change an option gamma. Figure 1-2 illustrates the value of gamma for a particular option at different times before expiration.

    ../images/371837_2_En_1_Chapter/371837_2_En_1_Fig2_HTML.jpg

    Figure 1-2

    Value of gamma at different dates before expiration

    Another option Greek that is closely related to time is theta. The theta of an option is proportional to the time left to expiration, and its value decays when it gets closer to the expiration date. You can think of theta as a measure of time potential for the option. For option buyers, higher theta is a desirable feature, since buyers want more probability of changes for the options they own. On the other hand, option sellers benefit from decreased theta, so short-term options are ideal for sellers due to the lower theta.

    Finally, we have an option Greek that is not really named after a Greek letter: vega. The vega of an option measures the amount of volatility of the underlying asset that is priced into an option. The higher the volatility, the more expensive an option has to be in order to account for the increased possibility of price changes. The differential equations that define the price of an option (as you will see in future chapters) take into account this volatility. Vega can be used to determine how much relative volatility is embedded in the option price. An important use of this measure is to help option buyers and sellers determine if this implied volatility is consistent with their expectations for future changes in the price of the underlying.

    There are other option Greeks that have been used in the academic community and in some financial applications; however, they are not as widely known as the ones mentioned here. You can see a summary of the most commonly used option Greeks in Table 1-2.

    Table 1-2

    Option Greeks and Their Common Meanings

    Using C++20 for Options Programming

    C++ has unique features that make it especially useful for programming software for the financial industry. With the new standard version of the language, C++20, these advantages became even more pronounced. Over the years, developers have migrated to C++ as a practical way to meet the requirements of intensive numeric, real-time algorithms used by the investment community. When it comes to creating decision support software for fast-paced investment strategies, it is very difficult to beat the C++ programming language in the areas of performance and stability.

    While it is true that several newer programming languages are available for the implementation of financial software, very few of them provide the combination of advantages available when using C++. Let’s now look at some of the areas where C++ provides a unique advantage when compared to other programming languages that could be used to implement financial and investment software.

    Availability

    When looking for a programming language to implement investment software, one of the first concerns you need to address is the ability to run the code in a variety of computational environments. Targets for such investment software can range from small and mobile processors to large-scale parallel systems and supercomputers. Moreover, it is not uncommon to have to interact with different operating systems, including the common software platforms based on Linux, Windows, and MacOS.

    Enjoying the preview?
    Page 1 of 1