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

Dic*_*ast 1 python string digits forex

Nb 在 Python 中询问!尝试用 Price.1(交易平仓)减去价格(开仓交易)以获得正确格式(不带小数)的点数。但是,由于涉及 split 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()
Run Code Online (Sandbox Code Playgroud)

jsc*_*urr 5

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

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
Run Code Online (Sandbox Code Playgroud)