Tuesday, June 28, 2011

What you can expect to be wrong with Windows 8...

Microsoft shares are getting some attention this morning, as there appears to be an "accelerated" time table for the release of their next OS, Windows 8.

If there is one thing we can expect from Windows with this new OS, is that it will glaringly fall short of Apple's Operating Systems...again...

Why? There is really only one reason.

Microsoft has had problems in the past and will continue to have problems with handling how third-party software interacts with the Operating System.

For anyone who has extensively used Windows computers, you are familiar with the fact that "Ctrl"+"Alt"+"Delete" is a must know tool for working with Windows. You will be running your Rosetta Stone software or even Microsoft Excel and the computer will start acting up. Next thing you know, you are moving the mouse pointer around the screen and nothing is happening. You have just experienced Microsoft's Operating System "refusal to play nicely" with your innocent software. So, now you struggle with the "Task Manager" attempting to end your program and salvage what else you have running on the OS...Maybe sometimes you are able to abort the program without having to take more drastic measures, or maybe the whole OS goes down and you have to restart.

Fundamentally, this is Apple's competitive advantage over Microsoft in the OS market. When you run software on an Apple computer, the software seamlessly integrates itself with the OS. This is very convenient if your third party software starts to act up because the Apple OS force quit tool is very efficient. Much more efficient than the "Task Manager" on a Windows machine.

Will Windows 8 come out with a more efficient way of dealing with third-party software when it malfunctions? Probably not... Which is why, ultimately, they can make the User Interface as "pretty" as they want, but it's what is under the hood that really matters? While Windows has been ground-breaking in so many ways, they are still not providing the most "head-ache free" OS on the market. Thus, expect more of the same when it comes to dealing with Windows 8, which looks to me like Microsoft decided to slap some more lipstick on Windows 7's UI and call it a new operating system.

Monday, June 27, 2011

Option Volatility Part 3

Now we are ready to look at the source code. I will once again post it to the usual place making it accessible to all. However, you will notice that this is the LITE version posted. If you are interested in a more efficient and user friendly version, then you can email me and I will send the PRO version to you for $3. The main difference in the PRO version is the more user-friendly graphical user interface. It is also more dynamic than the LITE version in the sense that will handle more of the work for you. I will point out the differences as we go through the source code. Also, one major advantage and distinction between the PRO and LITE version is that the PRO version will use the Black_Scholes model to calculate a "fair" option premium. Whereas, the lite version renders a buy or sell decision purely based on volatility. Lastly, the PRO version takes Gamma and Theta into account, while the Lite version does not. This means that the Lite version produces a very theoretical option premium and represents a snapshot in time.

Firstly, here it is: optionVolatilityLite.py .

We are going to do this analysis on an August 2011 340 Call .

When the program is first run, it produces the following GUI:
Notice that the entry fields are white, while the output fields are not able to be edited (grayed out).
Step 1: Select the file containing the closing price data for the stock you wish to analyze. (Similar to the pair trading program)
Step 2: Enter in the current price of the stock. (Pro version does this for you.)
Step 3: Enter in the strike price, days to expiration, call or put, option premium, implied volatility, delta, and vega values for the option you want to analyze. All of these values will be provided to you by your brokerage.

Now we will look at how that information is entered, using an August 2011 340 Call. The GUI will now look like this after you have entered in the appropriate information:
Notice that the Implied Volatility is entered in in decimal format. It will be given to you in a format such as 26.4%, but you will enter it in as .264. Also, you must type in, exactly, "Call" or "Put". After the information is entered, we are ready to press the "Compute Results" button.

