2017-12-14

Applications of the Real Time Streaming Processing with Edge Computing Gateways, by Mark Hsia

National Computer Symposium 2017 (NCS 2017), 14-15 December 2017, National DongHwa University, Hualien, Taiwan



Applications of the Real Time Streaming Processing
with Edge Computing Gateways


Chao-Yih Hsia(夏肇毅)
Taipei,Taiwan




ABSTRACT


Edge Computing Gateways are situated between cloud and local networks. It converts high-speed local network to low-speed remote network. Data must be reduced by extracting meaningful data only before sending out to the cloud. Real-time streaming data from cloud must be disseminated to all local nodes efficiently. All value added functions must be performed in this gateway. This paper demonstrates some  applications suitable for the streaming edge computing environment.


Keywords: Edge Computing, Complex Event Processing, Real-Time, Data Dissemination, Data Collection.



  1. Introduction
An edge computing gateway[1] plays multiple roles at the same time. It receives incoming data from the cloud,  processes it and disseminates them to the local nodes. On the other hand, it collects data from local nodes, summarizes the data and send them to the cloud centers. Key components of the edge computing gateway are: a  Complex Event Processor (CEP), an Message Queue (MQ) system and a fast real-time DataBase.






Figure 1: An Edge Computing Gateway in Between Two Systems

  1. Data
2.1 Streaming  data


Streaming data is the data generated continuously from multiple sources. Normally these data come with arrival timestamps to process them sequentially.  Since data keeps pouring into the system, so we have to use the sliding window technique to remove all expired data outside the sliding window. A typical example of streaming data is stock prices. Stock quotes, prices keep coming tick by tick. Each tick includes price, time stamp and other related information. Normally we keep these tick data in two places: the CEP sliding window and a database. The CEP processes data and throw them away, but a database always tries to keep them forever.


2.2 Tick by Tick data


Market data from the data feed is sent in a tick by tick way. A tick from the data feed must be shown on all users desktop immediately.  The high frequency trading system applications usually expect a very low latency environment. Industry gateway could offer a service level of less than 10 us latency. Top-notch products made by FPGA can reach a level of 3 us latency.




Figure 2: Tick Data Processing from a queue


2.3 Periodical Data: Minute Data


Periodical data like minute data, hourly data or even daily data could be generated from tick data in the sliding window. These types of data keep only the open, high, low, close data of each period. Therefore, converting  data from tick to period can offer a very high compression rate.


2.4 Tick by Tick or Micro-Batch Processing


If a process can handle 1000 tasks per second. When we do a task with tick by tick basis, then the maximum throughput will be 1000 tasks/sec. If each task can handle one message, the throughput will be 1000 messages/sec.


Figure 3: Batch Data Processing from a Sliding Window


But if we only do 100 tasks, but each task handles 20 messages, then the overall throughput becomes 2000 messages/sec. One task handles one message is a tick by tick process. One task handles multiple messages is a micro-batch process. The ratio of variable cost and fixed cost of a task decides which type of process performs better.  The smaller ratio is the variable cost, and the micro-batch performance will be better.


  1. Framework
3.1 Complex Event Processing


“Complex event processing, or CEP, is event processing that combines data from multiple sources to infer events or patterns that suggest more complicated circumstances. ” [2] For instance, if we heard church bells ringing and saw a group of people with a white gown woman, then we can guess there should be a wedding. This method depends on some key steps:
- Collect real-time data from different sources
- Keep data in a sliding window
- Match with the existing patterns
- Generate an output signal
- Distribute signal to all entities
3.2 Message Processing Queue


Data flows between nodes should be handled by a Message Queue system (MQ) in a real-time streaming processing system. Messages should be disseminated between nodes and the gateway in real-time with minimum latency. Also, not all but only selected data would be sent to the nodes as requested. Popular MQ systems like JMS, ZMQ, RabbitMQ[3]  and MQTT have been widely used in enterprise systems to exchange messages between units. MQ can be configured as queue, worker, rpc or publish / subscribe mode depending on the function we need. Some MQ system can handle persistent messages, but some can not. We need to choose correct system based on the application characteristic.


3.3 Market Data Hosted on the Edge Gateway


The most common real-time streaming data is the market data feed of stock prices in the financial institutions. Data feed from stock exchanges pours real-time broadcasted market data to the edge gateway. This data should be kept in the edge database and sent to all nodes depending on requested topics from MQ pub/sub channel. If there is any missing message, any node can re-request it from the edge gateway again thru the MQ rpc channel. All added value added data like VWAP, TA signal or AI price prediction should only be produced once by the gateway, and then be sent to all subscribing nodes.


  1. DataFlows
4.1 Real-time Data Flow on the Office


Exchange data feed sends market data to the edge gateway, and then the gateway sends them to the local nodes.  Most of time, the local nodes of the office are desktop PC or notebook workstations. People often use an Excel spreadsheet to generate reports with market data. Another tool called DDE server will be installed on each PC to transfer data into an Excel spreadsheet in real-time. Therefore, we can see that all desktop PC spreadsheets change their stock prices almost at the same time when any stock price changed.


4.2 Incoming Data Dissemination


MQ Publish / Subscribe mode should be used to handle data dissemination task to all local nodes. Each node is allowed to subscribe its owned topics. A publisher sends out the complete set of data, but only the subscribed topics will be received by subscribers.


Figure 4: MQ Topic Pub/Sub mode


4.3 Outgoing Data Collection


