Tuesday, August 2, 2011

Time to start trading again?? NOT SO FAST!!

To all my followers.... Stay out of equities for now, we have not hit the bottom yet.

The U.S. is still very much in danger of having its credit downgraded by one or more of the rating agencies. In not so many words, the measure that was passed today is PATHETIC. It does not address any of the problem children on the expense side of the U.S. government's income statement, such as MEDICARE, MEDICAID, or SOCIAL SECURITY. It is these entitlement programs that are racking up the charges on the U.S. governments "credit card", and these were the items least addressed in the proposal that passed today. What does this mean?

The picture is still very bleak for the U.S. economy and it's future. There will be an unemployment report out on Friday and be ready for some not so comforting numbers. The S&P still has at least 200 more points to drop before I would recommend broad purchasing of equities.

The indexes have pretty much been following their 200 day MA's right now, but for the most part are teetering over the edge of a cliff. A string of bad news, i.e. US downgrade, weak spending data, and weak unemployment data, could cause a breach downwards through that 200 day MA causing a "technical breakdown" in the markets.

Conclusion: Buy AFTER the breakdown, not before it.

Keep those trigger fingers at bay for now.

Monday, July 18, 2011

How to trade a possible U.S. default??

While the hard deadline for a deal is Aug. 2, the closer we get to that date without a deal the more fear will become a factor in the markets. So how do you play this "default vs. no default" scenario?

If a deal is not struck, then we know a few things will probably happen:
  • The Bond Market will be crushed.
  • Bank stocks will be crushed (for the above reason)
  • Volatility will shoot through the roof (usually an accurate measure of fear in the markets)
  • S&P and DIJA will take a hit
Based on these outcomes, there are a few steps you can take to protect your portfolio from a possible market response to the debt dilemma.
  1. Make a volatility play such as buying VXX . This is a S&P 500 VIX Futures ETN. Essentially, it is an ETN that gains in value as futures contracts on volatility become more valuable. Thus, as more and more fear of a default enters the market, there will be a premium on volatility causing this ETN to gain in value.
  2. Open up far out of the money PUT options on an S&P ETF like SPY . The option will be cheap if you go far enough out of the money and will be sure to gain value in the case of a default (as we would see a huge hit to the S&P 500.)
  3. Short bank stocks. These will be the companies most vulnerable to a bond market crash, and there will be a lot of negative trading action on banks stocks in the case of a default.

Monday, July 11, 2011

What would a Sprint iPhone do to smart phone market share?

Piper's estimates below are currently based on an "iPhone-less" Sprint:
However, what would these projections look like if Sprint and Apple were to come to a deal before the end of 2012?? Surely, the Android growth line would have to be trimmed downwards to correct for increased competition on the Sprint network. It is estimated that even from the Verizon deal, Apple gained 10% of market share on new smart phone sales. Any opinions?

Wednesday, July 6, 2011

Diversification Continued....

Below is a simple example of how you might start to think about diversification. Although it is not all encompassing, it does a good job at illustrating all the components that make up an investment decision. It shows that although you may be looking at two different stocks or bonds; they may still share many other qualities, which can hurt your goals of diversification.

Here are some examples of diversification strategies as well:

These figures barely/hardly scratch the surface of how I will attempt to quantify diversification into "levels." However, the lingo of "Conservative, Aggressive, etc.." will be relatively similar. It no longer suffices to include only the categories of "Large Cap, International, Small Cap, Bonds, and Cash" due to the prevalence of new financial instruments such as ETF's and derivatives. So, for the purpose of this post, we will solely define the scope of our application.

We will include the following:
  1. Stocks
  2. Options
  3. ETF's
  4. Bonds
  5. Mutual Funds
  6. Cash 
Furthermore, the first five items in the list can be broken down even further.

For Stocks:
  1. Market Capitalization
  2. Industry
  3. Geography
  4. Volatility
  5. Dividend or No Dividend
For Options:
  1. IN/OUT of the Money
  2. All Aspects of Stock Above
  3. Length to Expiration
