Tuesday, December 12, 2017

Convert Date Format In Python | Datetime 'strftime()'| 2017

Python Datetime 'strftime()' | Convert Date to Text Format

01:00 - 03:30 | Get Stock Data With Yahoo Finance
03:31 - 06:04 | Convert Date Format To Text
06:05 - 06:43 | Slicing doesn't work due to keyword "&" "and"

Quick note:

I couldn't slice the dataframe based on column 'df['new_date']' because the keyword "and"
was not used when coding in Python IDLE.

In Sublime Text 3, I used "&" instead of "AND" and the slicing worked.

So, remember to use "and" instead of "&" when coding in Python IDLE.


Sunday, December 10, 2017

Install Google Chrome Other Than C Drive| Windows| 2017

First of all, thank Matt Skaggs for his article regarding Google Chrome Installation Other Than C Drive:
http://smallbusiness.chron.com/change-installation-path-google-chrome-42689.html

He introduced the way to use the "Junction" program to create link between the original Chrome installation location (normally, "%LocalAppData%\Google\Chrome" ) and the destination folder
(wherever you want, e.g. D:\Program Files\Google\Chrome)

Here's my video showing the installation process.


#install_google_chrome_other_than_c_drive, #Matt_Skaggs, #Windows_7, #2017,

Tuesday, December 5, 2017

Freebie Download


This base file provides a template for any Excel program that supports multi-lingual features.
Download Multi-lingual Excel base file

Tuesday, November 14, 2017

Run Python With VSCode On USB | Anaconda Envs| Windows 10| 2017-11-14

Why Use Visual Studio Code

I am happy with Sublime Text 3 for my Python coding.
But since VSCode is free, I'd like to give it a try.
To be honest, the task runner setup was more complicated that I expected.

Anyhow, I managed to set this up on a USB.

Python Environment

1) Python 3.6.3 - Anaconda , with environment being created with Anaconda Navigator
2) Operating System: Windows 10 

Steps

1) Install Anaconda (location being set to D drive (drive other than default C))

2) Create Environment With Anaconda Navigator (Optional)
This step is optional if you're happy with the Anaconda root installation.
I tend to create different projects in different environments (Python virtual environment),
just a matter of habit.

 
3) Download VSCode and Setup
This can be quite tricky when you need to setup the task runner to run Python code.


Saturday, November 11, 2017

Aspen Mics Vs Zoom H1 via KV Connection To iPhone SE | Screen Recording Test iOS 11.1


I was testing whether I can record video using the camera app WITH iOS 11.1 screen recording feature (camera app not recording).

It turned out that no audio was recorded if I turned on the camera app.
But audio recording resumed when I switched out of the iPhone camera app.

Listed below are the time section of Aspen Mics and Zoom H1 to iPhone SE

01:45 - 02:27 | Aspec Mic to iPhone via iOS 11.1 Screen Recording
02:28 - 03:15 | Zoom H1 through KV Connection Line-in to iPhone SE iOS 11.1 Screen Recording
03:16 - 03:50 | Zoom H1 through KV Connection Mic-in to iPhone SE iOS 11.1 Screen Recording


Friday, November 10, 2017

Create Python Backtest With Jupyter Notebook Anaconda 3.5.0.1 On Windows 10| 2017-11-11

Backtest With Jupyter Notebook Anaconda 3.5.0.1


Just walkthrough the whole process of creating Python backtest in Anaconda, Windows 10.

The process is broken down into 5 major steps:
00x | Install Anaconda
10x | Get online stock (e.g. AAPL) | Market Data
20x | Create trade strategy | Strategy Class
30x | Generate trade signal | Signal Class
40x | Create investment portfolio | Portfolio Class
50x | Perfomance review | PnL + Graphing

A timeline is provided below for easy navigation:
In case you just want to use the Anaconda root setup, skip step 'Ana002'

mm:ss
00:00 - 03:02 ||Ana001| Install Anaconda
03:04 - 10:02 ||Ana002|Setup different environment other than root - optional step*
10:04 - 19:02 ||Ana101| Get Apple stock data from Yahoo Finance, save to local drive as Excel
19:04 - 29:11 ||Ana201| Create Strategy - calculate moving averages
29:12 - 35:53 ||Ana202| Create Strategy - get stock trend
35:55 - 41:22 ||Ana301| Get Trade Signal and Generate Order
41:24 - 49:50 ||Ana401402| Create Investment Portfolio and Trade Details
49:52 - 59:03 ||Ana501502| Calculate Profit and Loss and Graphing

