Author Archives: gmgolem

Binomial Tree methods for European options using GPU

Binomial methods are versatile in pricing options for it is suitable for American, European, and Asian options. With an European call option with maturity t, strike price k, spot price S, volatility σ, risk-free rate r:

binom1.1

For put option, the last effective term shall be in the max function shall be:
binomput2

Stock’s increment, decrements, and probability to move up are given by the below respectively:

binom2

One of the CUDA samples from Nvidia is to implement the binomial model on GPU.

binom3

 

Advertisements

BeMicro SDK with Quartus 18.1 Lite

With a new laptop there are tons of software to install for getting back my development environment in the old machine. One of these is the Quartus Prime from Intel for toying with an old BeMicroSDK. Quartus is the IDE for Altera FPGA. BeMciroSDK is a development kit from Altera well before the fabless company acquired by Intel in 2015.  It sports an EP4CE22 Cyclone IV with 22K LE.
quartus18-4

The latest version of Quartus Pro is 19.1, but it no longer supports the Cyclone IV family and have to settle for the Standard  or Lite edition. The software download is available here.

The installation is smooth on Windows 10 Pro. After the installation, I plugged in the FPGA stick into the USB port, and no lights turn on. Started the Prime Programmer to check and it does not detect any device. Then I opened the device manager and saw that USB Blaster is not installed.
quartus18-2

Simply click Update driver button and browse to the installation of Quartus to complete the driver installation (Online driver searching does not find anything useful).quartus18-1

Finally the FPGA programming is successful on the new laptop.quartus18-3

Unexpected error from Oracle DBMS_XMLGEN package

Oracle databases provides an XML package to convert query results into XML in DBMS_XMLGEN. This is a very flexible extension in the way it executes within any SQL statements and can be used in conjunction with normal query to achieve results that is not easy to accomplish with ordinary query. For example, the following query retrieves count of rows for all tables with a column named “strike_price” in a database:

select table_name
, to_number(extractvalue(xmltype(
dbms_xmlgen.getxml('select count(*) c from '||table_name))
,'/ROWSET/ROW/C')) cnt
from user_tables t
where
exists (select 'x' from user_tab_cols tc
where tc.table_name=t.table_name
and lower(column_name)='strike_price')

However, after an additional where clause to limit non-zero result, Oracle returned an error:

ORA-19202: Error occurred in XML processing
ORA-00942: table or view does not exist
ORA-06512: at "SYS.DBMS_XMLGEN", line 176
ORA-06512: at line 1
19202. 00000 - "Error occurred in XML processing%s"
*Cause: An error occurred when processing the XML function
*Action: Check the given error message and fix the appropriate problem

It turns out with Oracle database version 18 onward, the same query runs fine. The package that returned error is from a previous version of Oracle.

oracle1

Test driving Nvidia RTX 2060 with TensorFlow and VS2017

Finally my new laptop that sports the new GeForce Nvidia RTX 2060 arrived. It is time to check out the muscle of this little beast with the toolset I’m familiar with.

On the hardware, the laptop is a i7-8750 and 16G RAM with a Turing architecture based GeForce RTX 2060.

rtx1.PNG

The laptop came with full drivers installed. Nevertheless I downloaded the latest drivers and CUDA for the most up-to-date experience. The software include Nvidia GeForce drivers, Visual Studio Express 2017, CUDA Toolkit, and TensorFlow.

rtx6.PNG

Be careful when trying all these bleeding edge technologies, not only because TensorFlow 2.0 is currently in Alpha, compatibility issues may haunt like with previous 1.x TensorFlow on CUDA 10.1. I have to fallback to 10.0 to have TF happy with it (although one can always choose the compile from source approach).

rtx2

And here are my favorite nbody and Mandelbrot simulation, and also the Black Scholes sample in CUDA. The diagnostic tool in VS gives a nice real time profiling interface with graphs.

rtx5

Finally for this test drive – TensorFlow with GPU. The installation is smooth until I tried to verify TF on GPU. After several failed attempts I realized it could be that CUDA 10.1 may not be compatible with the TF version installed. There are couples of suggested solutions out there, including downgrading to CUDA 9, but since my GPU is the Turing series this is not an option. Actually TF supports CUDA 10 since v.13. So I finally decided to fall back CUDA to 10.0 from 10.1 and it worked!rtx7

 

The birthday paradox riddle with TI Nspire

In probability theory, the birthday paradox is an interesting problem in that it is an easy vehicle to grasp several important statistical concepts like likelihood and combinatorics and the surprising conclusion it arrives.

The problem of the birthday is simple, in a room with n people, how many of them will have to same birthday? It turns out, using the following equation, it only takes 23 people to reach a 50% probability of having two people with the same birthday.

birthday1
birthday2

Visualizing operating characteristic curve with TI Nspire

In the study of quality control, sampling is an important technique to assess the overall quality level of a lot of production run. Operating characteristic curve is a great tool to understand the quality profile of acceptance sampling.

In TI Nspire, the OC curve can be defined as following using binomial distribution as an alternative to hypergeometric distribution.

oc-1

With the function defined, visualizing of 10% failure rate and sampling size of 20 can be done by graphing this function.

oc-2

Interesting applications of Generative Adversarial Network to crack CAPTCHA

Interesting results from a recent paper presented at the 25th ACM conference on Computer and Communications Security shown advances in Generative Adversarial Network (GAN). In particular the paper focused on tackling Captcha with GAN. GANs take a game theory approach in the training of network and during the deep learning process two entities compete in a game that one trying to fool the other while the other strives not to be fooled.

Comparison of performance of machine learning the probability distributions are usually considered as metrics for benchmark. One such commonly used is the Jensen–Shannon Divergence and a generalization can be given as

jsd