PHPでFXを考えよう

まず適当に考えます。手持ち50万として、ドル円が109.958円の時、1ロットは

# 手持ち資金が50万円とする
$margin = 500000;

# レバレッジ25倍とする
$leverage = 25;

# 1ロット1万通貨
$lot = 10000;
$long = 1;
$short = -1*0;

# ドル円価格
$dollyen = 109.958;

$total = $dollyen * $lot * $long;
echo $total;

->1099580
当然、109万9580円です。ここから必要証拠金を考えます。

取引単位は1ロットからで、4万円とあります。

よって、requried marginを4%と置きます。

$lot = 10000;
$long = 1;
$short = -1*0;

# ドル円価格
$dollyen = 109.958;

$total = $dollyen * $lot * $long;
echo $total. "<br>";
$rmargin = $total * 0.04;
echo $rmargin;

-> 43983.2
必要証拠金は43,983円

証拠金維持率は、手持ちの金額から必要証拠金を割ったものだから、

$total = $dollyen * $lot * $long;
echo $total. "<br>";
$rmargin = $total * 0.04;
echo $rmargin . "<br>";
$mrate = $cash / $rmargin;
echo $mrate * 100;

1099580
43983.2
1136.7976863893
証拠金維持率は1136.79%
つまり、50万もってて、ドル円109.958を1ロット、ロングでもったら、証拠金維持率は1136.79%になるということだ。

>金融商品取引業等に関する内閣府令の「FX証拠金規制」により、個人のお客様からの外国為替証拠金取引においては、取引金額の4%以上の証拠金をお預け入れいただくことが義務付けられております。
なるほど、この必要証拠金4%ってのは、金商法の規制ってわけね。

で、肝心のロスカットはというと、

必要証拠金が50%を下回ると、強制ロスカットというわけですね。

# 手持ち資金が50万円とする
$cash = 500000;

# レバレッジ25倍とする
$leverage = 25;

# 1ロット1万通貨
$lot = 10000;
$long = 1;
$short = -1*0;

# ドル円価格
$dollyen = 109.958;

echo “ポジション:” . $dollyen.”円
“;
$total = $dollyen * $lot * $long;
echo “投資額:” .$total. “円
“;
$rmargin = $total * 0.04;
echo “必要証拠金:” .$rmargin . “
“;
$mrate = $cash / $rmargin;
echo “証拠金維持率:” .$mrate * 100 . “%
“;

if ($mrate < 0.5){ echo "ロスカットが発生しました"; } else { echo "ロスカットに注意してください。" } [/php] こうか?? 必要証拠金は、現在の値によって変化するからちょっと違うな。

禁則文字

When it comes to the beginning or end of a line, it is a character that is inappropriate in appearance or hard to read. Typical examples include punctuation marks and parentheses. There are two types of punctuation characters: line beginning and end line punctuation characters. The former refers to characters that are inconvenient to come to the beginning of the line, and the latter refers to characters that do not allow to come to the end of line.

終わり
括弧類:」』)}】>≫]など
拗促音:ぁぃぅぇぉっゃゅょァィゥェォッャュョなど
中点や音引:・(中点/中黒)ー(音引き)―(ダーシ)-(ハイフン)など
句読点:、。,.など
その他約物:ゝ々!?:;/など

