Friday, September 16, 2016

找到virtual environment 裡 python 的位置



sys.path
A list of strings that specifies the search path for modules. Initialized from the environment variable PYTHONPATH, plus an installation-dependent default.
As initialized upon program startup, the first item of this list, path[0], is the directory containing the script that was used to invoke the Python interpreter. If the script directory is not available (e.g. if the interpreter is invoked interactively or if the script is read from standard input), path[0] is the empty string, which directs Python to search modules in the current directory first. Notice that the script directory is inserted before the entries inserted as a result of PYTHONPATH.

這段寫的是如果 sys.path 回傳的list 的第一個元是空括號。代表python 會搜索目前所在
的資料夾。然後才是接下來所有的元。然後python 會搜索在pythonpath 裡面的packages.

In nest_project  virtual environment :

>>> import sys
>>> print sys.path
['', '/Users/pohsuanhuang/.local/lib/python2.7/site-packages/nupic-0.5.5.dev0-py2.7.egg','/Users/pohsuanhuang/miniconda/envs/nupic/lib/python2.7/site-packages/nupic.bindings-0.4.5.dev0-py2.7-macosx-10.6-x86_64.egg', '/Applications/Nest/ins/lib/python2.7/site-packages', '/Users/pohsuanhuang/miniconda/envs/nest_project/lib/python27.zip', '/Users/pohsuanhuang/miniconda/envs/nest_project/lib/python2.7', '/Users/pohsuanhuang/miniconda/envs/nest_project/lib/python2.7/plat-darwin', '/Users/pohsuanhuang/miniconda/envs/nest_project/lib/python2.7/plat-mac', '/Users/pohsuanhuang/miniconda/envs/nest_project/lib/python2.7/plat-mac/lib-scriptpackages', '/Users/pohsuanhuang/miniconda/envs/nest_project/lib/python2.7/lib-tk', '/Users/pohsuanhuang/miniconda/envs/nest_project/lib/python2.7/lib-old', '/Users/pohsuanhuang/miniconda/envs/nest_project/lib/python2.7/lib-dynload', '/Users/pohsuanhuang/.local/lib/python2.7/site-packages', '/Users/pohsuanhuang/miniconda/envs/nest_project/lib/python2.7/site-packages', '/Users/pohsuanhuang/miniconda/envs/nest_project/lib/python2.7/site-packages/cycler-0.10.0-py2.7.egg']
>>> import os
>>> os.environ['PYTHONPATH'].split(os.pathsep)
['/Applications/Nest/ins/lib/python2.7/site-packages']

In tensorflow virtual environment : 

import sys

print(sys.path)
['', '/Users/pohsuanhuang/.local/lib/python2.7/site-packages/nupic-0.5.5.dev0-py2.7.egg', '/Users/pohsuanhuang/miniconda/envs/nupic/lib/python2.7/site-packages/nupic.bindings-0.4.5.dev0-py2.7-macosx-10.6-x86_64.egg', '/Applications/Nest/ins/lib/python2.7/site-packages', '/Users/pohsuanhuang/miniconda/envs/tensorflow/lib/python27.zip', '/Users/pohsuanhuang/miniconda/envs/tensorflow/lib/python2.7', '/Users/pohsuanhuang/miniconda/envs/tensorflow/lib/python2.7/plat-darwin', '/Users/pohsuanhuang/miniconda/envs/tensorflow/lib/python2.7/plat-mac', '/Users/pohsuanhuang/miniconda/envs/tensorflow/lib/python2.7/plat-mac/lib-scriptpackages', '/Users/pohsuanhuang/miniconda/envs/tensorflow/lib/python2.7/lib-tk', '/Users/pohsuanhuang/miniconda/envs/tensorflow/lib/python2.7/lib-old', '/Users/pohsuanhuang/miniconda/envs/tensorflow/lib/python2.7/lib-dynload', '/Users/pohsuanhuang/.local/lib/python2.7/site-packages', '/Users/pohsuanhuang/miniconda/envs/tensorflow/lib/python2.7/site-packages', '/Users/pohsuanhuang/miniconda/envs/tensorflow/lib/python2.7/site-packages/IPython/extensions', '/Users/pohsuanhuang/.ipython']


Monday, June 13, 2016

US stock market perspective

Some observations of United States stock market in the last month.

1.  Its enough to transact once a month. Transaction fee is so high that it doesn't make sense to do transaction more than once per week. The fluctuation between the period are just investing emotions and speculations. One month is already the shortest duration to draw conclusion and make prediction in the next month.   (just an empirical rule, can be falsify, especially due to technological reason, such as AI trader.)

