关键词 > Python代写

Assignment #3 Python and Applications to Finance

发布时间:2021-10-20

Hello, dear friend, you can consult us at any time if you have any questions, add WeChat: daixieit


Assignment #3

Python and Applications to Finance


Exercise 1. FX Arbitrage

The foreign exchange (FX) market, where one currency is traded for another, is the largest financial market in the world, with about 5 trillion US dollars being traded every day. This market determines the exchange rate for local currencies when someone travels abroad and when international banks settle accounts between each other.


Let’s assume that the base currency is the US Dollar, hereafter referred to as USD. If one wishes to convert currency A or currency B, one could do the following:

1. Sell currency A and then Buy currency USD

2. Sell currency USD and then Buy currency B


Graphically, one can see the process of converting from one currency to another currency if quotes to buy and sell any currency to USD is known.

Let’s model a currency exchange’s FX rates as a weighted graph, where each node represents a currency (e.g. CNY, JPY, USD) and each edge represents the conversion to and from the currency and the base currency. The weighted graph’s edge cost is the FX conversion rate between the two end currencies.


Attached with this assignment is Python code that uses the Dijkstra’s Algorithm for finding the shortest path from two nodes along a weighted network, i.e. what is the conversion rate between currency B and currency A. In real terms, what is the conversion between, say JPY and CNY. This code works and gives accurate results.


From the results of the code given, modify the code so that CNY becomes the base cur-rency and re-run to compute exchange rates between all currencies. Are they the same exchange rates when using USD or any other currency as the base currency.