QFin


NameQFin JSON
Version 0.1.21 PyPI version JSON
download
home_page
SummaryA Python library for mathematical finance.
upload_time2023-04-07 14:38:57
maintainer
docs_urlNone
authorRoman Paolucci
requires_python
licenseMIT
keywords python finance
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Q-Fin
A Python library for mathematical finance.

## Installation
https://pypi.org/project/QFin/
```
pip install qfin
```

# Version '0.1.20'
QFin is being reconstructed to leverage more principals of object-oriented programming.  Several modules in this version are deprecated along with the solutions to PDEs/SDEs (mainly in the options module).

QFin now contains a module called 'stochastics' which will be largely responsible for model calibration and option pricing.  A Cython/C++ equivalent to QFin is also being constructed so stay tuned! 

# Option Pricing <i>(>= 0.1.20)</i>

Stochastic differential equations that model underlying asset dynamics extend the 'StochasticModel' class and posses a list of model parameters and functions for pricing vanillas, calibrating to implied volatility surfaces, and Monte Carlo simulations (particularly useful after calibration for pricing path dependent options).

Below is a trivial example using ArithmeticBrownianMotion - first import the StochasticModel...
```Python
from qfin.stochastics import ArithmeticBrownianMotion
```
Next initialize the class object by parameterizing the model...
```Python
# abm parameterized by Bachelier vol = .3
abm = ArithmeticBrownianMotion([.3])
```
The abm may now be used to price a vanilla call/put option (prices default to "CALL") under the given parameter set...
```Python
# F0 = 101
# X = 100
# T = 1
abm.vanilla_pricing(101, 100, 1, "CALL")
# Call Price: 1.0000336233656906
```
Using call-put parity put prices may also be obtained...
```Python
# F0 = 99
# X = 100
# T = 1
abm.vanilla_pricing(99, 100, 1, "PUT")
# Put Price: 1.0000336233656952
```
Calibration and subsequent simulation of the process is also available - do note that some processes have a static volatility and can't be calibrated to an ivol surface.

The arithmetic Brownian motion may be simulated as follows...

```Python
# F0 = 100
# n (steps) = 10000
# dt = 1/252
# T = 1
abm.simulate(100, 10000, 1/252, 1)
```
Results of the simulation along with the simulation characteristics are stored under the tuple 'path_characteristics' : (paths, n, dt, T).  

Using the stored path characteristics we may find the price of a call just as before by averaging each discounted path payoff (assuming a stock process) with zero-rates we can avoid discounting as follows and find the option value as follows...

```Python
# list of path payoffs
payoffs = []
# option strike price
X = 99

# iteration through terminal path values to identify payoff
for path in abm.path_characteristics[0]:
    # appending CALL payoff
    payoffs.append(max((path[-1] - X), 0))

# option value today
np.average(payoffs)

# Call Price:  1.0008974837343871
```
We can see here that the simulated price is converging to the price in close-form.

# Option Pricing <i>(deprecated <= 0.0.20) </i>

### <a href="https://medium.com/swlh/deriving-the-black-scholes-model-5e518c65d0bc"> Black-Scholes Pricing</a>
Theoretical options pricing for non-dividend paying stocks is available via the BlackScholesCall and BlackScholesPut classes.

```Python
from qfin.options import BlackScholesCall
from qfin.options import BlackScholesPut
# 100 - initial underlying asset price
# .3 - asset underlying volatility
# 100 - option strike price
# 1 - time to maturity (annum)
# .01 - risk free rate of interest
euro_call = BlackScholesCall(100, .3, 100, 1, .01)
euro_put = BlackScholesPut(100, .3, 100, 1, .01)
```

```Python
print('Call price: ', euro_call.price)
print('Put price: ', euro_put.price)
```

```
Call price:  12.361726191532611
Put price:  11.366709566449416
```

### Option Greeks
First-order and some second-order partial derivatives of the Black-Scholes pricing model are available.

#### Delta
First-order partial derivative with respect to the underlying asset price.
```Python
print('Call delta: ', euro_call.delta)
print('Put delta: ', euro_put.delta)
```
```
Call delta:  0.5596176923702425
Put delta:  -0.4403823076297575
```

