Tuesday, August 25, 2015

Understand leverage reset decay, 3X ETF decay

a picture is worth a thousand words, and I believe a chart or spreadsheet is much better than words too, check this first:

The first section assume the underline index changes 2% first day and -2% next day and repeat it for 20 days. If you put $100 at beginning, for 1X ETF, you will have $99.60 left, but for 3X ETF, you will have only $96.45, you lost $3, or 3% because of leverage reset decay.

Now let's check the 2nd scenario, for section 2, we assume the underline index changes 0.2% first day and -0.2% next day and repeat for 20 days, for 1X ETF you will have $99.996 left, for 3X ETF it is $99.964, you only lost 0.03% because of leverage reset decay.

What does this mean? This means if the underline index is running in a range and the change everyday is dramatic(high volatility), it is very risky to keep the 3X ETF for a long time. Compare the 2 sections and you find that if everyday's change is 10 times more, the decay is 100 times more. In real world, oil, natural gas and gold prices are changing in a wider range, that is why UGAZ/DGAZ, UWTI/DWTI, UVXY is similar to this, and you can see they loose value quickly. Take a look at the following chart for a better visual impression, if the underline index go up/down 2% every day for 60 trading days, which is about 3 months, the 3XETF lost 10% of value.

Let's move to the 3rd scenario, if the trend for underline index is going up, we can see using 3X ETF gains higher return than 1X ETF. What do all these mean? If you know the trend of an index, It's better to use 3XETF than 1XETF. If not, you better not touch 3XETF, and do not hold 3XETF for long time if the index is NOT moving on a trend!

Thursday, June 11, 2015

Regular Expression notes

I think I need to collect all my regular expression notes here to help myself and anyone who need it, I might not be smart enough to understand how it work thoroghly by just read tutorial, so I will collect all examples here to help:

1. Remove control characters and space (the red mark is a space) (oracle example):
select 'asdfo'||chr(9)||'dsu iue', regexp_replace('asdfo'||chr(9)||'dsu iue', '[[:cntrl:] ]','') from dual

2. The following will match utill second occurence, *? is lazy qualifier so it will stop when it find the next foo:
string: goo foo goo goo foo goo foo goo foo goo fo
3. The following will match utill last occurence, as we removed the lazy qualifier from #2, it will stop when it find the last foo: 
string: goo foo goo goo foo goo foo goo foo goo fo

Thursday, January 29, 2015

Put multiple images for a product in Odoo 8 ecommerce web page

I really like the idea that Odoo provide both a powerfull ERP solution as well as a quite functional ecommerce solution. However compare to other ecommerce solution Odoo is missing some functions, One concern is on Ebay, Amazon as well as many e-commerce websites, they use slides to show multiple pictures at the left-top section. But Odoo only allow one pictures. So I raised a question here: 
"Can an e-commerce pages show multiple pictures at the left top part of the page in V8?"

Luke Branch now provides a addon. (check https://github.com/OdooCommunityWidgets/website_multi_image). It works great and I want to share how I install this addon with you. 

Here is how I install the addon, please be aware you configuration/odoo folders may be different, if you follow my post to install Odoo you should be able to follow this instruction without issue.  

First stop odoo server and run the following to get the custom module. 

sudo su - odoo -s /bin/bash
mkdir custom_modules
cd /opt/odoo/custom_modules/
git clone -b 8.0 https://github.com/OdooCommunityWidgets/website_multi_image.git 
Now you have the file you need to Scaffolding this module. Still run as odoo user:
cd ..
./odoo.py scaffold website_multi_image addons
cp -R custom_modules/website_multi_image addons/.
At this point you need to start odoo server. Log into Odoo as admin, make sure "Technical Features" is turned on for admin, if not, go to Settings->Users, edit admin user by check "Technical Features" checkbox. 

No go to Settings->Modules->Update Modules List and click Update button. When finished, install "Product Multi-Image". 

Then you can go to Product configuration page -> product images and add more images for the product. 

Well here is how it looks like on website: 

And here is how it looks in product maintain page: 

Friday, January 9, 2015

Connect Oracle using ODBC 32 bit in 64 bit Windows 7

For some reason I need to build an ODBC connection to Oracle database, the Oracle database version is This turned out to be quite a big challenge. There are several issues during the installation, as usual, Oracle never make things easy. Anyway, here is how:

1. Download Instant Client basic 32 bit and ODBC 32 bit for from here.
2. Extract both zip files you downloaded, put the files in instantclient_11_2 folder into C:\instantclient_11_2\
3. Add C:\instantclient_11_2 into Windows Path
4. Run C:\instantclient_11_2\odbc_install.exe
    You may see a warning from Program Compatibility Assistant says: This program might not be installed correctly. Just ignore it.
5. Goto ODBC 32bit console, tt is not easy to find Windows ODBC 32 bit console, the fastest way is to run C:\Windows\SysWOW64\odbcad32.exe from Start->search
6. If you have ODBC 32bit console open, create a new ODBC connection using Oracle in instantclient_11_2. You will fill the TNS Service Name like this: //host_ip_or_url:port/instance_name.
6. At this point you can test the new ODBC connection, but mostly you will see this error:
    ORA-12705: Cannot access NLS data files or invalid environment specified
The solution was to find the registry key named NLS_LANG under:
and rename it to anything else. I put an "x" at the end. This key is left over from a full install of Oracle. The instant client ODBC works properly now.

Friday, January 2, 2015

Install Adobe Flash Player on Android 4.X

I just got a new Huawei Mate 7, a fantastic phone in my opinion. But I found now Android doesn't support Flash Player anymore, Photon browser can natively support Flash but the Ads is quite annoying. So I did some research and found a solution.

  1. Ensure that the Android device is connected to the Internet.
  2. Open the Settings menu.
  3. Select Security
  4. Select Unknown Sources.
  5. Tap OK to confirm your selection.
  6. Close Settings.
  7. Download flash player apk file here
  8. Open the apk file to install flash player. 
  9. Install Dolphin browser, you can find Dolphin browser from Play Store. I have tried different browsers, no luck with Chrome or Firefox. You may have better luck though. 
Thats it, I don't think you need to change any setting for Dolphin browser.