Friday, November 29, 2013

VBA Simulation of Shuffling and Distributing a Deck of Cards

Here's a simple VBA program that simulates shuffling and distributing a standard deck of 52 cards to 4 players. The program outputs the results in cells A1 through D13 of the current Excel spreadsheet, with the 4 rows corresponding to the 4 players' cards.
Sub ShuffleCards()
'This program simulates shuffling of a standard deck of 52 cards to 4 players
'Results are outputted in 4 columns in cells A1:D13

'H: heart, S: spades, D: diamod, C: club
'2 thru 10, J for jack, Q for queen, K for king, A for ace
'2H would be 2 of hearts, KD would be king of diamonds, etc.

'Creating
suits = Array("H", "S", "D", "C")
num = Array("2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K", "A")

Dim cards(0 To 51) As String
For i = 0 To 3
For j = 0 To 12
cards(13 * i + j) = num(j) & suits(i)
Next j
Next i

'Shuffling
For i = 1 To 1000
c1 = Int(52 * Rnd)
c2 = Int(52 * Rnd)
temp = cards(c1)
cards(c1) = cards(c2)
cards(c2) = temp
Next i
'Distributing
For k = 0 To 51
Cells(k Mod 13 + 1, Int(k / 13) + 1) = cards(k)
Next k
End Sub

The shuffling algorithm is to run through 1000 iterations of swapping two randomly chosen cards.

Sunday, November 24, 2013

“Comments on the Interpretations of Game Theory” Digest

In the paper “Comments on the Interpretations of Game Theory,” published in Volume 59, Issue 4 of Econometrica in July 1991, Ariel Rubinstein discusses notions of game theory and strategy that aims to highlight some of the inconsistency between the interpretation and application. Rubinstein argues that equilibrium strategy describes not only a player’s plan of action, but also the considerations that support the optimality of the plans. The paper also argues that models should encompass the perception of a real life situation by the decision makers. Game theory, as Rubinstein writes, is not simply about abstract mathematics but about the real world.

The first half of the paper deals with the notion of strategy. Rubinstein argues that the conventional interpretation is inconsistent with the way it is applied, leading to confusion. In one of the contexts, Rubinstein talks about extensive games with more than one moves. In the game, a player’s strategy is required to specify an action for each node in the game tree corresponding to that player’s movement. However, the incongruence comes when an action must be specified, even after earlier moves that would make the subsequent decision point inconsistent with the earlier moves. The necessity of this specification stems from the need to determine subgame-perfect equilibrium to test the rationality of the plans. In all, a strategy needs to encompass not only the player’s plan, but also the opponents’ belief in the chance that the plan was not followed.

Rubinstein also looks at the interpretation of strategy in mixed strategies. While intuitively problematic, there are clear cases in which players choose random actions, preferring over pure strategies. One interpretation of mixed strategy is to use a large population and having each occurrence take a random draw of the items from the population. Another interpretation is the purification idea, whereby a mixed strategy is dependent on private information not specified in the model. This interpretation argues that ostensibly random behaviors are actually deterministic. Finally, Rubinstein looks at the case of limited memory, which helps to keep modes of behavior simple. When probabilistic nature of doubt is introduced, there may be additional decision points that are unreachable, but added to the game form merely to allow the discussion of reasoning in the state of doubt.

From these discussions, Rubinstein tries to adopt the view that a game is not “a rigid description of the physical rules of the world,” but instead a “comprehensive description of the relevant factors involved in a specific situation as perceived by the players.” Towards that idea, model should include only the factors perceived by the players to be relevant, making the application of game theory “more of an art than a mechanical algorithm.” Finally, Rubinstein talks about regularity, which is necessary for employing game theory as a descriptive science. Game theory, in conclusion, builds models from intuition and from mathematical knowledge uses deductive arguments, which can’t discover the truth alone. Instead, game theory also deals with psychological elements, which help to distinguish humans from machines, which Rubinstein believes is “more exciting and certainly more meaningful.”

Monday, November 18, 2013

San Diego - Tijuana Border and Flight Comparison

A proposed solution to San Diego's crowded airport is to build a pedestrian bridge to Mexico. Tijuana's General Abelardo L. Rodriguez International Airport (TIJ) is located just across the US-Mexico border, and the proposed bridge, about 20 miles away from downtown San Diego, would allow people to cross the border into the airport. Otay-Tijuana Venture, the project's developer, cites that of the "roughly 4 million people who fly into and out of TIJ each year, more than half cross the border one way or the other." However, crossing the San Diego - Tijuana borders on automobile involves notoriously long waiting times. Some prefer to cross by foot and then catch transportation on the other side. San Ysidro crossing between the two cities is the world's busiest port of entry.

How much cheaper is it to fly out of Tijuana instead of the San Diego area airports? The following are the costs of the cheapest flights, for one adult roundtrip, from Expedia retrieved tonight, departing on Monday, December 7th and returning Wednesday, December 9th:

Destination San Diego Tijuana
New York $351.10 $972.59
London $2,214.60 $2,282.60
Tokyo $1,050.50 $3,932.80
Sydney $1,577.80 $3,082.21
Cairo $1,316.68 $3,930.00
Rio de Janeiro $1,269.49 $1,540.55
Panama City $800.40 $938.19
Mexico City $342.59 $291.16
Cancun $400.40 $371.04

For many of these cities, San Diego offers an enormous discount. Even for other Latin American destinations, San Diego offers cost advantage. It is only within Mexico that Tijuana offers cost advantages. The Tijuana flights to rest of Mexico are also more frequent and have fewer stops on average. Looking at just these results then, it would seem as though the pedestrian bridge serves to relieve those in Southern California traveling to various parts of Mexico by air. A positive externality would be slight relieving of the border crossing for those going to the airport.