After pressing the button, the GUI will now look like this:
The program will then calculate the Historical Volatility based on the text file full of closing prices for the most recent 30 days. If that calculated value is greater than the Implied Volatility you listed, then it will render a "Buy" decision. (If less than implied volatility, a "Sell" decision) It will then calculate a one standard deviation range of stock prices based on the current implied volatility and the number of days to expiration. Next, it will calculate the necessary volatility change to hit the upper or lower bound of the standard deviation range (depending on whether you are Buying/Selling a Call/Put.) Lastly, it will calculate a new theoretical premium for hitting the optimal bound (again, lower or upper bound depending on whether you are Buying or Selling, and whether it is a Call or Put) and the profit associated with that new premium.

Please look through the source code that I linked to and email me your questions. Also, if you would like to inquire about purchasing the PRO version email me, and it will be available through pay-pal.

Thursday, June 23, 2011

Option Volatility Part 2

Today we will discuss the methodology behind a Python program to calculate historic volatility, in order to generate a decision on whether to buy or short a particular option.

We need to keep a few things in mind before we move on. REMEMBER this: We want to buy when implied volatility is low and sell when implied volatility is high. Moreover, we want to buy when implied volatility is less than historical volatility and sell when implied volatility is greater than historical volatility.

Lets go over the inputs for our model:
  1. Historical Stock Prices (a text file full of closing prices, similar to the Pair Trading Program)
  2. Current Stock Price
  3. Strike Price
  4. Days to Expiration
  5. Call or Put
  6. Listed Option Premium
  7. Listed Implied Volatility
  8. Delta Value
  9. Vega Value
What we would like as outputs:
  1. Historical/Statistical Volatility (annualized)
  2. Indicator as to whether HV/SV is greater than, less than, or equal to IV
  3. One Standard Deviation Range of Stock Prices based on IV (at expiration with standard normal curve)
  4. Volatility change needed to hit upper and lower bound of Standard Dev. Range based on Vega
  5. Corresponding new THEORETICAL option premium price after the hitting upper or lower bound of the range
  6. Profit Per Contract based on theoretical new option premium
Methods for calculating outputs:
  1. To calculate HV/SV, we will read in the last 30 data points for closing prices of a given security, we will make a list of the day to day price changes, then we will calculate the standard deviation of the list and annualize it by multiplying by the square root of 254.
  2. Now that we have a number for HV/SV, we will compare it to the IV number that was an input. If HV > IV, then we will output a  BUY decision. If HV < IV, then we will output a SELL decision.
  3. We will take the Current Stock price that was given as an input, and we will multiply it by the Implied Volatility input and the square root of the days to expiration. Lastly, we will divide this number by the square root of 254, and add and subtract this number from the current price to get our range.
  4. After we have calculated an upper bound from step three, we will take the upper bound number and subtract the current stock price from it. Once we have this difference, we will multiply it by the delta value, then divide by the Vega value to come up with the necessary change in % of volatility.
  5. This was already calculated in the last step, but the new THEORETICAL option premium is equal to the current premium plus the difference in the current stock price and upper bound of the range calculated in step 3 multiplied by Delta.
  6. Simply, the theoretical option price minus the current option premium multiplied by 100.
Note that the calculations will vary based on whether we are BUYING a put/call, or SELLING a put/call. This will be detailed in the code. I will be making a LITE and PRO version of the tool, I will provide a link to the LITE version of the code. However, the PRO version of the tool, which will contain many enhancements, will be for sale. If you are experienced option trader, then you will note that I left out Gamma which is critical for determining the "acceleration" of an option premium. The PRO version will incorporate this input into its pricing model, but for simplicities sake, the LITE version will assume more linear/basic movement.

I know this is a lot to digest...So again, if you have any question please email me at programtotrade@gmail.com

Part 3 will consist of links to the actual source code, as well as a demonstration of the tool using a current option.

Wednesday, June 22, 2011

Option Volatility Part 1

Unfortunately, for the sake of brevity, I will not be able to explain every single concept or term that I invoke within this blog. But... any questions you may have can surely be answered here: Option Volatility . In fact, I would HIGHLY recommend that anyone interested in Options read the link above.

