Monday, April 14, 2014

Financial Markets with Professor Robert Shiller by YaleCourses

Return is between minus 100% to positive infinity and gross return equals 1 + return. (cannot be negative)
numerator/denominator
geometric mean and arithmetic mean (if the return is 100%, no meaning for arithmetic average)
the expected value for continuous x
variance and deviation
covariance (individual stock and index movement relationship for example)
correlation
variance of sum: var(x+y) = = var(x) + var(y) + 2cov(x,y)

We had a big financial crisis in the United States in 1987, when there was a stock market crash that was bigger than any before in one day. We will be
talking about that. But after the 1987 crash, companies started to compute a measure of the risk to their company, which is called Value at Risk.
VaR, V and R are capitalized so that to differentiate the variance.
The calculation (e.g): 5% probability to lose $10 million dollars in a year. Need the model to calculate the probability.

To do: 3. Technology and Invention in Finance

Tuesday, April 8, 2014

英语学习:Complete与finish的区別

2012年,在伦敦举行的语言大赛中,圭亚那选手Samsunder Balgobin 在回答比赛中最后一道问题"你如何用一种容易让人理解的方式解释 complete与finished 的区別"时,给出了他的答案: When you marry the right woman, you are COMPLETE. (娶对老婆,你这一生就完整了。) When you marry the wrong woman, you are FINISHED. (娶错老婆,你这一生就完蛋了。) And when the right one catches you with the wrong one, you are COMPLETELY FINISHED. (让大老婆逮到你跟小三,你就彻底地完蛋了。) 担任比赛的全世界一流的语言学家将桂冠戴在了这位选手的头上,奖品是环球游和一箱25年窖龄的朗姆酒,全场观众和评委为他起立鼓掌长达五分钟。 

From http://www.rolia.net/f/post.php?f=0&p=8693836

Sunday, April 6, 2014

Java Optimization Experience

To enable more than 1000 filter on more than 60k records with a lot of business rules, it can be spent only 2 seconds on my PC.
Use cqengine (with RadixTreeIndex and ReversedRadixTreeIndex) instead of looping collection.
For collections.removeAll, HashSet is much faster than ArrayList since HashSet contains implementation is map.containsKey(o); while ArrayList is:
    public boolean contains(Object o) {
return indexOf(o) >= 0;
    }

    /**
     * Returns the index of the first occurrence of the specified element
     * in this list, or -1 if this list does not contain the element.
     * More formally, returns the lowest index <tt>i</tt> such that
     * <tt>(o==null&nbsp;?&nbsp;get(i)==null&nbsp;:&nbsp;o.equals(get(i)))</tt>,
     * or -1 if there is no such index.
     */
    public int indexOf(Object o) {
if (o == null) {
   for (int i = 0; i < size; i++)
if (elementData[i]==null)
   return i;
} else {
   for (int i = 0; i < size; i++)
if (o.equals(elementData[i]))
   return i;
}
return -1;
    }

Saturday, April 5, 2014

Get the difference between two double string

import java.math.BigDecimal;
import java.math.RoundingMode;


public class DoubleDiff {

public static void main(String[] args) {
System.out.println(getDiff("3.1E-4","0.0032"));
System.out.println(getDiff("0.0031","0.0032"));
System.out.println(getDiff("0.0031","0.003"));
System.out.println(getDiff("0.0031","0.00319"));
System.out.println(getDiff("1","1.9"));
System.out.println(getDiff("2","2.1"));
System.out.println(getDiff("1","2.1"));
System.out.println(getDiff("NA","2.1"));
System.out.println(getDiff("0","Str"));
}

//may contains E/e
public static String getDiff(String acClose,String ssClose){
String result = "";
try {
BigDecimal acCloseDouble = new BigDecimal(acClose);
BigDecimal ssCloseDouble = new BigDecimal(ssClose);
if(acCloseDouble.compareTo(ssCloseDouble)==0){
result = "0";
}
else{
if(acCloseDouble.scale()==ssCloseDouble.scale()){
result = acCloseDouble.subtract(ssCloseDouble).stripTrailingZeros().toPlainString();
}
else{
int minScale = Math.min(acCloseDouble.scale(), ssCloseDouble.scale());
acCloseDouble = acCloseDouble.setScale(minScale, RoundingMode.DOWN);
ssCloseDouble = ssCloseDouble.setScale(minScale, RoundingMode.DOWN);
result = acCloseDouble.subtract(ssCloseDouble).stripTrailingZeros().toPlainString();
}
}
//stripTrailingZeros may has no impact for 0.000 because of the scale
if(result.matches("0\\.0*")){
result = "0";
}
} catch (Exception e) {
result = acClose+"-"+ssClose;
// e.printStackTrace();
}
return result;
}

}