* install optional Python packages that your project requires
** the strategy mentioned assumes zero borrowing cost so that whenever short position occurs,
we can borrow unlimited amount of money without needing to pay a penny of interest.
This is not real in real world.  So just be aware of that.


Here's the 59-min video(Complete Walkthrough - Jupyter Notebook Anaconda):



*** this video is rendered in 1.05x speed; feel free to visit the original speed videos below.

Install Anaconda 3.5.0.1(Ana001)


Setup Environment In Anaconda 3.5.0.1(Ana002) - Optional



Get Online Stock Data + Save To Local Drive(Ana101) 


Form Trade Strategy - Calculate Moving Average (Ana201) 



Form Trade Strategy - Get Stock Trend (Ana202) 


Generate Trade Signal - Get Stock Trend (Ana301)


Create Investment Portfolio (Ana401402) 


Measuring Performance & Graphing (Ana501502)


Backtest With Python Default Editor



My Thought

Comparing to buidling Python strategy backtest in default Python editor,
the Anaconda Jupyter Notebook takes a bit of time to get used to.
It takes time to load up the Jupyter Notebook while such load time is minimal in Python default editor.

But from layman's perspective, setting up multiple environments and installing packages
through the Anaconda Navigator are intuitive.
Anaconda basically organizes the folders under the 'env' folder.
That's good folder management.

In the future, I'll try using Sublime Text 3 to route to the Anaconda's environment folder.
See if I can take advantage of Sublime Text' speed while maintaining proper environment folder
management.

If you find this article helpful, feel free to discuss on my Facebook:

www.facebook.com/clueple


Disclaimer:
Everything shown in this video is just the author's personal experience with Anaconda.
All mentioned assumptions and tactics are used as demonstration for education purpose.
Trade details, not limited to, leverage level, deposit amount, transactions fees, and
any costs associated with the strategy are not meant to be complete.

No investment decision should be based on any information provided in this video.
No professional advice are provided or implied whatsoever.

Viewers are solely responsible for any loss associated to consumption of this video.

Monday, November 6, 2017

Setup Jupyter Notebook & Anaconda Environment On Windows 10

Jupyter Notebook

Just record how to create Anaconda environment to use Jupyter Notebook in folders other than the root folder, Windows 10.


#create_anaconda_environment_on_win10, #jupyter_notebook_on_anaconda, #use_jupyter_notebook_in_folders_other_than_root_folder,

Saturday, November 4, 2017

How I Create My 1st Backtest With Python | Example: Google (GOOG)

Finally finished up my 1st backtest with Python.
Just shoot this video to help remind myself the basics
and hopefully, this can help people get their feet wet
on Python coding ... (advanced users feel free to jump around using the time table below)

Here, I am showing you 2 videos where the first one is the Python setup (from scratch)
and the second one is the backtest creation.

YouTube video link - Install Python & Related Packages:

*Note that I installed Python to specific folder "py362"  but you can feel free to decide the destination folder location.
**Also, I setup the Sublime Text 3 as my code editor.  Again, you can pick your own editor.
In the backtest creation video, I used the Python built-in editor (IDLE).
***I created the virtualenv (virtual environment) for my trade algo.
You don't need that for backtest.  But it's highly recommended if you want to build Python projects, other than trade algo.




YouTube video link - Creating backtest:
https://www.youtube.com/watch?v=D73NyNb2YZs


Time Table |English Version
hh:mm:ss
00:00:09 - 00:08:24 | part 1| Get stock data from Yahoo Finance + Save to Excel
00:08:26 - 00:14:49 | part 2.1| Strategy class - defininng basic parameters
00:14:50 - 00:21:21 | part 2.2| Strategy class - calculate moving averages
00:21:22 - 00:30:53 | part 2.3| Strategy class - calculate trend details
00:30:54 - 00:37:58 | part3.1| Signal class - calculate trade signal and order
00:30:59 - 00:45:51 | part4.1| Portfolio class - calculate trade amount
00:45:52 - 00:52:26 | part4.2| Portfolio class - calculate cash balance and asset position
00:52:26 - 00:57:56| part 5.1| calculate profit and loss + plot graph