Sources:

Sunday, September 29, 2013

Informational Competitive Advantage from Freedom of Information Act

Last Monday's Wall Street Journal featured an article that illustrated a trend in investment firms obtaining information through the Freedom of Information Act to make strategic decisions. In particular, the article highlighted SAC Capital Advisors contacting the Food and Drug Administration for information regarding a drug from Vertex Pharmaceuticals. SAC was able to use this information and purchase 13,500 shares of Vertex, whose stock rose by over 60% in a single day when further benign results were announced.

According to the United States Department of Justice, Freedom of Information Act "is a law that gives you the right to access information from the federal government." Signed into law in 1966, the Act "provides individuals with a statutory right of access to certain federal agency records." There are exemptions, and one of which is concerned with "business trade secrets or other confidential commercial or financial information."

While investors typically don't solely rely on the information from the Act, the valuable piece of information "helps them to piece together investment strategies or evaluate a company's prospects." Over 650,000 requests were received in fiscal year 2012, out of which over 93% were released in full or part. Within the different agencies, Department of Homeland Securities overwhelmingly received the most requests.

Sources:

Sunday, September 22, 2013

Effects of Depreciation on Financial Statements

The effects of financial transactions on the three major forms of financial statements: balance sheet, income statement, cash flow statement, are important to understand the financial performance of any corporations. While most effects are intuitively understood, a few deserve special attention.

Depreciation: if depreciation amount and tax rate were 100 and 20%, respectively, then the net income would fall by 80. However, on the cash flow statement, there will be an increase of 20 in cash flow from operations. This is because the cash flow statement starts from the net income and adds back the full amount of depreciation. The depreciation itself caused no change in cash amount. The tax deduction from the depreciation allowed for more cash to be retained. Combining this all on the balance sheet, there would be 20 increase in cash and 100 decrease in net PPE. This 80 decrease is matched by the 80 decrease in equity, given the depreciation expense of 80.

Loss / gain on sale: if there was 100 loss on sale and given 20% tax rate, earning before tax would decrease by 100, and similarly net income would fall by 80. Assets would fall initially by 100 but with only 80 decrease in equity, the 20 is matched by increase in cash from not having to pay the additional tax, in similar fashion to depreciation. On the reverse, 100 gain on sale would only increase assets and equity by 80, given the additional tax expense.

Microsoft Nokia Deal Summary

Microsoft Corporation and Nokia Corporations announced a deal on September 3, in which Microsoft would pay $7.17 billion USD to purchase Nokia’s Devices & Services business and license Nokia’s patents. Microsoft will utilize its overseas cash reserves to complete the transaction. At the end of Q2-2013, Microsoft’s cash and short-term investments totaled more than $76 billion. Nokia’s mobile business, which Microsoft purchased for 3.79 billion Euros, generated nearly half of Nokia’s 30.2 billion Euro revenue. In all, the purchase was a bargain for Microsoft.

The challenge comes to integrating the businesses. More than 30,000 Nokia employees were brought into Microsoft, including former CEO Stephen Elop. The two companies have been in partnership since 2011, and this deal is the second largest acquisition Microsoft has ever done. The acquisition also marks a remarkable transition in the Windows business model: vertical integration, as Microsoft aims to introduce its Windows Phone software into the hardware units. Microsoft has long touted a separation of software and hardware in the PC era. But as mobile hardware has been less commodity-like than computer hardware, Microsoft expects this deal to be accretive to its adjusted EPS starting in fiscal year 2015. Microsoft had been receiving less than $10 in software licensing fees from Nokia, but now can make more than $40. The challenge becomes selling more Windows phones. Currently it lags behind Android and iOS. And with Apple introducing reduced-cost iPhone models, the challenge becomes even harder for Windows Phone to find its niche.

Two weeks after the Nokia deal, Microsoft announced that it would increase its dividend 22% over the previous quarter, and authorized up to $40 billion in share repurchases.

Sources:

Sunday, August 25, 2013

Marketing Myopia

Marketing myopia is an important paper first published in 1960 by Theodore Levitt, which argues that declining industries are results of failure of management to align their business with customers' needs. Levitt cites the railroads, which "assumed themselves to be in the railroad business rather than in the transportation business." By being "product oriented" instead of "customer oriented," the railroads allowed other modes to fulfill customers' transportation needs. Similarly, Levitt argues that Hollywood incorrectly defined its business as the movies, rather than the entertainment. By embracing a "specific, limited product," Hollywood "rejected TV when it should have welcomed it as an opportunity ... to expand the entertainment business."

This analysis resonates with the concept of business cycle. During the growth phase of an industry, its "assumed strength lay in the apparently unchallenged superiority of its product." However, Levitt believes that "there is no such thing as a growth industry," as there "are only companies organized and operated to create and capitalize on growth opportunities," while those who "assume themselves to be riding some automatic growth escalator invariably descend into stagnation."

Source:

Thursday, August 22, 2013

Reverse Percentage Change

It takes little computation to realize that the magnitude of percentage change from a to b isn't the same as that from b to a. The jump from 40 to 60 is 50% increase, but from 60 to 40 is 33.3% decrease. What's the exact formula for converting the magnitude of percentage changes? Let a and b be any nonzero integers.

For convention, let's have these labels:
  • a: starting number, 40 in this case
  • b: ending number, 60 in this case
  • x: change from a to b, calculated as (b - a) / a, 50% in this case
  • y: change from b to a, calculated as (a - b) / b, -33.3% in this case