1. You must make a transection once a month. It is not recommended just leave them their.  You should either sale those bad and bid in those good, and update your information library. Otherwise you will loose touch to the market. This is the basic of basic, just in case you are very r

2. Most traders also make transaction once a week for the same reason. It doesn't matter if you will hence miss the critical time point, since you shall profit from your long term prediction of the company, not from other trader's decision. (The huge fall or rise should have a very sane base, such as company actions or fiscal report, which should have been learned by you earlier if you are not lazy and stupid. The unpredictable rise and fall, are therefore, unpredictable to rational traders. Unpredictable unpredictables are what a good trader should avoid. What traders do is to predict unpredictables.) This kind of rise and fall are too short to capture, and again, too high the transaction fee to make it profitable.

3. Market rise slow like climbing mountains, and plunge fast like jumping from cliffs. It stems from human psychology. It is the nature of human beings to evade risks. Exploiting this is the only reason we are more probable to earn money than other 'instinct traders' who doesn't aware how emotion affects human decisions.  Practically speaking, we buy when people sell, we sale when people buy. How do you know when to buy if the stock price is falling. How do you know it is the time the stock will stop falling, and is about to rise ? 1. deceleration of the falling speed. 2. When the fear comes from the bottom of your heart, buy it. Your nature-born emotion is the best anti-indicator in stock market. It is the primary pitfall that most trader fall into.

4. Evaluate the objectives not by P/E (it is a fossil), but DIVIDEND AND EPS, the most direct number telling you how much you should expect to gain after a year. ROE decides the price of the stock. Second the growth of revenue by year. This also decides the price, but only partially. Third, the demand of the target market of the company. This decides the long term growth of the company. For example, Internet infrastructures such as cables and servers are in high demands, whilst energy production and downstream refinement, distribute and retail markets are shrinking. But there are nuances which require extensive study of the markets. 

5. Don't buy what experts or newspaper recommend you (those are almost always bullshit). Don't take action simply because of some information. Action follows your judgement. Always form judgement, and that's why you will have a better chance to profit if you start to write a blog about your judgements. You can later revisit your judgement and adjust is according to reality. 

However, do use public information to confirm/refute your portfolio selections by using their logic to challenging your logics. Besides, you can make a compare group to evaluate whether your portfolio performance is better than so called 'experts'.

6.  S&P500 is a very good benchmark to test your readiness. If your portfolio cannot outperform PURE500, you should just buy PURE500. Otherwise you are just wasting your money. 


7. Never buy any kind of trust, because those traders earn managing fees regardless their performance. They never take your money as seriously as you do. Second, You will feel disgruntled wether you earn money or lose money anyways, and you will always think you are better than them (which could be very likely true.) They Can make one VERY bad decision and ruined the whole years hard work and make you think are they idiots or not ? (rhetorical question here.)

8. Here are some observation of the market demands : First, uprising consumer market in China is huge and underdeveloped. China is a close market that protects local companies. Therefore, Chinese companies targeting consumers are likely to boom multiple times. Yirendai,  a online micro loan company in China. Its price has soared like rocket after POA. Second, the infrastructure of Internet are thriving due to the strong demand. Global Energy demand is shrinking, and has a VERY BAD prospect in the long run. US Domestic Energy companies are also suffering. (Warning, no liability of any consequence of any investments incurred.) This observation is subjective, which personal bias and preference, which breath in some fresh air to this hideous but inescapable chore.

9.  However, don't put all your eggs in one basket. Even some industries are not that hyped, it doesn't mean they are not a good objective for conservative, stable, and liquid source of revenue. You just don't want to loose all your money in a financial tsunami. Balance your portfolio by all means.



 







   

 

Saturday, April 30, 2016

Bash Script Note : How to write your first Bash Script



How to write your first Bash Script

https://linuxconfig.org/bash-scripting-tutorial


1. Create  a file called hello.sh in promt:
   
        cat > hello.sh 

2. Edit content

     # Test file

3. press CTRL+D to save file

4. display contents, type

    cat hello.sh

5. Edit contents
 
   vi hello.sh

6. make the file executable

   chmod +x hello.sh

7. execute your first bash script

  ./hello.sh

Bash Script Note : redirection, pipe, variable



The Note is a quite review of what has been learnt on website :

http://tldp.org/HOWTO/Bash-Prog-Intro-HOWTO-3.html