For part 4.2 "cash_balance and asset position",
you can read Isaac Kwan's code for traditional stock trade style.
He offered great help in explaining the use of abstract-based class of Python (I am still figuring that out :))

https://gitlab.com/snippets/1681494


Python script: (underlying stock being changed to 0388.HK)
https://github.com/clueple/algo/blob/master/hkex_full_example.py

Isaac Kwan's link on part 4.2 - cash balance and asset position
https://gitlab.com/snippets/1681494



Finally, please read the video disclaimer
and by no means, this video be used for real trade.

Tuesday, October 31, 2017

Wonder if Windows 10 Creator Breaks Asus Laptop

Just wonder if Win 10 Creator breaks my Asus laptop*

My laptop broke down for the 1st time after forced Win 10 Assistant Update
A few days ago, should be before Oct 29, 2017,
forced Win 10 Assistant Update again; breaks down on Nov 1, 2017

Asus laptop breaks down again on Nov 1, 2017

Asus laptop 1st break-down on Oct 11, 2017; Repair back on Oct 22


*
Asus A555 UQ-DM044T
i7-6500U
120 SSD + 1TB HDD
Purchase Date: Dec 08, 2016
1st Break-Down: Oct 11, 2017
1st Repair: Oct 22, 2017
2nd Break-Down: Nov 01, 2017

Monday, October 30, 2017

Sunday, October 29, 2017

FireFox Force English Interface Regardless Of Location

FireFox Force English Interface Regardless Of Location

Check this out:
https://addons.mozilla.org/en-US/firefox/addon/google-ncr/

FireFox Custom Installation

This link provides custom installation of FireFox.

Need to install on D drive instead of default C drive; also need to change the profile location.

Otherwise, the FireFox profile still sits inside %appdata%Firefox in C drive

https://support.mozilla.org/en-US/kb/custom-installation-firefox-on-windows

Wednesday, October 18, 2017

Counting Stock Trend With Numpy Array

Just shot a video to help me memorize how to do trend count with Numpy array:

a = np.array([0,0,0,1,1,1,0,0,1,0,1,1,0])

value_to_count = 1
value_to_reset = 0

no_reset = (a == value_to_count).cumsum()

reset = (a == value_to_reset)

excess = np.maximum.accumulate(no_reset*reset)

result = no_reset - access



Tuesday, October 17, 2017

Test iOS 11.0.3 Screen Recording On iPhone SE 2017

Test iOS 11.0.3 Screen Recording On iPhone SE 2017

Testing the iOS 11.0.3 update - screen recording feature
Device : iPhone SE (16 GB); Rendering platform: Facebook

Setup steps:
1) General ... Control Center ... add screen recording
2.1) General ... Restrictions ...type code to get in...
2.2) turn 'Screen Recording' to green ...Screen Recording inside 'Game Center'...

Recording Steps: ...starting from the main screen...
1) swipe the phone from the bottom
2) press the button ...screen recording button...
3) When you see flashing red ...see video start of this video..., you're recording
4) Once you finish recording, go back to step1... and press the button to stop


Thursday, August 24, 2017

Setup Python 3.6.2 Virtual Environment For Trade + Machine Learning Setup| Windows 10 Sublime Text 3

00:00 - 01:20 | Install Python
01:27 - 02:02 | Install virtualenv to system Python
02:06 - 03:02 | Create virtual environment
03:13 - 03:58 | Download Sublime Text 3
04:02 - 06:28 | Setup Sublime Text 3 Python path
06:29 - 07:31 | Setup Sublime Texxt 3 layout
07:38 - 08:36 | Install Python packages for trade
08:37 - 09:56 | Example reading stock data



Part 1

Part1

In this video
I'll be showing how to setup Python on Windows 10

Look up for the Python installation from your browser
and install the one that fits your system

Here I'm downloading the 64-bit Windows version

Save it to your download folder
and double click to install

Untick things that are not needed
and custom install to the drive you want

Untick the optional features
and set the destination folder

In this case
I'll be installing Python to F drive folder "py362"

