Saturday, October 3, 2015

How to compile Quantlib and Boost under Windows 10

(1) Download and install Visual Studio Express 2015 for Windows Desktop. Note that Express comes in a variety of versions. The one needed to compile console programs is Express for Windows Desktop (neither Express for Web nor Express for Windows will do)

(2) Download and install boost Prebuilt windows binaries - boost_1_59_0-msvc-14.0-32.exe from
say install to D:\local\boost_1_59_0

(3) Download and unzip from

(4) Start Visual Studio Express 2015 and open project solution QuantLib_vc14.sln in the extracted quantlib folder.

(5) Multi-select all projects (except the solution) and click the setting icon to bring up the property page.

(6) Select All Configurations and All Platforms. Add D:\local\boost_1_59_0; to the Property Pages : VC++ Include directories. And also add ;D:\local\boost_1_59_0\lib32-msvc-14.0; to the Library directories.

(7) Add /wd4819 to Command Line : Additional Options to disable C4819 warnings when compiling Quantlib.

(8) Build Debug / Release Win32 solution using shortcut key (Fn-F7)

(9) After build, highlight the quantlib solution and edit the solution property pages by clicking the setting icon or use the shortcut key (Shift-Fn-F4)

(9.1) Choose a project say Bonds as startup project

(9.2) And then Debug / Release Run (Control-Fn-F5)

Wednesday, September 30, 2015

CCS Selector for iPhone 6s Reservation Submission Form

For the iPhone 6s Reservation Submission Form, the required javascript code for selectors and the flow are analysed below in red.

URL = iPhone 6s Reservation
(2) javascript for Chrome console (Cmd + Opt + J for Mac)
iphone6s.js    Select all
var isDebug = true; var isSubmit = false; var storeOrder = ["R409","R428","R499","R485"]; // R409=CWB銅鑼灣, R485=FW又一城, R428=IFC, R499=CantonRoad廣東道 var timeslotOrder = ["2:00 PM","11:30 AM","12:00 PM","12:30 PM","1:00 PM","1:30 PM","3:00 PM","4:00 PM"]; //var timeslotOrder = ["下午 2:00","上午 11:30","下午 12:00","下午 12:30","下午 1:00","下午 1:30","下午 3:00"]; var quantity = 2; // maximum 2 for quantity, 購買數量, 最多2部 var firstname = "javacom"; // First Name 名, 必需填寫 var lastname = "NAME"; // Last Name 姓, 必需填寫 var email = ""; // Email Address 電郵, 必需填寫 var phonenumber = "98765432"; // Phone Number 電話, 必需填寫 var govtIdType = 1; /* HK 1="idHongkongCard" 香港永久性居民身份證 Hong Kong ID Card 2="travelPermitTaiwan" 台灣居民來往內地通行證 Mainland Travel Permit for Taiwan residents 3="entryExitPass" 往來港澳通行證 Entry/Exit Permit to Hong Kong and Macau 4="macauIDCard" 澳門永久性居民身份證 Macau ID Card 5="passport" 國際旅遊護照 Passport (International Visitors) */ var govtId = "A123456(7)"; // Government ID No 證件號碼,必需填寫 function autoSelect() { if (isDebug) console.log("autoSelect()"); if (isDebug) console.log($("#main #storeView .select-store select option").eq(0).val()); if ($("#main #storeView .select-store select option").eq(0).val() > "") selectStore(); else if ($(".reservation .select-store select option").eq(0).text() > "") insertContactInfo(); } function selectStore() { if (isDebug) console.log("selectStore()"); var isSelectedStore = false; var storeSelection_length = $("#main #storeView .select-store select option").length; for(i=0;i<storeOrder.length;i++) { if (isDebug) console.log("Checking Store " + storeOrder[i].toString()); for(a=1;a<storeSelection_length;a++) { if (isDebug) console.log("Against " + $("#main #storeView .select-store select option").eq(a).text()); if ($("#main #storeView .select-store select option").eq(a).val() == storeOrder[i].toString()) { if (isDebug) console.log("Selected Store is " + storeOrder[i].toString()); $("#main #storeView .select-store select option").eq(a).select().attr("selected","selected"); console.log($("#main #availabilityView .section-copy .availability-available").text()); isSelectedStore = true; break; } } if(isSelectedStore) break; } if(isSelectedStore) { $(".form-cell button").click(); } else { console.log("Sorry !! unavailable for in-store pickup"); } } function insertContactInfo() { if ($("select[name='selectedQuantity'] option").eq(quantity-1).val() > "") { $("select[name='selectedQuantity'] option").eq(quantity-1).select().attr("selected","selected").change(); } else { $("select[name='selectedQuantity'] option:last").select().attr("selected","selected").change(); } var isSelectedTimeslot = false; var timeSlotSelection_length = $("select[name='selectedTimeSlotId'] option").length; for(i=0;i<timeslotOrder.length;i++) { if (isDebug) console.log("Checking Timeslot " + timeslotOrder[i].toString()); for(a=1;a<timeSlotSelection_length;a++) { if (isDebug) console.log("Against " + $("select[name='selectedTimeSlotId'] option").eq(a).text()); if ($("select[name='selectedTimeSlotId'] option").eq(a).text().indexOf(timeslotOrder[i].toString()) == 0) { $("select[name='selectedTimeSlotId'] option").eq(a).select().attr("selected","selected").change(); console.log($("select[name='selectedTimeSlotId'] option").eq(a).select().text()); isSelectedTimeslot = true; break; } } if(isSelectedTimeslot) break; } if (!isSelectedTimeslot) { $("select[name='selectedTimeSlotId'] option:last").select().attr("selected","selected").change(); console.log($("select[name='selectedTimeSlotId'] option:last").select().text()); } $("input[name='firstName']").val(firstname); $("input[name='lastName']").val(lastname); $("input[name='email']").val(email) $("input[name='phoneNumber']").val(phonenumber) $(".gov-id-info select[name='selectedGovtIdType'] option").eq(govtIdType).select().attr("selected","selected").change(); $("input[name='govtId']").val(govtId); console.log($(".schedule-copy").text()); if (isSubmit) $(".form-cell button").click(); } autoSelect();

