-
Notifications
You must be signed in to change notification settings - Fork 999
Description
Issue (Code explaining the issue is included at the bottom):
File: pysystemtrade/data/futures/fx_prices_csv/EURUSD.csv
There is a duplicate value for 2019-10-24. This is the only duplicate value in the file.
As a result, the PnL calculation does not appear to be correct for dates from 2019-10-25 onwards.
For example, the PnL in base currency for 2019-10-25 is calculated as:
181.431080837765 = 16.3387394 × 10 × 1.110435
• PnL in points: 163.387394
• Value per point: 10
• FX rate used: 1.110435
However, 1.110435 is the FX rate for 2019-10-24, not 2019-10-25.
The issue affects all dates after 2019-10-24, not just 2019-10-25. The PnL calculation is using a lagged FX rate (lagged by one day because of the duplicate entry).
It seems the code cannot handle duplicate values in the EURUSD.csv file.
Code:
from systems.provided.futures_chapter15.estimatedsystem import futures_system
system=futures_system()
group = system.accounts.pandl_for_instrument_rules_unweighted("EUROSTX")
curve_ewmac16_64 = group["ewmac16_64"]
calc = curve_ewmac16_64._pandl_calculator_with_costs
df = pd.Series(calc.fx)
df.index = df.index.normalize()
startdate = '2019-10-23'
enddate = '2019-10-25'
df[startdate:enddate]
"""
index
2019-10-23 1.113300
2019-10-24 1.110100
2019-10-24 1.110435
2019-10-25 1.108025
"""
df_pnl_in_points = pd.Series(calc.pandl_in_points())
df_pnl_in_points.index = df_pnl_in_points.index.normalize()
df_pnl_in_points[startdate:enddate]
"""
index
2019-10-23 72.605228
2019-10-24 94.379872
2019-10-25 16.338739
"""
df_pnl_in_base_currency = pd.Series(calc.pandl_in_base_currency())
df_pnl_in_base_currency.index = df_pnl_in_base_currency.index.normalize()
df_pnl_in_base_currency[startdate:enddate]
"""
index
2019-10-23 808.314009
2019-10-24 1047.710960
2019-10-25 181.431081
"""