Hit "OK" and start installation

You can now remove the Python installer

Now we're going to install virtualenv

Open command prompt

Navigate to the system Python location
which is F:\py362\Scripts

from there
we pip install virtualenv

Hit [Enter]
and wait for the process

you can type pip list to check whether virtualenv is installed to the system

Part 2

We're now creating a folder in F drive to hold our virtual environment

Go to command prompt
Go to F drive and type md space "Trade"
We'll be using this folder to hold our Python trade projects

Part 3

Open a new command prompt

and navigate to our system Python location
which is F:\py362\Scripts

hit [Enter] and install a new virtual environment
to the path
F:\Trade\TradeEnv
then hit [Enter] to start installation

Exit command prompt
and go to the path to see whether the virtual environment is installed

Jump back to browser
and download Sublime Text 3
Click to download the one that fits your system

Once it's downloaded
extract all files
then cut and paste the Sublime Text folder
to your destination folder

Open up the Sublime Text folder
and doubleclick the execute file to start programming

Let's start typing some Python code
Save it as a Python file

Before you run the code
you go to Tools -> Build System and tick Python

But when you hit [Ctrl] [B] to run the code
you get error message

That's why we need to create new build
to point to our virtual environment

From the untitled sublime build file
we need to paste some codes

We can look up for these codes from web

Before we save
we need to change the "python" path
to our virtual environment

I just name it with my environment's name
so that I can easily remember

Go back to your Python file
and tick the Sublime build we've just created
and run the Python code to check if it works

Yeah! It works

Part 4

If you want to move the output panel
from bottom to right

simply hit [Ctrl], [Shift], [P]
and type "install package"

Hit [Ctrl], [Shift], [P] again
and type "install"
Hit it and you'll be able to type "buildview"

click the only selection
and wait for the installation

Now you can hit [Alt] [Shift] [2]
and see a split in between

Simply run the code again
and drag the result panel
to the right

Then you can now see the right side
displays the code result

Now
we're going to pip install several packages for trade

Open command prompt

Navigate to the virtual environment's Scripts folder
pip install pandas
This is a popular package to read and process data

We then pip install xlrd
to let us read and write Excel file with Python

Pip install matplotlib
We use this one to plot graph

We also need beautifulsoup 4 to grab web data

exit command prompt

I'm going to create a new Python file to test these packages
Before saving, make sure you're coding in the virtual environment

Save the file

We're going to read this csv file with Python packages

Let me type and run the code

Ooops I type the wrong file format excel instead of csv

Go back to change to csv in our code
and press [Ctrl] [B] to run it

There we go!

Thanks for watching


Please note that you can also install numpy + mkl, scipy, and sklearn for machine learning




Feel free to discuss trade algo at
www.facebook.com/clueple

Monday, August 21, 2017

Setup Sublime Text 3 To Use Python Virtualenv on Windows

Using Virtualenv in Sublime Text 3 (Windows)


I was just looking for this setup for long.
Finally, found that pointing the path in the Sublime Text 3 build file (video 05:14 - 08:07)
can make it work.

The reason why I setup virtual environment because I need to separate different projects
based on purposes.

In this video, I pip install 2 packages - pandas and xlrd - to my virtual environment "myTradeEnv" to read the stock data from a csv file.

When you're in Sublime Text, type your Python code and save as a new Python file.
Then you go to Tools -> new build system and paste your code there.

Once you save that Sublime Text build file, get back to your Python file
and hit [Ctrl] + [B] (build) to run your code.


00:00 - 01:23 | Download and install Python
01:23 - 03:01| install virtualenv to system
03:19 - 04:09| create virtual environment myTradeEnv
04:22 - 05:11| download sublime text 3
05:14 - 08:07| setup sublime text 3 to run Python virtual environment
08:10 - 11:10 | test running python code in virtual environment to grab stock data from a csv file

Monday, August 7, 2017

Running Python On USB | WinPython

Just tried using Python on USB via WinPython.
It's pretty handy.

Simply double-click the WinPython execute file downloaded from its official website.
And you'll see a zip folder.
Unzip it to wherever you want (in my case, a USB stick).

You're ready to code.

Simply double-click the icon "Spyder" to open up the code editor.




Wednesday, August 2, 2017

