無料のSSL証明書を使う (証明書更新編)

準備

80番ポートを開放していること
バックアップをとる
$ cp -pr /etc/letsencrypt/ /etc/letsencrypt.20230701

SSL証明書更新 (dry-run)

$ sudo certbot renew –webroot -w /var/www/html/wordpress01 –dry-run

Saving debug log to /var/log/letsencrypt/letsencrypt.log

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Processing /etc/letsencrypt/renewal/stonehills.tokyo.conf
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Cert is due for renewal, auto-renewing...
Plugins selected: Authenticator webroot, Installer None
Simulating renewal of an existing certificate for stonehills.tokyo
Performing the following challenges:
http-01 challenge for stonehills.tokyo
Using the webroot path /var/www/html/wordpress01 for all unmatched domains.
Waiting for verification...
Cleaning up challenges

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
new certificate deployed without reload, fullchain is
/etc/letsencrypt/live/stonehills.tokyo/fullchain.pem
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Congratulations, all simulated renewals succeeded:
  /etc/letsencrypt/live/stonehills.tokyo/fullchain.pem (success)

SSL証明書更新

$ sudo certbot renew –webroot -w /var/www/html/wordpress01

Saving debug log to /var/log/letsencrypt/letsencrypt.log

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Processing /etc/letsencrypt/renewal/stonehills.tokyo.conf
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Cert is due for renewal, auto-renewing...
Plugins selected: Authenticator webroot, Installer None
Renewing an existing certificate for stonehills.tokyo
Performing the following challenges:
http-01 challenge for stonehills.tokyo
Using the webroot path /var/www/html/wordpress01 for all unmatched domains.
Waiting for verification...
Cleaning up challenges

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
new certificate deployed without reload, fullchain is
/etc/letsencrypt/live/stonehills.tokyo/fullchain.pem
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Congratulations, all renewals succeeded:
  /etc/letsencrypt/live/stonehills.tokyo/fullchain.pem (success)

$ sudo systemctl restart apache2

ブラウザから、SSL証明書の更新日が変更されていることを確認する

Cronに登録した

$ cronta -e
これは毎月1日午前1時に証明書更新する場合

0 1 01 * * sudo certbot renew --webroot -w /var/www/html/wordpress01
0 2 01 * * sudo systemctl restart apache2

pythonでJ-Quants

J-Quants はJPX(日本証券取引所)の提供するAPI

無料プランの場合、3か月遅れの情報までしか取得できない

pypi


import json
import requests
import pandas as pd


# POSTするデータを作る。
email  = "xxxxxxxxxxxxx"
password = "xxxxxxxxxx"
account_data = json.dumps({
        "mailaddress": email,
        "password": password,
    })

auth_user_url = "https://api.jquants.com/v1/token/auth_user"

auth_result = requests.post(auth_user_url, data=account_data)
refresh_token = auth_result.json()["refreshToken"]

auth_refresh_url=f"https://api.jquants.com/v1/token/auth_refresh?refreshtoken={refresh_token}"

refresh_result = requests.post(auth_refresh_url)
id_token = refresh_result.json()["idToken"]

code = "7203" # 4桁のコードでも5桁のコード72030でもよい。
from_ = "2023-03-01"
to_ = "2023-03-01"

daily_quotes_url = f"https://api.jquants.com/v1/prices/daily_quotes?code={code}&from={from_}&to={to_}"
target_url= f"https://api.jquants.com/v1/fins/statements?code={code}"

# idトークンはヘッダーにセットする
headers = {"Authorization": f"Bearer {id_token}"}
result = requests.get(target_url, headers=headers)
print(result.json())

pythonでのYahoo Finance API

yfinanceのインストール

yfinanceはpythonのでYahoo Financeにアクセスするためのライブラリです。個人利用しか出来ないです。

https://pypi.org/project/yfinance/

pipをインストールして、yahoo finance ライブラリをインストールします。

   # apt install pip
   # pip install yfinance

テーブル作成

json型を使います。

    create database finance;
    CREATE USER 'finance'@'localhost' IDENTIFIED BY 'xxxxx';
    GRANT ALL PRIVILEGES ON * . * TO 'finance'@'localhost';
    use finance;
    CREATE TABLE YahooFINANCE (
      t_date date NOT NULL,
      ticker VARCHAR(255) NOT NULL,
      attr JSON,
      CHECK (JSON_VALID(attr)),
      PRIMARY KEY (t_date,ticker)
   );

GOOGLEの情報をデータベースにinsertし、selectするpy

import mysql.connector
import yfinance as yf
import json

ticker = yf.Ticker("GOOG")

conn = mysql.connector.connect(
    user="finance",
    password="xxxxx",
    host="localhost",
    database="finance")
cur = conn.cursor() 

sql = ('INSERT INTO YahooFINANCE (t_date, ticker, attr) VALUES (now(6), %s, %s) ON DUPLICATE KEY UPDATE attr = VALUES (attr);')

data = [
     ('GOOG', json.dumps(ticker.info)) 
]

cur.executemany(sql, data)

conn.commit() 

cur.execute("SELECT t_date,ticker FROM YahooFINANCE", ()) 

for id,ticker in cur: 
    print(f"TICKER: {ticker}, ID: {id}")

conn.commit() 

財務指標の見方

主要な財務指標


項目
一言でいうと目安
ROE利益 / 自己資本20 %以上
ROA利益 / 総資産
自己資本比率自己資本/総資本30% 以上
PER時価総額 / 利益15倍以下
PBR株価 / 1株当たり純資産
EPS1株あたりの利益
BPS1株あたりの純資産
PEG RatioPER / 一株当たりの予想利益成長率1倍以下なら割安

ROE (Return Of Equity)

意味

計算式
ROE(自己資本利益率)(%)=当期純利益÷自己資本×100

備考

自己資本比率

意味
自己資本比率とは、総資本のうち純資産(新株予約権を除く)の占める割合を言い、 自己資本に依存している割合のことです

計算式
自己資本比率=自己資本÷総資本×100

備考

PER

意味
1株当たり純利益の何倍の株価が付けられているかを、指し示します

計算式
株価÷EPS

US株の買い方

米国株と国内株の違い

国内株式と米国株式は、購入方法が異なります。米国株式の方が面倒です。

米国株国内株
購入通貨原則ドル※
購入サイト外国株式の口座が必要通常株式口座で可能
手数料20$0円から300円

※円決済も可能ですが、毎回為替手数料がかかります

外国株式口座

普通のオンライン株式口座は国内株式なので、外国株式口座の開設手続きが必要です。これはSBI証券の場合

ドルへの交換

為替取引で円からドルに交換する必要があります。これはSBI証券の為替取引画面

株式の購入

そして、外国株式の画面から購入します。これはSBI証券でGOOGLE(会社名はアルファベット)を購入しようとした場合

注意した方がいい点

売買単位は1株単位の場合が多いから、1株122ドルといった単位で購入 (国内株は100株単位)

手数料は国内株より高く、デイトレードには不向き。SBI証券で20ドル程度です。