Or... I have built a google search tool at the top right corner of the blog page that I have linked only to credible sources of information. You can type any financial term into that search bar and be confident that you will get a trustworthy answer to your question.

Continuing on, by the end of Part 3 of this series we will have a Python Program that takes in certain option inputs and calculates a fair value for the premium, which is very useful in terms of evaluating an option position. Today, I will go over some of the basic factors and inputs behind option pricing.

Before we begin, it is important to understand that the fair value of an option is using calculated using the Black-Scholes Model . Essentially, there are 5 inputs for option price calculation:
  1. Stock Price
  2. Strike Price
  3. Historical Volatility
  4. Days to Expiration
  5. Risk-free Rate of Interest
The output is the FAIR value of an option, which conveniently is not always equal to the market value.

Lets start with Volatility. There are two aspects:

Historical/Statistical Volatility - this is a value we can physically calculate based on past price movements. It basically tells us how much a security might move in the present or near future based on the price changes it experienced in the past. Note that HV/SV does not tell us anything about the direction of movement.

How HV/SV is calculated? It is calculated by taking looking at the closing prices for a given period (usually 10, 20, or 30 day period), calculating the percentage change from day to day (close to close), and finally we calculate a standard deviation of the percentage price changes and annualize it by multiplying the standard deviation by the square root of 254 (number of trading days in a year). For a detailed example calculation, reference the link at the top of the page. This method is the most basic and popular method for calculating HV/SV.

Implied Volatility - this metric is very important in determining whether an option is currently over-valued or under-valued. It is very often ignored by traders, but IV is often the reason that option traders are baffled when the underlying increases and their option premium does not. The link at the top of the post gives a great example using a tech stock in which a trader speculated a big move, however, when the big move occurred his option did not gain in value. This is because the move was already priced into the Option, which the trader would have seen if they had looked at how high the IV was.

How do we get the value for IV? Almost all online brokerages provide you with an IV number. Essentially, if you refer to the five inputs listed earlier, IV is calculated by changing the Fair Value output to a "market price" input, and then solving for volatility. It is a very math-y calculation, so I will spare you from it for now.

Actionable Result: Ultimately, we need HV/SV and IV to be different from each other. In this sense we can figure out if an option is under-valued or over-valued.

When IV > HV/SV -- Options are thought to be Over-Valued
When IV < HV/SV -- Options are thought to be Under-Valued

It is useful to define a few more Option relevant terms:

Delta - Measure of the sensitivity of an option price to the changes in the underlying's price (stock price).

Vega - Measure of the sensitivity of an option price to changes in Volatility.

It is important to have a firm grasp on both of these concepts because they can move together or against each other.

The delta value is one of the more straight-forward metrics of an Option, if the delta value is +0.5 for an Option, then for every $1 dollar that the Stock (Underlying) price increases, the option premium will increase by $0.5 dollars or 50 cents. It is simply a ratio of option price movement divided by underlying price movement.

For the Vega value, you can think of it as either betting on rising volatility ("long" volatility) or falling volatility ("short" volatility). This is very similar to being long or short on a stock, if you are "long" volatility and volatility increases then you are profiting. Conversely, if you are "short" volatility and volatility declines then you are profiting. Technically, Vega is defined as the amount that an option price changes for a 1% change in Volatility. For instance, if the Vega value for an option is -96, then if volatility increases by 1% the option price will decrease by $96 dollars.

We now have a basic understanding of all the inputs in option pricing. In Part 2, we will start to set up the methodology for our program, and how all the inputs come together to form a "decision." In Part 3, we will look at the actual source code and an execution of a decision on a particular option.

Tuesday, June 21, 2011

Greece....And Other European Countries that Don't Make Enough and Spend Too Much

Today will be the last post before I start the next series regarding Option Volatility. For the subject of Option Volatility, we will again be utilizing Python computer programming to write some programs.

Now on to the topic of why countries like Spain, Portugal, Ireland, and Greece are in the mess that they are.