The typical role of an edge computing gateway is to collect data from nodes periodically, such as heart beat rates, the water level of the river and measures of machines. Algorithms on the gateways check if there is anything wrong. If yes, it reports as and an issue event immediately. If no, it summarizes the data into statistics report and send them back to cloud hosts periodically. This computation power of the edge computation gateway could avoid sending huge amount of useless data to the hosts thru cloud.  


  1. Applications
5.1 Pattern Detection


Predefined patterns could be detected on the streaming data by CEP, such as up, down changes of stock prices, the convolution of the stream data like Code Division Multiple Access (CDMA), Volume Weighted Average Prices (VWAP) of the stock prices and trading volumes.


5.2 Over Threshold Detection


The CEP can compute the moving average(MA) of the data in the sliding window and then check whether any  data exceeds the level of MA times a constant. We can also compute the standard deviation (SD) of data and use the SD times a constant as a threshold. This is a way to detect the abnormal condition.



5.3 Cumulate Data


The edge computing gateway will buffer the input data in micro-batch processing mode and start processing after a small interval of waiting time. During this period, data can be kept in the CEP sliding window.


5.4 Edge AI Network Center


An edge gateway could be the center of the AI network. Each node of the AI network runs its algorithm on its own machine and then sends the result to the gateway. The gateway computes all necessary statistics from data aggregation. Based on this overall statistic of all nodes, problems could be found with a better chance.


5.5 Order Matching System


If a gateway performs the order matching server function like stock matching or bidding server, we can select either tick by tick or micro-batch execution way.  First, we sort the  buy-side and sell-side orders and  then match two lists to see if any execution price satisfies both sides.


5.6 Financial Data FIX Protocol Adaptor


If the application of edge computing gateway is used in a financial institution for trading, normally a FIX protocol adaptor must be implemented in the gateway. In this case, the latency will be the top issue to consider. To cut the latency, some steps were taken frequently:
- Do less in the critical path
- Reduce layers
- Optimize Physical Location and access


5.7 Credit Card Transactions Monitoring


We can use this structure to check personal credit card transactions on different shops of a mall to check whether any person who used many cards in different shops has exceeded a certain ratio threshold.  We can collect the transaction data from shops as (card, shop, product, amount) and add them together with a “Select .., SUM( amount) ... Group By card, shop, product” command. Then we can get amounts of all different (card, shop, product) combination. And then we can also compute the amounts of the (card, shop) combination with similar way. By checking the ratios the these two results, we will know the selling ratio of products in shops. Some applications check whether these ratios are too high, and some applications check these ratios are too low.


If  we have the card owner data (person, card), we can also combine the card transactions into personal transactions by mapping (card, shop, product) data into (person, shop, product) before summation.


5.8 Stock Trades Monitoring


A stock trading surveillance system could be implemented in a similar method. First, cumulate the values of Level 4:(account, broker, stock, amount) and Level 3:(account, broker, amount).  Then compute the ratio of these two values Level 4/Level 3. Finally, set an alarm if this ratio exceeds a threshold.  It means this account has bought too many of certain type of stocks in the broker. All ratios  of different levels can be checked and the order of data fields in the tuple can also be switched for different meanings.


5.9 Server Status Monitoring


Node Machines can send their status to their gateway like loading of CPU, memory, disk and network, temperature of CPU and Disk. The gateway computes their statistics and detect abnormal conditions. Summarized report and alarm will be sent to the remote hosts thru the cloud.


5.10 Intrusion Detection


As we mentioned in the CEP case, if we can check the pattern of first A, then B and finally C, then we can get a conclusion that some event happens. If we know the normal attacking method of hackers, by searching different logs for these patterns, we can detect intrusion attempts actively.


5.11 Summarizing Access Logs


A web site normally consists of many web and application servers. The director dispatches web requests randomly to any server. Access and execution logs are situated in each server. We can join these logs into the gateway to see if any client exceeds allowed quota.


  1. Conclusion
The key role of the edge computing gateway is to generate real-time value added signals from cumulate data and disseminate them. We’ve tested the edge computing gateway performance on streaming stock data processing. Our experiment with some fast streaming data processor can finish a GROUP BY aggregation command of around 13,000,000 rows within a few seconds[5]. The aggregation function reduces the data to less than 1,000,000 buy or sell signals. From here we can see that a fast CEP data aggregation ability is the key to implement the real-time applications of this paper successfully.


References:
  1. wikipedia,”Edge Computing”, https://en.wikipedia.org/wiki/Edge_computing
  1. wikipedia,”Complex Eevent Processing”, https://en.wikipedia.org/wiki/Complex_event_processing
  1. ”RabbitMQ”, https://www.rabbitmq.com
  1. hortonworks,”Apache storm design pattern micro batching”, https://hortonworks.com/blog/apache-storm-design-pattern-micro-batching
  1. Chao-Yih Hsia,”Fast Program Trading Strategies Performance Evaluation”, https://chaoyihhsia.blogspot.tw/2017/09/fast-program-trading-strategies.html

2017-11-28

A Knowledge Processing Network for Robo-Advisors

by Mark Hsia
Robo-Advisor Knowledge Processing Network


Let’s see how to handle an incoming Forex financial news:


”The safe-haven yen and Swiss franc were higher, with USD/JPY sliding 0.41% to 112.01, just off the previous session's two-month peak of 112.72, while USD/CHF fell 0.21% to trade at 0.9687.Elsewhere, EUR/USD gained 0.20% to trade at 1.1965, while GBP/USD edged down 0.10% to 1.3569, off Monday's 15-month highs of 1.3620.”