始め
括弧類:「『({【<≪[など

なるほどねー

python astモジュール

The ast module makes it easy to handle Python abstract syntax trees in Python applications. The abstract syntax itself can change with every release of Python. Using this module will help to learn the current grammer programmatically.

To create an abstract syntax tree, pass ast. PyCF_ONLY_AST as a flag for the built-in function compile() or use the helper function parse() provided by this module. The result is a tree of objects of classes that inherit from ast.AST. Abstract syntax trees can be compiled into Python code objects using the built-in function compile().

[vagrant@localhost test]$ python --version
Python 3.5.2
[vagrant@localhost test]$ cat << 'EOF' > helloworld.py
> !#/usr/bin/env python
> # -*- coding: utf-8 -*-
>
> def main():
>   print('hello, world!')
>
> if __name__ == '__main__':
>   main()
> EOF

[vagrant@localhost test]$ python
Python 3.5.2 (default, Jul 28 2018, 11:25:01)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-23)] on linux
Type “help”, “copyright”, “credits” or “license” for more information.
>>> FILENAME = ‘helloworld.py’
>>> with open(FILENAME, ‘r’) as f:
… source = f.read()
File ““, line 2
source = f.read()
^
IndentationError: expected an indented block

あれ、うまくいかんな。。

ib_logfile*

ibdata* is a shared table space (It managed all data)
ib_logfile* seems to be a log file.

Data is not updated directory to the table space, but once the update contents are written to the log file.
After that, it seems that the flow is reflected in table space.
Tablespace updates are expensive and are not reflected immediately.
By writing to the log file, the writing performance is improved.

中身を見てみましょう

cd /var/lib/mysql
ls
sud cat ib_logfile0

なんじゃこりゃーー

InnoDB

– Default storage engine from MySQL5.5
– General purpose storage engine with good balance of reliability and performance.
– DML operations process transactions according to the ACID model, such as commit rollback and crash recovery
– Data is aligned on disk so that queries are optimized based on primary key
– Operations that call different storage engine tables can be mixed in one query
– Foreign key constraints are also supported
– InnoDB stores in tablespaces whereas MyISAM always stores data in file
– The good thing about MyISAM is that it can be easily backed up and copied in units of tables, but innoDB is still poorly managed in this respect.
– Table spaces can be stored in files, but can also be written directly to partitions.
– There is unique buffer pool for caching data and indexes in many mamory, which helps high speed data access.

う~ん、。。。

ibdata1には何が入っているのか?

$ sudo cat /var/lib/mysql/ibdata1
ん?

# ./innochecksum /var/lib/mysql/ibdata1
0 bad checksum
13 FIL_PAGE_INDEX
19272 FIL_PAGE_UNDO_LOG
230 FIL_PAGE_INODE
1 FIL_PAGE_IBUF_FREE_LIST
892 FIL_PAGE_TYPE_ALLOCATED
2 FIL_PAGE_IBUF_BITMAP
195 FIL_PAGE_TYPE_SYS
1 FIL_PAGE_TYPE_TRX_SYS
1 FIL_PAGE_TYPE_FSP_HDR
1 FIL_PAGE_TYPE_XDES
0 FIL_PAGE_TYPE_BLOB
0 FIL_PAGE_TYPE_ZBLOB
0 other
3 max index_id

checksum以外は、FIL_PAGE_*だな。FILって何の略だろうか?

ibdata1には何が入っているのか?
– データディクショナリ(InnoDBテーブル)
– チェンジバッファ
– ダブルライトバッファ
– UNDOログ

んん??

disabled属性

buttonにdisabledを追加します。

<button disabled>ボタン</button><br>
<button>ボタン2</button>

なるほど、こうやって表示されるのかー

通信タイムアウト

通信タイムアウトの状況

デフォルトの制限値は30secondとあり、デフォルト値のままですね。
では、公式に沿って試してみましょう。

set_time_limit(20);

while ($i <= 10){ echo "i=$i "; sleep(100); $i++; } [/php] ん、止まってしまった。 sleep(100)の10回はさすがにやりすぎか。

What is load average?

Load average is an indicator that represents the load status of the entire system. It is represented by “the number of processes waiting for “the number of processes waiting for execution per unit time and disk I/O waiting for one CPU”.

If yuo want to increase the throughput of the system, the goal is to reduce the load average.

The Linux kernel has a process descriptor for each process, and manages the state of the process in its state member. The state of the process is distinguished as follows.

TASK_RUNNING: Possible state. It can be run if the CPU is free.
TASK_UNINTERRUPTABLE: Uninterruptible wait state. Those that return in a short time, such as waiting for disk I/O.
TASK_INTERRUPTABLE: An interruptible wait state. The return time can not be predicted, such as waiting for user input.
TASK_STOPPED: Execution has been suspended. It will not be scheduled until it is resumed.
TASK_ZOMBIE: Zombie process. The child process has not exited and has not been waited on by the parent process.

ロードアベレージを確認するコマンド
[vagrant@localhost ~]$ uptime
08:42:40 up 1 day, 16:57, 1 user, load average: 0.00, 0.00, 0.00
[vagrant@localhost ~]$ uptime
08:43:36 up 1 day, 16:58, 2 users, load average: 0.13, 0.03, 0.01

[vagrant@localhost ~]$ w
08:44:33 up 1 day, 16:59, 2 users, load average: 0.05, 0.02, 0.00
USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT
vagrant pts/1 192.168.35.1 08:43 1:08 0.42s 0.24s php -S 192.168.
vagrant pts/0 192.168.35.1 23:24 1.00s 7.38s 0.01s w

[vagrant@localhost ~]$ top
top – 08:45:38 up 1 day, 17:00, 2 users, load average: 0.02, 0.02, 0.00
Mem: 501796k total, 493992k used, 7804k free, 6144k buffers
Swap: 1015804k total, 419948k used, 595856k free, 30000k cached

PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
6854 vagrant 20 0 100m 700 468 S 51.0 0.1 0:00.34 sshd
9368 vagrant 20 0 15020 1308 1008 R 51.0 0.3 0:00.28 top
1 root 20 0 19232 192 60 S 0.0 0.0 0:00.90 init
2 root 20 0 0 0 0 S 0.0 0.0 0:00.00 kthreadd
3 root RT 0 0 0 0 S 0.0 0.0 0:00.00 migration/0
4 root 20 0 0 0 0 S 0.0 0.0 0:01.62 ksoftirqd/0
5 root RT 0 0 0 0 S 0.0 0.0 0:00.00 stopper/0
6 root RT 0 0 0 0 S 0.0 0.0 0:00.63 watchdog/0
7 root 20 0 0 0 0 S 0.0 0.0 3:13.04 events/0
8 root 20 0 0 0 0 S 0.0 0.0 0:00.00 events/0
9 root 20 0 0 0 0 S 0.0 0.0 0:00.00 events_long/0
10 root 20 0 0 0 0 S 0.0 0.0 0:00.00 events_power_ef
11 root 20 0 0 0 0 S 0.0 0.0 0:00.00 cgroup
12 root 20 0 0 0 0 S 0.0 0.0 0:00.00 khelper
13 root 20 0 0 0 0 S 0.0 0.0 0:00.00 netns
14 root 20 0 0 0 0 S 0.0 0.0 0:00.00 async/mgr
15 root 20 0 0 0 0 S 0.0 0.0 0:00.00 pm
16 root 20 0 0 0 0 S 0.0 0.0 0:01.11 sync_supers
17 root 20 0 0 0 0 S 0.0 0.0 0:00.02 bdi-default

おおおおおおおおおお、なんかわかった気になってきた。すげえ。