#### Gamma
Second-order partial derivative with respect to the underlying asset price.
```Python
print('Call gamma: ', euro_call.gamma)
print('Put gamma: ', euro_put.gamma)
```
```
Call gamma:  0.018653923079008084
Put gamma:  0.018653923079008084
```

#### Vega
First-order partial derivative with respect to the underlying asset volatility.
```Python
print('Call vega: ', euro_call.vega)
print('Put vega: ', euro_put.vega)
```
```
Call vega:  39.447933090788894
Put vega:  39.447933090788894
```

#### Theta
First-order partial derivative with respect to the time to maturity.
```Python
print('Call theta: ', euro_call.theta)
print('Put theta: ', euro_put.theta)
```
```
Call theta:  -6.35319039407325
Put theta:  -5.363140560324083
```

# Stochastic Processes
Simulating asset paths is available using common stochastic processes.

### <a href="https://towardsdatascience.com/geometric-brownian-motion-559e25382a55"> Geometric Brownian Motion </a>
Standard model for implementing geometric Brownian motion.
```Python
from qfin.simulations import GeometricBrownianMotion
# 100 - initial underlying asset price
# 0 - underlying asset drift (mu)
# .3 - underlying asset volatility
# 1/52 - time steps (dt)
# 1 - time to maturity (annum)
gbm = GeometricBrownianMotion(100, 0, .3, 1/52, 1)
```

```Python
print(gbm.simulated_path)
```

```
[107.0025048205179, 104.82320056538235, 102.53591127422398, 100.20213816642244, 102.04283245358256, 97.75115579923988, 95.19613943526382, 96.9876745495834, 97.46055174410736, 103.93032659279226, 107.36331603194304, 108.95104494118915, 112.42823319947456, 109.06981862825943, 109.10124426285238, 114.71465058375804, 120.00234814086286, 116.91730159923688, 118.67452601825876, 117.89233466917202, 118.93541257993591, 124.36106523035058, 121.26088015675688, 120.53641952983601, 113.73881043255554, 114.91724168548876, 112.94192281337791, 113.55773877160591, 107.49491796151044, 108.0715118831013, 113.01893111071472, 110.39204535739405, 108.63917240906524, 105.8520395233433, 116.2907247951675, 114.07340779267213, 111.06821275009212, 109.65530380775077, 105.78971667172465, 97.75385009989282, 97.84501925249452, 101.90695475825825, 106.0493833583297, 105.48266575656817, 106.62375752876223, 112.39829297429974, 111.22855058562658, 109.89796974828265, 112.78068777325248, 117.80550869036715, 118.4680557054793, 114.33258212280838]
```

### <a href="https://towardsdatascience.com/stochastic-volatility-pricing-in-python-931f4b03d793"> Stochastic Variance Process </a>
Stochastic volatility model based on Heston's paper (1993).
```Python
from qfin.simulations import StochasticVarianceModel
# 100 - initial underlying asset price
# 0 - underlying asset drift (mu)
# .01 - risk free rate of interest
# .05 - continuous dividend
# 2 - rate in which variance reverts to the implied long run variance
# .25 - implied long run variance as time tends to infinity
# -.7 - correlation of motion generated
# .3 - Variance's volatility
# 1/52 - time steps (dt)
# 1 - time to maturity (annum)
svm = StochasticVarianceModel(100, 0, .01, .05, 2, .25, -.7, .3, .09, 1/52, 1)
```

```Python
print(svm.simulated_path)
```