Friday, May 29, 2015

Android Studio 1.3 Release

Android Studio 1.3 Release
Link ->

Android Studio 1.3 <Preview 2>
Windows: (266 MB)
Mac: (265 MB)
Linux: (264 MB)

Use /usr/libexec/java_home -v 1.7 command on a Mac's terminal shell to figure out where is your java 1.7 home directory

Need JDK7 for Mac OSX here, if not already installed

Gradle Offline mode is here
See here for building apk files
app/build.gradle    Select all
apply plugin: 'android' android { compileSdkVersion 22 buildToolsVersion "22.0.1" defaultConfig { applicationId "com.mycompany.PeamonCalculator" minSdkVersion 8 targetSdkVersion 16 versionCode 1 versionName "1.0" archivesBaseName = "PeamonCalculator" + versionName } buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt' } } }

This is another build.gradle for building and linking native_app_glue static library in ndk (ugly but works in pre Android Studio 1.3)
app/build.gradle    Select all
apply plugin: 'android' def ndkFolder = file(plugins.getPlugin('').sdkHandler.getNdkFolder()).absolutePath android { compileSdkVersion 22 buildToolsVersion "22.0.1" defaultConfig { applicationId "com.beginndkgamecode.hellodroid" minSdkVersion 8 targetSdkVersion 20 versionCode 1 versionName "1.0" archivesBaseName = "HELLODRIOD" + versionName ndk { abiFilters "x86, armeabi-v7a, armeabi" moduleName "hellodroid" cFlags "-I"+ndkFolder+"/sources/android/native_app_glue" ldLibs "EGL", "GLESv2", "android", "log", file(projectDir).absolutePath+"/libs/local/\$(TARGET_ARCH_ABI)/libandroid_native_app_glue.a" } } // call regular ndk-build script task staticLibBuild(type: Exec, description: 'Build Static Library files') { // for windows: commandLine ndkFolder+'/ndk-build.cmd', commandLine ndkFolder+'/ndk-build', 'APP_BUILD_SCRIPT='+ndkFolder+'/sources/android/native_app_glue/', 'NDK_APPLICATION_MK='+file(projectDir).absolutePath+'/src/main/jni/', 'NDK_PROJECT_PATH='+ndkFolder, 'NDK_OUT='+file(projectDir).absolutePath+'/libs' } tasks.withType(JavaCompile) { compileTask -> compileTask.dependsOn staticLibBuild } task cleanLibDir(type: Delete) { delete 'libs' } clean.dependsOn cleanLibDir productFlavors { x86 { ndk { abiFilters "x86" versionCode 2 } } armv7 { ndk { abiFilters "armeabi-v7a" versionCode 2 } } arm { ndk { abiFilters "armeabi" versionCode 2 } } } buildTypes { debug { minifyEnabled false zipAlignEnabled true jniDebuggable true renderscriptDebuggable true } release { minifyEnabled false zipAlignEnabled true proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt' } } }

C/C++ Debugging is very limited in the first few previews of Android Studio 1.3, so logging might be helpful in C/CC source files like this below.
main.cpp    Select all
#include <android/log.h> ... #define ALOG(...) ((void)__android_log_print(ANDROID_LOG_INFO, __FILE__, __VA_ARGS__)) ... ALOG("This message came from C at line %d.", __LINE__);

For the source code of HelloDroid and PeamonCalculator, please see here and here.

Want to change to the awesome dark background theme. It is here

Android Studio 1.3 Release & 1.4 Preview using gradle-experimental

app/build.gradle (Module)   Select all
apply plugin: '' model { android { compileSdkVersion = 23 buildToolsVersion = "23.0.0" defaultConfig.with { applicationId = "com.beginndkgamecode.hellodroid" minSdkVersion.apiLevel = 8 targetSdkVersion.apiLevel = 23 versionCode = 1 versionName = "1.0" archivesBaseName = "HELLODRIOD_" + versionName } } android.ndk { moduleName = "hellodroid" /* * Other ndk flags configurable here are * cppFlags += "-fno-rtti" * cppFlags += "-fno-exceptions" * ldLibs = ["android", "log"] * stl = "system" */ cppFlags += "-I${file("src/main/jni/native_app_glue")}".toString() ldLibs += ["android", "log", "EGL", "GLESv2"] } android.buildTypes { release { minifyEnabled = false proguardFiles += file('proguard-rules.txt') } debug { ndk.with { debuggable = true } } } android.productFlavors { // for detailed abiFilter descriptions, refer to "Supported ABIs" @ // create("arm") { ndk.abiFilters += "armeabi" } create("arm7") { ndk.abiFilters += "armeabi-v7a" } create("arm8") { ndk.abiFilters += "arm64-v8a" } create("x86") { ndk.abiFilters += "x86" } create("x86-64") { ndk.abiFilters += "x86_64" } // To include all cpu architectures, leaves abiFilters empty create("all") } }

app/build.gradle (Project)   Select all
// build.gradle // Classpath for the plugin is instead of // The current version is 0.2.0. // Top-level build file where you can add configuration options common to all sub-projects/modules. buildscript { repositories { jcenter() } dependencies { classpath '' } } allprojects { repositories { jcenter() } }

./gradle/wrapper/    Select all
#The new plugin supports only gradle-2.5. distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists distributionUrl=https\://

Monday, April 27, 2015

RQuantLib 0.4 example

R version 3.1
dependencies ‘Rcpp’, ‘rgl’, ‘zoo’, ‘RUnit’
bond1.R  Select all
#Simple call with a flat curve require(RQuantLib) bond <- list(faceAmount=100, settlementDays=1, issueDate=as.Date("2014-11-30"), redemption=100)
scheduleparams <- list(effectiveDate=as.Date("2014-11-30"), maturityDate=as.Date("2018-11-30"), period=2, calendar="UnitedStates", businessDayConvention = 4, terminationDateConvention=4, dateGeneration=1, endOfMonth=1, dayCounter = 'Thirty360')
coupon.rate <- c(0.02875)
params <- list(tradeDate=as.Date('2014-2-15'), settleDate=as.Date('2014-2-19'), dt=.25, interpWhat="discount", interpHow="loglinear")
discountCurve.flat <- DiscountCurve(params, list(flat=0.05))
FixedRateBond(bond=bond, rates=coupon.rate, schedule=scheduleparams, calc=list(dayCounter='ActualActual.ISMA',compounding='Compounded', freq='Annual', durationType='Modified'),discountCurve=discountCurve.flat)

FixedRateBondPriceByYield( settlementDays=1, yield=0.05127, faceAmount=100, effectiveDate=as.Date("2014-11-30"), maturityDate=as.Date("2018-11-30"), period=2, calendar="UnitedStates", rates=c(0.05), dayCounter=2, businessDayConvention=4, compound=0, redemption=100, issueDate=as.Date("2014-11-30"))

FixedRateBondYield( settlementDays=1, price=99.54593, faceAmount=100, effectiveDate=as.Date("2014-11-30"), maturityDate=as.Date("2018-11-30"), period=2, calendar="UnitedStates", rates=c(0.05), dayCounter=2, businessDayConvention=4, compound=0, redemption=100, issueDate=as.Date("2014-11-30"))

calendar ->
dayCounter ->
compounding ->
freq ->
duration ->

Bond Utilities
matchBDC(bdc = c("Following", "ModifiedFollowing", "Preceding", "ModifiedPreceding", "Unadjusted"))
matchCompounding(cp = c("Simple", "Compounded", "Continuous", "SimpleThenCompounded"))
matchDayCounter(daycounter = c("Actual360", "ActualFixed", "ActualActual", "Business252", "OneDayCounter", "SimpleDayCounter", "Thirty360", "Actual365NoLeap", "ActualActual.ISMA", "ActualActual.Bond", "ActualActual.ISDA", "ActualActual.Historical", "ActualActual.AFB", "ActualActual.Euro"))
matchDateGen(dg = c("Backward", "Forward", "Zero", "ThirdWednesday", "Twentieth", "TwentiethIMM"))
matchFrequency(freq = c("NoFrequency","Once", "Annual", "Semiannual", "EveryFourthMonth", "Quarterly", "Bimonthly", "EveryFourthWeek", "Biweekly", "Weekly", "Daily"))

For Mac OSX, only 0.3.12 is available and quantlib-config should in in your path and executable

/usr/local/bin/quantlib-config  Select all
#!/bin/sh prefix=/usr/local exec_prefix=${prefix} exec_prefix_set=no usage="\ Usage: quantlib-config [--prefix[=DIR]] [--exec-prefix[=DIR]] [--version] [--libs] [--cflags]" if test $# -eq 0; then echo "${usage}" 1>&2 exit 1 fi while test $# -gt 0; do case "$1" in -*=*) optarg=`echo "$1" | sed 's/[-_a-zA-Z0-9]*=//'` ;; *) optarg= ;; esac case $1 in --prefix=*) prefix=$optarg if test $exec_prefix_set = no ; then exec_prefix=$optarg fi ;; --prefix) echo $prefix ;; --exec-prefix=*) exec_prefix=$optarg exec_prefix_set=yes ;; --exec-prefix) echo $exec_prefix ;; --version) echo 1.4.1 ;; --cflags) echo -I${prefix}/include -I/usr/local/include ;; --libs) echo -L${exec_prefix}/lib -L/usr/local/lib -lQuantLib ;; *) echo "${usage}" 1>&2 exit 1 ;; esac shift done

Friday, December 19, 2014

Microsoft Office for Android Tablets Preview

Minimum Requirements:
ARM based Android Tablet having more than 7" screen, 1GB RAM and running KitKat (4.4.x).
Please note that Lollipop/Android 5 are not supported in this preview program.

To get started, please follow these steps:
1) If you have not installed, pls follow below instructions to install
a) Become tester by visiting following links –
b) Wait for 10 minutes to 2 hours as Google play takes time to replicate permissions, then click below mentioned links and follow the download links to install apps using Google play store

Word Preview

Excel Preview

PowerPoint Preview

2) If you are getting error in updating the apps, pls uninstall the older version and install.
To install, visit –

