Total Pageviews

2014/10/27

How to use Google Guava to do Collection Filter

Requirement

We have a collection data (List of value object), we would like to find the objects which fyr is 101. 
Here has the collection data:
1:  dtoList=[  
2:  gov.nta.fms.dto.FmsSumRateDto@1a395e5a[fyr=101,accmon=01,alc=168407392348.53,alcavg=0.0809],   
3:  gov.nta.fms.dto.FmsSumRateDto@2c617429[fyr=101,accmon=02,alc=164834284030.53,alcavg=0.0792],   
4:  gov.nta.fms.dto.FmsSumRateDto@32114682[fyr=101,accmon=03,alc=180965071697.53,alcavg=0.0869],   
5:  gov.nta.fms.dto.FmsSumRateDto@c2c1a7c[fyr=101,accmon=04,alc=165659472439.53,alcavg=0.0796],   
6:  gov.nta.fms.dto.FmsSumRateDto@237ec922[fyr=101,accmon=05,alc=180372232532.53,alcavg=0.0866],   
7:  gov.nta.fms.dto.FmsSumRateDto@58c6e962[fyr=101,accmon=06,alc=176357775471.53,alcavg=0.0847],   
8:  gov.nta.fms.dto.FmsSumRateDto@6b044e76[fyr=101,accmon=07,alc=187368376522.53,alcavg=0.09],   
9:  gov.nta.fms.dto.FmsSumRateDto@67bb5bdd[fyr=101,accmon=08,alc=181824695849.53,alcavg=0.0873],   
10:  gov.nta.fms.dto.FmsSumRateDto@3d8c3f5f[fyr=101,accmon=09,alc=170308922011.45,alcavg=0.0818],   
11:  gov.nta.fms.dto.FmsSumRateDto@4294958a[fyr=101,accmon=10,alc=168308032423.95,alcavg=0.0808],   
12:  gov.nta.fms.dto.FmsSumRateDto@28e5b92c[fyr=101,accmon=11,alc=179491195734.95,alcavg=0.0862],   
13:  gov.nta.fms.dto.FmsSumRateDto@1e00cae[fyr=101,accmon=12,alc=157844063362.95,alcavg=0.0758],   
14:  gov.nta.fms.dto.FmsSumRateDto@1c607478[fyr=102,accmon=01,alc=170969213258.95,alcavg=0.0806],   
15:  gov.nta.fms.dto.FmsSumRateDto@7e80d6[fyr=102,accmon=02,alc=159840653037.95,alcavg=0.0753],   
16:  gov.nta.fms.dto.FmsSumRateDto@713c61da[fyr=102,accmon=03,alc=169579370948.95,alcavg=0.0799],   
17:  gov.nta.fms.dto.FmsSumRateDto@333c694a[fyr=102,accmon=04,alc=169624940547.95,alcavg=0.0799],   
18:  gov.nta.fms.dto.FmsSumRateDto@4324938d[fyr=102,accmon=05,alc=173064277154.95,alcavg=0.0816],   
19:  gov.nta.fms.dto.FmsSumRateDto@1653306b[fyr=102,accmon=06,alc=169616844409.95,alcavg=0.0799],   
20:  gov.nta.fms.dto.FmsSumRateDto@2f8fcc40[fyr=102,accmon=07,alc=175060305269.95,alcavg=0.0825],   
21:  gov.nta.fms.dto.FmsSumRateDto@9aa9625[fyr=102,accmon=08,alc=193638114494.95,alcavg=0.0913],   
22:  gov.nta.fms.dto.FmsSumRateDto@1e675c18[fyr=102,accmon=09,alc=198567712906.95,alcavg=0.0936],   
23:  gov.nta.fms.dto.FmsSumRateDto@13cf3b40[fyr=102,accmon=10,alc=181427982270.95,alcavg=0.0855],   
24:  gov.nta.fms.dto.FmsSumRateDto@a3af0e9[fyr=102,accmon=11,alc=187353709301.95,alcavg=0.0883],   
25:  gov.nta.fms.dto.FmsSumRateDto@239e563e[fyr=102,accmon=12,alc=172980508042.95,alcavg=0.0815]  
26:  ]  


How to Use Google Guava API
1. Create Predicate instance to determines a true or false value for a given input. (Line1~Line7)
2. Utilize Collection2.filter to return the elements of unfiltered that satisfy a predicate.(Line8~line9)