The goal is to derive y from x. Follow these steps:
  • x = (b - a) / a
  • -x = (a - b) / a
  • -x * a = (a - b)
  • - x * a / b = (a - b) / b
So given x as the percentage change from a to b, the percentage change from b to a is simply the - x * a / b. In this example, -(50%) * 40 / 60 = -33.3% indeed. This works when a is bigger than b as well: a = 20, b = 10, x = (10 - 20) / 20 = -50%, y = -50% * 20 / 10 = 100%.

Sunday, June 23, 2013

Generic Competitive Strategies

The second chapter of Competitive Strategy looks at three approaches in "coping with the five competitive forces" outlined in the previous chapter, which are industry competitors, potential entrants, substitutes, suppliers, and buyers. The three strategies include overall cost leadership, differentiation, and focus. While they are not mutually exclusive, it is "rarely possible" to pursue multiple approaches.

Overall cost leadership entails "aggressive construction of efficient-scale facilities" to minimize cost, which provides "high margins which can be reinvested." This strategy is usually associated with high volume and market share. Differentiation sacrifices volume for perception of uniqueness industry-wide. Finally, focus strategy is "built around serving a particular target very well." Honed onto a particular segment only, focus can pursue either low cost, high differentiation position, or both.

The chapter notes that a "firm failing to develop its strategy in at least one of these three directions ... is in an extremely poor strategic situation" and "is almost guaranteed low profitability." These firms lose both the high-volume customers looking for low costs, and the high-margin business that depends on differentiation. While each of these strategies has its set of risks, these three generic competitive strategies give an intuitive explanation of the U-shaped relationship between profitability and market share, as observed in some industries.

Thursday, June 20, 2013

Backward and Forward Integration

The first chapter of Competitive Strategy talks about structural analysis of industries, which aims to relate "a company to its environment." Among the five competitive forces surrounding a company are industry competitors, potential entrants, substitutes, suppliers, and buyers. A buyers or supplier can exert competitive force with credible threat of backward or forward integration, respectively.

Buyer can engage in backward integration by purchasing the parts it typically procures from suppliers. This poses competitive force on the suppliers. On the other hand, suppliers can engage in forward integration by expanding activity "to include control of the direct distribution of its products," posing competitive force on the buyers typically involved in the distribution. The same company can be both a buyer or supplier in different markets. A manufacturing company, for example, may be the buyer in the market for raw materials, but becomes the supplier in the market of the assembled goods to other companies.

Sources:

Monday, June 17, 2013

Look Into Historical Unemployment vs. CPI Data

Bureau of Labor Statistics (BLS) publishes and archives monthly unemployment and consumer price index data. The CPI data is stored as 1-month percentage change, indicative of the monthly inflation rate. The current data archive goes back to 2003 for each. A quick data manipulation procedure in Excel gets each tabular output into a series output for juxtaposition.


The Phillips Curve is a historical inverse relationship between unemployment and inflation rate. The data from the 10 years here demonstrates a very strenuous inverse relationship. Here the slope of the best-fit line is -0.02135, but the R^2 value was merely 1.29%.

Sources:

Growing Sectors From June BLS Data

On the first Friday of every money, Bureau of Labor Statistics publishes employment reports for the previous month in the United States. In the report published on June 7th, total nonfarm payroll increased by 175,000 in May, putting the unemployment rate at 7.6%. The growth is above the 172,000 figure, which has been the monthly average over the past 12 months. The report highlights that professional and business services added 57,000 jobs in May.

A look into Table B-1, which breaks down the nonfarm payrolls by industry sector and selected industry detail, reveals which sectors have shown the highest consecutive monthly growth. At the levels of detail provided by the report, only 4 selected entries illustrated 0.5% monthly growth for both March to April, and April to May: employment services, temporary help services, business support services, and home health care services. Employment services have seen 1.47% increase from seasonally-adjusted payroll of 3.286 million in March to 3.334 million. Compared to last May, it has climbed by 6.44% during the past year. Temporary help services claim the honor of seeing the highest year-over-year payroll growth at 7.46%.

Sources:

Friday, May 24, 2013

Strengthening Australian Dollar and Ford Shutting Down Production

It was reported this week that after nine decades of operating in Australia, Ford will shut down production in the country due to the strength of the Australia dollar and high costs, particularly wages. Ford reported that production costs in Australia "are twice that of Europe and nearly four times higher than in Asia." The factories are planned to close within 3 years.

Strength of the Australian dollar would make it more costly to operate there. How exactly has the Australian dollar fared against other major currencies? The AUD-USD is currently around 0.97. This is actually on the lower end of the 52-week range, and further down from the peak of around 1.10 reached in mid-2011. However looking at the 5 year chart, AUD-USD was as low as 0.6 in late 2008. Since the start of 2011, it has been steadily strong at above 1. Looking at AUD-JPY, again a similar strengthening trend can be observed. After hovering around 80 for most of mid-2009 to mid-2012, it has surpassed 100 this year and currently is around 97.78. Finally, looking at AUD-EUR, the pattern can be seen as it has strengthened from around 0.5 in late 2008 to currently around 0.75, although it was as high as 0.85 in mid-2012.

Sources:

Thursday, May 23, 2013

Mixed Headlines Regarding Housing Market

There were mixed headlines regarding the house market today. Sales of new homes in the United States climbed to an annualized rate of 454,000 in April. This was the second highest monthly figure since July 2008. Year-over-year, the median selling price increased 14.9% to $271,600, which is the highest on record. Partially fueling the rising demand are the low interest rates. This week the average 30-year fixed mortgage rate was 3.59%.