```
[98.21311553503577, 100.4491317019877, 89.78475515902066, 89.0169762497475, 90.70468848525869, 86.00821802256675, 80.74984494892573, 89.05033807013137, 88.51410029337134, 78.69736798230346, 81.90948751054125, 83.02502248913251, 83.46375102829755, 85.39018282900138, 78.97401642238059, 78.93505221741903, 81.33268688455111, 85.12156706038515, 79.6351983987908, 84.2375291273571, 82.80206517176038, 89.63659376223292, 89.22438477640516, 89.13899271995662, 94.60123239511816, 91.200165507022, 96.0578905115345, 87.45399399599378, 97.908745925816, 97.93068975065052, 103.32091104292813, 110.58066464778392, 105.21520242908348, 99.4655106985056, 106.74882010453683, 112.0058519886151, 110.20930861932342, 105.11835510815085, 113.59852610881678, 107.13315204738092, 108.36549026977205, 113.49809943785571, 122.67910031073885, 137.70966794451425, 146.13877267735612, 132.9973784430374, 129.75750117504984, 128.7467891695649, 127.13115959080305, 130.47967713110302, 129.84273088908265, 129.6411527208744]
```

# Simulation Pricing

### <a href="https://medium.com/swlh/python-for-pricing-exotics-3a2bfab5ff66"> Exotic Options </a>
Simulation pricing for exotic options is available under the assumptions associated with the respective stochastic processes.  Geometric Brownian motion is the base underlying stochastic process used in each Monte Carlo simulation.  However, should additional parameters be provided, the appropriate stochastic process will be used to generate each sample path.

#### Vanilla Options
```Python
from qfin.simulations import MonteCarloCall
from qfin.simulations import MonteCarloPut
# 100 - strike price
# 1000 - number of simulated price paths
# .01 - risk free rate of interest
# 100 - initial underlying asset price
# 0 - underlying asset drift (mu)
# .3 - underlying asset volatility
# 1/52 - time steps (dt)
# 1 - time to maturity (annum)
call_option = MonteCarloCall(100, 1000, .01, 100, 0, .3, 1/52, 1)
# These additional parameters will generate a Monte Carlo price based on a stochastic volatility process
# 2 - rate in which variance reverts to the implied long run variance
# .25 - implied long run variance as time tends to infinity
# -.5 - correlation of motion generated
# .02 - continuous dividend
# .3 - Variance's volatility
put_option = MonteCarloPut(100, 1000, .01, 100, 0, .3, 1/52, 1, 2, .25, -.5, .02, .3)
```

```Python
print(call_option.price)
print(put_option.price)
```

```
12.73812121792851
23.195814963576286
```

#### Binary Options
```Python
from qfin.simulations import MonteCarloBinaryCall
from qfin.simulations import MonteCarloBinaryPut
# 100 - strike price
# 50 - binary option payout
# 1000 - number of simulated price paths
# .01 - risk free rate of interest
# 100 - initial underlying asset price
# 0 - underlying asset drift (mu)
# .3 - underlying asset volatility 
# 1/52 - time steps (dt)
# 1 - time to maturity (annum)
binary_call = MonteCarloBinaryCall(100, 50, 1000, .01, 100, 0, .3, 1/52, 1)
binary_put = MonteCarloBinaryPut(100, 50, 1000, .01, 100, 0, .3, 1/52, 1)
```

```Python
print(binary_call.price)
print(binary_put.price)
```

```
22.42462873441866
27.869902820039087
```

#### Barrier Options
```Python
from qfin.simulations import MonteCarloBarrierCall
from qfin.simulations import MonteCarloBarrierPut
# 100 - strike price
# 50 - binary option payout
# 1000 - number of simulated price paths
# .01 - risk free rate of interest
# 100 - initial underlying asset price
# 0 - underlying asset drift (mu)
# .3 - underlying asset volatility
# 1/52 - time steps (dt)
# 1 - time to maturity (annum)
# True/False - Barrier is Up or Down
# True/False - Barrier is In or Out
barrier_call = MonteCarloBarrierCall(100, 1000, 150, .01, 100, 0, .3, 1/52, 1, up=True, out=True)
barrier_put = MonteCarloBarrierCall(100, 1000, 95, .01, 100, 0, .3, 1/52, 1, up=False, out=False)
```

```Python
print(binary_call.price)
print(binary_put.price)
```

```
4.895841997908933
5.565856754630819
```