Here has the code snippet:
1:     Predicate predicate = new Predicate() {  
2:        @Override  
3:        public boolean apply(FmsSumRateDto input) {  
4:          //Determines true or false value for a given input.  
5:          return "101".equqls(input.getFyr());  
6:        }  
7:      };  
8:      //Returns the elements of unfiltered that satisfy a predicate.  
9:      Iterator result = Collections2.filter(dtoList, predicate).iterator();  
10:      while(result.hasNext()) {  
11:        log.debug("result="+result.next().toString());  
12:      }  

Here is the result which statisfy the predicate:
1:  result=gov.nta.fms.dto.FmsSumRateDto@1a395e5a[fyr=101,accmon=01,alc=168407392348.53,alcavg=0.0809]  
2:  result=gov.nta.fms.dto.FmsSumRateDto@2c617429[fyr=101,accmon=02,alc=164834284030.53,alcavg=0.0792]  
3:  result=gov.nta.fms.dto.FmsSumRateDto@32114682[fyr=101,accmon=03,alc=180965071697.53,alcavg=0.0869]  
4:  result=gov.nta.fms.dto.FmsSumRateDto@c2c1a7c[fyr=101,accmon=04,alc=165659472439.53,alcavg=0.0796]  
5:  result=gov.nta.fms.dto.FmsSumRateDto@237ec922[fyr=101,accmon=05,alc=180372232532.53,alcavg=0.0866]  
6:  result=gov.nta.fms.dto.FmsSumRateDto@58c6e962[fyr=101,accmon=06,alc=176357775471.53,alcavg=0.0847]  
7:  result=gov.nta.fms.dto.FmsSumRateDto@6b044e76[fyr=101,accmon=07,alc=187368376522.53,alcavg=0.09]  
8:  result=gov.nta.fms.dto.FmsSumRateDto@67bb5bdd[fyr=101,accmon=08,alc=181824695849.53,alcavg=0.0873]  
9:  result=gov.nta.fms.dto.FmsSumRateDto@3d8c3f5f[fyr=101,accmon=09,alc=170308922011.45,alcavg=0.0818]  
10:  result=gov.nta.fms.dto.FmsSumRateDto@4294958a[fyr=101,accmon=10,alc=168308032423.95,alcavg=0.0808]  
11:  result=gov.nta.fms.dto.FmsSumRateDto@28e5b92c[fyr=101,accmon=11,alc=179491195734.95,alcavg=0.0862]  
12:  result=gov.nta.fms.dto.FmsSumRateDto@1e00cae[fyr=101,accmon=12,alc=157844063362.95,alcavg=0.0758] 


Reference


2014/10/23

要去哪裡查詢零股交易的相關資訊


有時候股票除了配現金以外,還會給零股給投資大眾,為了讓買賣比較容易(因為零股只能利用盤後交易),故通常會利用盤後交易來買零股湊成一張