Checked the sentences of this news, we found these keywords and phrases:
  • number and percentage
  • USD/JPY, USD/CHF, EUR/USD, GBP/USD
  • and, higher, sliding to, off peak of, fell to, gained to, edged down to, off highs of







figure : Financial knowledge stickers structure


Therefore, we should build various Knowledge Processing Units (KPUs) to handle numbers, symbols of Forex instruments and phrases of their movements. The first layer of KPUs handles words, the second layer of KPUs combines words to phrases and the last layers of KPUs processes the meaning of the sentences.


When a KPU finds the price of an forex instrument in the sentence, it should store this last price, change and date in memory and then computes all technical analysis indicators like Moving Average, Variance, RSI, MACD, Bollinger Band indicator,.. etc. Also, the KPUs can process correlation coefficients between various financial instruments.


The KPUs in charge of Robo-Advisor strategies should check the movements of the financial instruments to see how will they affect others and how much. Based on these predictions the final judgement of buying or selling financial instruments will be generated.


Also, the following rules should be defined:


- If the instrument A is up or down, then we should buy or sell what financial instruments and how many?
- What are mean-variances of all financial instruments?
- What are buying and selling points of all financial instruments?
- What is the optimal leverage ratio?


Financial Calculation Algorithms


Basic financial calculation algorithms like what I’ve implemented in the wealth management calculators website CubicPower.idv.tw  covering various aspects should also be included. Such as:


Time Value of Money:


Compounding
Discounting


Money generates interest in a saving account. So the money of the present time will be worth more than the same amount of money in the future. To interchange the values of two periods, compounding is used to convert present value to the future value of money and discounting is to convert the future money to present value.


Assets Allocation:


Capital Allocation Line(CAL)
Asset Allocation with Stocks and Bonds
Asset Allocation with Minimum Variance
Asset Allocation Optimal Risky Portfolio
Expected Return Scenario Analysis





figure : Risk and return of three asset classes combination


We can use the above tools to calculate the risks and rewards of different combination ratios of three asset classes - equities, fixed income and cash equivalents. A Robo-Advisor is in charge of portfolio management of these assets. The idea of efficient frontier should also be built into it.


Annuity:


Annuity Future Value
Annuity Present Value
Period Investment
PVOA
Investment Return Rate


An annuity is a group of fixed amount of  cash flows within a period of time.  We can discount each individual flow into its present value and add them up to get the present value of the annuity. This is the  way to evaluate the annuity. We can calculate the present and future values of the annuity easily with these tools.


Stocks/Bonds:


Stock Evaluation Dividend Discounting
Current Bond Price
Coupon Bond Price
Coupon Bond Yield
Zero Coupon Bond Price


Bondholders receive a fixed amount of interest in every period. Therefore, bond prices will change when interest rates changed. When the interest rate goes down, bonds become more valuable, so their prices will go up.


Futures/Options:


Stock Index Futures Hedge
Futures Long Hedge
Futures Short Hedge
European Stock Options
European Future Options

2017-11-19

The Real Time Streaming Processing with Edge Computing Gateways

by Mark Hsia

An edge computing gateway plays multiple roles at the same time. It receives incoming data from the cloud, processes it and disseminates them to the local nodes. On the other hand, it collects data from local nodes, summarizes the data and send them to the cloud centers. Key components of the edge computing gateway are: a Complex Event Processor (CEP), an Message Queue (MQ) system and a fast real-time DataBase.






Streaming data

Streaming data is the data generated continuously from multiple sources. Normally these data come with arrival timestamps to process them sequentially. Since data keeps pouring into the system, so we have to use the sliding window technique to remove all expired data outside the sliding window. A typical example of streaming data is stock prices. Stock quotes, prices keep coming tick by tick. Each tick includes price, time stamp and other related information. Normally we keep these tick data in two places: the CEP sliding window and a database. The CEP processes data and throw them away, but a database always tries to keep them forever.

Tick by Tick data



Market data from the data feed is sent in a tick by tick way. A tick from the data feed must be shown on all users desktop immediately. The high frequency trading system applications usually expect a very low latency environment. Industry gateway could offer a service level of less than 10 us latency. Top-notch products made by FPGA can reach a level of 3 us latency.


Periodical Data: Minute Data

Periodical data like minute data, hourly data or even daily data could be generated from tick data in the sliding window. These types of data keep only the open, high, low, close data of each period. Therefore, converting data from tick to period can offer a very high compression rate.

Tick by Tick or Micro-Batch Processing

If a process can handle 1000 tasks per second. When we do a task with tick by tick basis, then the maximum throughput will be 1000 tasks/sec. If each task can handle one message, the throughput will be 1000 messages/sec.



But if we only do 100 tasks, but each task handles 20 messages, then the overall throughput becomes 2000 messages/sec. One task handles one message is a tick by tick process. One task handles multiple messages is a micro-batch process. The ratio of variable cost and fixed cost of a task decides which type of process performs better. The smaller ratio is the variable cost, and the micro-batch performance will be better.


2017-09-05

夏肇毅觀點:打不贏就加入!金融科技搶走飯碗,我們只好拿人工智慧工具打敗它

夏肇毅觀點:打不贏就加入!金融科技搶走飯碗,我們只好拿人工智慧工具打敗它



創新工場董事長李開復前一陣子表示:「人工智能將快速爆發,十年後50%的人類工作將被AI取代」引起正反兩方辯論。他又提到國外研究早就證實這論點,而舉出牛津大學2013年的「The future of employment: How susceptible are jobs to computerisation?」作為立論依據。

