網頁

2011年8月11日星期四

技術分析

技術分析是指研究過去金融市場的資訊(主要是經由使用圖表)來預測價格的趨勢與決定投資的策略。純理論上,技術分析只考慮市場或金融工具真實的價格行為,在假設其價格會反應所有在投資者經由其他管道得知前的所有相關因素的前提之下。

技術分析的基本信仰建立在「歷史會不斷重演」,並試圖藉由大量的統計資料來預測行情走勢。 技術分析被交易者和金融專家們廣為使用,且有些研究表示,在外匯市場裡,技術分析的使用要比「基本」分析要來得廣泛。

一般描述

技術分析師會辨別金融市場上的非隨機價格圖樣和趨勢,並企圖利用這些圖樣。在技術分析師所使用的各種方法和工具之中,價格圖表是最主要的一種。技術分析師特別會去尋找所謂的原型圖樣,例如知名的頭肩反轉型態,以及研究此類型的指標,如價格、成交量與價格的移動平均等。許多的技術分析師亦會依著投資者心理(市場氛圍)的指標來操作。

技術分析師尋求著預測價格趨勢的方法,以期從成功的交易中所得到的巨大獲利能勝過較多但較少損失的失敗交易,好讓獲利在長期中能經由風險控制和金錢管理得到正值。

技術分析有許多個學派。每個學派(如K線、道氏理論和艾略特波浪理論)的擁護者或許會忽略其他的理論,但許多交易者會同時使用一個學派以上的理論來做分析。技術分析師使用經由經驗所得到的判斷依據來決定特定的工具在一定時間內所顯示的圖樣,以及圖樣的解譯為何。技術分析師可能會不同意他們之間對一特定圖樣的解譯。

技術分析經常會和「基本分析」(研究一些分析師說能影響金融市場價格的經濟因素的理論)相衝突。純粹的技術分析表示,價格在投資者認知到它們之前就已經反應了所有的影響因素,因此只需研究價格本身的作用。有些交易者只使用技術分析或只使用基本分析,而有些人則同時使用這兩者來做決定如何交易。

原理

技術分析師認為市場價格會反應出所有的相關資訊,所以其分析比起在如新聞事件等「外部」,更偏向於在「內部」分析。價格行為亦會慣於重複其本身的模式,因為投資者會集體地頃向某個制式的行為-因此,技術分析師主要專注在趨勢和形態的認定上。

市場行為會將任何東西都給打折

基於所有相關資訊都已經反應在價格上的前提之下,技術分析師相信基本分析是多餘的-他們說新聞和新聞事件從來不會嚴重地去影響價格,且庫特勒、波特巴和薩莫斯所著的《What Moves Stock Prices?》這篇研究也支持此一論點。

在大多數巨幅回檔的日子裡,被指為是市場價格移動原因的資訊一般都不是特別地重要。相連數天的新聞報導亦無法對獲利或折現率為何會如此改變提出任何一種可信的看法。對於認定對重大的市場價格移動的基本因素,我們無能的地方在於,難以跟此類的因素和其他大部份在股市回檔中的變異量相一致。

 隨著趨勢移動的價格

技術分析師相信有所謂的價格趨勢。技術分析師說市場會上漲、下跌或盤整。對價格趨勢的基本定義是道氏理論所提出的一個基礎。其中一個例子是,時代華納從2001年11月到2003年8月間的股票價格,可以看得出來有很明顯的趨勢。一個認定此一趨勢的技術分析師或交易者便會尋找賣出這支股票的機會。時代華納的股價持續地下探。每當股價有一點回升時,賣家就會進場並賣出股票;因此形成了鋸齒狀的價格移動。一連串的「較低高點」和「較低低點」可以說是下跌趨勢的一個很童話式般的信號。換句話說,每當股價開始下探時,它都會跌破它之前的相對低點。而當股價開始探高時,它卻都無法突破它之前的相對高點。

要注意的是,這一連串的較低低點和較低高點從8月後不再出現。然後,時代華納的低價在這個月並沒有低於之前的相對低點。同一月份,高點亦等同於之前的相對高點。在技術分析師的眼裡,這是個很強的訊息,代表著下跌趨勢至少會稍微暫停,且有可能會停止,因此會在這時主動地停止再賣出這支股票。

歷史慣於重複

技術分析師相信,投資者會集體地重複他們之前的投資者的行為。「每個人都想要參與下一代的微軟」、「若股價又再次地回到50元,我就會去買它」、這家公司的技術將會使整個產業界掀起一波革命,所以它的股價將會一飛沖天」-這些都是投資者們重複不斷的觀點。對一個技術分析師來說,市場上的情緒也許是不理性的,但它們確定存在。因為投資者通常會重複他們的行為,所以技術分析師相信可以找到一些可確認(且可預測)的價格圖樣,並繪製出一個圖表來。