#### Asian Options
```Python
from qfin.simulations import MonteCarloAsianCall
from qfin.simulations import MonteCarloAsianPut
# 100 - strike price
# 1000 - number of simulated price paths
# .01 - risk free rate of interest
# 100 - initial underlying asset price
# 0 - underlying asset drift (mu)
# .3 - underlying asset volatility
# 1/52 - time steps (dt)
# 1 - time to maturity (annum)
asian_call = MonteCarloAsianCall(100, 1000, .01, 100, 0, .3, 1/52, 1)
asian_put = MonteCarloAsianPut(100, 1000, .01, 100, 0, .3, 1/52, 1)
```

```Python
print(asian_call.price)
print(asian_put.price)
```

```
6.688201154529573
7.123274528125894
```

#### Extendible Options
```Python
from qfin.simulations import MonteCarloExtendibleCall
from qfin.simulations import MontecarloExtendiblePut
# 100 - strike price
# 1000 - number of simulated price paths
# .01 - risk free rate of interest
# 100 - initial underlying asset price
# 0 - underlying asset drift (mu)
# .3 - underlying asset volatility
# 1/52 - time steps (dt)
# 1 - time to maturity (annum)
# .5 - extension if out of the money at expiration
extendible_call = MonteCarloExtendibleCall(100, 1000, .01, 100, 0, .3, 1/52, 1, .5)
extendible_put = MonteCarloExtendiblePut(100, 1000, .01, 100, 0, .3, 1/52, 1, .5)
```

```Python
print(extendible_call.price)
print(extendible_put.price)
```

```
13.60274931789973
13.20330578685724
```



            