我們如果要去查詢零股最佳一檔買、賣價格的話,可以到基本市況報導網站( http://mis.twse.com.tw/stock/oddTrade.jsp ) 查詢



 假設如果我要找的是『食品類股』,在上市類股下拉單選取『食品工業』

 該網站就會顯示相關食品類股的零股揭示買價、賣價、成交價以及成交股數


有關零股更多資訊可以參考 http://www.masterlink.com.tw/service/qanda/Q&A-6.htm 

2014/10/21

How to copy text from Notepad++ to Microsoft Word and keep its color to distinguish keywords


Notepad++ can distinguish between different languages source code can be written in. For example, a language could distinguish certain keywords that have to be differently interpreted, and as such it can be useful to distinguish these keywords using another color or font. 


For example.
The language is Java.

The language is SQL.


Scenario
If we would like to copy SQL statement from Notepad++ to Microsoft Word in my system design document, but it seems cannot keep its color to distinguish keywords. 
For example.

Resolution
Step1. Select text you would like to copy.

Step2. Plugins --> NppExport --> Copy RTF to clipboard

Step3. Paste text to Microsoft word


2014/10/16

How to display Tradition Chinese Character in Git Bash

Problem
Why I cannot display Tradition Chinese Character in Git Bash correctly?

Solution
You need to edit three files under git\etc

1. edit gitconfig file and append configuration as following:
1:  [gui]  
2:  encoding = utf-8   
3:  #log编码  
4:  [i18n]  
5:  commitencoding = utf-8   
6:  #支持中文路径  
7:  [svn]  
8:  pathnameencoding = utf-8   

2. edit git-completion.bash file and append configuration  as following:
1:  #正常顯示中文  
2:  alias ls='ls --show-control-chars --color=auto'  

3. edit inputrc file and append configuration  as following:
1:  #bash中可以正常输入中文  
2:  set output-meta on   
3:  set convert-meta off  

Check Result

2014/10/15

JRebel - Reload any changes without restart server

As a developer, we do not want to waste time to restart server again and again to see the implace of code changes.
You can try JRebel to save your time.

If you are using Eclipse, here has good step-by-step installation and configuration guide: http://manuals.zeroturnaround.com/jrebel/ide/eclipse.html

For more information, please check http://zeroturnaround.com/software/jrebel/learn/

Demo

Here has code snippet, and it will print debug message as entering this method
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
  @RequestMapping(value = "/query/tab1", method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)  
  public @ResponseBody  
  List findTab1(@RequestBody Fms420rFormBean formBean, Alerter alerter) {  
    log.debug("test");  
    List dataList = service.queryTab1(formBean.getYear(), formBean.getMonth());  
    if (CollectionUtils.isEmpty(dataList)) {  
      alerter.info(Messages.warning_notFound());  
    } else {  
      alerter.info(Messages.success_find());  
     }  
     return dataList;  
   } 

And the console will print "test" debugging message as entering this method:
1:  19:15:45,493 INFO [stdout]  [20123] DEBUG gov.nta.fms.web.rest.Fms420rResource - test  

In order to test JRebel, I just modified the debug message to "JRebel test" and submit query without restart application server
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
 @RequestMapping(value = "/query/tab1", method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)  
 public @ResponseBody  
 List findTab1(@RequestBody Fms420rFormBean formBean, Alerter alerter) {  
   log.debug("JRebel test");  
   List dataList = service.queryTab1(formBean.getYear(), formBean.getMonth());  
   if (CollectionUtils.isEmpty(dataList)) {  
     alerter.info(Messages.warning_notFound());  
   } else {  
     alerter.info(Messages.success_find());  
    }  
    return dataList;  
  } 
 
See....I don't redeploy and restart application server, but the console print the up-to-date debug message. 
1:  19:16:19,742 INFO [stdout]  [20123] DEBUG gov.nta.fms.web.rest.Fms420rResource - JRebel test  

It's because of JRebel reload any changes classes automatically. 
When you change any class or resource in your IDE, the change will reflect in you application immediately, skipping the build and redeploy phases.




2014/10/14

How to find out the PID (process ID) of processes in Windows

Problem
If I would like to find out the PID of javaw.java proecess, how do I do?
Windows task manager seems does not have PID information.

Solution 1
View-->Selected Columns-->Checked PID-->OK

Then we can find out the PID information.


Solution 2
Open command prompt, and execute tasklist /fi "Imagename eq JAVAW.exe"
Then we can get the PID information
映像名稱                       PID 工作階段名稱      工作階段 #    RAM使用量
========================= ======== ================ =========== ============
javaw.exe                    10368 Console                    1  1,620,884 K



Reference

2014/10/01

[閱讀筆記] 拆開獲利的糖衣



  1. 債券價格的變動與利率負相關,利率上升,債券價格會下跌;利率下降,債券價格會上漲
  2. 短期投資來說,股票的波動大於債券。但是,若是拉長到30年,股票的波動只有債券的一半,但報酬好很多
  3. 波動是投資主要風險,但不是唯一風險。對許多長期投資者來說,如果採用波動不夠大的投資組合,這樣的投資成本長期看來會造成更大的壞處
  4. 多頭市場是在悲觀中生成,在懷疑中成長,在樂觀中成熟,在亢奮中消逝
  5. 股市是經濟的領先指標,投資人不會等經濟資料顯示經濟復甦才開始投資,他們會提前哄抬股價
  6. 如果你的投資期間很長,長期來說,由於貨幣升貶本質是零和、不規則的循環,貨幣對全球投資組合的影響會互相抵消,接近于零
  7. 貨幣的波動很大,長期來說,投資人很難掌握短期的市場時機,靠交易外匯獲利
  8. 如果每個人都在關注某一件事,你知道你可以放心忽略那件事,往別的方向看,關注大家沒注意的事,以及可能對未來市場走向有很大影響的事
  9. 衡量市場氛圍往往不是一種科學,反而更像藝術


2014/09/30

2014/09 南投

溪頭漢光樓

大學池


溪頭天空步道




竹山紫南宮



2014/09/25

[閱讀筆記] 漫步華爾街

  1. 股價過去的波動不能用來準確預測未來的走勢,因為股市沒有記憶
  2. 股價循環就和賭徒的好壞運一樣,沒有週期可言
  3. 股價波動的歷史,並不能提供有用的資訊,讓投資大眾在管理投資組合時,能持續表現得比長期持有更好
  4. 設定停損點來做買賣,在考慮高額佣金後,使用這套辦法買個股或股票指數,並不一定能勝過簡單的買進持有策略。因此個別投資者最好避免使用這套辦法,以及避開推薦他的經紀人
  5. 頻繁進出股市的代價是,你的交易手續費會大增,計入手續費成本後,投資人所獲反不如簡單地買進並持有多種股票
  6. 技術分析的信號和接下來的股價表現間沒有關係。如果你跟著信號買進賣出,扣掉手續費,報酬仍不比買進持有好
  7. 籃球選手上一次射進籃框與下一次射進籃框的無關,其影響的是球員的『預期』,不是『表現』。股市情況亦然,昨日上漲,所以預期今日也會上漲,過去表現良好,所以預期未來也會表現良好
  8. 相信股市大師預言的人,必定抱憾而終
  9. 股市的行為是隨機漫步的,他就像一個醉漢,在空曠的地面上顢頇行走,他是非理性的,他是不可預測的
  10. 證券分析師無法預測長期持續的成長,因為這根本不存在
  11. 無論是穩定的公共事業,或是隨景氣循環起伏的電子公司,沒有一個產業是容易預測的
  12. 證券分析師平均每年錯誤率為31.3%,代表其在預測時,面對著極大的困難。投資人進行投資決策時,如果盲從這些預測,最後往往希望落空
  13. 影響分析師預測的五大因素:ㄧ、隨機事件的影響;二、創意的會計程序創造令人存疑的盈餘;三、分析師能力不足;四、最好的分析師往往轉任銷售部門或擔任投資組合的管理;五、在擁有大量投資銀行業務的公司裡,分析師面對利益衝突的困境
  14. 公司的損益表好比三點式泳裝,露出來的部分有趣,遮住的地方更重要
  15. 世俗的智慧告訴我們,隨俗而失敗,比不隨俗而成功,更能得到讚美
  16. 投資人購買共同基金的獲利,並不比買進並持有沒有管理的廣泛股票指數好
  17. 共同基金以往的良好績效不能用來推測其未來績效。決定基金績效排名的一項重要因素,仍然是我們的老朋友-運氣
  18. 宣布股票分割不能帶來有用的新資訊,雖然宣布股票分割的公司其股價在宣布的前一段時間就上漲了,宣布後的相關表現卻和市場其他股票沒什麼兩樣。蛋糕不會因為多切幾塊而變大
  19. 股價的變動非常快速,快到沒有人每次都能迅速的從中獲利。如新聞的發生是隨機的,無法預測的,不論是研讀過去的技術資料或基本面資料,都沒有幫助
  20. 股票的價值取決於未來的成長幅度和持續時間,但是要估計它們非常困難
  21. 如果過去股價對於預測未來股價沒什麼用,就不必採用任何技術分析規則來選擇買賣時間點。簡單的買進並長期持有,並不亞於任何技術分析策略
  22. 市場經常反應過度,因此最好遠離眼前時髦的股票,專注於購買那些目前失寵的股票
  23. 尋找價值的投資人,要選擇本益比低、股價與帳面價值比低的股票。價值是基於目前的現實而非未來
  24. 股價與帳面價值比低的股票,未來報酬通常較高
  25. 選擇低本益比的股票比較好,如果成長實現,將帶來加倍利潤;若成長失敗,損失也有限
  26. 股票是衡量機制,不是投票機制
  27. 購買可展期的定期保險,你可以不斷更新保單而不必重新體檢。所謂「遞減」的定期保險是,保單更新時保額可逐次降低,因為隨著時間逝去,需要的保險會跟著遞減
  28. 決定股票報酬三因素:購買時的股利報酬率、盈餘成長率、本益比的改變
  29. 債券的報酬決定於購買時債券到期日的報酬率、利率的改變對債券價格的影響
  30. 平均成本投資法是指在一段很長的時間中,每隔一段時間已一定的金額購買投資標的,如此可以大大減低股票投資風險,因為不會發生所有股票都在最高點的情形
  31. 投資普通股票和債券的持有期越長,風險就越低,但是你得有耐性忍受過程中,投資價值逐年波動的情形
  32. S&P 500指數的表現,長期優於共同基金與機構投資人的平均績效。成長型和價值型共同基金能勝過股票指數的,屈指可數
  33. 四項成功選股原則:只購買至少維持五年盈餘成長超過平均的股票、不購買股價高於合理價值的股票、購買有故事題材的股票、盡可能減少進出
  34. 事實上,少數表現超群、打敗超群的人,其成功有99%可能來自運氣,雖然人們自吹自捧自己的行動,但是那多半來自機運,較少來自偉大的構想



2014/09/21

如何知道債券配息的金額是否來自本金


當我們在看一些基金或債券的資訊的時候,常會看到類似這樣的警語:本基金主要係投資於非投資等級之高風險債券且配息來源可能為本金

有看到這句警語的話,就要想一下,每個月配給我們的現金,是不是從我們的本金拿出來的,如果是的話,就要考慮一下了,那我們要怎麼知道配給我們的現金有沒有從本金拿出來呢?當他的宣傳廣告宣稱有5%年化報酬率,是不是真的有5%呢?

我們分別會需要四個資訊:年化配息率、可分配淨利益佔配息比率、本金佔配息比率以及還原配息率,以下會以聯博全球高收益債券基金AT股當做範例

1. 年化配息率
年化配息率 = 每單位配息金額 / 淨值 * 12
鉅亨網得來的資訊,每單位配息金額為0.0213,淨值為4.67


所以,年化配息率為

2, 3 可分配淨利益佔配息比率、本金佔配息比率
先到聯博的網站找出此檔基金

點進去該檔基金後,滑鼠往下滾,可以找到配息組成詳情

打開pdf後可以看到可分配淨利益佔配息比率、本金佔配息比率


 4. 還原配息率
查到可分配淨利益佔配息比率、本金佔配息比率以後,可以得知其報酬率名符其實,因為本金佔配息比率是0%,所以還原配息率=年化配息率*可分配淨利益佔配息比率還是5.47%


如果用另外一檔房貸收益基金AT股,來看從其每單位分配金額除以淨值,可以得出他的年化配息率是4.99%,但是實際上本金佔配息比例高達51%,所以經過還原以後,實際上的配息率只有2.45%





2014/09/07

Warren Buffett's 23 Most Brilliant Insights About Investing

挺不錯的投資建議
  1. Buying a stock is about more than just the price. 
  2. You don't have to be a genius to invest well.
  3. But, master the basics. 
  4. Don't buy a stock just because everyone hates it. 
  5. Bad things aren't obvious when times are good.
  6. Always be liquid.
  7. The best time to buy a company is when it's in trouble. 
  8. Stocks have always come out of crises. 
  9. Don't be fooled by that Cinderella feeling you get from great returns.
  10. Think long-term. 
  11. Forever is a good holding period. 
  12. Buy businesses that can be run by idiots. 
  13. Be greedy when others are fearful.
  14. You don't have to move at every opportunity.
  15. Ignore politics and macroeconomics when picking stocks.
  16. The more you trade, the more you underperform. 
  17. Price and value are not the same. 
  18. There are no bonus points for complicated investments. 
  19. A good businessperson makes a good investor.
  20. Higher taxes aren't a dealbreaker.
  21. Companies that don't change can be great investments.
  22. Time will tell.
  23. This is the most important thing. "Rule No. 1: never lose money; rule No. 2: don't forget rule No. 1"

發現最近看的幾本書,漸漸歸納出一些原則
  • 要正確預測未來股價、營收成長是很難的,所以股價長跌勢不可預測的,這就是統計學家或經濟學家所提出的隨機漫步(random walk)
  • 投資的原則越簡單越好
  • 股價不代表其真實價值,運用本益比來協助判斷
  • 不要購買股價高過其價值的股票
  • How to Value a Business, and How to Think About Market Prices是兩個最基本且重要的課題
  • 長期持有的報酬率,遠大於一直殺進殺出的投資人
  • 找個笨蛋都能會經營的產業
  • 汰弱留強,好的股票繼續持有,不好的股票就賣掉
  • 長期來說,股市報酬率會是正數
  • 危機入市
  • 不要跟著群眾一窩蜂,在人們恐懼時貪婪,在人們貪婪時恐懼

http://www.businessinsider.com/warren-buffetts-investing-quotes-2014-8?op=1


2014/09/06

A good web site to learn AngularJS


If we would like to learn AngularJS, you can go to here, http://jsbin.com/, to learn. You just need a web browser, do not need to have any IDE(Integrated Development Environment) tools.

Here has a quick start.
1. Go to http://jsbin.com/

2. Click "Add Library"


3. Choose "Angular 1.2.14 stable"


 4. It will import "angular.min.js" automatically

5. Place "ng-app" directive in html tag 

6. create a input text for typing name

7. Check output preivew

8. Design the welcome message as user type in name

9. Demo



2014/09/05

SQL Query Order of Operations

Problem
Here is the select SQL statement:
SELECT YEAR,
       PERIOD,
       NVL(YEAR_PERIOD, ' ') AS YEAR_PERIOD, --年度+期別
       START_DATE, --日期
       NVL(AMT1, 0) AS AMT1, --舉借數額 -國庫券(1)
       NVL(AMT2, 0) AS AMT2,  --舉借數額 -短期借款(2)
       NVL(AMT3, 0) AS AMT3,  --償還數額-國庫券(3)
       NVL(AMT4, 0) AS AMT4 --償還數額-短期借款(4)
FROM FMS435FB
WHERE START_DATE BETWEEN :LAST_YEAR||'1201' AND :LAST_YEAR||'1231'
ORDER BY START_DATE DESC , PERIOD DESC, YEAR_PERIOD DESC
And I would to get the first record from the result set.

Therefore, I add rownum=1 in my where clause. 
Owning to I need to do union with another select statement, so I move it into subquery as bellows:
SELECT *
FROM
  (SELECT YEAR,
          PERIOD,
          NVL(YEAR_PERIOD, ' ') AS YEAR_PERIOD, --年度+期別
          START_DATE,  --日期
          NVL(AMT1, 0) AS AMT1, --舉借數額 -國庫券(1)
          NVL(AMT2, 0) AS AMT2, --舉借數額 -短期借款(2)
          NVL(AMT3, 0) AS AMT3, --償還數額-國庫券(3)
          NVL(AMT4, 0) AS AMT4 --償還數額-短期借款(4)
   FROM FMS435FB
   WHERE START_DATE BETWEEN :LAST_YEAR||'1201' AND :LAST_YEAR||'1231' AND ROWNUM=1
   ORDER BY START_DATE DESC , PERIOD DESC, YEAR_PERIOD DESC)
UNION ALL .....
But I get this record!

Root Cause
This unexpected result result from the SQL query order of operations, the order is:
FROM clause --> WHERE clause --> GROUP BY clause --> HAVING clause --> SELECT clause -->ORDER BY clause

If we marked rownum=1 and order by cluase
SELECT *
FROM
  (SELECT YEAR,
          PERIOD,
          NVL(YEAR_PERIOD, ' ') AS YEAR_PERIOD, --年度+期別
          START_DATE, --日期
          NVL(AMT1, 0) AS AMT1, --舉借數額 -國庫券(1)
          NVL(AMT2, 0) AS AMT2, --舉借數額 -短期借款(2)
          NVL(AMT3, 0) AS AMT3, --償還數額-國庫券(3)
          NVL(AMT4, 0) AS AMT4 --償還數額-短期借款(4)
   FROM FMS435FB
   WHERE START_DATE BETWEEN :LAST_YEAR||'1201' AND :LAST_YEAR||'1231'-- AND ROWNUM=1
 --ORDER BY START_DATE DESC , PERIOD DESC, YEAR_PERIOD DESC
 )
UNION ALL .....
We can find the first record is '1021226' not '1021227', if we marked rownum=1 and order by cluase. Owing the query order operation is from --> where --> select --> order by, 'rownum=1' have already get the first record before order by. So it's the reason why we get the unexpected result.

Solution
We need to get the result which had already been sorted, and apply rownum=1 to get the first record.
SELECT *
FROM
  (SELECT YEAR,
          PERIOD,
          NVL(YEAR_PERIOD, ' ') AS YEAR_PERIOD, --年度+期別
          START_DATE, --日期
          NVL(AMT1, 0) AS AMT1, --舉借數額 -國庫券(1)
          NVL(AMT2, 0) AS AMT2, --舉借數額 -短期借款(2)
          NVL(AMT3, 0) AS AMT3, --償還數額-國庫券(3)
          NVL(AMT4, 0) AS AMT4 --償還數額-短期借款(4)
   FROM FMS435FB
   WHERE START_DATE BETWEEN :LAST_YEAR||'1201' AND :LAST_YEAR||'1231'
   ORDER BY START_DATE DESC , PERIOD DESC, YEAR_PERIOD DESC)
WHERE ROWNUM=1
UNION ALL .....


Reference
[1] http://www.bennadel.com/blog/70-sql-query-order-of-operations.htm