Code for Efficient Frontier, Global Minimum Variance Portfolio, Tangeng Portfolio

By , August 7, 2012 8:57 pm
/* 
 * This pseudo-code class entails the risk and expected return values for efficient frontier
 * In real code, accessors and mutators should be provided
 */
class EfficientFrontier()
{
	float[] return;	// series of expected returns on efficient portfolios
	float[] risk;	// series of standard deviation of returns of efficient portfolios
	float gmvpReturn;	// expected return of Global Minimum Variance Portfolio
	float gmvpRisk;	// standard deviation of returns of Global Minimum Variance Portfolio
	float tangentReturn;		// expected return of the efficient portfolio tangent to Capital Market Line
	float tangentRisk;	// standard deviation of returns of the efficient portfolio tangent to Capital Market Line
	float shortConstraintMaxReturn;	// maximum expected return that an efficient portfolio can reach
	float shortConstraintMaxRisk;	// standard deviation of returns of the efficient portfolio with maxmimum return
}

/* 
 * This pseudo-code function produces position of Markowitz Efficient Frontier
 */
EfficientFrontier getEfficientFrontier(float[][] price)
{
	const float c1 = 0.1;	// first substitute of risk-free rate for Black's shortcut
	const float c2 = 0.2;	// second substitute of risk-free rate for Black's shortcut
	float[] annualReturn = annualReturn(price);
	float[][] annualVarcovar = annualVarcovarMatrix(price);
	annualVarcovar = InverseMatrix(annualVarcovar);
	
	for (i = 0 ; i < NUMBER_OF_VARIABLES ; i++)
	{
		for (j = 0 ; j < NUMBER_OF_VARIABLES ; j++)
		{
			z1[i] += annualVarcovar[i][j] * (annualReturn[j] - c1);
		}
		sumz1 += z1[i];
		x1[i] = z1[i] / sumz1;
	}
	
	// repeat for z2 & x2;
	
	float expectedReturn1, expectedReturn2;

	for (i = 0 ; i < NUMBER_OF_VARIABLES ; i++)	// calculate expected return
	{
		expectedReturn1 += annualReturn[i] * x[i];
	}
	
	// repeat for expectedReturn2;
	
	variance1 = z1[] * annualVarcovar * z1[];	// this is a shorthand for tri-matrices multiplication. Actual code should extend the calculation of matrix multiplication
	
	// repeat for variance2;
	
	covariance = z1[] * annualVarcovar * z2[];

	return = discreteReturn(price);
	risk = stdDev(price);

	for (i = 0 ; i < NUMBER_OF_OBSERVATIONS ; i++)
	{
		if (maxReturn < return[i])	maxReturn = return[i];
		if (maxRisk < risk[i])	maxRisk = risk[i];
		// the maximum return and standard deviation here are not exactly value due to limitation of the method
	}

	do
	{
		w2 = 1 - w1;	// rebalance the two asset portfolio
		EfficientFrontier.return[i] = w1 * expectedReturn1;	// for demonstration only, a mutator should be used
		EfficientFrontier.risk[i] = (w1^2 * variance1 + w2^2 * variance2 + 2 * w1 * w2 * covariance)^(1/2);	// for demonstration only, a mutator should be used
		w1 += INCREMENT;
		i++;
	}
	while(EfficientFrontier.return[i] <= maxReturn);	// for demonstration only, an accessor should be used
}

/* 
 * Global Minimum Variance Portfolio
 */

	gmvpWeight1 = (variance2 - covariance) / (variance1 + variance2 + 2 * 

covariance);	// Bodie Kane Marcus Investments 8e page 204
	gmvpWeight2 = 1 - gmvpWeight1;
	EfficientFrontier.gmvpReturn = gmvpWeight1 * expectedReturn1 + 

gmvpWeight2 * expectedReturn2;
	EfficientFrontier.gmvpRisk = (gmvpWeight1^2 * variance1 + gmvpWeight2^2 * 

variance2 + 2 * gmvpWeight1 * gmvpWeight2 * covariance)^(1/2);

	tangentWeight1=(expectedExcessReturn1*variance2-

expectedExcessReturn1*covariance)/

(expectedExcessReturn1*variance2+expectedExcessReturn2*variance1-

(expectedExcessReturn1+expectedExcessReturn2)*covariance);
	// Bodie Kane Marcus Investments 8e page 207
	tangentWeight2 = 1 - tangentWeight1;
	EfficientFrontier.gmvpReturn = tangentWeight1 * expectedReturn1 + 

tangentWeight2 * expectedReturn2;
	EfficientFrontier.gmvpRisk = (tangentWeight1^2 * variance1 + 

tangentWeight2^2 * variance2 + 2 * tangentWeight1 * tangentWeight2 * covariance)^

(1/2);

	return EfficientFrontier;

UNSW Coat of Arms

By , August 7, 2012 7:12 pm

Universitas Nova Cambria Australis

The lion and the four stars of the Southern Cross on the St George’s Cross have reference to the State of New South Wales which established the University;

The open book with "Scientia" (knowledge) across its pages is a reminder of its purpose.

The placement of "Scientia" on the book was inspired by its appearance on the arms of the Imperial College of Science, Technology and Medicine, formed in 1907.