Raw data

            {
    "_id": null,
    "home_page": "",
    "name": "QFin",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "python,finance",
    "author": "Roman Paolucci",
    "author_email": "<romanmichaelpaolucci@gmail.com>",
    "download_url": "https://files.pythonhosted.org/packages/fd/9d/e0d7d49e38fdd3f74a9bee4c3615a3e72fb9e2f8cc10c294b0ed3fd0e62f/QFin-0.1.21.tar.gz",
    "platform": null,
    "description": "# Q-Fin\r\nA Python library for mathematical finance.\r\n\r\n## Installation\r\nhttps://pypi.org/project/QFin/\r\n```\r\npip install qfin\r\n```\r\n\r\n# Version '0.1.20'\r\nQFin is being reconstructed to leverage more principals of object-oriented programming.  Several modules in this version are deprecated along with the solutions to PDEs/SDEs (mainly in the options module).\r\n\r\nQFin now contains a module called 'stochastics' which will be largely responsible for model calibration and option pricing.  A Cython/C++ equivalent to QFin is also being constructed so stay tuned! \r\n\r\n# Option Pricing <i>(>= 0.1.20)</i>\r\n\r\nStochastic differential equations that model underlying asset dynamics extend the 'StochasticModel' class and posses a list of model parameters and functions for pricing vanillas, calibrating to implied volatility surfaces, and Monte Carlo simulations (particularly useful after calibration for pricing path dependent options).\r\n\r\nBelow is a trivial example using ArithmeticBrownianMotion - first import the StochasticModel...\r\n```Python\r\nfrom qfin.stochastics import ArithmeticBrownianMotion\r\n```\r\nNext initialize the class object by parameterizing the model...\r\n```Python\r\n# abm parameterized by Bachelier vol = .3\r\nabm = ArithmeticBrownianMotion([.3])\r\n```\r\nThe abm may now be used to price a vanilla call/put option (prices default to \"CALL\") under the given parameter set...\r\n```Python\r\n# F0 = 101\r\n# X = 100\r\n# T = 1\r\nabm.vanilla_pricing(101, 100, 1, \"CALL\")\r\n# Call Price: 1.0000336233656906\r\n```\r\nUsing call-put parity put prices may also be obtained...\r\n```Python\r\n# F0 = 99\r\n# X = 100\r\n# T = 1\r\nabm.vanilla_pricing(99, 100, 1, \"PUT\")\r\n# Put Price: 1.0000336233656952\r\n```\r\nCalibration and subsequent simulation of the process is also available - do note that some processes have a static volatility and can't be calibrated to an ivol surface.\r\n\r\nThe arithmetic Brownian motion may be simulated as follows...\r\n\r\n```Python\r\n# F0 = 100\r\n# n (steps) = 10000\r\n# dt = 1/252\r\n# T = 1\r\nabm.simulate(100, 10000, 1/252, 1)\r\n```\r\nResults of the simulation along with the simulation characteristics are stored under the tuple 'path_characteristics' : (paths, n, dt, T).  \r\n\r\nUsing the stored path characteristics we may find the price of a call just as before by averaging each discounted path payoff (assuming a stock process) with zero-rates we can avoid discounting as follows and find the option value as follows...\r\n\r\n```Python\r\n# list of path payoffs\r\npayoffs = []\r\n# option strike price\r\nX = 99\r\n\r\n# iteration through terminal path values to identify payoff\r\nfor path in abm.path_characteristics[0]:\r\n    # appending CALL payoff\r\n    payoffs.append(max((path[-1] - X), 0))\r\n\r\n# option value today\r\nnp.average(payoffs)\r\n\r\n# Call Price:  1.0008974837343871\r\n```\r\nWe can see here that the simulated price is converging to the price in close-form.\r\n\r\n# Option Pricing <i>(deprecated <= 0.0.20) </i>\r\n\r\n### <a href=\"https://medium.com/swlh/deriving-the-black-scholes-model-5e518c65d0bc\"> Black-Scholes Pricing</a>\r\nTheoretical options pricing for non-dividend paying stocks is available via the BlackScholesCall and BlackScholesPut classes.\r\n\r\n```Python\r\nfrom qfin.options import BlackScholesCall\r\nfrom qfin.options import BlackScholesPut\r\n# 100 - initial underlying asset price\r\n# .3 - asset underlying volatility\r\n# 100 - option strike price\r\n# 1 - time to maturity (annum)\r\n# .01 - risk free rate of interest\r\neuro_call = BlackScholesCall(100, .3, 100, 1, .01)\r\neuro_put = BlackScholesPut(100, .3, 100, 1, .01)\r\n```\r\n\r\n```Python\r\nprint('Call price: ', euro_call.price)\r\nprint('Put price: ', euro_put.price)\r\n```\r\n\r\n```\r\nCall price:  12.361726191532611\r\nPut price:  11.366709566449416\r\n```\r\n\r\n### Option Greeks\r\nFirst-order and some second-order partial derivatives of the Black-Scholes pricing model are available.\r\n\r\n#### Delta\r\nFirst-order partial derivative with respect to the underlying asset price.\r\n```Python\r\nprint('Call delta: ', euro_call.delta)\r\nprint('Put delta: ', euro_put.delta)\r\n```\r\n```\r\nCall delta:  0.5596176923702425\r\nPut delta:  -0.4403823076297575\r\n```\r\n\r\n#### Gamma\r\nSecond-order partial derivative with respect to the underlying asset price.\r\n```Python\r\nprint('Call gamma: ', euro_call.gamma)\r\nprint('Put gamma: ', euro_put.gamma)\r\n```\r\n```\r\nCall gamma:  0.018653923079008084\r\nPut gamma:  0.018653923079008084\r\n```\r\n\r\n#### Vega\r\nFirst-order partial derivative with respect to the underlying asset volatility.\r\n```Python\r\nprint('Call vega: ', euro_call.vega)\r\nprint('Put vega: ', euro_put.vega)\r\n```\r\n```\r\nCall vega:  39.447933090788894\r\nPut vega:  39.447933090788894\r\n```\r\n\r\n#### Theta\r\nFirst-order partial derivative with respect to the time to maturity.\r\n```Python\r\nprint('Call theta: ', euro_call.theta)\r\nprint('Put theta: ', euro_put.theta)\r\n```\r\n```\r\nCall theta:  -6.35319039407325\r\nPut theta:  -5.363140560324083\r\n```\r\n\r\n# Stochastic Processes\r\nSimulating asset paths is available using common stochastic processes.\r\n\r\n### <a href=\"https://towardsdatascience.com/geometric-brownian-motion-559e25382a55\"> Geometric Brownian Motion </a>\r\nStandard model for implementing geometric Brownian motion.\r\n```Python\r\nfrom qfin.simulations import GeometricBrownianMotion\r\n# 100 - initial underlying asset price\r\n# 0 - underlying asset drift (mu)\r\n# .3 - underlying asset volatility\r\n# 1/52 - time steps (dt)\r\n# 1 - time to maturity (annum)\r\ngbm = GeometricBrownianMotion(100, 0, .3, 1/52, 1)\r\n```\r\n\r\n```Python\r\nprint(gbm.simulated_path)\r\n```\r\n\r\n```\r\n[107.0025048205179, 104.82320056538235, 102.53591127422398, 100.20213816642244, 102.04283245358256, 97.75115579923988, 95.19613943526382, 96.9876745495834, 97.46055174410736, 103.93032659279226, 107.36331603194304, 108.95104494118915, 112.42823319947456, 109.06981862825943, 109.10124426285238, 114.71465058375804, 120.00234814086286, 116.91730159923688, 118.67452601825876, 117.89233466917202, 118.93541257993591, 124.36106523035058, 121.26088015675688, 120.53641952983601, 113.73881043255554, 114.91724168548876, 112.94192281337791, 113.55773877160591, 107.49491796151044, 108.0715118831013, 113.01893111071472, 110.39204535739405, 108.63917240906524, 105.8520395233433, 116.2907247951675, 114.07340779267213, 111.06821275009212, 109.65530380775077, 105.78971667172465, 97.75385009989282, 97.84501925249452, 101.90695475825825, 106.0493833583297, 105.48266575656817, 106.62375752876223, 112.39829297429974, 111.22855058562658, 109.89796974828265, 112.78068777325248, 117.80550869036715, 118.4680557054793, 114.33258212280838]\r\n```\r\n\r\n### <a href=\"https://towardsdatascience.com/stochastic-volatility-pricing-in-python-931f4b03d793\"> Stochastic Variance Process </a>\r\nStochastic volatility model based on Heston's paper (1993).\r\n```Python\r\nfrom qfin.simulations import StochasticVarianceModel\r\n# 100 - initial underlying asset price\r\n# 0 - underlying asset drift (mu)\r\n# .01 - risk free rate of interest\r\n# .05 - continuous dividend\r\n# 2 - rate in which variance reverts to the implied long run variance\r\n# .25 - implied long run variance as time tends to infinity\r\n# -.7 - correlation of motion generated\r\n# .3 - Variance's volatility\r\n# 1/52 - time steps (dt)\r\n# 1 - time to maturity (annum)\r\nsvm = StochasticVarianceModel(100, 0, .01, .05, 2, .25, -.7, .3, .09, 1/52, 1)\r\n```\r\n\r\n```Python\r\nprint(svm.simulated_path)\r\n```\r\n\r\n```\r\n[98.21311553503577, 100.4491317019877, 89.78475515902066, 89.0169762497475, 90.70468848525869, 86.00821802256675, 80.74984494892573, 89.05033807013137, 88.51410029337134, 78.69736798230346, 81.90948751054125, 83.02502248913251, 83.46375102829755, 85.39018282900138, 78.97401642238059, 78.93505221741903, 81.33268688455111, 85.12156706038515, 79.6351983987908, 84.2375291273571, 82.80206517176038, 89.63659376223292, 89.22438477640516, 89.13899271995662, 94.60123239511816, 91.200165507022, 96.0578905115345, 87.45399399599378, 97.908745925816, 97.93068975065052, 103.32091104292813, 110.58066464778392, 105.21520242908348, 99.4655106985056, 106.74882010453683, 112.0058519886151, 110.20930861932342, 105.11835510815085, 113.59852610881678, 107.13315204738092, 108.36549026977205, 113.49809943785571, 122.67910031073885, 137.70966794451425, 146.13877267735612, 132.9973784430374, 129.75750117504984, 128.7467891695649, 127.13115959080305, 130.47967713110302, 129.84273088908265, 129.6411527208744]\r\n```\r\n\r\n# Simulation Pricing\r\n\r\n### <a href=\"https://medium.com/swlh/python-for-pricing-exotics-3a2bfab5ff66\"> Exotic Options </a>\r\nSimulation pricing for exotic options is available under the assumptions associated with the respective stochastic processes.  Geometric Brownian motion is the base underlying stochastic process used in each Monte Carlo simulation.  However, should additional parameters be provided, the appropriate stochastic process will be used to generate each sample path.\r\n\r\n#### Vanilla Options\r\n```Python\r\nfrom qfin.simulations import MonteCarloCall\r\nfrom qfin.simulations import MonteCarloPut\r\n# 100 - strike price\r\n# 1000 - number of simulated price paths\r\n# .01 - risk free rate of interest\r\n# 100 - initial underlying asset price\r\n# 0 - underlying asset drift (mu)\r\n# .3 - underlying asset volatility\r\n# 1/52 - time steps (dt)\r\n# 1 - time to maturity (annum)\r\ncall_option = MonteCarloCall(100, 1000, .01, 100, 0, .3, 1/52, 1)\r\n# These additional parameters will generate a Monte Carlo price based on a stochastic volatility process\r\n# 2 - rate in which variance reverts to the implied long run variance\r\n# .25 - implied long run variance as time tends to infinity\r\n# -.5 - correlation of motion generated\r\n# .02 - continuous dividend\r\n# .3 - Variance's volatility\r\nput_option = MonteCarloPut(100, 1000, .01, 100, 0, .3, 1/52, 1, 2, .25, -.5, .02, .3)\r\n```\r\n\r\n```Python\r\nprint(call_option.price)\r\nprint(put_option.price)\r\n```\r\n\r\n```\r\n12.73812121792851\r\n23.195814963576286\r\n```\r\n\r\n#### Binary Options\r\n```Python\r\nfrom qfin.simulations import MonteCarloBinaryCall\r\nfrom qfin.simulations import MonteCarloBinaryPut\r\n# 100 - strike price\r\n# 50 - binary option payout\r\n# 1000 - number of simulated price paths\r\n# .01 - risk free rate of interest\r\n# 100 - initial underlying asset price\r\n# 0 - underlying asset drift (mu)\r\n# .3 - underlying asset volatility \r\n# 1/52 - time steps (dt)\r\n# 1 - time to maturity (annum)\r\nbinary_call = MonteCarloBinaryCall(100, 50, 1000, .01, 100, 0, .3, 1/52, 1)\r\nbinary_put = MonteCarloBinaryPut(100, 50, 1000, .01, 100, 0, .3, 1/52, 1)\r\n```\r\n\r\n```Python\r\nprint(binary_call.price)\r\nprint(binary_put.price)\r\n```\r\n\r\n```\r\n22.42462873441866\r\n27.869902820039087\r\n```\r\n\r\n#### Barrier Options\r\n```Python\r\nfrom qfin.simulations import MonteCarloBarrierCall\r\nfrom qfin.simulations import MonteCarloBarrierPut\r\n# 100 - strike price\r\n# 50 - binary option payout\r\n# 1000 - number of simulated price paths\r\n# .01 - risk free rate of interest\r\n# 100 - initial underlying asset price\r\n# 0 - underlying asset drift (mu)\r\n# .3 - underlying asset volatility\r\n# 1/52 - time steps (dt)\r\n# 1 - time to maturity (annum)\r\n# True/False - Barrier is Up or Down\r\n# True/False - Barrier is In or Out\r\nbarrier_call = MonteCarloBarrierCall(100, 1000, 150, .01, 100, 0, .3, 1/52, 1, up=True, out=True)\r\nbarrier_put = MonteCarloBarrierCall(100, 1000, 95, .01, 100, 0, .3, 1/52, 1, up=False, out=False)\r\n```\r\n\r\n```Python\r\nprint(binary_call.price)\r\nprint(binary_put.price)\r\n```\r\n\r\n```\r\n4.895841997908933\r\n5.565856754630819\r\n```\r\n\r\n#### Asian Options\r\n```Python\r\nfrom qfin.simulations import MonteCarloAsianCall\r\nfrom qfin.simulations import MonteCarloAsianPut\r\n# 100 - strike price\r\n# 1000 - number of simulated price paths\r\n# .01 - risk free rate of interest\r\n# 100 - initial underlying asset price\r\n# 0 - underlying asset drift (mu)\r\n# .3 - underlying asset volatility\r\n# 1/52 - time steps (dt)\r\n# 1 - time to maturity (annum)\r\nasian_call = MonteCarloAsianCall(100, 1000, .01, 100, 0, .3, 1/52, 1)\r\nasian_put = MonteCarloAsianPut(100, 1000, .01, 100, 0, .3, 1/52, 1)\r\n```\r\n\r\n```Python\r\nprint(asian_call.price)\r\nprint(asian_put.price)\r\n```\r\n\r\n```\r\n6.688201154529573\r\n7.123274528125894\r\n```\r\n\r\n#### Extendible Options\r\n```Python\r\nfrom qfin.simulations import MonteCarloExtendibleCall\r\nfrom qfin.simulations import MontecarloExtendiblePut\r\n# 100 - strike price\r\n# 1000 - number of simulated price paths\r\n# .01 - risk free rate of interest\r\n# 100 - initial underlying asset price\r\n# 0 - underlying asset drift (mu)\r\n# .3 - underlying asset volatility\r\n# 1/52 - time steps (dt)\r\n# 1 - time to maturity (annum)\r\n# .5 - extension if out of the money at expiration\r\nextendible_call = MonteCarloExtendibleCall(100, 1000, .01, 100, 0, .3, 1/52, 1, .5)\r\nextendible_put = MonteCarloExtendiblePut(100, 1000, .01, 100, 0, .3, 1/52, 1, .5)\r\n```\r\n\r\n```Python\r\nprint(extendible_call.price)\r\nprint(extendible_put.price)\r\n```\r\n\r\n```\r\n13.60274931789973\r\n13.20330578685724\r\n```\r\n\r\n\r\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "A Python library for mathematical finance.",
    "version": "0.1.21",
    "split_keywords": [
        "python",
        "finance"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "c9bc272017345f914b9054b888ee4d731823c1ea6e00cdef9f09f3347119a9e9",
                "md5": "b0d0ec366955e8cbbb840afdd9547c3d",
                "sha256": "f41bf34cdc726d1f3b62b3d01a7027d4f20ab76d4abcf268993d21c968ba027e"
            },
            "downloads": -1,
            "filename": "QFin-0.1.21-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "b0d0ec366955e8cbbb840afdd9547c3d",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 9965,
            "upload_time": "2023-04-07T14:38:53",
            "upload_time_iso_8601": "2023-04-07T14:38:53.250593Z",
            "url": "https://files.pythonhosted.org/packages/c9/bc/272017345f914b9054b888ee4d731823c1ea6e00cdef9f09f3347119a9e9/QFin-0.1.21-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "fd9de0d7d49e38fdd3f74a9bee4c3615a3e72fb9e2f8cc10c294b0ed3fd0e62f",
                "md5": "65d38a56e3ffec8d37815fe6cb1c8c02",
                "sha256": "4ff88749c990711c5ada2058eec0943b1f7ebc0e8a95011ab372491e669d2f46"
            },
            "downloads": -1,
            "filename": "QFin-0.1.21.tar.gz",
            "has_sig": false,
            "md5_digest": "65d38a56e3ffec8d37815fe6cb1c8c02",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 13906,
            "upload_time": "2023-04-07T14:38:57",
            "upload_time_iso_8601": "2023-04-07T14:38:57.582211Z",
            "url": "https://files.pythonhosted.org/packages/fd/9d/e0d7d49e38fdd3f74a9bee4c3615a3e72fb9e2f8cc10c294b0ed3fd0e62f/QFin-0.1.21.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-04-07 14:38:57",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "lcname": "qfin"
}
        
Elapsed time: 0.21077s