技術分析師不一定侷限在圖表中,也不總是只關心價格的趨勢而已。舉個例子,許多的技術分析師會監看投資者心理的報告。這些報當會估測出市場參與者們的態度,尤其是看空或看多。技術分析師利用這些報告來幫助他們判斷一個趨勢是將會持續下去,或會將會開始反轉;他們最能預測出會有一個改變的是在報告顯示出了一個極端的投資者心理時。例如,若報告顯示出絕大多數的人都看多時,上漲的趨勢就有可能會反轉-前提是看多的投資者都已經買進了股票(預測會有較高的價格)。而因為大多數的投資者都看多且已經下場投資,可以假設只剩少數一些的買家而已。其他則是多於這些買家的潛在型賣家,儘管市場上濃厚的看多氛圍。這一推論猜測股價將會開始下跌。此即為反向投資法的一個例子。

系統交易和技術分析

神經網路

從第一個可實用的型式於90年代初期出現之後,人工神經網路即迅速地普及了起來,並以模擬生物的神經網路製造出了適應人工智慧的軟體系統。它們因為可以學習偵測資料裡的複雜模式而流行了起來。以數學的語言來說,它們是一般非線性函數逼近器,意指若給與正確的資料且將其正確地派置,就可以獲到並模擬任何的輸入/輸出關係。這不只是移除了人類解釋圖表或一串產生輸入/輸出訊息的規則的需要而已,亦提供了通往基本分析的一個橋樑,因為其中的輸入可以換成基本分析中的變數。

另外,當人工神經網路是一個真正的非線性統計模型時,其精確性和預測能力便可以經由數學和經濟兩方面來測試。在許多的研究中,用來產生交易訊息的神經網路的效利大幅地超越買持策略,以及傳統的線性技術分析方法。

因為此類系統深奧的數學本性,使得用於金融分析的神經網路大多都還停留在學術界裡。但最近幾年,已經有越來越多對使用者友善的神經網路軟體開始出現。

循規交易

循規交易是指以嚴謹且明確的規則來訂定交易計畫的過程。不同於其他的一些技術分析方法或是大部份的基本分析,循規交易定義了一組決定整場交易的規則,只留下最少的人為決策。

例如,一個交易者可能訂下一個規則:當某一投資工具的價格收在50天移動平均之上時,即做多;若在其之下的話,則做空。

圖表及指數
下表為較廣為人所知的技術分析概念:

累積/分佈指數
真實波動幅度均值
布林帶
突破
商品通道指數
艾略特波浪理論和斐波那契回調
引掛模式
MACD
動量
金錢流
移動平均
OBV
拋物轉向系統
軸點分析
點線圖
相對強弱指數
支撐線和壓力線
隨機指標
趨勢線
Trix指標

2011年8月9日星期二

Linux Permission

Users and Group
每個檔案的擁有者、群組與 others 的示意圖

Linux file properties

To change the file properties and permission

  • chgrp
    • change group
  • chown
    • change owner
  • chmod
    • change permission




From: http://linux.vbird.org/linux_basic/0210filepermission.php

Normalization

Numpy

matplotlib

matplotlib is a python 2D plotting library which produces publication quality figures in a variety of hardcopy formats and interactive environments across platforms.


plotting commands