Saturday, November 22, 2014

Android Studio RC1

To install Android Studio manually:
Windows: (235 MB)
Mac: (234 MB)
Linux: (233 MB)

Saturday, November 15, 2014

How to compile C++ Game for Andorid NDK using Mac Terminal and Ant

This is a walkthrough of building C++ application with Android ndk and ant without using Eclipse IDE

1. Download the latest Android SDK from

and install Java SDK SE from Oracle say jdk-7u71-macosx-x64.dmg
2. Download Android NDK from say

3. Install apache ant

Please take note that for Mac OSX Mavericks, ant is no longer in Mac, just download a binary distribution of Ant from . and unzip/untar it, and add its bin directory to PATH.

4. Use Mac Terminal and add path to the above three installation folders
e.g. export PATH=${PATH}:~/android-sdk-macosx/tools:~/android-sdk-macosx/platform-tools:~/android-ndk-r9d:~/apache-ant-1.9.4/bin

5. Use Terminal command android sdk and android avd to update the sdk (install sdk of minimum of API-15 (Android 4.0.x) and create a new avd)

If you use Intel HAX for fast virt mode in emulator, please set Use Host GPU to on.

6. Download some C++ game source code e.g. here . Just download the Source Code from the book website and extract say
If you want to support multiple platforms add this APP_ABI in HelloDroid/jni/
APP_PLATFORM := android-16
APP_ABI := armeabi armeabi-v7a x86

7. ndk-build
cd ~/Download/HelloDroid
ndk-build clean && ndk-build

list target (assume sdk installed already in step 5 above)
android list target

update project with target 1 (assume target id 1 is already created with API-16 in step 5 above)
android update project -n com.beginndkgamecode.hellodroid -t 1 -p .

list avd (assume "NokiaX" is created in step 5 above)
android list avd

8. start emulator
emulator -avd NokiaX -scale 0.5 &

debug build
ant clean && ant debug

install apk to emulator
ant debug install

(1) use ant uninstall if need to remove
(2) use Control-fn-F12 to rotate the emulator in Mac
(3) the generated apk file is bin/com.beginndkgamecode.hellodroid-debug.apk
(4) add android:icon to AndroidManifest.xml like this to add a default icon.
<application android:icon="@drawable/ic_launcher" android:label="@string/app_name" ...