The Note is driven by examples of short snippets. The brief command function is formatted as COMMAND:DESCRIPTION.

ECHO: the function is the same as printf


3. All about redirection

Stdout, Stderr to a file

This will cause the ouput of a program to be written to a file.
        ls -l > ls-l.txt

This will cause the stderr ouput of a program to be written to a file.
        grep da * 2> grep-errors.txt
4.Pipes 

Pipes let you use the output of a program as the input of another one.
This is very simple way to use pipes.
        ls -l | sed -e "s/[aeio]/u/g"   
        
Here, the following happens: first the command ls -l is executed, and it's output, instead of being printed, is sent (piped) to the sed program, which in turn, prints what it has to.
Probably, this is a more difficult way to do ls -l *.txt, but it is here for illustrating pipes, not for solving such listing dilema.
        ls -l | grep "\.txt$"
        
Here, the output of the program ls -l is sent to the grep program, which, in turn, will print lines which match the regex "\.txt$".

5.Variables
You can use variables as in any programming languages. There are no data types. A variable in bash can contain a number, a character, a string of characters.
You have no need to declare a variable, just assigning a value to its reference will create it.

            STR="Hello World!"
            echo $STR    
            

Line 2 creates a variable called STR and assigns the string "Hello World!" to it. Then the VALUE of this variable is retrieved by putting the '$' in at the beginning. Please notice (try it!) that if you don't use the '$' sign, the output of the program will be different, and probably not what you want it to be.


A very simple backup script
           #!/bin/bash          
           OF=/var/my-backup-$(date +%Y%m%d).tgz
           tar -cZf $OF /home/me/
           
This script introduces another thing. First of all, you should be familiarized with the variable creation and assignation on line 2. Notice the expression '$(date +%Y%m%d)'. If you run the script you'll notice that it runs the command inside the parenthesis, capturing its output.

Notice that in this script, the output filename will be different every day, due to the format switch to the date command(+%Y%m%d). You can change this by specifying a different format.
Some more examples:
echo ls
echo $(ls)

Local variables can be created by using the keyword local.

                #!/bin/bash
                HELLO=Hello 
                function hello {
                        local HELLO=World
                        echo $HELLO
                }
                echo $HELLO
                hello
                echo $HELLO

Wednesday, July 11, 2012

Nokogiri error


How to use Nokogiri to collect data?

The first step is to Install Nokogiri 

When I tried to install Nokogiri on my Windows OS using


gem install nokogiri


I confronted an error shows


 It looks like it is about the conversion of the binary code. I can imagine a real computer engineer could solve this with casual enthusiasm, but now I have to count on myself. 
 I turn to Google of help. Nothing.
Then I turn to Nokogiri-talk , no helpful information. 
 I post my question on it , and I am suggested to upgrade my RDoc packet. The suggestion really helped!

 And I found on the blog :


 that it is prerequisite to install libxml or libxml before installing Nokogiri. Do what it ask you to do.
  
but I encounter another trouble, 

when I typed    irb(main):001:0> require 'rubygems'
an error occured...



We can get example of Nokogiri by googling "Nokogiri css example"







Tuesday, July 10, 2012

Ruby Programming Language: Basic Ruby command


We have learned how to run Ruby on cmd.exe on Windows

So let's learn some Ruby.

Concise Ruby Language Tutorial 
A short, but quite enough tutorial for beginners. But we don't spend too much time going through every chapter here, because our goal is to learn data-mining, not Ruby. We can review it when we need it.


Quick Note
 
A quick overview of the most basic commands, in case we forgot.

   







Tuesday, July 3, 2012

Ruby Programming Language Note: Basic Commands for cmd.exe


Ruby Programming Language Note


The first class of learning ruby is not learning ruby language, but leaning some command for cmd.exe. It's because we data miners don't use Interactive Ruby, but Command Prompt Ruby.
we run ruby on cmd.exe.



command                           description
---------------------------------------------------------------------------------------------------
dir                                      list the files/directory under the current directory
                                          Its equivalent is ls on Linux and OS

cd                                      enter the directory/ file

cd ..                                   return to the previous directory, remember the space before tow
                                         periods.  // very similar to Linux commnad ^^
mkdir                                 make directory

move                                 move

copy                                 copy

ruby                                 run ruby files

You can find all commands and its explanation HERE

Tutorial for cmd.exe commands

For people who haven't learn Linux before, I recommend the Bible of Linux- 鳥哥的Linux私房菜

------------------------------------------------------------------------------------------------------

OK, this is the first class here.