← Back to Problems
Cost of Carry
Easy standard Pricing
Time limit: 1 s per test  ·  Memory: 256 MB

A stock trades at S_0 and pays a continuous dividend yield q. The continuously compounded risk-free rate is r. A forward contract expiring at T obliges its holder to buy one share at expiry for the delivery price agreed today.

Compute the fair delivery price: the one that makes the contract worth zero today.

Input

Four numbers S_0, r, q and T.

Output

One real number: the delivery price, with absolute or relative error at most 1e-9.

Constraints

0 < S_0 <= 10^4

-0.05 <= r <= 0.1

0 <= q <= 0.12

0.001 <= T <= 30

Scoring

This is a standard problem: a submission scores full points if it produces the correct output for every test case, and zero otherwise.

Numeric answers are accepted if they are within an absolute tolerance of 1e-09 or a relative tolerance of 1e-09 of the expected value.

Examples

input
100 0.05 0.02 1
output
1.030454533954e+02
input
250 0.03 0.08 2
output
2.262093545090e+02
Python 3.13 i Execution environment Isolated microVM · 1 vCPU · no internet access Time and memory limits are set per problem Available packages numpy 2.5.0scipy 1.18.0pandas 3.0.0scikit-learn 1.9.0statsmodels 0.15.0cvxpy 1.9.2