マーチンゲールのアルゴリズムを考える

マーチンゲールとは?

追加のエントリーをする際、枚数(ロット)を増やしていく手法です。

例
1枚(1ロット) ↓
↓
2枚(2ロット) ↓
↓
4枚(4ロット) ↓
↓
8枚(8ロット) ↓
↓

というように、エントリーごとに枚数を「倍、倍」にしていきます。

100円で最初のポジションを持った後に下落し、
98円でポジションを持つ際に倍の2枚でエントリーします。

そうすることで、
100円 + 98円 + 98円 = 平均98.67円
というところまで、利益となるボーダーラインが下がってきます。
先ほどの「ナンピン」は99円でしたので、より早く利益確定を狙うことができます。

よって、一回ポジションを持ったら、利益になるまで諦めない手法と言えるでしょう。

つまり、(1)ポジションと逆にいった場合に、エントリーをするということだ。
よって、どれくらい逆にいった場合にエントリーするか、を設定する必要がある。
ナンピンの場合は、単純にエントリーだが、マーチンゲールの場合は、エントリーのロットが増える。よって、(2)最初のエントリーの倍のロットでエントリーする必要がある。

この(1)、(2)をコードに反映させる必要がある。
うむ。。。これ、以外と頭使うなー。

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回はさすがにやりすぎか。