Beneath the shield is the motto "Manu et Mente" (with hand and mind), which was the motto of the Sydney Technical College, from which the University developed.

Nivi.vn officially launches

By , August 7, 2012 12:14 pm

5 months after the leak, Nivi.vn officially launched.

The character limit is 250, understandably because of length of Vietnamese language. Case study: LinkHay blast limits 250.

The site provides verification badge for using real name and real profile picture. Users can choose to remain anonymous, however.

Follow me on Nivi: @taitran

Chỉ số VN30

By , July 27, 2012 11:13 am

Stock Return Forecast – Theory and Empirical Evidence

By , July 20, 2012 8:58 pm

For the entrepreneur: what type of fund you want to work with

By , July 5, 2012 8:48 am

Stage Type(s) of investor relevant to you What you should ideally have had General goal
Seed Angel investors
  1. Business plan (at least with business model, product development plan, marketing & sales plan, pricing structure, KPI forecast, risk management plan, industry analysis, key member details of skills)
  2. Co-founding team
  3. Incorporated
To develop products
Early Venture capitalists Working products
  • To market the products
  • To develop business
  • To scale the business
Growth Private equity funds Profit To become (a) market leader
Pre-IPO Mutual funds IPO roadmap To raise fund from the capital market for sustaining growth
Post-IPO Mutual funds, hedge funds, ETFs … More projects for growth To sustain growth
Going private LBO funds LBO plan To grow in private
Turnover Turnover funds
  • Turnover plan
  • Restructuring plan
To turnover the business

Outline of investment thesis for VCCorp

By , June 28, 2012 5:20 pm

Monte Carlo method for Option Pricing: Pseudo-Code

By , June 25, 2012 1:44 pm
/*
 * Pseudo-code
 * Monte Carlo method for option pricing
 */

double S;	// price of underlying asset
double r;	// interest rate
double sigma;	// volatility
double t;	// time to maturity
double X;	// exercise price
double n;	// number of simulations
double i;	// loop parameter

/*
 * Code to get the variables from user input
 */

/*
 * Function to retrieve lognormal random variable
 */
double getLognormalRandomVariable(S, r, sigma, t)
{
	return S * exp( (r - 0.5 * sigma ^2) * t + sigma * sqrt(t) );
}

/*
 * Pricing European Call option
 */
double R;
double sd;
double St;
double sumPayoff = 0;

double  getEuropeanCallPrice(S, X, r, sigma, t, n)
{
	R = (r - 0.5 * sigma ^ 2) * t;
	sd = sigma * sqrt(t);

	for (i = 0 ; i < n ; i++)
	{
		St = S * exp (R + sd * randomNormal() );
		sumPayoff += max (0, St - X);
	}
	return exp (-r * t) * (sumPayoff / n);
}

/*
 * Calculate Delta
 */
double q;
double c;
double cq;
double sumPayOffQ = 0;

double getEuropeanCallDelta(S, X, r, sigma, t, n)
{
	q = S * 0.01;

	for (i = 0 ; i < n ; i++)
	{
		St = S * exp (R + sd * randomNormal() );
		sumPayoff += max (0, St - X);
		Stq = (S + q) * exp (R + sd * randomNormal() );
		sumPayoffQ += max (0, Stq - X);
	}
	c = exp (-r * t) * (sumPayoff / n);
	cq = exp (-r * t) * (sumPayoffQ / n);
	return (cq - c) / q;
}

double[] motions;

double[] getBrownianMotion (S, r, sigma, t)
{
	motions = new double[n];

	for (i = 0 ; i

Merchant’s risks when running Groupon deals

By , June 9, 2012 10:49 am

  1. The sales team loses sale skill, leads to redeal addiction.
  2. Conflict between business development department and servicing departments (production, customer service, supply chain, logistics).
  3. At least 100% capacity is utilized during deal leading to overload, distress, attrition, accelerated depreciation, process change, and even company culture.
    Shift from actively serving customers to responding to waves of customers.
    Overloaded customer service leads to deteriorated service quality.
    Dominated by mass + low margin products and lose the opportunity to sell sophisticated + high margin products.
  4. Lose transparency of pricing structure, leading to loss of trust from customers and potential customers, and even company employees. Marking up then reducing price make the company "forget" the original target price. Intra-company information diffusion worsens this.
  5. High inflation leads to appreciation of supply costs. The company may get stuck if the groupon service provider refuse to increase selling price. Worse, groupon service providers are good in Search Engine Optimization and potential customers can easily search for expired price list.
  6. The customer segment directed from groupon mostly includes deal hunters. If the product / service is not essential they will not return to pay full price.
  7. Brand dilution. Unable to sell mid-end and hi-end products.
  8. Lack of experience in running deal leads to tricky situation when following consultation of groupon salesperson (pricing, maximum number of vouchers to sell, terms, deal duration). Interests of merchants and those of groupon salesperson are not always aligned.
  9. Peer pressure: running deal seeing competitors’ deal, leading to industry deterioration.

Vietnam e-Commerce May 2012

By , May 25, 2012 6:20 pm

I gave a presentation on Vietnam e-Commerce in mid 2012 for Open Consultant’s event.

My slide can be viewed here:


Panorama Theme by Themocracy