Sunday, July 19, 2015

Vim as a IDE

I have been using vim as my main editor and development tool for more than ten years.  I love its lightweight and speed. I especially love its idea of editing with having your hands leaving the keyboard. It greatly improves my efficiency.
I used to use a bare vim without any plugins. Since I have a few development environments, I do not like to install a lot of dependencies before I can start editing freely. However, bare vim does lack some advantages provided by modern IDE, I took a weekend to investigate some.
Recently I mainly do development in python environment, thus my research foci on python.

.vimrc settings

The settings in .vimrc is very important to make a comfortable development environment.
The following settings does the following tweaks to the development vim environments:
  1. Turn on syntax highlight
  2. Expand tabs to spaces
  3. Show line number on each line
  4. Enable auto indentation
  5. Set the colouring to be friendly to a dark background
  6. Highlight the search keywords
syntax on
set expandtab
set shiftwidth=4
set softtabstop=4
set tabstop=4
set number
set cindent 
set autoindent
set bg=dark
set hls 

The plugin for plugins - Vundle

Before installing plugins, a tool for managing the plugins will make the job much more easier.
Virtually all blogs or tutorials would recommend either Vundle or Pathogen.
Both plugins can help you organize the vim plugins in a centralized way. But Vundle does it in a more elegant way.
To install Vundle, we simply clone the git repository to the vim plugin directory, by:
git clone https://github.com/gmarik/Vundle.vim.git ~/.vim/bundle/Vundle.vim
After that, add the following lines to the top of the .vimrc file.
set nocompatible              " be iMproved, required
filetype off                  " required

" set the runtime path to include Vundle and initialize
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()
" alternatively, pass a path where Vundle should install plugins
"call vundle#begin('~/some/path/here')

" let Vundle manage Vundle, required
Plugin 'gmarik/Vundle.vim'

" All of your Plugins must be added before the following line
call vundle#end()            " required
filetype plugin indent on    " required

Then Vundle will manage other plugins, including installation and update. To install a plugin, we just add a line under "Plugin 'gmarik/Vundle.vim'", and run ":PluginInstall" in vim.
This command support different formats of git repositories, including github, other git hosts and local git repositories, etc. You may check the Vundle github page for more details.

Python-mode

Python-mode is a plugin that adds a lot of IDE-like features to vim.
To install python-mode, we simply add this line to .vimrc:
Bundle 'klen/python-mode' 
And then type :BundleInstall in vim to let vundle install it.
After installation, you may need to change some settings to make it most useful for yourself. Type :h pymode in vim to get the full documentation.
If you have no idea what to change, you may check some references such as this.

Some of the most useful features include code checking, autofix PEP8 errors and go to definition, etc.

One thing I cannot make it working is the autocompletion. The shortcut for autocomplete is Ctrl-Space. However, in Mac, it will bring Spotlight instead. I have searched for a while but seems no one else is having this problem.

NERDTree

NERDTree is a filesystem explorer that let people look for and open files.
To install Nerd, add this to .vimrc:
Bundle 'scrooloose/nerdtree'

And More

After trying for a few plugins, I think they do help to increase productivity. They are more to try. I will introduce other interesting findings here in the future.

References:

  • Pathogen vs Vundle: http://lepture.com/en/2012/vundle-vs-pathogen
  • Vim as a Python IDE: http://unlogic.co.uk/2013/02/08/vim-as-a-python-ide/
  • Vundle homepage: https://github.com/VundleVim/Vundle.vim
  • Pymode homepage: https://github.com/klen/python-mode
  • Some more useful vim plugins: http://vimawesome.com/?q=tag:python

Saturday, July 11, 2015

期權定價

期權的定價分為兩部份:內涵值及時間值。

內涵值

期權的內涵值是指執行期權時產生的價值,等於期權的執行價與相關資產現價之差。只有實值期權擁有內涵值,平值和虛值期權都不具備內涵值。

時間值

