Program : libFinHk
Status : Development
License : MIT opensource
Version : 0.0.x
Compiler : nim 0.11.3
Description : A library to support financial calculations with Nim
with focus on Hongkong Stock Exchange data
Project : https://github.com/qqtop/NimFinLib
Tested on : Linux
ProjectStart: 2015-07-07
ToDo :
Programming : qqTop
Contributors:
Requires : nimFinLib
Notes : it is assumed that terminal color is black background
and white text. Other color schemes may not show all output.
For comprehensive tests and usage see nimFinT3.nim & nimFinT4
Procs
proc hkexToYhoo*(stc: string): string
-
hkexToYhoo
mainly used in conjunction with getHKEXcodes or getHKEXcodesFromFile
converts a hkex stockcode like 00001 to 0001.HK only longer ones
not starting with 0 need not be cut
current yahoo historical data links for csv download need this format
proc yhooToHKEX*(stc: string): string
-
yhooToHKEX
convert a yahoo code of type 0001.HK into a HKEX code
of type 00001
proc getHKEXcodes*(): seq[seq[string]]
-
getHKEXcodes
this proc scraps public data from http://www.hkex.com.hk
data returned are 3 seqs which hold stockcodes,companynames and boardlots
of companies listed on the exchange mainboard .
this allows to create custom portfolios,random portfolios
the stock codes can be massaged into yahoo codes for further
current or historical data downloads
this routine was successfully tested in 2015-07
it may take a few seconds as abt 1500 stocks are currently listed
proc getHKEXcodesFromFile*(fname: string): seq[seq[string]]
-
getHKEXcodesFromFile
read a csv file created with getHKEXcodes into three seqs
stockcodes,companynames,boardlots
proc initHKEX*(): seq[seq[string]]
-
initHKEX
convenience proc to load from web or read from file
list of HK Stock Exchange mainboard listed stocks
proc getHKEXseq*(stockslist: seq[string]; acode: string): int
-
getHKEXseq
this is used to get an index into the hkex.csv data
for a single stockcode
hkexcodes = initHKEX() var bigMseq = newSeq[int]() bigMseq.add(getHKEXseq(hkexcodes[0],"00880")) echo bigMseq
here hkexcodes[0] holds the list of stockcodes in HKEX format this is used to query the hkexcodes for company name and boardlots
proc hkPfseq*(anf: Portfolio; hkexcodes: seq[seq[string]]): seq[int]
-
hkPfseq
hkPfseq returns the index seq of stocks in a Portfolio objects dx Stocks
proc showQuoteTableHk*(apfData: Portfolio)
-
showQuoteTable
a table with kurtosis, stdDev close ,ema22 , company name and latest quote from yahoo
for usage example see nimFinT3
proc hkRandomPortfolio*(sz: int = 10; startdate: string = "2014-01-01"; enddate: string = getDateStr()): (Portfolio, seq[int])
-
hkRandomPf
a fast automated random Portfolio generator
just pass in number of stocks and optionally start and enddate
the portfolio is also returned as Portfolio object for further use as desired
for example use see nimFinT4.nim