Despite these news, limitation on home supply is put by the lack of equity to sell homes. In a report released by Zillow (NASDAQ: Z), a real estate information provider with a "database of more than 110 million U.S. homes," keeping the property listing tight are the "about 22 million Americans ... [who] lack enough home equity to move." The report stated that 44% of homeowners with mortgages had less than 20% equity in their home, and 20% is usually required to purchase a new home. This figure includes 13 million Americans, or a quarter of homeowners with mortgages, who were underwater, or owed more than what their homes are worth. Zillow projects that by Q1-2014, only about 1.4 million homeowners will regain positive equity.

Sources:

Tuesday, May 21, 2013

A Look into Venture Capital Firms Behind Tumblr

Yahoo's acquisition of Tumblr was a boon for many, including Union Square Ventures and Spark Capital, the two venture capital firms who made initial investments into Tumblr during its infancy. The combined investments of $10 million translated to 47% ownership of the company, giving them a 50-fold return in the recent deal with Yahoo that valued Tumblr at $1.1 billion. The deal was also a spark for the New York start-up community, as Tumblr represents the "largest venture-backed purchase for a New York company."

Union Square Ventures, based in New York, describes itself on its website as a "small collegial partnership that manages $450,000,000 across three funds" and invests in companies that "create services that have the potential to fundamentally transform important markets." Spark Capital, based in Boston, manages about $1.5 billion. Common across both funds include Twitter.

On Tuesday, the front page of Union Square Ventures highlights the Tumblr acquisition, which characterizes Tumblr as "world's greatest platforms for self expression." Tumblr has 108 million blogs across its network, and generates about $13 million in revenue annually, which is the amount Yahoo generates daily. Nevertheless, it is the younger audience and mobile users whom Yahoo seeks to attract through this acquisition.

Sources:

Saturday, May 11, 2013

Column Generation Illustration

This example illustrates the first few steps of using column generation method to solve an integer program. In particular, this is a cutting beam example, where given beams of length L = 100, determine the minimum number of beams to satisfy demand of size n_i for length d_i: n1 = 21, d1 = 13, n2 = 39, d2 = 31, n3 = 61, d3 = 36, n4 = 14, d4 = 45

The initial objective function is to minimize x1 + x2 + x3 + x4, given the following constraints:

1 0 0 0  >= 21
0 1 0 0  >= 39
0 0 1 0  >= 61
0 0 0 1  >= 14

Objective value is 135. This is the dummy case where no cutting takes place. The dual solution is (1, 1, 1, 1), so the next LP to solve is: max p1 + p2 + p3 + p4 subject to 13*p1 + 31*p2 + 36*p3 + 45*p4 <= 100. The solution is (7, 0, 0, 0), and since the objective value of 7 is greater than 1, continue. Add this column in the next run. The pattern generated here (7, 0, 0, 0) means that 7 pieces of length 13 will be cut from the stock, whose length is 100.

Now with the addition of a new variable, minimize x1 + x2 + x3 + x4 + x5, given the following constraints:

1 0 0 0 7  >= 21
0 1 0 0 0  >= 39
0 0 1 0 0  >= 61
0 0 0 1 0  >= 14

The objective value has decreased to 117, and the dual solution is (1/7, 1, 1, 1), so the next LP to solve is: max 1/7*p1 + p2 + p3 + p4 subject to 13*p1 + 31*p2 + 36*p3 + 45*p4 <= 100. The constraint is the same as the earlier maximization problem. The solution is (0, 3, 0, 0), so this would be the next column to generate, given that the the objective value of 3 is still greater than 1. Continue this process.

Thursday, March 21, 2013

Interest Rate Swap and Swaption

Interest rate swap is also known as plain vanilla swap, or fixed and fixing swap. It is the exchange of cash flows on a notional value (say $1 million) given a fixed interest rate (say 3%), for the cash flows from on the same notional value given a floating interest rate (say LIBOR + 0.5%). The notable aspect is that the notional value never gets traded, and thus is rather arbitrary. Over the life of the swap, the payments are made to the counterparty at intervals that are usually 6 months. The swap benefits entities that may want more exposure or mitigate exposure to interest rate risk.

Swaption is an option on the swap, whereby the writer has the option but not the obligation to enter into a swap agreement by a certain date. But furthermore, the contract specifies whether the buyer will be the recipient of the fixed or floating rate cash flows.

Sources:

Tuesday, March 19, 2013

Simulation of Simplified Version of Showcase Showdown Using MATLAB

See previous related post: Showcase Showdown Analysis: Circular Reasoning and Oscillating Nash Equilibrium

In the show The Price Is Right, contestants spin the Big Wheel, which has 20 sections randomly distributed, from 5 cents to $1.00 in 5-cent increments. The objective is to get the highest amount without going over $1, with one initial spin and an optional second spin. Clearly the first contestant is at a disadvantage, as the later contestants simply opt for the second optional spin if the first spin is not enough. For the first contestant, there needs to be a strategy consisting of a critical value for the first spin, at or above which the second spin is not preferred, as the probability of going over is too high. It's also a discrete case, as the critical value can only be from 5 to 100, in increments of 5.

In the actual show, there are three contestants. For the sake for simplicity, only two contestants are assumed in this simulation. In the case of tie, rerun the trial. For each possible critical value from 5 to 100 cents, 1 million trials are run in this Monte Carlo simulation to determine the winning percentage of player 1 under that strategy.

Here's the graph with the critical point on the x-axis and the winning percentage on the y-axis:


The maximum occurs at critical value of 55, corresponding with a winning percentage of 45.55%. At a value of 50, the winning percentage is up there at 45.22%. Even closer is 45.52% at a value of 60. The winning percentage gradually tapers off. Even at a value of 70, the winning percentage is still at 44.25%. Here's the MATLAB script to generate the data and graph:
x = zeros(1,20);
y = zeros(1,20);

for crit = 1:20
    x(crit) = 5*crit;
    n = 1000000;
    win = zeros(1,n);

    for i = 1:n
        done = false;
        while ~done
            firstSpin = ceil(20*rand)*5;

            if firstSpin >= x(crit)
                playerOne = firstSpin;
            else
                playerOne = firstSpin + ceil(20*rand)*5;
            end

            if playerOne > 100
                playerOne = 0;
            end

            playerTwo = ceil(20*rand)*5;
            if playerTwo < playerOne
                playerTwo = playerTwo + ceil(20*rand)*5;
            end
            if playerTwo > 100
                playerTwo = 0;
            end

            if playerOne > playerTwo
                win(i) = 1;
                done = true;
            elseif playerOne < playerTwo
                done = true;
            end
        end
    end
    
    y(crit) = sum(win)/n;
end
plot(x,y); grid on; xlabel('player 1 critical point'); ylabel('player 1 winning percentage')

In the code above, simply vary the value of n to change the number of trials at each strategy. Of course, this optimal strategy will be different if the third contestant is taken into consideration in the actual game.

Time Difference: New York & Sydney

Calculating the time difference between New York and Sydney is tricky, not only because both cities observe daylight saving time, but they also are on the opposite hemispheres, so one city's summer is winter for the other. Sydney is GMT +1000 and New York is GMT -0500, yet the time difference between the two cities is rarely 15 hours.

For New York, DST is observed from the second Sunday in March to first Sunday in November. For Sydney, DST is observed from the first Sunday in October to the first Sunday in April. For the sake of convenience, the four relevant Sundays for 2013 are as follows: March 10, Nov 3, Oct 6, and April 7, respectively.

Sorting the dates by groups:
  • Jan 1 to March 10: Sydney on DST, New York off DST --> 16 hour difference
  • March 10 to April 7: both on DST --> 15 hour difference
  • April 7 to Oct 6: Sydney off DST, New York on DST --> 14 hour difference
  • Oct 6 to Nov 3: both on DST --> 15 hour difference
  • Nov 3 to Dec 31: Sydney on DST, New York off DST --> 16 hour difference
In all, for only 56 days of the year is the time difference between New York and Sydney actually 15 hours.

Sources:

Time Difference: New York & London

The time difference between New York and London is crucial, especially for the financial service sector. For most of the year, London is 5 hours ahead of New York. However, while both areas observe daylight saving in summer, the onset and ending dates aren't exactly aligned, causing a shift in the time difference for moments in the spring and fall.

In the United States, daylight saving begins on the second Sunday in March, and lasts until the first Sunday in November. In Britain, it begins on the last Sunday in March, and lasts until the last Sunday in October. So in all, daylight saving in London begins later, and ends earlier. During those gap periods, New York is only 4 hours behind London, as opposed to the 5 hour difference, when both cities are on daylight saving or when both cities are off. Because there isn't a moment at which London is on and New York is off daylight saving, the London - New York time difference will never be 6 hours.

In conclusion, the time difference between New York and London is as follows:
  • First Sunday in November - second Sunday in March: 5 hour (both off DST)
  • Second Sunday - last Sunday in March: 4 hour
  • Last Sunday in March - last Sunday in October: 5 hour (both on DST)
  • Last Sunday in October - first Sunday in November: 4 hour
Sources:

Quick Glance into Ryanair

Ryanair, the Dublin-based airliner known for its operation of low-cost passenger airline service, is in the news for signing an order from The Boeing Company worth $15.6 billion. Ryanair is one of the few airliners that orders exclusively from Boeing, and has now expanded its fleet by 30% to over 400 units in order to grow its capacity to over 100 million across Europe by 2018. Boeing (NYSE: BA), which has seen its stock price soar by over 10% in the past month to close at around $85, welcomed the news, as its Commercial Airplanes CEO Ray Conner remarked the Next-Generation 737 "as the most efficient, most reliable large single-aisle airplane flying today," which "has been and will continue to be the cornerstone of the Ryanair fleet."

Ryanair Holdings (NASDAQ: RYAAY), the holding company for Ryanair, has market cap of around $12 billion. Its net profit margin in Q4-2012 fell to 1.87% after posting 12.76% for Q3. A visit to Ryanair's website indeed illustrates the low-cost business that it operates. There's a roundtrip from London to Dublin one month in advance available for only 44 GBP. On flight search websites that offer comparison, it becomes even more evident that the $56 value is significant that of its competitors, including $194 from British Airways. The low fares do come at some costs though; as users go on the website to search for flights, they are prompted to enter a "security code," which is obtained by viewing a short advertisement. Nevertheless, the colossal deal was signed today in New York.

Sources:

Thursday, March 7, 2013

Acceptance Rejection Method for Simulation

In simulation, use the acceptance rejection method to simulate a random variable X with density f(x), for which there is no direct method to use the inverse transformation to generate it. However, suppose that there is a known algorithm to generate random variable Y with density g(x) such that f(x) / g(x) is bounded, that is f(x) / g(x) ≤ c. To find c, take the derivative of f(x) / g(x) to find the maximum value. Here's the algorithm:
  1. Generate Y according to the known algorithm
  2. Generate U, the uniform distribution from 0 to 1
  3. If U ≤ f(Y) / c*g(Y), then set X = Y
  4. Otherwise, start all over
Note that to produce each copy of X, the loop runs until condition 3 is satisfied. In the end, c become the average number of runs to produce a copy of X. In the following, a random variable with f(x) = 2x*e^(-x^2) is generated using MATLAB. The chosen g(x) = e^(-x), so f(x) / g(x) = 2x*e(x-x^2), and the maximum value c turns out to be exactly 2. 

There's no way to verify that this method does indeed generate a random variable with the given f(x). Instead, to test the accuracy of the algorithm here, two values (a and b) are inputted at the end. The program first calculates the integral of f(x) from [a, b], or the probability that X falls between the range of [a, b]. Finally, the program uses the simulated copies of X to count the proportion of the copies of X that fell in that interval of [a, b]. The two values should be close to each other.
func = @(x) 2*x.*exp(-x.^2);
n = 100000;
results = zeros(1,n);
numTimes = zeros(1,n);

for i=1:n
    trialDone = false;
    count = 0;
    while ~trialDone
        count = count + 1;
        y = -log(rand);
        u = rand;
        if u <= y*exp(y-y^2)
            results(i) = y;
            trialDone = true;
        end
    end
    numTimes(i) = count;
end

a = input('Lower bound for x: ');
b = input('Upper bound for x: ');
disp 'Evaluated integral using f(x): ';
quad(func, a, b)
disp 'Simulated integral using acceptance / rejection method: ';
length(results(results>a & results
disp 'Average trial runs per simulated copy: '
mean(numTimes)

Choose values between 0 and 2.5 for a and b, for over 99.8% of the data are in that range. Upon running the script using different values, the calculated integral closely matches the frequency proportion obtained from the simulation technique using the acceptance rejection method. While this does not verify the accuracy of the method, it at least illustrates that the resultant output resembles what the expected output should be. Finally, the resultant average trial runs per simulated copy hovers closely to 2 as expected.

Sunday, March 3, 2013

Simulating Correlated Pairs of Normally Distributed Random Variables

See previous related article: Simulating Normal Distribution with Polar Method

The previous article walked through how to generate independent copies of normally distributed random variables using the polar method. Here's an extension of that on how to generate pairs of normally distributed variables with a certain correlation between them. Polar method is still used to generate the variables. Recall that correlation ρ = cov(x,y) / (σ_x*σ_y). Both x and y can have its own σ and μ values.

n = input('Input the number of copies: ');
u_x = input('Input the mean of x: ');
s_x = input('Input the standard deviation of x: ');
u_y = input('Input the mean of y: ');
s_y = input('Input the standard deviation of y: ');
p = input('Input the correlation between x and y: ');
x = zeros(1,n);
y = zeros(1,n);

for i = 1:n
    z1 = sqrt(-2*log(rand))*cos(2*pi*rand);
    z2 = sqrt(-2*log(rand))*sin(2*pi*rand);
    x(i) = s_x*z1+u_x;
    y(i) = s_y*p*z1+s_y*sqrt(1-p^2)*z2+u_y;
end

disp 'Calculated mean and standard deviation for x:';
[mean(x), std(x)]
disp 'Calculated mean and standard deviation for y:';
[mean(y), std(y)]
disp 'Calculated correlation between x and y:';
corr(x',y')

The middle block of the codes here is the most essential. Variables z1 and z2 denote two independent copies of N(0,1). One copy is then used to generate x1 as σ_x*z1 + μ_x. Then the correlated pair y1 is generated as σ_y*ρ*z1 + σ_y*sqrt(1-ρ^2)*z2 + μ_y. Note that the z1 term is used in generating x1 as well as y1. Furthermore, note that the middle term σ_y*sqrt(1-ρ^2)*z2 disappears when ρ = ±1.

Simulating Normal Distribution with Polar Method

The polar method allows for quick generation of normally distributed random variables. For each trial, generate r^2 as exponentially distributed with λ = 1/2, and θ uniformly distributed between 0 and 2π. Within each trial, in fact 2 independent copies of the normally distributed random variables are generated: Z1 = sqrt(r^2)*cos(θ) and Z2 = sqrt(r^2)*sin(θ), both with μ = 0 and σ = 1. For normally distributed random variables with different parameters of μ and σ, simply use the transformation σ*Z+μ.
n = input('Input the number of copies: ');
u = input('Input the mean: ');
s = input('Input the standard deviation: ');
results = zeros(1,n);
for i = 1:2:n
    rsq = -2*log(rand);
    theta = 2*pi*rand;
    results(i) = s*sqrt(rsq)*cos(theta)+u;
    results(i+1) = s*sqrt(rsq)*sin(theta)+u;
end
disp 'Calculated mean and standard deviation using the polar method:';
[mean(results), std(results)]

The program at the end calculates the μ and σ values of the n copies of the random variables created as a result of this simulation, stored in the array named "results."

Friday, February 1, 2013

“Math Will Rock Your World” Digest

The article “Math Will Rock Your World”, a cover story featured in BusinessWeek and published on January 23, 2006, talks about the increasingly important role that mathematics and data analysis have played in industries and daily lives. In particular, subjects seemingly incongruous with analytic, such as linguistics, have become intertwined. This was discussed in the startup company Inform Technologies LLC, in which the algorithm “combs through thousands of press articles and blog posts” and “analyze each article by its language and context.” At the foundation of this data analysis are mathematical algorithms. Subjects and relationships between subjects combine to construct the polytope, “an object floating in space that has an edge for every known scrap of information.” This development is today’s informational revolution.

Technology companies, from Google to Facebook, are increasingly trying to make use of the gigabytes of information they have. The challenge is to use the information, most of which are stored as qualitative idea, into quantitative algorithms that can be propagated. These developments can be observed presently through efforts such as personally-targeted advertisement on Google searches or Facebook profiles. The article stresses the importance of data analysis in today’s business when it talks about how Ford Motor “could have sold an additional $625 million worth of trucks if it had lifted its online ad budget from 2.5% to 6% of the total.” Online advertisement allows companies to “profile customers” as the companies “know where their prospective customers are browsing, what they click on, and often, what they buy.” These ideas altogether illustrate the idea that access to information and the efficient mathematical analysis of the information can lead to great business solutions.

While this development fosters efficiency, it also raises some concerns that the article addresses. Utmost concern is privacy, which companies from Google and Facebook have all grappled with in the recent years. The inevitability of the “power of mathematicians to make sense of personal data and to model the behavior of individuals” will compromise privacy, and this is a concern not just for the individuals who data are being utilized. If the individuals fear for their data being manipulated beyond their range of comfort, they may lock the information up and prevent them from being utilized. This would hamper efforts of the mathematicians to develop algorithms and determine business or practical solutions. Another concern is the complexity of the new development. Managers must “understand enough about math to question the assumptions behind the numbers,” given that it becomes much easier to deceit “someone by having analysis based on lots of data and graphs.” As a result, this is the challenge for United States, as the article mentions. The country “must breed more top-notch mathematicians at home” by revamping education and simultaneously “cultivate greater math savvy” as the subject becomes more prevalent in the business profession.

For students studying mathematics and related fields, now is a great opportunity to foster these interests. Computer scientists and quantitative analysts are in high demand, and there is much room for development in this inchoate field. But even for those not directly working in this field, an understanding of the subject becomes increasingly important as well. A solid knowledge foundation allows for critical analysis of the technological improvements. As the field of data mining continues to revolutionaries business and the way society progresses, it is in the best interest of individuals to not only know how to best utilize these developments, but also to protect one’s own information to ensure that privacy is not greatly compromised in the reach for progress.

Source:

Tuesday, January 29, 2013

Inverse Transform Demonstration with Excel VBA

Given F(x) = 1-e^(-λ*x) as the cumulative distribution function, the inverse transform gives -1/λ*ln(U) as the function that has F(x) as its cdf, where U is the uniform distribution from [0, 1]. Here, the following VBA codes allow users to visualize this transformation in Microsoft Excel.

Upon the execution of this procedure, the user inputs a value for lambda. Then 10,000 simulations are run, initially generating a random number from [0, 1] and then inputting that random number into -1/λ*ln(U), and outputting the result in column A. At the end of the execution, column C contains the different x values from 0 to the maximum, in increments of 0.001. Column D reflects the cdf by counting entries of A that are smaller than the corresponding x value. Finally, column E calculates the true value of 1-e^(-λ*x). The idea is that the outputs in columns D and E are similar.

Sub InverseTransform()
'Demonstrates inverse transform of the cdf F(x) = 1-e^(-lambda*x)
Columns("A:E").Clear
Range("B1").Value = 1# * InputBox("Enter a positive value for lambda: ", "Input", 2)

'10,000 simulation trials to be performed
'Transform of F(x) gives -1/lambda*ln(U), where U is uniform distribution [0,1]
For i = 1 To 10000
Cells(i, 1) = -1 / Range("B1").Value * Log(Rnd)
Next i

'Determine the maximum for the range of numbers to work with
Range("B2").FormulaR1C1 = "=MAX(C[-1])"

'To determine the cumulative probability density, use 0.001 gradient from 0 to the maximum value as the counter
i = 1
While i / 1000 <= Range("B2").Value
Cells(i, 3).Value = i / 1000
'In column D, count entries in column A that are smaller than the counter, then divide by the number of trials
Cells(i, 4).FormulaR1C1 = "=COUNTIF(C[-3],""<""&RC[-1])/10000"
'In column E, calculate the true value of 1-e^(-lambda*x)
Cells(i, 5).FormulaR1C1 = "=(1-EXP(0-R1C2*RC[-2]))"
i = i + 1
Wend
Range("B2").Clear
End Sub

After the execution of this procedure, the user can perform further analysis. Graphing columns C through E does reveal that values in columns D and E are similar, as the points almost completely overlap. Error calculations from those two columns illustrate a similar result that the inverse transform method takes a function F(x), exponential function in this case, to produce a function whose cdf is F(x).

Wednesday, January 23, 2013

Monte Carlo Simulation of Pi with MATLAB

Using Monte Carlo simulation, the value of π can be approximated as (1/n) * Σ(4*sqrt(1-U_i^2)), where n is a large number representing the number of simulation trials, and U_i represents the i-th trial result from a uniform distribution in [0,1], for 1 ≤ i ≤ n. The MATLAB codes to run this simulation is quite straightforward:

numTrials = 1000000000;    %number of simulation trials
count = 0;
for trial = 1:numTrials
    roll = rand;    %uniform distribution [0,1]
    count = count + 4*sqrt(1-roll^2);
end
sum(count)/numTrials

In this simulation, n = 1,000,000,000. The output of 3.1416 matches the value of pi in all 4 displayed decimal places.

Monday, January 21, 2013

Intricacies of VLOOKUP

In Microsoft Excel, VLOOKUP is a very useful function that "searches for a value in the first column of a table array and returns a value in the same row from another column in the table array." The basic syntax of the function is =VLOOKUP(lookup_value, table_array, col_index_num, range_lookup), with the range_lookup being optional.

If range_lookup is FALSE, the function will look for only exact matches. In this case, the values in the first column of table_array do not need to be sorted. However, this is not the case if range_lookup is TRUE, which is the selection by default if omitted. Then the values in the first column must be in ascending order, as the function will use the largest value smaller than the lookup_value, if an exact match is not found.

Finally, two wildcard characters allow flexibility in the lookup_value when it is a text and the range_lookup is FALSE. A question mark (?) matches any single character, while asterisk (*) matches any sequence of characters. Use a tilde (~) before either the question mark or asterisk if they are the actual characters in the lookup_value. So as an example, the text value "abc" can be matched by both "a??" and "a*".

Source:

Tuesday, January 15, 2013

Seattle at a Glance

The largest city of the Pacific Northwest region, Seattle is home to over 600,000 people in the city proper and with 3.7 million residents, the Seattle-Tacoma-Bellevue Metropolitan Statical Area (Seattle MSA) is the 15th largest in the nation. The population grew by 8% between the 2000 and 2010 Census. A notable characteristic of the Seattle demographics is the level of education. For people over the age of 25, 56% of the residents have Bachelor's Degree or higher, which ranks Seattle among the top of major cities in the United States. University of Washington, the largest employer in the city proper, has over 40,000 students.

Seattle MSA accounts for 1.93 million jobs and generates an estimated gross metropolitan product of $218 billion. Aerospace, largely due to The Boeing Company, accounts over 80,000 jobs and $32 billion in revenue. Information technology is another important sector to the economy of Seattle MSA, employing over 100,000 and with companies such as Microsoft and Amazon.com headquartered in the region. Other notable companies headquartered in Seattle MSA include Costco, Starbucks, and Nordstrom.

International commerce is crucial to Seattle, which is situated roughly equidistant from Tokyo and London. Washington State ranks first in exports per capita, with Mainland China, Canada, and Japan as the top trading partners. Seattle-Tacoma International Airport is the closest airport on the continental US to Asia and served 31.2 million passengers in 2009. Internally, King County Metro and Sound Transit combine to offer express bus, light rail, and commuter rail services for the region.

In terms of the cost of living, Seattle trails major Northeastern and California cities from Boston to Los Angeles, and is comparable to that of Chicago. In 2010, 2 bedroom /1 bath apartment rental on average cost slightly over $1,100. Average high temperature in July is around 75F, while average low in winter hovers around the freezing point. At 36.2 inches, the average annual precipitation is actually lower than that of New York; summer is the dry season, while light precipitation and partly cloudy skies dominate the winter months.

Sources:

Monday, January 14, 2013

Currency Movements and Global Macro Calls

2013 Year Ahead Report published by Bank of America Merrill Lynch Global Research features 10 macro calls on the world economy. One call regarding interest rates and currencies states that "the U.S. dollar and euro could rally on the global recovery and greater fiscal clarity, pushing the yen lower and emerging market currencies higher." Another recall, regarding the crisis in Europe, states that "the big tail risk of a eurozone breakup has likely passed."

With this theme in mind, it was announced on Monday that Japan would further devalue its currency. It has already fallen 14% since October, and this has been helping the country's exports. Prime Minister Abe has "[stepped] up the pressure for the Bank of Japan to ease monetary policy" and increase the inflation target to 2%. The yen currently trades at 88.95 on the US dollar, which is near its 52-week high. While the yen has been pushed lower, the euro has hit an 11-month high against the US dollar, at $1.3382. Yields on Italian and Spanish 10-year bonds have stabilized to 4.19% and 5.03%, respectively. These numbers do go along the macro call from report that "European economy should stabilize as the year progresses."

Sources:

Friday, January 11, 2013

Principle World Cities by Time Zones

Here are the principle cities by time zones. This is not a comprehensive list of the time zones, as it excludes certain zones in the Pacific and Atlantic that do not have major cities. Most of North America and Europe utilize daylight saving time, as well as some of the major cities in South America and Australia. During the summer months, daylight saving time adds one hour forward.
  • UTC -1000: Honolulu
  • UTC -0900: Anchorage
  • UTC -0800: Los Angeles, Vancouver, Tijuana
  • UTC -0700: Denver, Calgary
  • UTC -0600: Chicago, Mexico City, Winnipeg
  • UTC -0500: New York, Toronto, Lima
  • UTC -0430: Caracas
  • UTC -0400: Santiago, San Juan, Halifax
  • UTC -0330: St. John's
  • UTC -0300: Sao Paulo, Buenos Aires
  • UTC ±0000: London, Lisbon, Casablanca, Accra
  • UTC +0100: Paris, Rome, Berlin, Madrid, Lagos, Zurich, Stockholm
  • UTC +0200: Cairo, Johannesburg, Athens, Istanbul, Helsinki, Jerusalem
  • UTC +0300: Nairobi, Baghdad, Riyadh
  • UTC +0330: Tehran
  • UTC +0400: Moscow, Dubai
  • UTC +0430: Kabul
  • UTC +0500: Karachi
  • UTC +0530: Delhi, Colombo
  • UTC +0545: Kathmandu
  • UTC +0600: Almaty, Dhaka
  • UTC +0630: Yangon
  • UTC +0700: Jakarta, Bangkok
  • UTC +0800: Beijing, Hong Kong, Perth, Singapore
  • UTC +0900: Tokyo, Seoul
  • UTC +0930: Adelaide
  • UTC +1000: Sydney
  • UTC +1100: Vladivostok
  • UTC +1200: Auckland, Suva