公布阻力位核心源码(Python版)
来源:互联网 发布:迅捷网络初始密码 编辑:程序博客网 时间:2024/04/28 13:23
下面公布阻力位核心源码, 在此感谢江老师的教导!
因使用本算法导致投资失败, 本人概不付任何责任(包括法律责任)! 切记!!
# -*- coding: gb2312 -*-
import logging
__version__ = "1.6"
def GetKeyPositions (AllEnabled = True):
Ret = []
n = 2
for ix in range (1, 9 * n):
if ix % 2 == 0:
#
# left-top corner line
#
val = ix**2 + 1
if AllEnabled: Ret.append (val - ix/2)
Ret.append (val)
#
# left-bottom corner line
#
val = (ix + 1)**2 - ix
if AllEnabled: Ret.append (val - ix/2)
Ret.append (val)
#end for
for ix in range (1, 10 * n):
if ix % 2 <> 0:
#
# rith-bottom corner line
#
val = ix**2
if AllEnabled and (val > 1): Ret.append (val - ix/2)
Ret.append (val)
#
# right-top corner line
#
val = (ix + 1)**2 - ix
if AllEnabled: Ret.append (val - (ix + 1)/2)
Ret.append (val)
#end for
Ret.sort ()
return Ret
#end def
def CompDiffPrice (ImpPrice, DiffRate, DynPrice):
if (ImpPrice * (1 - DiffRate) <= DynPrice) and
(ImpPrice * (1 + DiffRate) >= DynPrice):
return True
return False
#end def
def Succeeded (PointsFound):
Count = 0
for ix in range (len (PointsFound)):
if PointsFound[ix]:
Count += 1
#end for
if Count == len (PointsFound):
return True
return False
#end def
def PrintPrices (KeyPos, Prices):
PriceStr = ''
Mark = '#'
PrevDiff, CurrDiff = 0, 0
for ix in KeyPos:
if ix == KeyPos[len (KeyPos)-1]:
PriceStr = '%s %s%-8s' % (PriceStr, Mark, Prices[ix-1])
break
NextPricePos = KeyPos[KeyPos.index (ix)+1]
CurrDiff = int (1000 * round (Prices[NextPricePos] - Prices[ix-1], 2))
if PrevDiff == CurrDiff:
PriceStr = '%s%-8s' % (PriceStr, Prices[ix-1])
continue
PrevDiff = CurrDiff
PriceStr = '%s %s%-8s' % (PriceStr, Mark, Prices[ix-1])
#end for
print '[Prices(%d)] %s ' % (len (KeyPos), PriceStr)
#end def
def IsPosAtMiddlePrice (CurrentPrice, KeyPos, Prices):
Start = KeyPos[20]
End = KeyPos[23]
if (CurrentPrice >= Prices[Start]) and (CurrentPrice <= Prices[End]):
return True
return False
#end def
def ScanPrices (CurrPrice, InitVal, ImpPoints, StepBeginVal,
StepEndVal, StepSpinVal = 0.01, AllPos = True):
if (InitVal < 0) or (StepBeginVal < 0) or
(StepEndVal < 0) or (len (ImpPoints) == 0):
logging.warning ('Invalid parameters, pls try again!')
return
ValTimes = 1000
stepBegin = int (StepBeginVal * ValTimes)
stepEnd = int (StepEndVal * ValTimes)
stepSpin = int (StepSpinVal * ValTimes)
AllKeyPos = GetKeyPositions ()
ImptKeyPos = GetKeyPositions (False)
PointsCount = len (ImpPoints)
PointsFound = []
for ix in range (PointsCount): PointsFound.append (False)
for OffsetRate in range (1, 50, 1):
for Step in range (stepBegin, stepEnd, stepSpin):
Prices = []
PointsFound = []
for ix in range (PointsCount): PointsFound.append (False)
for ix in range (1, 9**2*5):
Prices.append (round (InitVal + (ix-1)*Step*1.0/ValTimes, 3))
#end for
for PntIx in range (PointsCount):
for iy in AllKeyPos:
if (not PointsFound[PntIx]) and
CompDiffPrice (ImpPoints[PntIx], OffsetRate/1000.0, Prices[iy - 1]):
PointsFound[PntIx] = True
break
#end for
#end for
if not Succeeded (PointsFound):
continue
if not IsPosAtMiddlePrice (CurrPrice, ImptKeyPos, Prices):
continue
print '[Params] InitPrice=%.3f, Step=%.3f, OffsetRatio=%.5f'
% (InitVal, Step*1.0/ValTimes, OffsetRate/1000.0)
print '[Points] ', ImpPoints
PrintPrices (ImptKeyPos, Prices)
return
#end for
#end for
#end def
if __name__ == "__main__":
"""
Step1. Input the lowest price in its hitory
Step2. In the light of historical prices,
input those trough prices you could see
Step3. Retrieves them
Step4. Copy all of those prices to UltraEdit
Step5. Find out the accurate date by these important key prices
Step6. Draw the horizen-line
"""
while raw_input ('Continue? (0: Quit; Enter: go ahead): ') <> '0':
try:
CurrPrice = input ('Current price: ')
except:
logging.warn ('Invalid current price!')
continue
try:
InitPrice = input ('Historical lowest price: ')
except:
InitPrice = 0.0
logging.warn ('Invalid initial price, default is %.2f', InitPrice)
"""
Computing dynamic step length according to the price level
"""
StepBegin = int(CurrPrice/10)
if StepBegin == 0:
StepBegin = 0.01
else:
StepBegin = StepBegin * 10 * 0.005
StepEnd = 5.0
try:
ImpPoints = input ('A set of important points: ')
except:
ImpPoints = []
logging.warn ('Invalid important points, default is none')
ScanPrices (CurrPrice, InitPrice, ImpPoints, StepBegin, StepEnd)
# enf of file
import logging
__version__ = "1.6"
def GetKeyPositions (AllEnabled = True):
Ret = []
n = 2
for ix in range (1, 9 * n):
if ix % 2 == 0:
#
# left-top corner line
#
val = ix**2 + 1
if AllEnabled: Ret.append (val - ix/2)
Ret.append (val)
#
# left-bottom corner line
#
val = (ix + 1)**2 - ix
if AllEnabled: Ret.append (val - ix/2)
Ret.append (val)
#end for
for ix in range (1, 10 * n):
if ix % 2 <> 0:
#
# rith-bottom corner line
#
val = ix**2
if AllEnabled and (val > 1): Ret.append (val - ix/2)
Ret.append (val)
#
# right-top corner line
#
val = (ix + 1)**2 - ix
if AllEnabled: Ret.append (val - (ix + 1)/2)
Ret.append (val)
#end for
Ret.sort ()
return Ret
#end def
def CompDiffPrice (ImpPrice, DiffRate, DynPrice):
if (ImpPrice * (1 - DiffRate) <= DynPrice) and
(ImpPrice * (1 + DiffRate) >= DynPrice):
return True
return False
#end def
def Succeeded (PointsFound):
Count = 0
for ix in range (len (PointsFound)):
if PointsFound[ix]:
Count += 1
#end for
if Count == len (PointsFound):
return True
return False
#end def
def PrintPrices (KeyPos, Prices):
PriceStr = ''
Mark = '#'
PrevDiff, CurrDiff = 0, 0
for ix in KeyPos:
if ix == KeyPos[len (KeyPos)-1]:
PriceStr = '%s %s%-8s' % (PriceStr, Mark, Prices[ix-1])
break
NextPricePos = KeyPos[KeyPos.index (ix)+1]
CurrDiff = int (1000 * round (Prices[NextPricePos] - Prices[ix-1], 2))
if PrevDiff == CurrDiff:
PriceStr = '%s%-8s' % (PriceStr, Prices[ix-1])
continue
PrevDiff = CurrDiff
PriceStr = '%s %s%-8s' % (PriceStr, Mark, Prices[ix-1])
#end for
print '[Prices(%d)] %s ' % (len (KeyPos), PriceStr)
#end def
def IsPosAtMiddlePrice (CurrentPrice, KeyPos, Prices):
Start = KeyPos[20]
End = KeyPos[23]
if (CurrentPrice >= Prices[Start]) and (CurrentPrice <= Prices[End]):
return True
return False
#end def
def ScanPrices (CurrPrice, InitVal, ImpPoints, StepBeginVal,
StepEndVal, StepSpinVal = 0.01, AllPos = True):
if (InitVal < 0) or (StepBeginVal < 0) or
(StepEndVal < 0) or (len (ImpPoints) == 0):
logging.warning ('Invalid parameters, pls try again!')
return
ValTimes = 1000
stepBegin = int (StepBeginVal * ValTimes)
stepEnd = int (StepEndVal * ValTimes)
stepSpin = int (StepSpinVal * ValTimes)
AllKeyPos = GetKeyPositions ()
ImptKeyPos = GetKeyPositions (False)
PointsCount = len (ImpPoints)
PointsFound = []
for ix in range (PointsCount): PointsFound.append (False)
for OffsetRate in range (1, 50, 1):
for Step in range (stepBegin, stepEnd, stepSpin):
Prices = []
PointsFound = []
for ix in range (PointsCount): PointsFound.append (False)
for ix in range (1, 9**2*5):
Prices.append (round (InitVal + (ix-1)*Step*1.0/ValTimes, 3))
#end for
for PntIx in range (PointsCount):
for iy in AllKeyPos:
if (not PointsFound[PntIx]) and
CompDiffPrice (ImpPoints[PntIx], OffsetRate/1000.0, Prices[iy - 1]):
PointsFound[PntIx] = True
break
#end for
#end for
if not Succeeded (PointsFound):
continue
if not IsPosAtMiddlePrice (CurrPrice, ImptKeyPos, Prices):
continue
print '[Params] InitPrice=%.3f, Step=%.3f, OffsetRatio=%.5f'
% (InitVal, Step*1.0/ValTimes, OffsetRate/1000.0)
print '[Points] ', ImpPoints
PrintPrices (ImptKeyPos, Prices)
return
#end for
#end for
#end def
if __name__ == "__main__":
"""
Step1. Input the lowest price in its hitory
Step2. In the light of historical prices,
input those trough prices you could see
Step3. Retrieves them
Step4. Copy all of those prices to UltraEdit
Step5. Find out the accurate date by these important key prices
Step6. Draw the horizen-line
"""
while raw_input ('Continue? (0: Quit; Enter: go ahead): ') <> '0':
try:
CurrPrice = input ('Current price: ')
except:
logging.warn ('Invalid current price!')
continue
try:
InitPrice = input ('Historical lowest price: ')
except:
InitPrice = 0.0
logging.warn ('Invalid initial price, default is %.2f', InitPrice)
"""
Computing dynamic step length according to the price level
"""
StepBegin = int(CurrPrice/10)
if StepBegin == 0:
StepBegin = 0.01
else:
StepBegin = StepBegin * 10 * 0.005
StepEnd = 5.0
try:
ImpPoints = input ('A set of important points: ')
except:
ImpPoints = []
logging.warn ('Invalid important points, default is none')
ScanPrices (CurrPrice, InitPrice, ImpPoints, StepBegin, StepEnd)
# enf of file
用法不赘述.
推荐书籍:
- 公布阻力位核心源码(Python版)
- 公布动力源(股票代码:600405)阻力(支撑)位
- 公布上海辅仁(股票代码:600781)阻力(支撑)位
- 公布天士力(股票代码:600535)阻力(支撑)位
- 公布福星科技(股票代码:000926)阻力(支撑)位
- 公布陕国投A(股票代码:000563)阻力(支撑)位
- 公布酒钢宏兴(股票代码:600307)阻力(支撑)位
- 公布金融街(股票代码:000402)阻力(支撑)位
- 完成智能查找阻力位的核心代码
- 公布海王生物(股票代码:000078)阻力(支撑)位
- 公布五粮YGP1(股票代码:038004)阻力(支撑)位
- 公布靖远煤电(股票代码:000552)阻力(支撑)位
- 公布国栋建设(股票代码:600321)阻力(支撑)位
- 公布中成股份(股票代码:000151)阻力(支撑)位
- 公布申能股份(股票代码:600642)阻力(支撑)位
- 公布本钢板材(股票代码:000761)阻力(支撑)位
- 什么是支撑位和阻力位
- 再到关键阻力位,欧元何去何从
- Linux平台下NS2的安装
- 日语900句
- 微软新版操作系统Windows Vista
- 一个acm试题,怎样判断是不是数据结尾
- 一个完整的hibernate的one-to-many的例子
- 公布阻力位核心源码(Python版)
- 基于Dot Net平台和AE9.0开发通用地理信息系统平台
- OpenBSD基金会成立
- 内存详解
- 使用Ant进行增量快速构建
- Porting Linux to MPC860SR Processor Card
- 处理窗口缩放
- JAVA利用递归删除文件和文件夹
- JDK Overview-java.lang包概述--错误 选项