自從ATM大量設置以來,人們就很少去銀行櫃檯了。這幾年很明顯的,因科技進步而人手一機。加上網路銀行、行動支付發展起來,更連ATM都不用了,所以分行逐漸地縮編、裁撤。股市看盤、下單用手機就行,現在正流行教你怎樣用人工智慧API下單。交易量下跌,所以營業員也要縮編,或轉做財富管理。報載「近2年來,券商營業據點從上千家大舉滑落至目前865家。」,是實現中的工作消失實例。

其實這應該與人工智慧無關,而是3C設備普及,萬事電腦化的成果。再加上ARM CPU的授權,讓IoT物聯網設備物美價廉,30塊美金就能買一片能裝Linux的控制板。能和很貴的伺服器跑一樣的軟體,只是較慢罷了。到處都是便宜的電腦,就讓人們產生要開發機器人來取代人力的的企圖心。加上最近AlphaGo打敗人類棋王的消息出來,便將原是電腦設備取代人力的現象,轉變為人工智慧取代工作的說法。

其實任何工作都應該是可以被電腦化的,牛津大學的論文中舉出工作電腦化的關鍵—電腦設備開發製造成本。想想號稱最不可能被電腦取代的藝術家或舞蹈家等工作,花大量的金錢和時間下去,應該還是可以開發出類似的機器人的,問題只是有沒有經濟價值而已。

我們與其擔心什麼工作會被人工智慧機器取代,倒不如研究如何讓自己的工作方法不斷翻新,永遠跑在人工智慧前面,讓開發機器人的速度趕不上你進步的腳步。

其中的關鍵就是要擁抱人工智慧新知,操縱它讓它幫你工作,以增加工作的附加價值。事實上,人工智慧研究的歷史悠久,只是一直都成效不彰。相關工具也隨手可得,像由大學開發在大數據中Data Mining免費挖寶工具Weka也有十多年歷史。任何覺得自己工作汲汲不保的人,今天開始學,也不用花很多時間就可學會。這些工具的原理可能都很複雜,一堆數學式子。但你只要學會怎麼用,怎麼看結果就好,複雜的事讓它幫你做,就像你不用設計車子就能開車一樣。

最簡單的人工智慧例子,就是建決策樹來決定今天天氣適不適合球賽。我們可以蒐集過去晴雨天、溫度、溼度與有沒有比成的十餘筆資料存在檔案裡後,餵給人工智慧工具。它就可以根據這些資料做成一個判斷天候、溫度、溼度而產生結論的決策樹,之後可以再餵給它一些資料,以驗證這決策樹的正確度。

再來我們也可以把人工智慧用在關聯性分析,分析商場買賣大數據。看看買尿布的人是不是也買啤酒,還是也會買些什麼別的東西,日後據以做交叉銷售時推廣活動的篩選參考。

銷售時對不同客群推銷不同東西,是行銷ABC。怎樣把客戶分成我們固有印象中的頂客族、銀髮族、小亨利族應有一些簡單的判斷公式。但人工智慧工具很強的一部份,是你不用告訴它什麼,它能自動地找出一些不同特性的族群出來,清楚地劃定各族群的國界出來,這些是屬於非監督式學習的範圍。沒人教就會,正是機器學習的強項。

更神奇的是,有人拿幾天股票的開高低收變化,餵給人工智慧工具學習,之後能產生一個決策樹來判斷明天這股票會漲還是會跌。我們要知道它訓練後的準確度有多高,可以自己來試一試,看看這點子是否可行。

第一次工業革命,發明了蒸氣機,讓機械力取代人力與獸力。後來設計出汽車,馬車車伕因而失業,但是更多汽車司機的工作也因而產生,這些工作是給那些會開車的人的。

今日金融科技革命造成大量金融櫃檯人員失業,也許日後許多轉為戴著VR眼鏡與客戶交易在家上班的人。有工作消失就會有新工作產生,只要大家跑得快,學得快,跟上時代腳步,就永遠都有你的位置在。


作者簡介:夏肇毅,提供雲端理財機與教學服務之CubicPower.idv.tw創辦人。曾服務於緯創軟體、英商路透社等金融與科技單位從事金融軟體開發專案工作。







夏肇毅觀點:複製小抄大腦,讓金融科技搭起人工智慧塔

夏肇毅觀點:複製小抄大腦,讓金融科技搭起人工智慧塔



小抄英文叫cheat sheet,就是考試時作弊用的濃縮重點。所以演講時把重要數字寫成小抄,採買辦事前把所需明細記成小抄,拜訪客戶及接待來賓時也將對方姓名資料記在小抄裏。所以後來除了作弊用品的原意外,便成也是速查表與備忘單的意思。就是將最實用的步驟、方法及知識寫成一小張紙,以便往後碰到問題時能快速的提供錦囊妙計。

因為它只是一小張紙,所以只有這個主題下最常見的問題會寫在上面,不同主題就用不同小抄。好比說影印機有一張小抄,提供快速操作與問題排除方法,筆電也有一張小抄,不同產品都有自身的操作小抄。後來人們發現這太好用了,就加以發揚光大,演變成叫Post-it的小貼紙,可以隨手寫,到處貼。一旦人腦經過數十次反覆的訓練學習,就能把這些小抄內容複製貼入腦中。如果我們天天用它,這些小抄就能一直在腦中貼得牢牢地。可是沒複習的話,小抄很快就掉下來了。

從小到大,經過辛苦的學習,我們把各種知識都在腦中寫成小抄。怎麼說話,怎麼寫字,怎麼讀英文,怎麼算數學,上自天文下至地理,課文的內容,參考書的講義,老師的問題與答案,同學間的嘻笑怒罵,大大小小,全用小抄記著。日積月累後,腦中就有數不盡的小抄。每晚大腦都要將小抄瀏覽整理一遍,看看哪些常用的留著,哪些可以送入倉庫中堆著,這些都是最高階的腦部活動,有人說這就是做夢的過程。


小抄大腦模型

大腦皮質由大量的神經元所組成,彼此連接。今年年初一篇“A Giant Neuron Has Been Found Wrapped Around The Entire Circumference of The Brain”的報導中發現橫跨老鼠腦部的巨大神經元,這意味著信號可以有效率的傳遍整個大腦,而不必靠神經元一個接一個的慢慢傳遞。

我們可以假設當眼睛耳朵接收到信號時,它能夠快速的傳遍所有的神經元。想像有些最底層的神經元專職在處理母音、子音與文字部首的識別,當它偵測到認識的信號時,就會舉手,將這發現傳給下一層神經元。於是下一層神經元就處理單字發音與字型的識別,接著還有再下一層神經元能識別句子,一路下去,就形成我們這有意識的大腦。

筆者把每一組神經元想像成一張小抄,底層小抄紀錄著字音、字型、單詞或句子。一路向上,更上層的小抄就記著公式、原理、步驟、方法等所有人類的知識。每張小抄隨時都在平行運作著,當它接收到與小抄內容相同的輸入信號時,就會輸出信號讓後面連接的小抄接著做事,一層跟著一層執行。所以我們聽到講話的聲音後,就能接著轉成單字,再組成句子,等最後了解意義之後再做出反應。

每個小抄平時也會自己發出信號,想讓別人知道它的存在。當幾組小抄的信號湊在一起時,有時就會有新創意產生,就如同我們常說的「突然靈機一動」一樣。大腦每天會整理數不清的小抄,常看常聽的就留著,其他就慢慢往後堆。所以如果要持續留存知識,不斷的學習與複習是不二法門。

這就是筆者個人所想像的「小抄大腦模型」(Sticker Brain Model)。根據這「小抄大腦模型」假設的原理,我們就可以開發出「人工智慧小抄電腦」(AI Post Computer)。簡單的說,就是根據人類大腦記憶思考的原理,來讓人工智慧運作。這比較偏向傳統以知識為基礎的專家系統路線,與現在當紅靠大量機器數學模式計算的機器學習方向不同。

傳統機器學習演算法

雖然「大演算(The Master Algorithm)」一書排斥傳統以知識工程為基礎的程式系統,認為以機器學習為基礎的系統已經開始席捲各個領域。它指出現在機器學習有五大學派,包括符號理論,類神經網路,演化論,貝氏定理與類比推理。它認為結合這五大學派而發展出的終極演算法,將可靠機器學習大數據中獲得世界上所有的知識。

其中符號理論學派利用建立決策樹的方式來執行歸納,類神經網路學派模擬人類的神經元運作來做識別與預測功能(如最近最流行的CNN),演化論學派模仿大自然交配與演化來設計程式,貝氏定理學派利用機率來推論各種狀況發生的可能性,而類比推理學派使用支援向量機SVM等方法來將資料分群找出相似度高的群體。

但這五大學派的機器學習方法,都是以數學運算模式來訓練機器做判斷,比較像是人類的快速辨識與直覺反應。和思考不同,直覺反應速度快,但它卻不知道為什麼。像運動、操作、語言等需要快速反應的事情,就要靠不斷的重複練習,來讓身體肌肉能應付外界變化。

但思考卻是知識性的,需要將存在腦內的小抄一一檢視,看看哪一種方法可以應付當前的狀況,它需要比較長的時間。這就像拳擊與國術的對比一般,前者靠不斷練習對打以訓練臨場反應,一直到最後幾乎練成了反射動作,就和機器學習一樣。而後者是把所有招式,像一本書般從頭到尾不斷演練。臨上場時,還要一頁一頁來檢視應該要使用哪一招來應付比較好,速度自然比較慢。語言學習也是一樣,如果是對話式的整句練習,使用時自然比還需要從文法開始想造句要來得快。

金融科技小抄電腦

但以知識為基礎的「人工智慧小抄電腦」,卻是用前人的智慧來運作,同時還能告訴你為什麼,因為它是靠大腦裡小抄記著的方法來做事。筆者個人喜好收集知識與方法,所以自然就偏好知識思考這條路,希望能慢慢將知識方法製成小抄,塞入機器人的人工智慧腦中,堆出小抄知識塔。然後再模仿人類大腦的方式運作,讓這小抄電腦知識塔動起來。

如果我們要將「人工智慧小抄電腦」運用在金融科技的理財機器人上的話,首先就要先把理財知識的小抄灌入理財機器人中。
比如說:
-若利率上漲,則債券下跌。
-若中東發生戰爭,則黃金石油大漲。

然後我可以問我的理財機器人:
-若美國FED升息,那會有什麼影響?
-如果戰爭開打,那麼金價如何變動?