期權的時間值是指除內涵值以外的價值。
時間值不只受時間影響,會影響它的因素包括:
  1. 剩餘時間
    剩餘時間越少,期權價值越低
  2. 利率
    利率會影響資金成本,從而影響期權價格
    與買入股票相比,買入認購期權可延遲至期權到期日才付出買入股票的金額,該筆款項可獲得無風險利率。因此,利率上升會導至認購期權價格上升,反之亦然。
    與賣出股票相比,買入認沽期權延遲至期權到期日才獲得賣出股票的金額,該筆款項可獲得的無風險利率減少。因此,利率上升會導至認沽期權價格下降,反之亦然。
  3. 相闗資產波幅
    波幅的提高,會令期權的賣方風險增加,導致期權價格上升。
  4. 相闗資產分紅率
    分紅只有資產的持有者可以享有,買入認購期權並不會獲得相關資產。因此,若相關資產在認購期權到期日分紅,分紅上升會導致認購期權價格下降,反之亦然。
    買入認沽期權可延遲賣出相關資產的時間,若相關資產在到期日前分紅,分紅上升會導致期權價上升,反之亦然。

理論價格與市場價格

以上影響期權價格的因素之中,只有波幅在計算價格時是未知的。期權的確實波幅,只有在到期日才能計算。計算波幅時,己知的只有過去的歷史波幅,未來波幅只能根據各項資料作出預測,以得出一個理論價格。
理論價格與市場價格可能不同,由於所有因素之中唯一的未知值是波幅,假設計算無誤,價格的差異反映雙方預測的波幅不同。從市場價格得出的波幅稱為引伸波幅。

Reference

港交所期貨及期權價格:https://www.hkex.com.hk/chi/ddp/ddp_index_c.asp


Sunday, July 5, 2015

證券衍生工具初探

本篇將簡單介紹三種證券衍生工具:股票期權、認股證(窩輪)及牛熊證。

股票期權 (Stock Options)

簡單地說,股票期權是一個在指定期限內買(認購期權、Call)或賣(認沽期權、Short)股票的權利,就像為股票價格買保險。

認購期權(Call)

認購期權是買入股票的權利。
舉例說,如我以5元買了一隻與ABC股票掛勾、下月到期、行使價100元的認購期權,我便有權在到期前以100元的價格向賣家買入ABC股票。假如在到期日ABC股票升至超過105元,我便獲利;反之,若當日股價低於100元,與其行使認購期權購入股票,倒不如直接在市場上購入股票,認購期權不會被行使,並在到期日變成廢紙。
認購期權的操作包括買入認購期權(Long Call)及賣出認購期權(Short Call)。
與買入同樣數量的股票相比,Long Call由於要付出期權金,其盈利永遠比購入股票少;可是,股票最大虧損是全部股票價值,期權的最大虧損則不會超過全部期權金。

認沽期權(Short)

認沽期權是賣出股票的權利。
與例說,如我以5元買入一隻與ABC股票掛勾、下月到期、行使價100元的認沽期權,我便有權在到期前以100元的價各向賣家賣出ABC股票。假如在到期日ABC股票跌至低於100元,我便可在市場以低價購入股票,並以100元賣出獲利;反之,若當日股價高於100元,與其行使認沽期權以賣出股票,例不如直接在市場上賣出股票,認沽期權不會被行使,並在到期日變成廢紙。


認股證

認股證(Warrant)又稱窩輪,是跟期權非常相似的概念。認股證跟期權有以下幾個不同:
  1. 期權投資者可作購入(Long)及賣出(Short)的操作,但認股證則只可做Long。
  2. 行使股票期權時,會涉及現貨(股票)交收;但認股證則只會現金交收。
  3. 港股期權由港交所發行,選擇較少,只有部份指數及指數成份股可選;認股證由金融機構發行,選擇較多,流通量亦較大。
  4. 買賣期權需以特定的期權戶交進行,認股證則可像一般股票般在普通證券戶口交易。

牛熊證

牛熊證是跟認股證相似的衍生工具,跟認股證有以下幾個不同:
  1. 牛熊證設有回收機制,當掛勾資產的價格觸及回收價,牛熊證便會被強制回收。根據不同的牛熊證種類,被回收的牛熊證可能會一文不值或有部份剩餘價值。
  2. 引伸波幅影響認股證價格,但對牛熊證價格影響輕微。
  3. 牛熊證時間值較認股證低。
  4. 牛熊證選擇較認股證少。

總結

本篇介紹了三隻衍生工具的基本概念,之後會介紹期權的定價及策略。

Reference: