查找点数值 - 3到5位外汇定价计算

问题描述 投票:0回答:1

在Python问Nb!试图用price.1(交易收盘)减去价格(交易开盘),以获得正确格式化的点数,不带小数。但是,由于涉及拆分x列表的限制,我无法继续。我正在尝试下面的解决方案:,但是,似乎是还原剂..我创建了4个列表和4个循环来将float转换为字符串,将格式更改为进行减法。知道如何格式化正确的数字吗?直接进入列(结果)浮动的东西..如果在十进制标点前有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()
python string digits forex
1个回答
0
投票

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

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
© www.soinside.com 2019 - 2024. All rights reserved.