這些問題它一定答不出來,因為機器人還不懂「美國、FED、升息、影響、開打、金價、如何、變動」的意義。所以要能讓機器人回答問題,先要把基本的語文能力一併建立才行。人類從小學到高中花了十二年,才將基礎知識存到腦中。前六年上小學,勉強把基礎字詞認完。後六年,再把世界基本常識學會,達到看得懂報紙的地步。如果有唸大學,才再鑽入某一學門中,學習專業知識。

想讓機器人理解問題,也必須讓它像人類一樣從頭學起才行。要經過NLP自然語言處理後,讓文字產生如同大腦認知般的意識。這一點,需要長時間的投入才有可能見效。畢竟自然語言處理和類神經網路一樣,都已經是有悠久歷史的學派。這麼多年,經過多少人腦精英,跟著開山祖師爺的腳步,被吸入這些腦力黑洞中,也不過發展到目前的境界而已。因此在實務應用上,使用簡單的問答系統,像是人工智慧客服系統,電話秘書等就比較普遍。只要蒐集某一業務上客服人員常用的問題,列出詳細問答範本後再加以處理,應該就能夠回答大部份的問題了。

相形之下機器學習反而是比較容易處理的方法。讓理財機器人利用機器學習的五大學派理論,針對歷史金融大數據做分析,找出每一商品的買賣點,尋求最佳的投資組合。然後針對每個策略在歷史數據中回測,以找出性能最佳的運算法。之後就能對世事變化,隨時提出買賣投資建議。

最後,我們還要把這些變化,一一套入小抄的知識規則中來檢視,驗證看看到底這些知識正不正確。不正確的話就要重新產生小抄,以便將最新的研究結論記下。這樣知識與直覺的結合才能讓金融科技不斷地自我增強學習,慢慢衍生出人工智慧塔來。

機器學習的直覺辨識與小抄電腦的知識思考,兩者各擅勝場缺一不可。最終還是要結合起來一前一後的運作,才能相輔相成發揮人工智慧小抄電腦的最大效用。

作者簡介:夏肇毅,提供雲端理財機與教學服務之CubicPower.idv.tw創辦人。曾服務於緯創軟體、英商路透社等金融與科技單位從事金融軟體開發專案工作。


夏肇毅觀點:國防工業亟待人工智慧與雲端運算技術助力

夏肇毅觀點:國防工業亟待人工智慧與雲端運算技術助力


日前AlphaGo Master人工智慧又打敗了世界第一的大陸棋王柯潔,自此擺脫人類知識,走向左右手對戰的自我學習之路。

為什麼AlphaGo那麼利害?因為它將下一步棋可走的最終成功率,建成了一個「蒙地卡羅決策樹」。然而棋盤中可以走的路實在太多了,所以第一步就是要向人類老師學習。將過去各高手所下的棋都學一遍,然後將勝負記進這蒙地卡羅決策樹中。這就是所謂的「監督學習」,有老師在旁邊看著。再來就是自已左右手對戰,把過程和勝負同樣輸入決策樹中,變成了「增強學習」。如今再沒有人類老師可以學習了,所以AlphaGo就剩下增強學習一途。

AlphaGo Master同時並應用了目前人工智慧中最流行的CNN。噢,不是我們想的那個,而是「Convolution Neural Network」。一種當今最熱門,模仿人類大腦結構的人工智慧類神經網路,照片識別、語音秘書、自動駕駛都靠它。數十年來沒什麼進展的類神經網路,拜雲端運算所提供的大量運算能量之賜,這幾年突然又掀起了一股熱潮。

這個類神經網路提供了「全局觀」,並經由「策略網路」與「價值網路」來決定下一步棋的落子位置。前一版的AlphaGo可以考慮未來50步棋的優劣,這真的不是人腦所能能負荷。到此,人類也要繼象棋和西洋棋之後,在圍棋這一塊再舉起白旗了。

現在人工智慧可以運用的地方越來越多,去年美國辛辛那堤大學開發的空戰人工智慧無人機ALPHA,就擊敗了資深的飛行教官。它運用了遺傳模糊樹(genetic fuzzy tree)的決策系統,將高階戰術、射擊、逃脫、防禦等各式戰鬥方法建入這個人工智慧系統中。你一有動作,它馬上會有應變措施,反應比人類快了兩百五十倍,弄得教官精疲力竭。整個空戰是在一個由波音公司開發像電動玩具般的AFSIM系統中進行。它真實得複製了現代空戰環境中的戰機、偵測器和武器的行為模式,在加入雜訊與失敗率後,將偵測器資料送給無人機ALPHA,讓ALPHA根據指派任務與決策系統邏輯來操縱飛機與武器系統。這些設計細節都在2016年6月的「Journal of Defense Management」中揭露。

現在這類的無人戰鬥系統有兩條發展路線,一條路線是製造全新的無人機,另一條路線則是將現有設備改裝成為無人操控機。最近美國洛克希德馬丁公司就展示了由F-16改裝的無人機跟隨有人機飛行,讓無人自動駕駛機與有人機隊結合成一個團隊一起行動。這裝有自動防撞系統的無人機,能跟著有人機組編隊飛行,待接近目的地時就離隊去執行對地攻擊任務,同時也應付各種突發威脅,待任務完成之後再重新加入團隊編隊飛行。

