- 唯有願意承擔重大風險的人才能享有高報酬。如果你追求的是豐厚的報酬,就必須準備好承受一次又一次的痛苦損失;假設你追求的是絕對安全,結果就會是乏善可陳的報酬
- 用來辨識投資詐術的最佳指標就是,既有豐厚報酬又無虞風險的報酬。追求高報酬不可能避開高風險,安全投資的報酬一定低
- 歷史上的投資報酬很難用來預測未來的投資報酬。歷史紀錄的真正價值是用來衡量風險,而非報酬
- 小型股比大型股的報酬更高,但是風險也更大。風險與報酬之間永遠都是心手相連。你當然可以追求更高的報酬,只要你願意承擔更高的風險
- 從投資報酬率來看,營收不穩,充滿危險的股票,要比穩定營收的成長型股票更具優勢。好公司通常是爛股票,而壞公司卻通常是好股票
- 當政治與經濟局勢看起來前途光明的時候,就是報酬最低的時候,而當一切看起來黯淡無望時,才會有最高的報酬
- 風險資產持有愈久,損失的機會愈低
- 股市與債市的歷史紀錄指出,在風險與報酬之間有著無法分割的緊密聯繫,不要期待有什麼投資標的可以帶來高報酬而無需承擔風險,也不要期待低風險的投資會有高報酬
- 資本的價值在於有多少收入變成現金,除此之外,別無其他。例如假設你有一個果園,果園的價值不在於有多少果樹或面積,而是在於可創造出多少收入。公寓的價值也不在於可賣得多少錢,而在於未來可帶來多少現金流。你自己的房子價值為何?價值在於這些年裡這種房子帶給你多少庇護與歡樂
- 股票或債券的價格,只不過是未來預期收入的現值
- 「如何區分投機或投資?」基於財務考量,購入一枚稀有硬幣或精緻畫作,顯然就是投機,因為這項資產不會創造收入,所有的報酬來自於之後有人用更高的價錢跟你購買
- Great fool theory:如果你買進了一項快速增值,但 intrinsic value (內在價值)有限的資產,你就是在等待有人比你更笨,願意用更高的價格從你手中買進這項資產
- 若因期待股息增加而購買某隻股票的話,這也是空泛的想像,而非投資
- 今天收入的一美元,與三十年後才收入的一美元,比不上今天收入的一美元。因此,未來收入的價值必須重新折算,以反映出這個未來收入的現在價值。這個折算過程必須考慮四項因素:
- 實現收入前必須等待的時間:等待的時間越遠,對於此刻的你價值愈低
- 通貨膨脹率:通貨膨脹率愈高,未來預期收入的貨幣實際購買力便愈低,價值也愈低
- 社會對於未來消費的「渴望程度」:社會對於即刻消費的偏好愈高,利率就會愈高(貼現率愈高),未來收入的現今價值就愈低
- 風險本身:未來收入的風險愈高,現值就愈低,如 30 年後根本拿不回來
- 貼現率(discount rate)與現值彼此成反比關係,貼現率愈高,現值愈低。影響貼現率的因素就是「利率」。舉個例子來說,飢腸轆轆的人願為誤時餐點付出的代價必定低於剛剛飽餐的人,代表餓漢對於食物的貼現率偏高,因為餓漢對食物的即時需求遠高於已吃飽的人;闊少爺的利率(貼現率)就是比吝嗇鬼高
- 貼現率的上升,意味著未來某項物品的現值將會降低;如果現在的巴黎七日遊折換成未來旅遊時,會從一週增加到五週,就代表未來旅遊的現值又降低了
- 長期而言,企業營利的成長才能促使股價成長
- 就算是全能的主,也無法知道任何一支普通股的本益比倍數 (price-earning multiple)應該要多少才適當。任何人都不可能知道股票或股市的內在價值
- 當股價劇烈下滑時,就會變成金融世界裡人人避之惟恐不及的怪物;相反地,當價格迅速崛起,每個人則都想要過去湊熱鬧
- 股市的基本報酬(即股息成長率和股息收益率之加總)在某些程度上是可以預期的,但是只能針對長時間的狀況。短期的股市投資報酬則純屬投機,且無法預期,不論是誰都無能為力
Total Pageviews
2018/03/02
[閱讀筆記] The Four Pillars of Investing (3/12)
Labels:
Investment,
Reading
2018/03/01
[閱讀筆記] Seriously... I'm Kidding
- 你要了解你自己,並且接受這樣的你。
- 每個人都有缺點,因為只要是人類都會有缺點。如果我們能接受缺點是我們的一部份,這些缺點就不會是個問題。當你學會接受自己,別人就會學著接受你
- 年紀是我們的一部份,也是一個不可改變的事實。當你 7 歲半時,若人家說你7 歲,你還會生氣的說我已經 7 歲半。但是當你 42 歲時,還會向別人強調你是 42 歲半嗎? 只要是人就會天天變老,但是在變老的過程中,記得從每一天的錯誤中學習,讓自己更加睿智。
- 如何讓自己在伸展台上變成 supermodel
- The Look: 總是讓自己看起來很生氣的樣子
- The Walk: 有侵略性的快步走,彷彿一匹試圖避開水坑的馬
- The Squint: 瞇著眼看人,彷如剛起床,看到陽光般的眼睛
- The Pout: 噘起你的嘴唇,猶如吸著吸管般
- The Pose: 動作要神秘,總是將一隻手放在口袋裡,讓人永遠不知道口袋裡的那隻手有可能是隻 hook hand
- The Breeze: 總是帶著一個巨大的電扇
- 當你住得越久,買的東西會越來越多,家裡的東西就會越來越多,你可能衣櫥塞滿了過季、穿不到的衣服,抽屜塞滿了再也用不到的雜物。記住,保持整潔乾淨的環境很重要,我不喜歡凌亂的家裡,我堅信每個東西都有一個歸屬的地方。將不需要、用不到的東西丟掉、送人或放到拍賣網站上面賣掉它吧
- 世界上最重要的事情就是幸福 (happiness),絕對不是金錢,當你找到幸福的時候,你就會發現 the secret of life。不要一直看著背後,也不要花太多時間憂心未來,好好地享受當下。在每天走過的地方停下來聞聞花香,起床後聞聞咖啡的味道,享受成功當下甜美的味道,當你聞越多,你就會感覺得越快樂與幸福
- 我喜歡獨特,我喜歡有自己的風格、自己的意見。能夠從廣大的群眾中凸顯出自己的與眾不同會是一件很棒的一件事情,若一眼望去發現一堆跟自己很像的人,這世界將會變得很乏味無趣。常有人說哪個比較好或比較差?甚至是什麼比較正常或一般?記住,我們都是不同的人,也允許別人與你不同
- 人生的道路猶如在道路上開車,道路有時筆直、有時彎曲,有時你會加速、有時會減速,有時候你會短暫的停車加油或維修,加油、維修結束後,勇敢、努力地繼續往前走
- 人們總是很喜歡幫別人貼標籤,貼標籤導致刻板印象 (stereotypes),刻板印象導致以偏概全 (generalizations),以偏概全導致臆測 (assumptions),臆測又回到刻板印象,這是一個惡性循環 (vicious cycle)。若你認定刻板印象是精確的話,那恐怕是非常危險的一件事,不是所有的紐約客都是粗魯的,也不是加州人都是嬉皮。不是所有有錢人都是勢利眼的,也不是所有名人都是以自我為中心的。在你做出貼標籤、刻板印象、以偏概全、臆測前,不如走過去跟他們聊聊天、問問題
- 你永遠不會太晚學習新事物,你只會太晚穿低腰牛仔褲 (low-rise jeans)
- 有些人很擅長做決策,因為他們知道他們要什麼,所以可以很快地做出決策,我稱這些人為 Quick Decision Makers;有些人則是非常拙於做決策,常常猶豫不決,花了好幾天、或好幾周甚至好幾年還決定不了,我稱這些人為 Annoying。你會在星巴克發現一個有趣的事實:Quick Decision Makers 常常在星巴克排隊隊伍中被 Annoying 卡住
- 當在做重大的決策時,我會把決策的正面與反面的清單列出來,如此一來我可以看到所有正面與負面的清單,如此一來可以決定哪個方案對我是最好的
- 我覺得世界上有兩種人,deep thinkers 與 not so deep thinkers。deep thinkers 會問很多問題,對於他們的行動是有意識的,對於每天所做、所見、所聞,都會尋找理由與合理的解釋;not so deep thinkers 就像人們去丟垃圾一樣毫無所感。記得要當個 deep thinkers!
- 讓自己保持正面,會讓自己的生活很不一樣。這會讓你周遭都是正面的人,沒有人喜歡負面、陰沉的人。當你保持正面與快樂,你的體內會充滿 endorphins (腦內嗎啡) ,endorphins 可以提升你的免疫系統、健康,讓你感到更幸福
- 人生就是在維持平衡,人生總是有好有壞,有高有低,充滿著酸甜苦辣。幸福緣自於內心,想辦法避免負面、不好的想法入侵你的心理,將其取代為愉快、正面的想法吧
- 幸福是一段旅程,而非終點 (Happiness is a journey, not a destination)
- 這個以消費為主的社會,不斷鼓勵人們消費,超出實際所需,甚至到了不健康的地步。如果你覺得儲蓄很難,那你的問題就很大。最簡單的致富方式就是盡可能少花錢
- 你要有自我的主見,不要憂心別人怎麼說你,怎麼看待你,就讓那些唱反調的人去說吧
Labels:
Reading
2018/02/28
2018/02/27
2018/02/14
[Fortify] Fix Cross-Site Scripting: Persistent
Problem
Before
Code snippet in JSP file:
After
Add dependency in pom.xml
Updated code snippet in JSP file:
Reference
[1] https://github.com/OWASP/owasp-java-encoder/wiki/2)-Use-the-OWASP-Java-Encoder
Before
Code snippet in JSP file:
1 2 | String content = report.getContent();
out.print(content);
|
After
Add dependency in pom.xml
1 2 3 4 5 | <dependency> <groupId>org.owasp.encoder</groupId> <artifactId>encoder</artifactId> <version>1.2.1</version> </dependency> |
Updated code snippet in JSP file:
1 2 3 4 5 | <%@ page import="org.owasp.encoder.Encode"%> String content = report.getContent(acct_no,schema+"://"+server+":"+port); out.print(Encode.forHtml(content)); |
Reference
[1] https://github.com/OWASP/owasp-java-encoder/wiki/2)-Use-the-OWASP-Java-Encoder
Labels:
Fortify
2018/02/13
[HP Laptop] Function Keys 問題
Problem
剛拿到 HP Laptop 時,發現當我要按 F1 ~ F12 按鈕,都需要先按下 fn key 才能使用,若否則會啟動音量調整、螢幕亮度調整的功能。該如何設定,讓與系統預設的設定對調?
How-To
剛拿到 HP Laptop 時,發現當我要按 F1 ~ F12 按鈕,都需要先按下 fn key 才能使用,若否則會啟動音量調整、螢幕亮度調整的功能。該如何設定,讓與系統預設的設定對調?
How-To
須進入BIOS Setup 畫面進行設定,處理流程如下
Screenshot for Step 2
Screenshot for Step 3 and Step 4
Screenshot for Step 5
2018/02/12
[Jackson] How to convert JSON string to YAML?
Problem
Assume I have a JSON string:
I would like to convert JSON string to YAML:
How to do it?
How-To
Take advantage of libraries can fulfill this requirement.
Add the following dependencies in pom.xml
Here has sample code:
Assume I have a JSON string:
1 2 3 4 5 6 7 8 9 10 11 | { "id": 1, "name": "Albert", "email": "albert@gmail.com", "phone": "0900123456", "address": { "streetAddress": "信義區信義路五段7號", "city": "台北市", "zipCode": "110" } } |
I would like to convert JSON string to YAML:
1 2 3 4 5 6 7 8 9 10 | --- id: 1 name: "Albert" email: "albert@gmail.com" phone: "0900123456" address: streetAddress: "信義區信義路五段7號" city: "台北市" zipCode: "110" |
How to do it?
How-To
Take advantage of libraries can fulfill this requirement.
Add the following dependencies in pom.xml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | <dependency> <groupId>com.fasterxml.jackson.core</groupId> <artifactId>jackson-core</artifactId> <version>2.9.3</version> </dependency> <dependency> <groupId>com.fasterxml.jackson.core</groupId> <artifactId>jackson-databind</artifactId> <version>2.9.3</version> </dependency> <dependency> <groupId>com.fasterxml.jackson.core</groupId> <artifactId>jackson-annotations</artifactId> <version>2.9.3</version> </dependency> <dependency> <groupId>com.fasterxml.jackson.dataformat</groupId> <artifactId>jackson-dataformat-yaml</artifactId> <version>2.9.3</version> </dependency> |
Here has sample code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | package test.albert.jackson; import java.io.IOException; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.dataformat.yaml.YAMLMapper; import lombok.extern.slf4j.Slf4j; @Slf4j public class JacksonTest { public static void main(String[] args) throws IOException { Address address = Address.builder().zipCode("110").city("台北市").streetAddress("信義區信義路五段7號").build(); Employee albert = Employee.builder().id(1).name("Albert").email("albert@gmail.com").phone("0900123456") .address(address).build(); ObjectMapper mapper = new ObjectMapper(); // convert object to JSON String json = mapper.writeValueAsString(albert); log.debug(json); // convert JSON to YAML JsonNode jsonNode = mapper.readTree(json); String yaml = new YAMLMapper().writeValueAsString(jsonNode); log.debug("yaml = \n " + yaml); } } |
Labels:
jackson
2018/02/11
[Liquibase] How to fix checksum validation error
Problem
I am editing changelog-master.yaml, I got error message as I start up Spring boot:
How-To
Here has the process to solve this problem:
1. drop all tables which had already created in liquibase
2. clear all data in databasechangelog table
I am editing changelog-master.yaml, I got error message as I start up Spring boot:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'liquibase' defined in class path resource [org/springframework/boot/autoconfigure/liquibase/LiquibaseAutoConfiguration$LiquibaseConfiguration.class]: Invocation of init method failed; nested exception is liquibase.exception.ValidationFailedException: Validation Failed: 1 change sets check sum classpath:/db/changelog/db.changelog-master.yaml::1::albert was: 7:6e574692a29b35c6788f06c99fe2eecc but is now: 7:c5994a0c5ad9c2ba211a4f8e3ced2ec9
How-To
Here has the process to solve this problem:
1. drop all tables which had already created in liquibase
2. clear all data in databasechangelog table
delete from databasechangelog
Labels:
liquibase
2018/02/10
[Ant] java.lang.UnsupportedClassVersionError: com/sun/tools/javac/Main : Unsupported major.minor version 52.0
Problem
When I use Ant 1.10.1 to build my Java project, it occurs error as bellows:
How-To
The problem is 1.10.x releases require Java 8 at run time, but I am using Java 7 in my project.
Therefore, I need to use Ant 1.9.x releases instead of 1.10.x releases
When I use Ant 1.10.1 to build my Java project, it occurs error as bellows:
java.lang.UnsupportedClassVersionError: org/apache/tools/ant/launch/Launcher : Unsupported major.minor version 52.0
How-To
The problem is 1.10.x releases require Java 8 at run time, but I am using Java 7 in my project.
Therefore, I need to use Ant 1.9.x releases instead of 1.10.x releases
Labels:
ant
2018/02/09
[Maven] How to stop Maven to check for updates for artifacts in offline mode ?
Problem
I am using offline mode to build my project, the command is as bellows:
How-To
Go to your local repository (ex. C:/Users/albert/.m2), and delete all *.lastupdated and _remote.repositories files.
Then Maven won't check updates any more.
I am using offline mode to build my project, the command is as bellows:
mvn -o -Dmaven.repo.local="C:/Users/albert/.m2" clean install -Dmaven.test.skip=trueDuring the build process, Maven still check for updated for certain artifacts even in offline mode. How to avoid it?
How-To
Go to your local repository (ex. C:/Users/albert/.m2), and delete all *.lastupdated and _remote.repositories files.
Then Maven won't check updates any more.
Labels:
Maven
2018/02/08
[PostgreSQL] How to assign customized numbering rule in primary key
Problem
Assume I have a table, loan_main, which have a primary key, loan_id, with numbering rule : LN_YYYYMMDD_9999999999.
How to insert data into loan_main automatically without caring how to build loan_id with this numbering rule.
How-to
In this case, we need to know
1. how to concatenate string, i.e. ||
2. how to get current date with specific format:
3. how to get value from sequence and pad zero to the left:
The syntax looks like:
Assume I have a table, loan_main, which have a primary key, loan_id, with numbering rule : LN_YYYYMMDD_9999999999.
How to insert data into loan_main automatically without caring how to build loan_id with this numbering rule.
How-to
In this case, we need to know
1. how to concatenate string, i.e. ||
2. how to get current date with specific format:
select to_char(now(), 'YYYYMMDD')
3. how to get value from sequence and pad zero to the left:
select LPAD(nextval('loan_sequence')::text, 10, '0')
The syntax looks like:
ALTER TABLE loan_main ALTER COLUMN loan_id SET DEFAULT ('LN_' || (to_char(now(), 'YYYYMMDD')) || '_' || LPAD(nextval('loan_sequence')::text, 10, '0'));
Labels:
Database
2018/02/07
Java Bean Validation example
Add dependencies to your pom.xml
Scenario
Assume I have a Customer bean, it have 6 attributes which include id, name, gender, age, email and dateOfBirth.
These attributes have its validation rules:
The Java bean with bean validation annotation looks like:
Assume I have a CustomerService class to create Customer, it should validate Customer Java Bean before do insert. The main validate logic will be in validate method (line 25 ~ 38).
The resource class will prepare Customer Object and invoke create method which provide by CustomerService
Execution message in console:
<!-- validation start --> <dependency> <groupId>javax.validation</groupId> <artifactId>validation-api</artifactId> <version>2.0.0.Final</version> </dependency> <dependency> <groupId>org.hibernate</groupId> <artifactId>hibernate-validator</artifactId> <version>6.0.2.Final</version> </dependency> <dependency> <groupId>org.glassfish</groupId> <artifactId>javax.el</artifactId> <version>3.0.1-b08</version> </dependency> <!-- validation end --> <!-- DI start --> <dependency> <groupId>com.google.inject</groupId> <artifactId>guice</artifactId> <version>4.1.0</version> </dependency> <!-- DI end --> <!-- lombok --> <dependency> <groupId>org.projectlombok</groupId> <artifactId>lombok</artifactId> <version>$1.16.18</version> <scope>provided</scope> </dependency> <dependency> <groupId>com.google.guava</groupId> <artifactId>guava</artifactId> <version>21.0</version> </dependency>
Scenario
Assume I have a Customer bean, it have 6 attributes which include id, name, gender, age, email and dateOfBirth.
These attributes have its validation rules:
- id should not be null
- name should not by null or empty
- gender should not be null
- age should be between 18 and 60
- email should not be null or empty and should have valid format
- dateOfBirth should be before today
The Java bean with bean validation annotation looks like:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 | package albert.practice.validation; import java.util.Date; import javax.validation.constraints.Email; import javax.validation.constraints.NotEmpty; import javax.validation.constraints.NotNull; import javax.validation.constraints.Past; import org.hibernate.validator.constraints.Range; import lombok.AllArgsConstructor; import lombok.Data; import lombok.NoArgsConstructor; import lombok.ToString; @AllArgsConstructor @NoArgsConstructor @ToString @Data public class Customer { public static enum Gender { MALE, FEMALE; } @NotNull(message = "顧客編號不可為 null") private Long id; @NotEmpty(message = "姓名不可為空") private String name; @NotNull(message = "性別不可為空") private Gender gender; @Range(min = 18, max = 60, message = "年齡必須介於 18 到 60 歲之間") private Integer age; @NotEmpty(message = "Email 不可為空") @Email(message = "Email 格式不合法") private String email; @Past(message = "生日必須要今天以前") private Date dateOfBirth; } |
Assume I have a CustomerService class to create Customer, it should validate Customer Java Bean before do insert. The main validate logic will be in validate method (line 25 ~ 38).
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 | package albert.practice.validation; import java.util.ArrayList; import java.util.List; import java.util.Set; import javax.validation.ConstraintViolation; import javax.validation.Validation; import javax.validation.Validator; import com.google.common.base.Joiner; import com.google.common.base.Strings; import com.google.inject.Singleton; import lombok.extern.slf4j.Slf4j; @Slf4j @Singleton public class CustomerService { public void create(Customer customer) { validate(customer); } public static void validate(Object obj) { List<String> errors = new ArrayList<>(); Validator validator = Validation.buildDefaultValidatorFactory().getValidator(); Set<ConstraintViolation<Object>> violations = validator.validate(obj); for (ConstraintViolation<Object> violation : violations) { errors.add(violation.getMessage()); } String completeErrorMsg = Joiner.on("\n").join(errors); if (!Strings.isNullOrEmpty(completeErrorMsg)) { throw new IllegalArgumentException(completeErrorMsg); } } } |
The resource class will prepare Customer Object and invoke create method which provide by CustomerService
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | package albert.practice.validation; import com.google.inject.Guice; import com.google.inject.Inject; public class CustomerResource { @Inject private CustomerService service; public static void main(String[] args) { Customer customer = new Customer(); customer.setId(null); customer.setAge(12); customer.setEmail("test@gmail."); new CustomerResource().createCustomer(customer); } public void createCustomer(Customer customer){ service = Guice.createInjector().getInstance(CustomerService.class); service.create(customer); } } |
Execution message in console:
1 2 3 4 5 6 7 8 9 | Exception in thread "main" java.lang.IllegalArgumentException: 性別不可為空 年齡必須介於 18 到 60 歲之間 Email 格式不合法 顧客編號不可為 null 姓名不可為空 at albert.practice.validation.CustomerService.validate(CustomerService.java:35) at albert.practice.validation.CustomerService.create(CustomerService.java:20) at albert.practice.validation.CustomerResource.createCustomer(CustomerResource.java:22) at albert.practice.validation.CustomerResource.main(CustomerResource.java:17) |
Labels:
Java
Subscribe to:
Posts (Atom)