Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/336.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 查找Pips值-3到5位数的外汇定价计算_Python_String_Digits_Forex - Fatal编程技术网

Python 查找Pips值-3到5位数的外汇定价计算

Python 查找Pips值-3到5位数的外汇定价计算,python,string,digits,forex,Python,String,Digits,Forex,Nb在Python中询问!尝试用price.1(交易结束)减去price(交易开始)以获得格式正确且没有小数点的点数。但是,由于涉及拆分x列表的限制,我无法继续。我尝试了以下解决方案:,但是,似乎是冗余的。。 我已经创建了4个列表和4个循环,将float转换为string,将格式更改为proceed with减法。知道如何格式化正确的数字吗?直接进入列(结果)浮动的内容。。如果小数点前有3位数字。做1000*100。。如果前面有一个数字*100/10. # Price Trade Op

Nb在Python中询问!尝试用price.1(交易结束)减去price(交易开始)以获得格式正确且没有小数点的点数。但是,由于涉及拆分x列表的限制,我无法继续。我尝试了以下解决方案:,但是,似乎是冗余的。。 我已经创建了4个列表和4个循环,将float转换为string,将格式更改为proceed with减法。知道如何格式化正确的数字吗?直接进入列(结果)浮动的内容。。如果小数点前有3位数字。做1000*100。。如果前面有一个数字*100/10.

    # Price Trade Opened
    listp = []
    listpf = [] 
    for i in df2['Price']:
        listp.append(format(i,'.5f'))

    for i in listp:
        listpf.append(str(i))

    # Price.1 trade closed.

    listpp = [] 
    listppf = []

    for i in df2['Price.1']:
        listpp.append(format(i,'.5f'))

    for i in listpp:
        listppf.append(str(i))


     # Transform list into DF and remove punctuation. Thereby, I could 
        subtract. 

     df3 = pd.DataFrame(listp)
     col = ['Price']
     df3.columns = col
     df3 = df3.stack().str.replace('.', '').unstack()

     df4 = pd.DataFrame(listpp)
     col = ['Price1']
     df4.columns = col
     df4 = df4.stack().str.replace('.', '').unstack()

     dfc = pd.concat([df3, df4], axis=1)
     dfc.fillna(0)
     dfc.replace({'nan': 0}, inplace=True)

     dfc['Price'] = pd.to_numeric(dfc['Price'])
     dfc['Price1'] = pd.to_numeric(dfc['Price1'])
     dfc['Result'] = (dfc['Price'] - dfc['Price1'])
     dfc.head()

您应该能够计算打开值和关闭值之间的差值,并除以该对的相关乘数。像这样:

def pip_calc(open, close):
    if str(open).index('.') >= 3:  # JPY pair
        multiplier = 0.01
    else:
        multiplier = 0.0001

    pips = round((close - open) / multiplier)
    return int(pips)


pip_calc(112.65, 112.68)
# 3

pip_calc(1.6566, 1.6568)
# 2

您应该能够计算打开值和关闭值之间的差值,并除以该对的相关乘数。像这样:

def pip_calc(open, close):
    if str(open).index('.') >= 3:  # JPY pair
        multiplier = 0.01
    else:
        multiplier = 0.0001

    pips = round((close - open) / multiplier)
    return int(pips)


pip_calc(112.65, 112.68)
# 3

pip_calc(1.6566, 1.6568)
# 2

刚刚以:results=[]结束,用于zip中的i,ii(df2['Price',df['Price.1']):如果str(i).find('.')>=3:multiplier=0.01,否则:如果str(ii).find('.'),multiplier=0.0001>=3:multiplier=0.01其他:multiplier=0.0001 pips=round((i-ii)/multiplier)结果。追加(pips)df2['pips']=results df2.head()刚刚以:results=[]结束,用于zip中的i,ii(df2['Price',df['Price.1']):如果str(i).find('.')>=3:multiplier=0.01,否则:如果str(ii).find('.'),multiplier=0.0001>=3:multiplier=0.01其他:multiplier=0.0001 pips=round((i-ii)/multiplier)结果。追加(pips)df2['pips']=results df2.head()