1. Slow Growth Rates

 Note that Spain, Ireland, Greece, and Portugal are all sitting well below average in growth rates. This is an alarming statistic, unless they can control their spending by an equal or greater percentage as their declining growth rate. (UNLIKELY!)

2. High Unemployment Percentages
Notice again the higher than average unemployment rates present in Spain, Portugal, Ireland, and Greece. Spain for example is hovering around 20 percent unemployment; if they continue to sustain that high of an unemployment level while also maintaining slow growth rates, then the country will implode in a similar fashion as Greece.

3. Living Beyond Their Means

Here we look at debt as a percentage of overall GDP. The countries that are in trouble, as you can see, are looking at elevated percentages of debt as compared to GDP.

These countries continue to take on more and more debt, while their growth rates stagnate and unemployment increases.

It doesn't take much more than looking at these three charts to see that, maybe -- just maybe, Greece is really just the tip of the iceberg. Hold on Europe, you are in for a rough ride.

Monday, June 20, 2011

Whats next for BlackBerry (RIMM) ??

Things could not look more grim for BlackBerry right now....They are losing market-share at an alarming rate, and they have not produced a phone or OS with any sort of WOW factor as of late. Management is a laughing stock in the sense that they have two CEO's (Seriously guys?), what else could go wrong? That depends on what is next....

What is next? I will give my opinions on the subject, then open it for comments from abroad.

Without any major innovations apparent on the horizon, RIMM 's price will continue to get hammered by traders and institutional investors alike. Why? On top of the aforementioned market share decline issue, they no longer have any sort of competitive advantage over AAPL or GOOG in the smart phone OS industry. Their once claim to fame was the Enterprise system exclusivity which is now a thing of the past. So, while RIMM's price continues to decline what could happen?

1. Will they be forced to buy-back their shares and pull themselves off the market?

2. Will they be purchased by a private-equity firm or even someone like MSFT ??

3. Will they innovate and surprise us with a new and exciting product (on their own...)?

My current vote goes to... 2. I believe that Microsoft will buy BlackBerry and finally put their hat in the smart phone arena (for real this time)!

Lets hear what you have to say!

Friday, June 17, 2011

Thoughts on an APPL 10-1 Split?

We will shift gears for a little while here while I build code for the next topic of "Option Volatility" and discuss a topic that is on a lot of traders minds...

AAPL needs to conduct a 10-1 split.....

I know this is a practice that is highly debated, so I wanted to spark some discussion here about the merits and drawbacks associated with such a move.

I found an interesting article AAPL P/E Ratio. Basically, Apple trades at a relatively low P/E ratio (~15 P/E) when compared to current growth companies like AMZN (~80 P/E) and NFLX (~70.58). Why??? AAPL consistently tops estimates and over performs on all metrics, while AMZN and NFLX rarely beat expectations.

My opinion :  AAPL is the MOST EXPENSIVE and CHEAP stock all at the same time.

