设为首页 收藏本站
查看: 611|回复: 0

[经验分享] 公布阻力位核心源码(Python版)

[复制链接]

尚未签到

发表于 2017-5-4 12:12:46 | 显示全部楼层 |阅读模式
<script language="JavaScript"> zmap_id=88800000091;</script><script language="javascript" src="http://www.zmto.com/gds/web_lm/js/h8.js"></script><script language="JavaScript">eLong_Affiliate_MemberID=4053787;</script><script language="javascript" src="http://icons.elong.com/adjs/jd_jp/sw/13.js"></script>  下面公布阻力位核心源码, 在此感谢江老师的教导!
  因使用本算法导致投资失败, 本人概不付任何责任(包括法律责任)! 切记!!
#-*-coding:gb2312-*-
importlogging

__version__="1.6"

defGetKeyPositions(AllEnabled=True):
Ret
=[]
n
=2
forixinrange(1,9*n):
ifix%2==0:
#
#left-topcornerline
#
val=ix**2+1
ifAllEnabled:Ret.append(val-ix/2)
Ret.append(val)
#
#left-bottomcornerline
#
val=(ix+1)**2-ix
ifAllEnabled:Ret.append(val-ix/2)
Ret.append(val)
#endfor


forixinrange(1,10*n):
ifix%2<>0:
#
#rith-bottomcornerline
#
val=ix**2
ifAllEnabledand(val>1):Ret.append(val-ix/2)
Ret.append(val)
#
#right-topcornerline
#
val=(ix+1)**2-ix
ifAllEnabled:Ret.append(val-(ix+1)/2)
Ret.append(val)
#endfor
Ret.sort()
returnRet
#enddef

defCompDiffPrice(ImpPrice,DiffRate,DynPrice):
if(ImpPrice*(1-DiffRate)<=DynPrice)and
(ImpPrice
*(1+DiffRate)>=DynPrice):
returnTrue
returnFalse
#enddef

defSucceeded(PointsFound):
Count
=0
forixinrange(len(PointsFound)):
ifPointsFound[ix]:
Count
+=1
#endfor
ifCount==len(PointsFound):
returnTrue
returnFalse
#enddef

defPrintPrices(KeyPos,Prices):
PriceStr
=''
Mark
='#'
PrevDiff,CurrDiff
=0,0
forixinKeyPos:
ifix==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))
ifPrevDiff==CurrDiff:
PriceStr
='%s%-8s'%(PriceStr,Prices[ix-1])
continue

PrevDiff
=CurrDiff
PriceStr
='%s %s%-8s'%(PriceStr,Mark,Prices[ix-1])
#endfor
print'[Prices(%d)] %s '%(len(KeyPos),PriceStr)
#enddef

defIsPosAtMiddlePrice(CurrentPrice,KeyPos,Prices):
Start
=KeyPos[20]
End
=KeyPos[23]
if(CurrentPrice>=Prices[Start])and(CurrentPrice<=Prices[End]):
returnTrue
returnFalse
#enddef

defScanPrices(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(
'Invalidparameters,plstryagain!')
return

ValTimes
=1000
stepBegin
=int(StepBeginVal*ValTimes)
stepEnd
=int(StepEndVal*ValTimes)
stepSpin
=int(StepSpinVal*ValTimes)
AllKeyPos
=GetKeyPositions()
ImptKeyPos
=GetKeyPositions(False)
PointsCount
=len(ImpPoints)
PointsFound
=[]
forixinrange(PointsCount):PointsFound.append(False)

forOffsetRateinrange(1,50,1):
forStepinrange(stepBegin,stepEnd,stepSpin):
Prices
=[]
PointsFound
=[]
forixinrange(PointsCount):PointsFound.append(False)

forixinrange(1,9**2*5):
Prices.append(round(InitVal
+(ix-1)*Step*1.0/ValTimes,3))
#endfor

forPntIxinrange(PointsCount):
foriyinAllKeyPos:
if(notPointsFound[PntIx])and
CompDiffPrice(ImpPoints[PntIx],OffsetRate
/1000.0,Prices[iy-1]):
PointsFound[PntIx]
=True
break
#endfor
#endfor
ifnotSucceeded(PointsFound):
continue

ifnotIsPosAtMiddlePrice(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
#endfor
#endfor
#
enddef


if__name__=="__main__":
"""
Step1.Inputthelowestpriceinitshitory
Step2.Inthelightofhistoricalprices,
inputthosetroughpricesyoucouldsee
Step3.Retrievesthem
Step4.CopyallofthosepricestoUltraEdit
Step5.Findouttheaccuratedatebytheseimportantkeyprices
Step6.Drawthehorizen-line
"""

whileraw_input('Continue?(0:Quit;Enter:goahead):')<>'0':
try:
CurrPrice
=input('Currentprice:')
except:
logging.warn(
'Invalidcurrentprice!')
continue

try:
InitPrice
=input('Historicallowestprice:')
except:
InitPrice
=0.0
logging.warn(
'Invalidinitialprice,defaultis%.2f',InitPrice)

"""
Computingdynamicsteplengthaccordingtothepricelevel
"""
StepBegin
=int(CurrPrice/10)
ifStepBegin==0:
StepBegin
=0.01
else:
StepBegin
=StepBegin*10*0.005
StepEnd
=5.0

try:
ImpPoints
=input('Asetofimportantpoints:')
except:
ImpPoints
=[]
logging.warn(
'Invalidimportantpoints,defaultisnone')

ScanPrices(CurrPrice,InitPrice,ImpPoints,StepBegin,StepEnd)


#enfoffile




  用法不赘述.


推荐书籍:


运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-373019-1-1.html 上篇帖子: Python enumerate遍历数组示例应用 下篇帖子: Python os和os.path函数简介
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表