I have to define a function, forward_price
which takes three parameters:
spot: float
interest_rate: float
time: float
This function should compute and return the forward price, rounded at 2 decimals, of an asset in a forward contract using this classical formula:
I tried this :
from math import e
interest_rate = 1.03 #risk free-rate is 3%
spot_price = 40
time = 30/360 #there is 30 days remaining
forward_price = spot_price * e ** interest_rate * time
print(forward_price)
the result is 9.336886115663596
while the true result should be 40.10
Does someone know how to get this result and round it?
The issue seems to come from adding 1 to the interest rate. If you leave the interest_rate
as 0.03
and add parentheses around the exponent, you get the expected value.
from math import e
interest_rate = 0.03 #risk free-rate is 3%
spot_price = 40
time = 30/360 #there is 30 days remaining
forward_price = spot_price * e ** (interest_rate * time)
print(forward_price)