It is CHEAP from almost every valuation metric (AAPL's PEG value is currently <1.... ~0.98), BUT.... it is EXPENSIVE in the sense that there is only a small market of individual investors who are willing to spend $330 dollars to get 1 share...

So how does AAPL save their distressed P/E ratio??

A 10-1 split, I would be willing to bet substantial amounts of money that if AAPL conducted a 10-1 split and moved the share price down to $33 dollars a share, that within 1 year it would be trading over $100 dollars a share....

What is their to lose?? That is where you come in.... Lets get a healthy debate going here.

Thursday, June 16, 2011

Final Part of Pair Trading Analysis Using Python 3.1!

Before I begin, here are the links to the source code itself (pairAnalysis.py) and two examples of data for closing prices of Coke and Pepsi.

Here is the source code in Python: (Make sure to open it with the Pythone IDLE)
Also, it is worth noting that every time you wish to conduct an analysis you must close out the GUI and Python terminal and re- run it to prevent overlapping data structures.

Here are the files containing the closing prices for Coke and Pepsi over the last three years:

Download these three files and save them to a directory you can remember because through the GUI created by the source code you will select the files for analysis.

So after downloading the source code and then opening the file with Python IDLE, you are now reading to run the program. You can do this simply by pressing F5.

You should now be looking at a GUI (Graphical User Interface) that looks like this:
1.  Click the top Select File button and select the KO.txt file that you downloaded. Do the same for the
Stock 2 but select the PEP.txt file.

Enter the current price of  KO in the Current Price of Stock 1 box, and enter the current price of PEP in the box below.

3. Select the number of data points you wish to analyze.

4. Set the variance increment, this is the range plus/minus the average difference that points must fall in.

5. Set the threshold percentage, this is the necessary percentage of data points that must fall within the average difference plus/minus the variance you set in the box below.

You should now be looking at something like this:
We are now ready to press the Compute Results button. After pressing the compute results button we will be looking at this screen:
Notice first off that it rendered a "Good Match" decision. Above the GUI, I included the terminal for Python with some observations that were made while going through the code. It states that the average difference in daily price is 0.598, which means that on average Pepsi closes 60 cents higher than Coke does (Because the difference is calculated as Stock2 - Stock1). The next thing we see is that 100 percent of the data points fell within the variance we set of 4. This means that 100% of the difference data points (difference in daily closing price for each of the last 25 days) fell within the range of
[0.598 - 4 , 0.598 + 4] or [-3.402 , 4.598]. Now, with a 100% result, we surpass the threshold we set of 0.7 or 70%. That is why we have a "Good Match" decision and continue on to calculate adjusted prices. After calculating adjusted prices we see that KO is undervalued and PEP is overvalued. We calculate the adjusted prices in this case by adding the average difference to the current price of
KO (65.92 + 0.598 = 66.518) and subtracting the average difference from the current price of
PEP (69 - 0.598 = 68.402). Because 66.518 (adjusted price of Coke) is less than 68.402 (adjusted price of Pepsi), we say buy Coke and short Pepsi.

Going forward..... Download as many different securities as you have time for and start conducting analysis on them! See if you find any stocks that trade in pairs that you might not expect, BECAUSE if you do not expect them to be pairs - then most people do not either. This means they are ripe for profit opportunities!! I encourage you to think outside the box, try things like comparing OIL index prices with different shipping companies or Cotton indexes with different clothing companies. Keep in mind that the tighter you set the variance and the higher you set the threshold, the more accurate the decision is. For instance, if you set a variance of 1 and a threshold of 95%, then if you get a "Good Match" indicator you can conclude strongly that they trade in a tight pair pattern.

Please leave comments if you have questions or find any interesting results!

Have a great day!

Wednesday, June 15, 2011

Part Two of Pair Trading Using Python 3.1!!

Today I am going to showcase the methodology, from a coding stand-point, we would use to determine whether two securities are good candidates for pair trading. Whereas, the next posting will show the actual source code that I wrote to do the analysis.

Step 1: We need to get the data. The analysis is worthless without having sufficient data to use. For this exercise, I pulled 3 years worth of daily closing prices from AAPL Closing Prices . Notice, this data source is freely available and located at Yahoo! Finance . Make sure you set the parameters at the top to indicate that you want daily prices, and make sure you select the same time frame for each set of data you want to compare. In this example, I pulled Jan 1, 2008 to yesterday (Jun 14, 2011). After we arrive at this web address, at the bottom of the page is a link to "Download to Spreadsheet." Select this link and now the data should be in a spreadsheet. Next, we open a blank ".txt" file and type in the Ticker Symbol for the Security you just pull data from on the top line of the file, e.g. "AAPL". Lastly, we copy the closing price column from the spreadsheet we just downloaded and paste it into the .txt file below the ticker symbol.

Step 2: After you have pulled one data set, repeat the same procedures outlined in Step 1 for the security you wish to compare with the first data set. MAKE SURE YOU SELECT THE SAME TIME FRAME! We should now have two .txt files titled with the two ticker symbols you wish to compare, for example, KO.txt and PEP.txt.

Step 3: Now that we have two data sets that represent the closing prices of two securities for a set period of time, we are ready to do some analysis. The first step in analysis is to calculate an average difference in price for the two securities during the time frame. For example, if we select a time frame of the last 50 closing prices, we want to know the difference in closing price between the two securities for every day in that 50 day window. We will store those "difference data points" in a list. Then we will calculate the average difference by taking the average of the "difference data points list." This overall average difference is going to be critical in determining whether or not the two securities represent a "good" pair.

Step 4: The next step in the analysis is to determine how many of those "difference data points" are "close" to the actual average difference. In other words, we are checking to see if the average resulted from consistent differences in price, or from wild, varying differences. This is important to know because in order to profit from price movement, we want there to be a consistent difference in price. That way, when the prices move away from this average difference, we can make "bets" on the fact that they will once again return to that average difference in price. The way we will approach this problem is by setting a "variance." We want to check how many of the "difference data points" in the list fall within the range of the "average difference" plus/minus a "variance." This will result in a simple "count" of the number of data points in the "difference data points list" that fall within the overall average difference plus/minus a variance that we set earlier.

Step 5: Now that we have this "count" value from Step 4, we will now do some more analysis to determine if that is a sufficiently large count value. Simply, we set an overall "threshold percentage" that represents the percentage of data points that need to fall within the variance range to represent a "good" pair. If the "count" value divided by the total number of data points we selected is greater than the "threshold percentage" that we established, then we say that the two securities are a "Good Match."

Step 6: Lastly, if the two securities resulted in a "Good Match" decision, then we need to do some analysis to determine which security needs to be shorted and which one needs to be bought. If the decision rendered was that they were a "Bad Match", then the analysis is done and we do nothing with that pair. In the case of a "Good Match", the logic to determine which one is a short and a buy is relatively simple. First, it is noteworthy that we are calculating the difference in data points as Security2 closing price - Security1 closing price. In other words, the first security you get data from is being subtracted from the second security you gathered data on. So, if the overall average difference is greater than or equal to 0, then that means that on average Security2's price is greater than Security1's price. With this information we are ready to create adjusted prices. If the average difference in price is greater than or equal to 0, then the adjusted price for Security1 is equal to the current price of Security1 plus the average difference between the two securities. The adjusted price for Security2 would then equal the current price of Security2 minus the average difference between the two securities. In the case that the average difference is less than or equal to 0 (meaning on average the price of Security1 is greater than Security2), we do the opposite and subtract the average difference from the current price of Security1 and add the average difference to the current price of Security2 to come up with the overall adjusted prices. Finally, if the adjusted price of Security1 is greater than Security2, that would mean that we should short Security1 and buy Security2. If the adjusted price of Security2 is greater than Security1, then we would short Security2 and buy Security1.

Summarily, we are getting the data points for two different securities. We are making a list of the difference in prices for each day. We then take the average of that list of differences. We are then calculating a percentage based on how many of those data points are close to the average difference. If the percentage is high, we would say the two securities are a good match because that means that the difference in price is usually the same between the two securities. Last, we do some math to see which one is priced too high, and we short that security and buy the other one.

Hopefully, this explanation of the methodology is sufficient for you understanding. However, if you still do not fully understand, then the next posting containing the source code should drive the point across. Do keep in mind that my Inbox is always open for questions ( progamtotrade@gmail.com ).

A preview of the agenda for upcoming posts:

Next Post: Source code for pair trading analysis

Next Series: How does the delta value for an option as well as the corresponding option premium relate to the premium of a VIX (Volatility Index) option for the same time frame? Is there a relationship? If so, what is the underlying relationship and how can it be utilized for profits?? We will explore these questions through the use of functional programming in Python 3.1!

Take Care!