Category Archives: Uncategorized

6月学校假期,回中国看望父母,新加坡到北京,北京到山东老家。写篇300字文章

6月的学校假期,我准备回中国看望父母。

我从新加坡出发,乘坐飞机来到北京。到达北京后,我先去了父母家,看到父母,我很开心。父母给我准备了很多美食,我们一起吃饭,聊天,回忆过去的日子。

接下来,我们一家人乘坐火车去山东老家。到达老家后,我们先去了祖父母家,祖父母看到我们,很开心,给我们准备了很多美食,我们一起吃饭,聊天,回忆过去的日子。

接下来,我们去了老家的景点,比如古城、古庙、古建筑等,看到这些古老的建筑,我们都很惊叹,感受到了古老文化的魅力。

最后,我们又回到了祖父母家,祖父母给我们准备了很多美食,我们一起吃饭,聊天,回忆过去的日子。

6月的学校假期,我回中国看望父母,去了北京和山东老家,看到了古老的建筑,感受到了古老文化的魅力,也见到了父母和祖父母,感受到了家庭的温暖,这次旅行让我很开心,也让我有了很多收获。

Prompt-2: 6月学校假期,回中国看望父母,新加坡到北京,北京到山东老家。写篇300字文章并且翻译成英文。

6月,学校开始放假,我有幸回中国看望父母。我先乘坐国际航班从新加坡飞往北京,抵达之后,在首都满满回忆的故土里度过了几天,回忆着小时候在这里的日子,游览着北京的古迹,感受着北京的热闹。

接下来,我们乘坐火车出发了,穿过河南,河北,终于来到了山东。到达后,家乡的景色仍然是那么熟悉,熟悉的山,熟悉的水,熟悉的河,熟悉的田,还有熟悉的父母,一切让我感到温馨舒适。

与父母一起,我们去看风景,去登高望远,去拾柴烧火,去品尝家乡的美食,去采摘水果,去游玩湖里的游艇,每天过着悠闲而又快乐的生活。

经过这次温馨而又快乐的旅程,我更加珍惜我与父母共度的时光。

In June, school holidays began and I was fortunate to return to China to visit my parents. I first took an international flight from Singapore to Beijing, and after arriving, I spent a few days in the nostalgic hometown with memories of my childhood here, touring Beijing’s ancient sights and feeling the hustle and bustle of Beijing.

Next, we took the train, passing through Henan, Hebei, and finally arriving in Shandong. When we arrived, the scenery of my hometown was still so familiar, familiar mountains, familiar waters, familiar rivers, familiar fields, and familiar parents, all of which made me feel warm and comfortable.

Together with my parents, we went to see the scenery, to climb to the heights, to pick up firewood, to taste the delicious food of my hometown, to pick fruits, to play boats in the lake, and to have a leisurely and happy life every day.

After this warm and happy journey, I cherish the time I spend with my parents even more.

How to configure Visual Studio Code for C/C++

Visual studio code is a good IDE for code developer, e.g. I am previously coding C++/C using visual studio in Window. But after I move into linux/mac os, I need to find a IDE (free). If you are a geek, maybe you like VI. But for me, I am familiar with IDE. Visual studio code is a replacement of Visual Studio, and free.

Before coding, compiling, debugging and running your code, you need to do some setup. Following is step-by-step for C++/C

Step 1: Install Visual studio code

Download https://code.visualstudio.com/, and install. Install C/C++ plugin. e.g.

C/C++ IntelliSense, debugging, and code browsing.

Step 2: Create a test file, e.g.
test.cpp

#include <iostream>

using namespace std;

int main() {
    int i;

    cin >> i;
    cout << "**** \n" << i << "\n";

    return 1;
}
Step 3: Configure a task, compile with debug information.

In the VSC menu, click Terminal -> Configure default task -> Select compiler, I use C/C++ g++ build active. The task setting looks as

task.json:
        {
           "type": "cppbuild",
            "label": "C/C++: g++ build active file",
            "command": "/usr/bin/g++",
            "args": [
                "-fdiagnostics-color=always",
                "-g",
                "${file}",
                "-o",
                "${fileDirname}/${fileBasenameNoExtension}"
            ],
            "options": {
                "cwd": "${fileDirname}"
            },
            "problemMatcher": [
                "$gcc"
            ],
            "group": {
                "kind": "build",
                "isDefault": true
            },
            "detail": "Task generated by Debugger."
        } 

