ããªã³ã¸ã£ã¼ãã³ããç®åºãã
ã¯ãªãã¯è¨¼å¸ã®ã¹ã¯ã¬ã¤ãã³ã°çãã©ã°ã¤ã³ãã ãã¶ã§ãã¤ã¤ãã(ç¾å¨ç¨¼åãã¹ã&ãããã°ä¸)ã®ã§ãã¼ã¡ã¼ã¡çµã¿è¾¼ã¿ã®ã©ã¤ãã©ãªãå å®ããã¦ç°¡åã«ã¨ã¼ã¸ã§ã³ããä½ããããã«ãã¦ãããããã¨ãããã¨ã§ãã¨ããããããªã³ã¸ã£ã¼ãã³ããç®åºããã©ã¤ãã©ãªãæ¸ãã¦ã¿ã¾ãããjijiæ·»ä»ã®ãMovingAverageãã¨åããããªå½¢ã§ä½¿ãã¾ãã
# ããªã³ã¸ã£ã¼ãã³ããå¾ã class BollingerBands #ã³ã³ã¹ãã©ã¯ã¿ #range:: éè¨æé def initialize( range=25, pivot=[0,1,2] ) @rates = [] # ã¬ã¼ããè¨é²ãããããã¡ @range = range @pivot = pivot end def next_rate( rate ) # ãããã¡ã®ãã¼ã¿ãæ´æ° @rates.push rate @rates.shift if @rates.length > @range # ãããã¡ãµã¤ãºãååã§ãªããã°ãnilãè¿ãã return nil if @rates.length != @range # ããªã³ã¸ã£ã¼ãã³ããç®åº return BollingerBands.get_bollinger_bands(@rates, @pivot) end 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 #===ããªã³ã¸ã£ã¼ãã³ãå¤ãå¾ãã # # TPï¼ãã£ãã«ã«ãã©ã¤ã¹ï¼ï¼ï¼é«å¤ï¼å®å¤ï¼çµå¤ï¼Ã·3 # +2Ïï¼TPã®ç§»åå¹³åï¼æ¨æºåå·®Ã2 # +Ïï¼TPã®ç§»åå¹³åï¼æ¨æºåå·® # -Ïï¼TPã®ç§»åå¹³å-æ¨æºåå·® # -2Ïï¼TPã®ç§»åå¹³å-æ¨æºåå·®Ã2 # æ¨æºåå·®ï¼âï½ï¼åTPâTPã®æéä¸å¹³åå¤ï¼ã®2ä¹ãæéåå ¨é¨å ãããã®ï½Ã·æé # ï¼âã¯å¼å ¨ä½ã«ãããï¼ # #rates:: å¤ãåå¾ããç¯å²ã®æ ªä¾¡ã®é å 25ãä¸è¬çã #range:: æ¨æºåå·®ã®åæ°ãåæå¤[0,1,2] #æ»ãå¤:: ããªã³ã¸ã£ã¼ãã³ãã®åå¤ã®é åãä¾) [+2Ï, +1Ï, TP, -1Ï, -2Ï] # def self.get_bollinger_bands( rates, range=[0,1,2] ) ma = get_moving_average( rates ) total = rates.inject(0.0) {|t,s| t+= (( (s.end + s.max + s.min ) / 3 ) - ma ) ** 2 t } sd = Math.sqrt((total / rates.length)) res = [] range.each { |r| res.unshift( ma + sd * r ) res.push( ma + sd * r * -1 ) if r != 0 } return res end end
å©ç¨å´ã®ã¨ã¼ã¸ã§ã³ãã¯ä»¥ä¸ãåå¼ã¯ãããã°ã©ããã¼ã¿ã®åºåã®ã¿è¡ã£ã¦ãã¾ãã
#ããªã³ã¸ã£ã¼ãã³ãã使ãã¨ã¼ã¸ã§ã³ãã®ãµã³ãã« class BollingerBandSampleAgent < JIJI::PeriodicallyAgent def description <<-STR ããªã³ã¸ã£ã¼ãã³ãã使ãã¨ã¼ã¸ã§ã³ãã®ãµã³ãã«ã§ãã STR end # ã¨ã¼ã¸ã§ã³ããåæåããã def init @bollinger_band = JIJI::Agent::Shared::BollingerBands.new(@range) # 移åå¹³åãã°ã©ãã§è¡¨ç¤ºããããã®Output @out = output.get( "ããªã³ã¸ã£ã¼ãã³ã", :graph, { :column_count=>5, :graph_type=>:rate, :colors=>["#779999","#557777","#335555","#557777", "#779999"] } ) end # 次ã®ã¬ã¼ããåãåã def next_period_rates( rates ) res =@bollinger_band.next_rate( rates[:EURJPY].bid ) return unless res @out.put( *res ) end # UIããè¨å®å¯è½ãªããããã£ã®ä¸è¦§ãè¿ãã def property_infos super().concat [ Property.new( "range", "éè¨æé", 25, :number ) ] end end
デモサイトã«ãç½®ããã®ã§éã³ããæ¹ã¯ã©ããã