Try Loading Video Source With OpenCV in Python Virtual Environment

I tried out the New Boston's OpenCV script to load up a video source.

I could get the video feed when only loading the webcam but not the capture card being hooked up to my laptop.

I did get the choice to select video source.  But still, couldn't get it worked.

If you know how to grab the video source to play on PC, please let me know.

Many thanks.


Monday, July 31, 2017

Get Started In Video Editing In 22 Minutes

What You Need To Know For Video Editing

Tools

The editor I pick is Shotcut.
There are only 2 reasons for that - ease of use and free!

The version I pick is the 64-bit Windows portable. (Download here).
You might choose the one that fits your own setting.

Setup (00:53 - 01:56 of video)

To use the program, simply extract the downloads to your destination drive.
Get into the Shotcut folder and double click the "Shotcut" exe file.

When you get into Shotcut, you will see a blank interface.
The first thing to do is adding a timeline (see  02:54 - 03:43 of video)


Basic Principles

I am talking about the fancy effects here.
Simply learn the hotkey to
1) move along the playhead (cursor of timeline) (forward, pause, rewind)
2) cut (called "split" in Shotcut) and ripple delete (delete part of the clip and snap the following one to the previous clip)
3) transition (from one clip to another)
4) change clip speed (make the video faster or slower, applicable to audio as well)
and do
5) picture in picture (PIP, that means, put an image/video on top of another video track)

The details are shown in the YouTube video below.


Conclusion

If you used other editor before, you might notice the lack of keyframming feature in Shotcut.
It's the major disadvantage of this little giant.
But still, I like the hotkey and ability to add effects (filters) with simple CSS and HTML.
Shotcut might not be suitable for big projects though.

Anyhow, It's a good starting point to learn video editing.

Forza! 

Disclaimer:  All features are applicable to my setup which might not function the same in your cases.  Use at your own risk.

Wednesday, July 26, 2017

Install OpenCV on Python 3.6 in Virtual Environment

Step1 - Downloaded The Wheel File (whl file)

In this case, my downloaded whl file "opencv_python-3.2.0-cp36-cp36m-win_amd64.whl" is in my folder "Downloads" inside "F" drive

Step 2 - Activate Virtual Environment

If you haven't setup a virtual environment, please follow along the following video
(00:09 sec - 00:17 sec) to install virtualenv
and
(00:18 sec - 01:16 sec) to virtual environment setup

https://www.facebook.com/clueple/videos/1930124850534185/

Go to the virtual environment that you want to use the whl file
In this case, my virtual environment "testGraphics" inside
folder "graphics" in "F" drive.

Go to "F" drive (if you're from default C drive,
simply type "F:"; if you're already in "F" drive,
type "cd \" to get back to the top directory of "F" drive

Activate your virtual environment with the script below:

.\graphics\testGraphics\Scripts\activate.bat

where "graphics" is the folder that holds the virtual environment
and "testGraphics" is the virtual environment folder

Step 3 - Get to the Whl File Location

Once you've activated the virtual environment ("testGraphics"),
go to the file location that your downloaded whl file sits:

In this case, my whl file ("opencv_python-3.2.0-cp36-cp36m-win_amd64.whl")
sits inside folder (F:\Downloads).

Since I am in F drive already, I simply type:
cd Downloads
to get to the "F:\Downloads" folder

Step 4 - Pip Install The whl File And Import Package

Now, you're in F:\Downloads folder.
Type the code below to install the whl file:

pip install "opencv_python-3.2.0-cp36-cp36m-win_amd64.whl"
(hit [enter])

You're ready to use the new Python package

Step 4 (Optional) - To use openCV in Python 3,
you need to import the following:

import cv2
import matplotlib
import numpy

Hope it helps.

Feel free to discuss here:

www.facebook.com/clueple

Pip Install OpenCV in Python 3 virtual environment

P.S. I just shoot a video on how to install OpenCV in Python 3.6 virtual environment (Windows 7)
The steps are more or less the same


Saturday, July 22, 2017

Record Screen From Other PC | Capture Card Avermedia C875 LGP Method

Intro

My desktop (name it "deskA") can't run certain programs that I target to capture.
But that program can be run on my laptop (name it "lapB") .

Therefore, I decide to play the program on "lapB" and mirror everything there to "deskA"
To do this I prepare the following hardware route:

1) "lapB"(laptop) - running the program
1.1) HDMI male-to-male cable 