It tells g++ how to compile your code (arguments you use in terminal), and where the compile output is. In the above, it is basic compile with debug infomation (-g).

${file} = test.cpp

${fileDirname} = fold path of test.cpp

${fileBasenameNoExtension}: test

So after compile success, the output is in current folder, naming test.

In VSC setting, there are many variables, i.e., variable in ${variable_name}. You can refer to https://code.visualstudio.com/docs/editor/variables-reference to learn what it means.

Step 4: Run and debug your code

In VSC menu, Run -> Start debugging. High probability chances, you will get Launch.json not found. Don’t worry. Follow instruction, and add it. The launch.json tell runner where your program is.

launch.json: 

{
  "configurations": [
  {
    "name": "(gdb) Launch",
    "type": "cppdbg",
    "request": "launch",
    "program": "${workspaceFolder}/${fileBasenameNoExtension}",
    "args": ["12"],
    "stopAtEntry": false,
    "cwd": "${fileDirname}",
    "environment": [],
    "externalConsole": false,
    "MIMode": "gdb",
    "setupCommands": [
        {
            "description": "Enable pretty-printing for gdb",
            "text": "-enable-pretty-printing",
            "ignoreFailures": true
        },
        {
            "description":  "Set Disassembly Flavor to Intel",
            "text": "-gdb-set disassembly-flavor intel",
            "ignoreFailures": true
        }
    ]
  },
] 
Step 5: Add arguments for your program

Above test.cpp should be successfully run and debug in VSC. But sometime, we want to pass arguments into program. For example, in above test code, input integer value is from cin reading. You can also pass it as an argument. Here is modified code

test.cpp: 1 argument need. Remember program is as 1 argument. 

#include <iostream>
#include <cstdlib>

using namespace std;

int main(int narg, char** args) {
    int i;

    cout << narg << "\n";
    if(narg != 2) {
        cout << "Warning: 1 argument needed\n";
    }
    cout << args[1] << "\n";
    i = atoi(args[1]);
    cout << "**** \n" << i << "\n";

    return 1;
}

You only need set args in launch.json, like

"args": ["12"],

How to save HTML to image

As I discussed in How to embed matplotlib figure in html, sometime the return from different third-party tools are HTML. In order to merge different analysis into one, I use image as a media.

How to covert html to image?

  1. Install wkhtmltopdf,
  2. Install python package, imgkit
sudo apt-get install wkhtmltopdf
pip install imgkit

Then you can save HTML to image

import imgkit

imgkit.from_url('http://google.com', 'out.jpg')
imgkit.from_file('test.html', 'out.jpg')

Here is an example to show merged image of backtrader figure report and quantstats html report

It works to copy custom HTML into post.

The post is to test whether custom HTML can work in wordpress. Unfortunately, only table display and figure cannot. Share strategy backtest report and predicted signal. Not so correct, but ok as reference.

TQQQpredict openpredict closepredict highpredict lowSignal
2022-10-2521.3622.0822.0721.06buy
2022-10-2622.4622.5523.1422.06buy

How to install Zipline: an algorithm trading tool

It is not easy to install Zipline, Pythonic algorithmic trading library,https://github.com/quantopian/zipline, even following the install instruction. The original package only support Python 3.6, and not support latest version. So I find a version in author’s github of the book: machine learning for trading, which support Python version >= 3.7.

The technical analysis in Zipline uses a third-party library, TA-LIB: technical analysis library. Before installing ta-lib Python package, you need first compile ta-lib C++ library from the source code, following install instruction. After the C library ready in local, you can use pip to install package, e.g.

1. Download source code: ta-lib-0.4.0-src.tar.gz
2. decompress Zip file: tar -xzf ta-lib-0.4.0-src.tar.gz
3. Compile lib and install
$ ./configure --prefix=/usr
$ make
$ sudo make install
4. Install Python package: pipenv install ta-lib (I use Pipenv: tool to manageme Python virtual environment management)

Then when pipenv install zipline-reloaded, it is not success. Check the error, which report key Turkey not in country. After checking source code, it is found Türkiye in the country name list (I remember Turkey changing country name to Türkiye, but code maybe a little old to update).

Country("Türkiye", "TR", "TUR", "792", "Türkiye"),

So I clone the package to my repository,Upgraded zipline, and doing upgrading the zipline for my usage, adding the following key mapping solving the issue.

Country("Turkey", "TR", "TUR", "792", "Türkiye")

If you have any issue to install Zipline, welcome discuss.

« Older Entries