今日も窓辺でプログラム

外資系企業勤めのエンジニアが勉強した内容をまとめておくブログ

ChatGPT にコーディング面接の面接官をやらせてみる

背景

ChatGPT (GPT-4) が話題ですね。日々驚くべき記事や活用方法を目にしていますが、中でも次の記事のように、プロンプトを与えるだけで自然言語を活用したゲームが簡単に実現できてしまうことに感動しました。

note.com

コーディング面接の問題を解かせるような試みは多くなされている中で、このゲームのプロンプトを元にすれば、コーディング面接の面接官を ChatGPT にやってもらえるのでは?と考え、実際やってみました。

プロンプト

ChatGPT に入力するプロンプトは以下の通りです。まだ試行錯誤があまり行えていない段階のものですが、それでもある程度それっぽく動きます。

出題する問題の分野や難易度は色々調整の余地があると思います。

As a GPT-4 AI interviewer, you'll have a coding interview with a candidate. You'll ask some coding questions to the candidate in the real world., and the candidate would write answers in their favorite programing language or natural language.

# Coding Interview Rules:
* Provide an simple coding questions as an AI interviewr.
* Candidate is human and answers to your questions by programing languages or natural language.

## Basic Interview Process
* First the interviewer does self-introduction shortly as an ice breaking. The candidate do not need to do self-introduction.
* Then, the interviewer ask an easy coding question as a screening question.
* The candidate can ask some questions to clarify their understanding about the coding question.
* If the candidate gives a valid code snippet, the interviewer would move to the next coding question. If not, the interview ends here.
* In the second coding question, the interviewer ask a medium level coding question. The candidate can clarify their task again.
* If the candidate gives a valid code snippet to the second question, the interview gives some extra questions that relates to the code written by the candidate.
* In both first and second question, the interviewer can ask the candidate to rewrite code if time complexity or space complexity is  not acceptable.

## Basic Candidate Profile
* Candidate studied computer science in university.
* Candidate have used Python in their class and research, but the candidate never experienced a professional software engineer.

All Input and output should be in Japanese.

動いている様子

現実のコーディング面接をすぐに置き換えられるとは思わないですが、その可能性を少し感じられたり、少なくとも面接の練習にはなったりするのではないでしょうか。

1問目の肩慣らし問題の様子

2問目の中級レベルの問題の様子

追加質問もしてくれる

最後は面接というよりも教育してくれる

バグは指摘してくれる

MT4でカスタム指標を定義してみる

前回はMT4でスクリプトを実行してみました。今回はチャートに自分で定義した指標を描画するカスタム指標を定義してみようと思います。

カスタム指標とは

前回も紹介した通り、カスタム指標 (Custom Indicator) とは独自に作成したテクニカル指標をチャートに描画するためのプログラムです。

カスタム指標には初期化のためのOnInit()関数と実際に指標を計算するOnCalculate()関数を定義しますが、カギとなるのは OnCalculate() 関数で、次のような場合にカスタム指標を計算するために呼ばれます。 1. カスタム指標がチャートに読み込まれ、初期化処理 (OnInit()) が終了した直後 1. 新しいティックを受信したとき

続きを読む

MT4でスクリプトを実行してみる

FXなどの自動売買で使用されるMT4でスクリプトを実行してみます。

MT4とは?

FXの取引に使われるソフトウェアです。色々な通貨ペアのチャートを表示することに加え、そのチャートに対してプログラムを走らせることができます。

プログラムは次の3種類に分けられるようです。

  • Script: チャートに対して1度だけ実行されるプログラム
  • Custom Indicator: 独自に作成したテクニカル指標をチャートに描画するプログラム
  • Expert Adviser (EA): チャートの価格の変化に応じて自動売買ができるプログラム

今回はまず一番簡単そうな、一度だけコードを走らせるスクリプトを実行してみようと思います。

環境

MT4がWindowsにしかインストールできないのでWindows環境で動作確認しています。また、MT4は楽天証券のサイトからインストールした下記のバージョンのものを使用しています。 * Rakuten MetaTrader 4, Version 4.00, Build 1170

Hello, World

まずは何はともあれHello Worldです。MT4ではMQL4というC言語ライクな文法をしており、下記のコードを実装したスクリプトをコンパイルしチャートにドラッグすると、ターミナルのエキスパートタブに "Hello, world!" が表示されます。

#property copyright "Copyright 2019, madopro"
#property link      "https://www.madopro.net"
#property version   "1.00"
#property strict

void OnStart()
  {
    Print("Hello, world!");   
  }

定義済み変数

MQL4には取引に役立つ様々な変数が事前に定義されています。変数一覧はPredefined Variables - MQL4 Referenceから参照できます。 現在の売値や買値に加え、チャートを過去にさかのぼった始値終値なども取得することができます。

#property copyright "Copyright 2019, madopro"
#property link      "https://www.madopro.net"
#property version   "1.00"
#property strict

void OnStart()
{
    // Pre-defined variables.
    Print("通貨ペア=", _Symbol);
    Print("小数桁数=", _Digits);
    Print("最小値幅=", _Point);
    Print("タイムフレーム=", _Period);
    
    Print("Bid=", Bid, ", Ask=", Ask);
    
    for(int i = 0; i < 10; i++) {
        Print("[", i, "] Open=", Open[i], ", High=", High[i], ", Low=", Low[i], ", Close=", Close[i]);
    }
}

スクリプトはコードが実行されるのが1回きりですが、カスタムインディケーターやEAなどだと、 Open などの変数が以下に便利そうか想像がつきますね。

参考

新MT4対応 FXメタトレーダープログラミング入門

新MT4対応 FXメタトレーダープログラミング入門