2) capture card - take in what's done in on "lapB" via the HDMI-in
2.1) capture card (micro-usb 2.0 out to "deskA" (desktop))

3) "deskA" - turn on the recording program to record everything
passed through the capture card in (2)

Step-by-Step Instruction

Step 1 - Install capture card to your recording PC ("deskA")

In my case, I have a legacy capture card, Avermedia C875 (LGP) that can record up to 1080p @60fps.

1.1)Plug the usb cable (given along with your capture card) to "deskA" .
1.2)Switch to the PC mode (in this case, the blue light indicates PC mode is on whereas red light
signals PC-free mode is on) 
1.3) Go download the driver at the following site (depends on your capture card)
https://www.avermedia.com/gaming/download/live_gamer_portable
1.4) download ALL the drivers and then follow the installation (basically double click the firmware and follow along the installation process)

Now, you're done and you're in PC mode (that means your PC ("deskA") will be able to take in video and audio signal via the capture card.
What you'll see is the capture card with Blue light on (fixed no flashing blue light)





That capture card is hooked up to "deskA" (your recording machine) via micro-USB cable like below



Since we're going to capture what's done from another computer ("lapB"), we need to setup
our capture card to capture "Other PC"

Step 2 - Hookup your video source (e.g. "lapB") to the capture card

Before that, you need to hookup your video source device (e.g. "lapB") to the capture card's via HDMI.  It'll be like this:


At that point, you're hooking up the machine like this:

Recording PC ("deskA") -> micro-USB -> capture card -> HDMI(in) -> Video Source (e.g. "lapB" HDMI(out))

Step 3 - Setup capture card on recording PC ("deskA") to grab video 

Now, go back to "deskA".

Turn on the setup program (in our case, the RECentral),
Click the "Wizard" and go to "Platform", select "Other PC" like below

This means "asking "deskA" to get signal from "Other PC", which is "lapB" that we just hooked up".

Click "Video Source" and you'll see what's playing on "lapB" like below:
If you're playing game or YouTube, whatever, then, you'll see them in "deskA" also.
Remember, the above screen is on "deskA".

Then move on to "Audio Source" and you'll see below:

At this stage, your "deskA" (recording PC) is ready to capture both video and audio from
"lapB" (video source PC).

But, things get tricky here.

Normally, you "lapB" (laptop) won't be playing sound from the capture card
(you'll only hook up the capture card to your laptop ONLY WHEN YOU NEED TO RECORD)

So, we need to jump to step 4

Step 4 - Route the video source PC's audio ("lapB") to play through capture card

You're now back to your video source ("lapB" laptop that you want to capture)

Normally, you play your audio with the default speaker.
First of all, from your laptop ("lapB"), move your cursor to the "speaker" icon and then "right click" it.

Then, click the "Recording Device" tab.
Your default audio recording device (which in my case, the default speaker) has a green "tick" beside.

Double click the default device (e.g. the default speaker) icon and you can select "listen to"
devices (like the right hand side of the above image)

"Tick" the "listen-to device" and select your capture card (e.g. Avermedia C875 capture card) like below


Now, both the video and audio you play on "lapB" will be streamed to "deskA"

Step 4 - Record on "deskA"



Go back to "deskA" and start recording:

At this stage, you have 2 options:
1) Use the capture card's software (e.g. RECentral) to record to "deskA"
OR
2) Use other recording software to record the "screen being streammed from "lapB" to "deskA")

I prefer the route (2) because I can use software like OBS Studio (download here) to add overlay and other tweaking on my video rather than purely recording the raw screen being streamed from "lapB".
Again, this is a personal preference.
Do whatever you see fit.


Final Note

The way of capturing other PC from one PC is called "Dual PC setup".

It's mainly adopted in gaming on legacy PC.
Let's say if I want to game on my more advanced laptop ("lapB") but I don't want to push too hard
to it.  Then I will record my laptop with another desktop ("deskA").

Of cause it might seem costly but if, in my case, I got an extra legacy desktop and capture card,
I could use the dual PC setup to capture much better video and audio.

Hope it helps.