-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
unageanu
committed
Aug 16, 2009
1 parent
4f97f7d
commit 3874d1c
Showing
644 changed files
with
107,999 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
|
||
2009-8-15 1.2.0 | ||
* エージェントエディタを一新 | ||
- 複数のエージェントや共有ライブラリをタブで同時に編集できるようになりました。 | ||
- エージェントや共有ライブラリをディレクトリで分類できるようになりました。 | ||
|
||
* 標準ライブラリの追加 | ||
標準添付の共有ライブラリとして、以下を追加。 | ||
- 移動平均などの各種シグナル算出クラス | ||
- ロスカットやトレーリングストップを容易に実現するPositionManager | ||
- クロスアップ、クロスダウンを判定するためのユーティリティ | ||
|
||
* バックテストの再実行機能を追加 | ||
- バックテストを1クリックで再実行できるようになりました。 | ||
|
||
* グラフ出力の不具合修正 | ||
- エージェントを削除するとそのグラフも表示できなくなる問題を改修しました。 | ||
- この変更でリアルトレードでは古いグラフが蓄積されていくようになったため、 | ||
不要なグラフを破棄する機能も追加しました。 | ||
|
||
2009-8-8 1.1.4 | ||
* クリック証券デモ取引Webサービスの提供終了にあわせて、デモ取引接続プラグインを | ||
無効化 | ||
|
||
2009-7-5 1.1.3 | ||
* クリック証券のデモ取引に接続する場合に、設定でプロキシを空のまま確定すると | ||
接続エラーになる不具合を改修。 | ||
|
||
2009-6-29 1.1.2 | ||
* クリック証券プラグインを標準添付 | ||
|
||
2009-6-20 1.1.1 | ||
* uuidtools 2.0.0 との組み合わせで動作しなかった問題を改修 | ||
* クリック証券デモトレードにアクセスする際に使用するプロキシを指定できるようにした。 | ||
|
||
2009-5-6 1.1.0 | ||
* 証券会社へのアクセスロジックを、プラグインで後から追加できるように修正。 | ||
|
||
2009-4-19 1.0.3 | ||
* グラフの色を変更してもリロードすると元に戻る不具合を修正。 | ||
|
||
2009-4-14 1.0.2 | ||
* 以下の不具合を修正。 | ||
- システムを再起動すると、動作中のエージェントが全て停止状態となる。 | ||
- リアルトレードで建玉にエージェント名が設定されない場合がある。 | ||
- リアルトレードで追加したエージェントのグラフ設定ができない。 | ||
- 月の初めに、取引一覧の範囲絞込みの初期値が不正な値になる。 | ||
|
||
2009-3-29 1.0.0 | ||
* 初版リリース |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
# | ||
# 移動平均を使うエージェント。 | ||
# -ゴールデンクロスで買い。 | ||
# -デッドクロスで売り。 | ||
# | ||
class MovingAverageAgent < JIJI::PeriodicallyAgent | ||
|
||
# エージェントの説明 | ||
def description | ||
<<-STR | ||
移動平均を使うエージェントです。 | ||
-ゴールデンクロスで買い&売り建て玉をコミット。 | ||
-デッドクロスで売り&買い建て玉をコミット。 | ||
STR | ||
end | ||
|
||
# エージェントを初期化する。 | ||
def init | ||
# 移動平均の算出クラス | ||
# 共有ライブラリのクラスを利用。(JIJI::Agent::Sharedモジュールに定義される。) | ||
@mvs = [ | ||
JIJI::Agent::Shared::MovingAverage.new(@short), | ||
JIJI::Agent::Shared::MovingAverage.new(@long) | ||
] | ||
@prev_state = nil | ||
|
||
# 移動平均をグラフで表示するためのOutput | ||
@out = output.get( "移動平均線", :graph, { | ||
:column_count=>2, # データ数は2 | ||
:graph_type=>:rate, # レートにあわせる形式で表示 | ||
:colors=>["#779999","#557777"] # デフォルトのグラフの色 | ||
} ) | ||
end | ||
|
||
# 次のレートを受け取る | ||
def next_period_rates( rates ) | ||
|
||
# 移動平均を計算 | ||
res = @mvs.map{|mv| mv.next_rate( rates[:EURJPY].bid ) } | ||
|
||
return if ( !res[0] || !res[1]) | ||
|
||
# グラフに出力 | ||
@out.put( *res ) | ||
|
||
# ゴールデンクロス/デッドクロスを判定 | ||
state = res[0] > res[1] ? :high : :low | ||
if ( @prev_state && @prev_state != state ) | ||
if state == :high | ||
# ゴールデンクロス | ||
# 売り建玉があれば全て決済 | ||
operator.positions.each_pair {|k,p| | ||
operator.commit(p) if p.sell_or_buy == JIJI::Position::SELL | ||
} | ||
# 新規に買い | ||
operator.buy 1 | ||
else | ||
# デッドクロス | ||
# 買い建玉があれば全て決済 | ||
operator.positions.each_pair {|k,p| | ||
operator.commit(p) if p.sell_or_buy == JIJI::Position::BUY | ||
} | ||
# 新規に売り | ||
operator.sell 1 | ||
end | ||
end | ||
@prev_state = state | ||
end | ||
|
||
# UIから設定可能なプロパティの一覧を返す。 | ||
def property_infos | ||
super().concat [ | ||
Property.new( "short", "短期移動平均線", 25, :number ), | ||
Property.new( "long", "長期移動平均線", 75, :number ) | ||
] | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
|
||
# 一定期間の移動平均を得る | ||
class MovingAverage | ||
def initialize( range=25 ) | ||
@rates = [] # レートを記録するバッファ | ||
@range = range | ||
end | ||
|
||
def next_rate( rate ) | ||
# バッファのデータを更新 | ||
@rates.push rate | ||
@rates.shift if @rates.length > @range | ||
|
||
# バッファサイズが十分でなければ、nilを返す。 | ||
return nil if @rates.length != @range | ||
|
||
# 移動平均を算出 | ||
return MovingAverage.get_moving_average(@rates) | ||
end | ||
|
||
# 前の結果(引数で指定した件数だけ記録。) | ||
attr :prev, true | ||
|
||
private | ||
# 移動平均値を計算する。 | ||
def self.get_moving_average( rates ) | ||
total = 0 | ||
rates.each {|s| | ||
total += s.end | ||
total += s.max | ||
total += s.min | ||
} | ||
return total / ( rates.length * 3 ) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
|
||
#===交差状態を判定するユーティリティ | ||
#先行指標と遅行指標を受け取って、クロスアップ/クロスダウンを判定するユーティリティです。 | ||
# | ||
# require 'cross' | ||
# | ||
# cross = Cross.new | ||
# | ||
# # 先行指標、遅行指標を受け取って状態を返す。 | ||
# # :cross .. クロスアップ、クロスダウン状態かどうかを返す。 | ||
# # - クロスアップ(:up) | ||
# # - クロスダウン(:down) | ||
# # - どちらでもない(:none) | ||
# # :trend .. 現在の指標が上向きか下向きかを返す。 | ||
# # 「先行指標 <=> 遅行指標」した値。 | ||
# # trend >= 1なら上向き、trned <= -1なら下向き | ||
# p cross.next_data( 100, 90 ) # {:trend=>1, :cross=>:none} | ||
# p cross.next_data( 110, 100 ) # {:trend=>1, :cross=>:none} | ||
# p cross.next_data( 100, 100 ) # {:trend=>0, :cross=>:none} | ||
# p cross.next_data( 90, 100 ) # {:trend=>-1, :cross=>:down} | ||
# p cross.next_data( 80, 90 ) # {:trend=>-1, :cross=>:none} | ||
# p cross.next_data( 90, 90 ) # {:trend=>0, :cross=>:none} | ||
# p cross.next_data( 100, 100 ) # {:trend=>0, :cross=>:none} | ||
# p cross.next_data( 110, 100 ) # {:trend=>1, :cross=>:up} | ||
# | ||
class Cross | ||
|
||
#コンストラクタ | ||
def initialize | ||
@cross_prev = nil | ||
@cross = :none | ||
@trend = 0 | ||
end | ||
|
||
#===次の値を渡し状態を更新します。 | ||
#fast:: 先行指標 | ||
#lazy:: 遅行指標 | ||
def next_data( fast, lazy ) | ||
return unless fast && lazy | ||
# 交差状態を算出 | ||
@trend = fast <=> lazy | ||
if @cross_prev && @trend != @cross_prev && @trend != 0 | ||
@cross = @trend > @cross_prev ? :up : :down | ||
else | ||
@cross = :none | ||
end | ||
@cross_prev = @trend | ||
return {:cross=>@cross,:trend=>@trend} | ||
end | ||
|
||
#===クロスアップ状態かどうか判定します。 | ||
#戻り値:: 「先行指標 < 遅行指標」 から 「先行指標 > 遅行指標」 になったらtrue | ||
def cross_up? | ||
@cross == :up | ||
end | ||
#===クロスダウン状態かどうか判定します。 | ||
#戻り値:: 「先行指標 > 遅行指標」 から 「先行指標 < 遅行指標」 になったらtrue | ||
def cross_down? | ||
@cross == :down | ||
end | ||
#===上昇トレンド中かどうか判定します。 | ||
#戻り値:: 「先行指標 > 遅行指標」 ならtrue | ||
def up? | ||
@trend > 0 | ||
end | ||
#===下降トレンド中かどうか判定します。 | ||
#戻り値:: 「先行指標 < 遅行指標」 ならtrue | ||
def down? | ||
@trend < 0 | ||
end | ||
|
||
#交差状態( :up, :down, :none ) | ||
attr_reader :cross | ||
#トレンド ( 直近の falst <=> lazy 値。) | ||
attr_reader :trend | ||
end |
Oops, something went wrong.