發展這些人工智慧系統時背後需要有龐大的運算能力,否則機器少N倍,就要多花N倍的時間來運算。在上月大陸神威超級電腦躍居全球速度最快的超級電腦後,美國國家安全局發表報告,認為失去超級運算的領先地位,將嚴重威脅美國的國家安全。它認為現代武器系統的設計、發展和分析中,超級電腦都扮演了關鍵角色,包括核子武器、網絡戰能力、戰艦、飛機等等。雖然我們沒有核子武器要靠超級電腦試爆,但現在開始的人工智慧機制卻是要靠龐大電腦來讓訓練機械學習。加上機密性考量,這時就要考慮建立自己的國防高速分散式雲端運算機房。然而不同於傳統武器一用數十年,現在的電腦投資,大概兩三年就落伍了。所以電腦的折舊期就是四五年,時間到就可汰換,因此規劃上可能要像每年都要消耗的作業費用一樣對待。

如今人工智慧已開始踏入國防軍事領域,日後想光憑人腦來想策略與操作系統,根本毫無勝算。電腦兵棋推演,就像AFSIM一樣也到了該連上人工智慧系統的時候了。事先訓練好攻守方,讓電腦戰電腦,應該可以發展出令人驚訝的方法。除了武器軟硬體研發投資外,在雲端運算機房與各式國防人工智慧研發也應加緊腳步才是。以免十數年後,到了無人武器系統時代時,才發現也許傳統武器都已變無用武之地了。

作者簡介:夏肇毅,提供雲端理財機與教學服務之CubicPower.idv.tw創辦人。曾服務於緯創軟體、英商路透社等金融與科技單位從事金融軟體開發專案工作。

2017-09-04

Get Technical Analysis Indicators from BigObject In-Data Computing

Get Technical Analysis Indicators from BigObject In-Data Computing

BigObject In-Data Computing allows users to write their own program with LUA programming language. Similar to the store procedure concept of the SQL server, but a LUA script can do whatever users want to do together with the data stored in the BigObject. Like technical analysis applications of the financial market, BigObject can generate indicators like SMA,EMA,..etc. by walking thru data of the table with a LUA function ta().
The definition of SMA(simple moving average) is:
SMA(p,N)= ∑i=1,N pi / N

And the EMA(exponential moving average) is:

EMA(p,N)i = α x pi + (1-α) x EMA(p,N)i-1
α=2/(N-1)

Convert these formulas into LUA we can get the attached sample code.

When we want to run this TA function, we simply use the APPLY command to call it up like:
APPLY ta('sma','stock','Close','ma', 120, 0,0,0,0)
APPLY ta('ema','stock','Close','ma', 120, 0,0,0,0)
APPLY ta('var','stock','Close','ma', 120, 0,0,0,0)
APPLY ta('sd','stock','Close','ma', 120, 0,0,0,0)


Source Code:

function ta(fun,v1,v2,v3,v4,v5,v6,v7,v8)
function sma(bt, col, rt_col, n)
t = bo.getTable(bt)
rt = t:getColumnValue(col);
for i = 2, #rt do
s=0.0
cnt=0
for j = 0, n-1 do
if (i-j>0) then
s = s + rt[i-j]
cnt=cnt+1.0
end
end
rt[i] = s/cnt
end
t:setColumnValue(rt_col, rt)
end

function ema(bt, col, rt_col, n)
t = bo.getTable(bt)
rt = t:getColumnValue(col);
alpha=2/(N+1)
for i = 2, #rt do
rt[i] = alpha*rt[i]+(1-alpha)*rt[i-1]
end
t:setColumnValue(rt_col, rt)
end

function var(bt, col, rt_col, n)
t = bo.getTable(bt)
rt = t:getColumnValue(col);
for i = 2, #rt do
s=0.0
cnt=0
for j = 0, n-1 do
if (i-j>0) then
s = s + rt[i+j]
cnt=cnt+1.0
end
end
av = s/cnt
s=0.0
cnt=0
for j = 0, n-1 do
if (i-j>0) then
s = s + math.pow((rt[i-j] - av),2)
cnt=cnt+1.0
end
end
rt[i] = s/cnt

end
t:setColumnValue(rt_col, rt)
end

function sd(bt, col, rt_col, n)
t = bo.getTable(bt)
rt = t:getColumnValue(col);
for i = 2, #rt do
s=0.0
cnt=0
for j = 0, n-1 do
if (i-j>0) then
s = s + rt[i-j]
cnt=cnt+1.0
end
end
av = s/cnt
s=0.0
cnt=0
for j = 0, n-1 do
if (i-j>0) then
s = s + math.pow((rt[i-j] - av),2)
cnt=cnt+1.0
end
end
rt[i] = math.pow(s/cnt,0.5)

end
t:setColumnValue(rt_col, rt)
end

if (fun=='sma') then
sma(v1,v2,v3,v4)
elseif (fun==’ema’) then
var(v1,v2,v3,v4)
elseif (fun=='var') then
var(v1,v2,v3,v4)
elseif (fun=='sd') then
sd(v1,v2,v3,v4)
end
end




2017-09-02

夏肇毅觀點:當金融科技揮舞人工智慧利劍砍向傳統金融



日前在「經濟50大論壇」金融專題演講中,主管機構與傳統金融業競相嘲諷國內金融科技業者,謂其捧著創新光環來破壞傳統金融,並對其創新技術內容不屑一顧。這些說法徒然揮霍了在眾人目光匯集的舞台上,展現其宏闊視野與優雅身段的機會。其實此時金融科技熱潮爐火漸息,創新業者規模尚小,並無法威脅傳統金融業者,實無需急於排擠這些嗷嗷待哺的新創幼苗。

國外如何面對Fintech