For ETF's:
  1. Allocation of Assets
  2. All Aspects of Stocks Above
  1. Credit Rating
  2. Length to Maturity
  3. Type of Bond
Mutual Fund:
  1. Manager
  2. All Aspects of Stock
I will build an algorithm that is capable of taking into account all the factors present for each of the different asset classes outlined above. It will then output a rating of diversification. I will start with a python application, and then progress to an iPhone application.

Tuesday, July 5, 2011

Apple App Ideas? Lets talk about DIVERSIFICATION

First and foremost, I hope that everyone had a good Fourth of July weekend.

While Python programming will continue to stay under the scope of this blog, I am going to start incorporating some Objective-C applications into the discussions as well. Essentially, I am going to start discussing different Application ideas that would be valuable to those interested in trading securities.

Today, the app idea that I am going to discuss is in regards to Portfolio Diversification.

I am going to step out on a limb here and assume that if you are a frequenter of this blog, then you already are familiar with the term Diversification. However, this blog is not in the business of discriminating against people who are interested in learning about the topic of trading and programming but have experience in neither. So, here is a definition of Diversification.

If one thing is certain about successful iOS apps, it is that you need a "gimmicky" title that is easy to remember (and therefore spread by word of mouth). For now, though, we will stick with the title, "Diversified??".

The purpose of the app would be to allow users to input the percentage of their portfolio dedicated to different securities, commodities, ETFs, bonds, cash, etc... And then based on a certain algorithm, determine a "level" of diversification that the user's portfolio achieves. This could then be used as a forward looking tool to determine whether an investment decision "lowers or raises your diversification level."

If I receive positive feedback on this app idea, then the next post will be dedicated to establishing an "algorithm" that would output an accurate "diversification level." Please comment with your thoughts on the usefulness of an app such as this or send me an email.


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!

Thursday, February 24, 2011

Pair Trading Hedge Strategy

Hey all,

Today is going to be the first of a three part series discussing pair trading as a hedging strategy.

For those of you unfamiliar with the concept of pair trading, I will take some time to describe it. Essentially, pair trading involves tracking two equities, or other financial instruments over time, and how they move in relation to each other. For example, if we pick the two equities Coke (KO) and Pepsi (PEP) , we want to find an average difference in price between the two. Now on the programming side, which I will go into more in later parts of this series, we can read in a file containing the data for Coke's Stock Price and Pepsi's Stock Price and compute an average difference in price. Once we have this average difference, for clarities sake, lets assume the average difference in stock price is KO is on average $1 dollar more expensive then PEP. With the pair trading hedge strategy, anytime Coke moved more than $1 more expensive than Pepsi, we would short a predetermined amount of KO shares and buy a predetermined amount of PEP shares. The reasoning for this is that we expect these two stock prices to converge back to their average difference in price.

Come back for part two of this series, where I will demonstrate the coding techniques necessary to compute the price differences we need. In part three, I will demonstrate a successful pair trade using real life numbers and stocks!

If you are thirsty for more information on pair trading, click here!

Wednesday, February 23, 2011

First Post!

Hello Everyone!

This is going to be a collaborative space to discuss profitable trading strategies. We will discuss a wide range of products, with a large emphasis on hedging strategies and advanced option strategies. I will try to post a relevant post per day describing the current state of the market, and a subsequent strategy to attack it.

Now the blog is called Program to Trade because "sit and hold" investing is dying and high frequency trading is becoming a reality for anyone who wants consistent profit. I will discuss varioius brokerage tools, as well as some computer programming tools. Namely I will be using Python 3.1 to create my programs. This is a free programming language that can be downloaded at Python 3.1.

If you are new to computer programming, then don't be worried! I will be reviewing all of the basics, so that you can begin to create your own code! It is a great skill to learn and maybe it will even make you some money.

I am currently in the process of setting up a website, titled, programtotrade.com. However, I figured where else to start than from the king of web development, Google. I will keep you updated to the status of the webpage's development.

You can reach me by email at programtotrade@gmail.com