用Python实现著名的江恩四方形

本文介绍了使用Python编程实现著名的江恩四方形的方法,旨在解决分析过程中阻力位和支撑位价码不清晰的问题。通过代码实现,可以方便地查看和运行结果,包括一系列的价格和参数值。
部署运行你感兴趣的模型镜像

本人觉得用大智慧中的江恩正方实在是太烦了,因为它没有将阻力位(支撑位)的价码明显标识出来,而是要用鼠标一个个点击小方格。出于分析的考虑,就开始尝试用Python实现它,代码部分不用我多说了,大家细细体会便可,或者干脆直接在Python中运行也行。

# Gann_Matrix.py

def GetKeyPositions ():
  Ret 
= []
  Ret.append (
1)

  
# left-top corner line
  for ix in range (19):
    
if ix % 2 == 0:
      val 
= ix * ix + 1
      Ret.append (val 
- ix/2)
      Ret.append (val)

  
# rith-bottom corner line
  for ix in range (310):
    
if ix % 2 <> 0:
      val 
= ix * ix
      Ret.append (val 
- ix/2)
      Ret.append (ix 
* ix)

  
# right-top corner line
  for ix in range (18):
    
if ix % 2 <> 0:
      val 
= (ix + 1)*(ix + 1- ix
      Ret.append (val 
- (ix + 1)/2)
      Ret.append (val)

  
# left-bottom corner line
  for ix in range (19):
    
if ix % 2 == 0:
      val 
= (ix + 1)*(ix + 1- ix
      Ret.append (val 
- ix/2)
      Ret.append (val)
      
  Ret.sort ()
  
return Ret


def DisputablePrices (InitVal, Step, Format):
  
if (InitVal < 0) or (Step < 0):
    
return

  Prices 
= []
  
for ix in range (182):
    Prices.append (InitVal 
+ (ix-1* Step)

  KeyPos 
= GetKeyPositions ()

  
if Format:
    PriceStr 
= ''
    
for ix in KeyPos:
      PriceStr 
+= '%.2f  ' % (Prices[ix - 1])
      
if (KeyPos.index (ix) + 1% 8 == 0:
        PriceStr 
+= ' '

    
print '%s %s' % ('[Prices]', PriceStr)
  
else:
    
for ix in KeyPos: print Prices[ix - 1]
  
  
print '%s InitValue = %f; Step = %f; RecordCount = %d' % 
    (
'[Params]', InitVal, Step, len (KeyPos))

# 下面主代码体中提供了两种方式显示数据,一种是按每行8个价格排列,另一种是按竖列一次性排列出,参数Format的值可为True/False;

# 使用时,要先设置初始价格(InitPrice)和单位步长(Step);

# 对于寻找阻力位而言,通常选择历史最低点作为初始价格,相反,对于寻找支撑位而言,通常选择历史最高点作为初始价格;

# 单位步长的设置,通常有两种方式。一种是按波动率(一定时长内的波动点数),另一种是按1,0.1,0.01,0.001,0.0001方式设置(遵循宇宙中所有物质的自然规律,总是由量变到质变的过程)

if __name__ == "__main__":
  InitPrice 
= 4.74
  Step 
= 0.1
  Format 
= True
  DisputablePrices (InitPrice, Step, Format)
 

# enf of file


 

输出执行结果如下:

[Prices]
4.74  4.84  4.94  5.04  5.14  5.24  5.34  5.44 
5.54  5.74  5.94  6.14  6.34  6.54  6.74  6.94 
7.14  7.44  7.74  8.04  8.34  8.64  8.94  9.24 
9.54  9.94  10.34  10.74  11.14  11.54  11.94  12.34 
12.74 
[Params]
InitValue = 4.740000; Step = 0.100000; RecordCount = 33

您可能感兴趣的与本文相关的镜像

Python3.8

Python3.8

Conda
Python

Python 是一种高级、解释型、通用的编程语言,以其简洁易读的语法而闻名,适用于广泛的应用,包括Web开发、数据分析、人工智能和自动化脚本

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值