我們先來看看國際傳統金融業者Swift與Visa,是用什麼態度來面對這股金融科技浪潮。下面是他們面對金融科技的最新行動:
  • SWIFT正式選用Hyperledger,與3大金融機構聯手進行區塊鏈跨國交易驗證
  • 3大變革Visa引領行動支付向前行
    • 開放架構建立行動支付生態系
    • 結合Fintech新創發展多元支付樣貌
    • 預見需求優化消費者支付體驗

大體上,都是積極擁抱。

強大平台業者才是傳統金融的威脅

安永(Ernst & Young)與星展銀行(DBS),於2016年11月所聯合推出的「The Rise of FinTech in China」報告中明白指出,大陸在2016變成世界FinTech的領頭羊,起因是由未被滿足的金融需求而來。而百度、阿里、騰訊三大網路、電商、社群平台業者藉由強大平台力量,滿足了這些被傳統金融業遺棄的客戶。加上管理機關的默許,因而造就了今日大陸金融科技的爆炸性成長。平台業者同時也砍斷了原本流向付款卡業者的金流與資訊流,日後將對傳統金融業者產生雪上加霜的後果。

有台灣傳統金融業者覺得,台灣是overbanked大陸是underbanked,大陸的情況不容易在台灣複製。也有人認為,如果現在要花好幾億來發展金融科技來打自己,到時候又得花好幾億去資遣員工,因而對金融科技抱著遲疑、能拖就拖的態度。

依據資策會調查結果,台灣每人平均擁有4個社群帳號,其中Facebook涵蓋90.9%的人,LINE 87.1% 以及YouTube佔60.4%。資策會去年預估,2017年台灣電子商務規模可望達1兆2515億元,持續成長約11%,B2C電商仍扮演領頭羊。而Line在全台灣有1,700萬用戶基礎,PCHome、MoMo、Yahoo有電商會員基礎,橘子、智冠、歐買尬有遊戲會員基礎。這些台灣平台業者,都正在積極地拓展行動支付業務。

傳統金融業者的真正威脅,就是這些網路、社群、購物平台業者。最怕他們複製大陸經驗,將所有會員金流改道,到時傳統金融業者對這些客戶的金流資料流皆斷。

除此之外,金融業同時也還需解決自身分行大幅縮減,以及人工智慧取代傳統人力問題。

金融科技正乘著人工智慧的浪潮前進

金融科技業者推出的機器人理財,以更低的手續費及門檻,廣邀年輕族群參與。巴菲特在最新年度致股東公開信中宣稱:「在波克夏2005年度報告中,我說所有專家主動投資策略表現都會在幾年之後落後業餘坐著不動的投資人。我解釋各種『幫手』所收的龐大費用只會讓... 我再說一次讓『所有』他們的客戶更糟,還比不上僅投資低成本、無管理的指數型基金。」既然如此,誰還要投入傳統金融機構人員操盤的基金,來讓他們抽取高額管理費呢?讓理財機器人來不就好了。

看起來好像金融科技正揮舞人工智慧利劍,砍向傳統金融,實則是金融科技正乘著人工智慧的浪潮前進。自AlphaGo開始擊敗人類棋手後,人類才意識到第四次工業革命已像海嘯般席捲世界。結合人工智慧的機器開始取代中產階級的工作,像在文件中尋找證據的寄生律師,檢視保險合約的保險公司職員,編寫每日財經動態的記者等。

現在股票下單、存款轉帳,早就在手機上就能解決。人們前往金融機構營業點的需求越來越低,閒置的辦公處所與服務人員,皆需大幅調整。所以外商銀行開始關閉分行,2016年已裁撤19家。而郵局也積極調整營業據點活化資產,改以分租、改建、都更等方式來提高收益。

前兩年人工智慧的熱門書「大演算(The Master Algorithm)」,作者排斥傳統以知識工程為基礎的程式系統,認為以機器學習為基礎的系統已開始席捲各個領域。他指出現在機器學習有五大學派,包括符號理論,類神經網路,演化論,貝氏定理與類比推理。認為結合這五大學派而發展出的終極演算法,將可從大數據中獲得世界上的所有知識。這也許是個虛無遙遠的期望,但目前針對不同應用所開發出的各式電腦程式,如IBM Watson認知運算,人工智慧律師ROSS等產品目前都已達實際銷售階段。

金融業自己積極擁抱金融科技

這整個人工智慧的崛起,才是傳統金融職位的真正殺手。金融業只有從思想改造開始,擁抱人工智慧來開發新服務,建立金融科技社群,結合眾人之力,來徹底翻轉本身結構以適應未來潮流。

所幸目前已有新換牌銀行,自己就推出理財機器人來拉攏年輕學生族群,希望朝普惠金融的方向前進。有的銀行推出副品牌行動數位化分行,來鮮明自身年輕形象。也有銀行結合了台大與SAS,聚焦大數據應用及機器學習運算機制,以提供個人化金融服務。這些都是了解趨勢後所做的因應行動。此時台灣的各種恐龍交易系統,好像也該爬起來跟著人家跑一跑了。

革命容易革心難,心態調整最是困難,如果上頭都老大心態僵化頑固,那下面就更是石頭一塊動不了。反之若上面的人積極跟上趨勢潮流,那麼日後必能順勢而上。當知掌握趨勢重於優勢,否則當趨勢變時,過去的優勢就不再是優勢了。


作者簡介:夏肇毅,提供雲端理財機與教學服務之CubicPower.idv.tw創辦人。曾服務於緯創軟體、英商路透社等金融與科技單位從事金融軟體開發專案工作。