FunctionDescription
acorrplot the autocorrelation function
annotateannotate something in the figure
arrowadd an arrow to the axes
axescreate a new axes
axhlinedraw a horizontal line across axes
axvlinedraw a vertical line across axes
axhspandraw a horizontal bar across axes
axvspandraw a vertical bar across axes
axisset or return the current axis limits
barbsa (wind) barb plot
barmake a bar chart
barha horizontal bar chart
broken_barha set of horizontal bars with gaps
boxset the axes frame on/off state
boxplotmake a box and whisker plot
claclear current axes
clabellabel a contour plot
clfclear a figure window
climadjust the color limits of the current image
closeclose a figure window
colorbaradd a colorbar to the current figure
coheremake a plot of coherence
contourmake a contour plot
contourfmake a filled contour plot
csdmake a plot of cross spectral density
delaxesdelete an axes from the current figure
drawForce a redraw of the current figure
errorbarmake an errorbar graph
figlegendmake legend on the figure rather than the axes
figimagemake a figure image
figtextadd text in figure coords
figurecreate or change active figure
fillmake filled polygons
fill_betweenmake filled polygons between two curves
findobjrecursively find all objects matching some criteria
gcareturn the current axes
gcfreturn the current figure
gciget the current image, or None
getpget a graphics property
gridset whether gridding is on
hexbinmake a 2D hexagonal binning plot
histmake a histogram
holdset the axes hold state
ioffturn interaction mode off
ionturn interaction mode on
isinteractivereturn True if interaction mode is on
imreadload image file into array
imsavesave array as an image file
imshowplot image data
isholdreturn the hold state of the current axes
legendmake an axes legend
locator_paramsadjust parameters used in locating axis ticks
logloga log log plot
matshowdisplay a matrix in a new figure preserving aspect
marginsset margins used in autoscaling
pcolormake a pseudocolor plot
pcolormeshmake a pseudocolor plot using a quadrilateral mesh
piemake a pie chart
plotmake a line plot
plot_dateplot dates
plotfileplot column data from an ASCII tab/space/comma delimited file
piepie charts
polarmake a polar plot on a PolarAxes
psdmake a plot of power spectral density
quivermake a direction field (arrows) plot
rccontrol the default params
rgridscustomize the radial grids and labels for polar
savefigsave the current figure
scattermake a scatter plot
setpset a graphics property
semilogxlog x axis
semilogylog y axis
showshow the figures
specgrama spectrogram plot
spyplot sparsity pattern using markers or image
stemmake a stem plot
subplotmake a subplot (numrows, numcols, axesnum)
subplots_adjustchange the params controlling the subplot positions of current figure
subplot_toollaunch the subplot configuration tool
suptitleadd a figure title
tableadd a table to the plot
textadd some text at location x,y to the current axes
thetagridscustomize the radial theta grids and labels for polar
tick_paramscontrol the appearance of ticks and tick labels
ticklabel_formatcontrol the format of tick labels
titleadd a title to the current axes
tricontourmake a contour plot on a triangular grid
tricontourfmake a filled contour plot on a triangular grid
tripcolormake a pseudocolor plot on a triangular grid
triplotplot a triangular grid
xcorrplot the autocorrelation function of x and y
xlimset/get the xlimits
ylimset/get the ylimits
xticksset/get the xticks
yticksset/get the yticks
xlabeladd an xlabel to the current axes
ylabeladd a ylabel to the current axes
autumnset the default colormap to autumn
boneset the default colormap to bone
coolset the default colormap to cool
copperset the default colormap to copper
flagset the default colormap to flag
grayset the default colormap to gray
hotset the default colormap to hot
hsvset the default colormap to hsv
jetset the default colormap to jet
pinkset the default colormap to pink
prismset the default colormap to prism
springset the default colormap to spring
summerset the default colormap to summer
winterset the default colormap to winter
spectralset the default colormap to spectral





pyplot
 provides a Matlab-like plotting framework.





import numpy as np
import matplotlib.pyplot as plt

x = np.arange(0, 5, 0.1);
y = np.sin(x)
plt.plot(x, y)



 From: http://matplotlib.sourceforge.net/index.html

2011年8月8日星期一

Python-wikitools

MediaWiki provides a good API for us to access to the data contained in the MediaWiki database. The MediaWiki API is based on HTTP calls. Python-wikitools is python scripts and modules to interact with the MediaWiki API. I think it is very easy to use.

Python-wikitools: http://code.google.com/p/python-wikitools/

There are three modules that I often use, i.e. wiki, page and api. In the beginning of python script, it is required to import these three modules.

from wikitools import wiki
from wikitools import page
from wikitools import api

To access the MediaWiki, we need to create Wiki object.
myWiki = wiki.Wiki('http://my.wikisite.org/w/api.php')

If I want to get a page information, I can create a WIKI page object. Then, I can get the information by the method, "getWikiText()".
wikiPage = page.Page(myWiki, title)
wikiText = wikiPage.getWikiText()


Limitations:
Can only do what MediaWiki API can do.

2011年8月6日星期六

Correaltion

A correlation is a single number that describes the degree of relationship between two variables.


Correlation Example

This is an example showing how to find the relationship between height and self esteem.

Person Height Self Esteem
1 68 4.1
2 71 4.6
3 62 3.8
4 75 4.4
5 58 3.2
6 60 3.1
7 67 3.8
8 68 4.1
9 71 4.3
10 69 3.7
11 68 3.5
12 67 3.2
13 63 3.7
14 62 3.3
15 60 3.4
16 63 4.0
17 65 4.1
18 67 3.8
19 63 3.4
20 61 3.6

hist1.gif (3391 bytes)


corrbv.gif (2807 bytes) 
We can see that the relationship between the variables is a positive one. A positive relationship means that higher score on one variable tend to be paired with higher scores on the other.

Calculating the Correlation
The above is a graphical method to show the relationship. Actually, there is a method to compute a value to represent the relationship, that is correlation coefficient.

corrform1.gif (3131 bytes) 
 We user the symbol r to stand for the correlation. Through the magic of mathematics, it turns out that r will always be between -1.0 and +1.0.If the correlation is negative, we have a negative relationship.

The correlation Matrix
In most studies, we have considerably more than two variables.




From: http://www.socialresearchmethods.net/kb/statcorr.php