I am studying you Futures Tradings coourse. I would like to ask that for the additiive adjustment python code, how can I combine three or more futures contracts in one graph with additive adjustment. I have tried to amend the code but which is not successful. Please find my code in the link.
Hey Alan,
The link you've shared is not accessible. Could please share the access?
Thanks
Rushda
Right granted. Please find the link again.
https://drive.google.com/drive/folders/1oZLf9_c63xeQUkmiI7hAEvLy1upUf_6D?usp=sharing
To combine more than two contracts you need to follow the same process as you did for the first two contracts (defined in the notebook above cell 3).
In the code that you shared, it looks like you have not defined adjustment factor 2. You can do this by getting the difference between the second and third contract (similar to what you did for 1st and 2nd contract)
Hope this helps!
Please find my link again, I have added adjustment factor 2 but still can't plot the additive futures chart to include three futures contract. Kindly advice. Thanks!
https://drive.google.com/drive/folders/1oZLf9_c63xeQUkmiI7hAEvLy1upUf_6D?usp=drive_link
After calculating the adjustment factor there are a few more steps that you need to follow:
- Store the second contract's data in the variable named continuous_futures_by_addition.
- Add the adjustment factor to the continuous_futures_by_addition till the expiry of the second contract.
- Append the third contract to continuous_futures_by_addition to get the continuous data.
Hope this helps
I have added those steps but didn't work. Could you please help to amend my code in following link?
https://drive.google.com/drive/folders/1oZLf9_c63xeQUkmiI7hAEvLy1upUf_6D?usp=drive_link
Well done! Looks like you've successfully added the steps and the code is running without any errors.
In case you are getting any FutureWarning for the append() method, you can ignore the same as this is a non-critical warning.
Other than that, if you have any specific issues, do let me know
Could you please look into my code a bit serious?
I can't see the third contract in the chart when I tried to visualize with following code:
Define the plot size
plt.figure(figsize=(15, 7))
plt.title('Adjusted Futures Contracts', fontsize=14)
plt.xlabel('Year-Month', fontsize=12)
plt.ylabel('Price', fontsize=12)
Plotting the continous contract
plt.plot(continuous_futures_by_addition)
Show the plot
plt.show()
I re-checked your code and was able to see the third contract (mentioned in your code as: Third Contract - DCE Iron Ore Sep 2021 Futures) on the plot.
Here's a screenshot of the output of the code shared by you. The third contract has been highlighted in red:
If there's any confusion, please let me know I'd be happy to help.
I got it. Thank you very much!
I have finished the code for adding 9 contracts. Could you please help to check my code again as follows?
Additive Adjustment (Iron Ore).ipynb - Google Drive
The starting point of my Adjusted Futurres Contracts graph become 0.
Hey Alan,
It looks like you've successfully added all the 9 contracts.
If you have any specific questions regarding this code, please let me know. I'd be happy to help!
The starting point of my Adjusted Futurres Contracts graph become 0. This is the problem I raised!
Hey Alan,
Usually, when transitioning from one contract to the next, the new contract's price is lower than the previous contract's price on the expiry date. Over an extended period of using additive adjustments, this can result in the starting point of the series becoming negative.
One drawback of the additive adjustment method is that it can lead to a series going negative after multiple adjustments, as you're observing in your code.
To overcome this issue, you might want to consider using a proportional adjustment approach. This is covered in Section 8, Unit 13 of the course. With proportional adjustment, when transitioning from one contract to the next, the first contract's price is adjusted using a ratio, rather than adding a fixed number.
Hope this helps!
Thanks
Rushda
Understood. Thanks!