I won't say much nonsense, everyone should just look at the code!
# - *- coding: utf-8-*-"""
Created on Tue May 2308:57:022017
@ author: yunjinqi
E-mail:[email protected]
Differentiate yourself in the world from anyone else."""
import pandas as pd
import numpy as np
import datetime
import time
# retrieve data
df=pd.read_csv('C:/Users/HXWD/Desktop/000001.csv',encoding='gbk')
df.columns=['date','code','name','close','high','low','open','preclose','change','change_per','volume','amt']
df=df[['date','open','high','low','close','volume','amt']]
df.head()
def get_EMA(df,N):for i inrange(len(df)):if i==0:
df.ix[i,'ema']=df.ix[i,'close']if i 0:
df.ix[i,'ema']=(2*df.ix[i-1,'close']+(N-1)*df.ix[i,'close'])/(N+1)return df['ema']
def get_PBX(df):
df['a1']=(get_EMA(df,4)+df['close'].rolling(8).mean()+
df['close'].rolling(16).mean())/3
df['a2']=(get_EMA(df,6)+df['close'].rolling(12).mean()+
df['close'].rolling(24).mean())/3
df['a3']=(get_EMA(df,9)+df['close'].rolling(18).mean()+
df['close'].rolling(36).mean())/3
df['a4']=(get_EMA(df,13)+df['close'].rolling(26).mean()+
df['close'].rolling(52).mean())/3
df['a5']=(get_EMA(df,18)+df['close'].rolling(36).mean()+
df['close'].rolling(72).mean())/3
df['a6']=(get_EMA(df,24)+df['close'].rolling(48).mean()+
df['close'].rolling(96).mean())/3return df
get_PBX(df)
df.tail()'''
Waterfall line
Principle: moving average indicator
usage:
The waterfall line is a trend indicator, because its shape is very similar to the waterfall during its operation, so it is called the waterfall line.
The waterfall line is glued at the low position, and the short-term waterfall line crosses the long-term waterfall line upwards and diverges upwards, buy.
The waterfall line is glued at a high position, and the short waterfall line crosses the long waterfall line downwards and diverges downwards to sell.
When the long, medium and short-term waterfall lines are arranged from bottom to top to form a long arrangement, shares can be held.
When the long, medium and short-term waterfall lines are arranged from top to bottom to form a short arrangement, the position should be short.
'''
Supplementary knowledge: Python uses logical operators and, or, nor to determine the positive or negative of an integer
When I brushed Leetcode today, I flipped the integers. Since Python's division is rounded down, it is necessary to judge the positive or negative of the input integers. At that time, I thought of using trinocular arithmetic, but when I looked at the reference answer, I found it used It is the logical operator that makes the judgment of positive and negative numbers. At that time, I was confused and understood the principle after searching for relevant information, so I made a record.
The answer code is as shown:
sign = x<0 and -1 or 1
Where x is the input integer, if x is a positive number, it returns 1, and if it is a negative number, it returns -1.
Since I first came into contact with the C language, when I learned Python, I didn’t pay much attention to the logical operators. I thought it would return a Boolean value just like the C language. I don’t know why 1 and -1 were returned. I checked the relevant information and found the logic in Python. The operation principle is as follows:
x and y | Boolean "and"-If x is False, x and y return False, otherwise it returns the calculated value of y. |
---|---|
x or y | Boolean "or"-If x is True, it returns the value of x, otherwise it returns the calculated value of y. |
not x | Boolean "not"-If x is True, return False. If x is False, it returns True. |
When the input is a negative number, the calculation process is as follows:
-123<0
True
True and -1-1-1 or 1-1
First judge -123<0 and return True. At this time, True is ANDed with -1. If x is true, the return value of y is -1; then -1 and 1 are ORed. Since non-zero integers are all False, At this time, the value of x is -1.
When the input is a positive number, the calculation process is as follows:
123<0
False
False and -1
False
False or 11
First judge 123<0 and return False. At this time, False is ANDed with -1, x is false, and False is returned, and then False is ORed with 1. Since x is false, the value of y is returned to 1.
All in all, the use of logical operators in Python does not return false or True, but is related to the input x and y.
In addition, you can also use trinocular arithmetic to determine the sign of the input integer, as shown below:
sign = 1 if x 0 else -1
Attached is the complete code for flipping integers:
classSolution(object):
def reverse(self, x):"""
: type x: int
: rtype: int
"""
a =0
sign = x<0 and -1 or 1
x =abs(x)while(x !=0):
a = a*10+ x%10
x //=10return a*sign if a<2**31else0
The above example of Python waterfall line indicator compilation is all the content shared by the editor. I hope to give you a reference.
Recommended Posts