All Projects → boyac → pyOptionPricing

boyac / pyOptionPricing

Licence: other
Option pricing based on Black-Scholes processes, Monte-Carlo simulations with Geometric Brownian Motion, historical volatility, implied volatility, Greeks hedging

Programming Languages

python
139335 projects - #7 most used programming language

Projects that are alternatives of or similar to pyOptionPricing

Black-Scholes-Option-Pricing-Model
Black Scholes Option Pricing calculator with Greeks and implied volatility computations. Geometric Brownian Motion simulator with payoff value diagram and volatility smile plots. Java GUI.
Stars: ✭ 25 (-86.84%)
Mutual labels:  derivatives, volatility
PROJ Option Pricing Matlab
Quant Option Pricing - Exotic/Vanilla: Barrier, Asian, European, American, Parisian, Lookback, Cliquet, Variance Swap, Swing, Forward Starting, Step, Fader
Stars: ✭ 85 (-55.26%)
Mutual labels:  derivatives, option-pricing
optlib
A library for financial options pricing written in Python.
Stars: ✭ 166 (-12.63%)
Mutual labels:  derivatives, volatility
PyFENG
Python Financial ENGineering (PyFENG package in PyPI.org)
Stars: ✭ 51 (-73.16%)
Mutual labels:  derivatives, option-pricing
market-monitor
Interactive app to monitor market using Python
Stars: ✭ 20 (-89.47%)
Mutual labels:  option-pricing
nordnet
Uonfficial wrapper for financial data api from the Scandinavian broker Nordnet
Stars: ✭ 13 (-93.16%)
Mutual labels:  derivatives
ftx-api-wrapper-python3
FTX Exchange API wrapper in python3
Stars: ✭ 31 (-83.68%)
Mutual labels:  derivatives
AbstractOperators.jl
Abstract operators for large scale optimization in Julia
Stars: ✭ 26 (-86.32%)
Mutual labels:  derivatives
eth option
ERC20-compatible Option Contracts
Stars: ✭ 22 (-88.42%)
Mutual labels:  derivatives
heston
Implementations of the Heston stochastic volatility model
Stars: ✭ 21 (-88.95%)
Mutual labels:  option-pricing
python-api
Trading API for Quedex Bitcoin Derivatives Exchange.
Stars: ✭ 20 (-89.47%)
Mutual labels:  derivatives
optionmatrix
Financial Derivatives Calculator with 168+ Models (Options Calculator)
Stars: ✭ 121 (-36.32%)
Mutual labels:  derivatives
FinancialDerivatives.jl
Financial derivatives modeling and pricing in Julia.
Stars: ✭ 37 (-80.53%)
Mutual labels:  derivatives
Derbit-Volatility-Visulization
Visualization Tool for Deribit Options
Stars: ✭ 66 (-65.26%)
Mutual labels:  volatility
core
SIREN Core Smart Contracts
Stars: ✭ 39 (-79.47%)
Mutual labels:  derivatives
Atosym
algebraic expressions parsing and evaluation through a property system based algorithm
Stars: ✭ 15 (-92.11%)
Mutual labels:  derivatives
Causing
Causing: CAUsal INterpretation using Graphs
Stars: ✭ 47 (-75.26%)
Mutual labels:  derivatives
Sword
Sword — A financial derivative language for the blockchain
Stars: ✭ 27 (-85.79%)
Mutual labels:  derivatives
autoVolatility
Run several volatility plugins at the same time
Stars: ✭ 63 (-66.84%)
Mutual labels:  volatility
quincy
Implementation of the DIMVA 2017 publication "Quincy: Detecting Host-Based Code Injection Attacks in Memory Dumps"
Stars: ✭ 66 (-65.26%)
Mutual labels:  volatility

pyOptionPricing

Content

  • use python 2.7
  • option pricing

Your Support

  • You can contribute to the project by reporting bugs, suggesting enhancements, exchanging portfolio management experiences or you can make a donation to this project:
    *paypal

Traditional Historical Volatility Calculation

alt tag

# -*- coding: utf-8 -*-
# @Author: boyac
# @Date:   2016-05-02 18:28:28
# @Last Modified by:   boyac
# @Last Modified time: 2016-05-02 19:09:29

from pandas import np
import pandas_datareader.data as web

def historical_volatility(sym, days): # stock symbol, number of days
    "Return the annualized stddev of daily log returns of picked stock"
    try:
        # past number of 'days' close price data, normally between (30, 60)
        quotes = web.DataReader(sym, 'yahoo')['Close'][-days:] 
    except Exception, e:
        print "Error getting data for symbol '{}'.\n".format(sym), e
        return None, None
    logreturns = np.log(quotes / quotes.shift(1))
    # return square root * trading days * logreturns variance
    # NYSE = 252 trading days; Shanghai Stock Exchange = 242; Tokyo Stock Exchange = 246 days?
    return np.sqrt(252*logreturns.var()) 
    
    
if __name__ == "__main__":
    print historical_volatility('FB', 30) # facebook: 0.296710526109

Garman-Klass Historical Volatility

alt tag

# -*- coding: utf-8 -*-
# @Author: boyac
# @Date:   2016-05-02 18:28:28
# @Last Modified by:   boyac
# @Last Modified time: 2016-05-02 19:09:29

from pandas import np
import pandas_datareader.data as web


def gk_vol(sym, days):
    """"
    Return the annualized stddev of daily log returns of picked stock
    Historical Open-High-Low-Close Volatility: Garman Klass
    sigma**2 = ((h-l)**2)/2 - (2ln(2) - 1)(c-o)**2
    ref: http://www.wilmottwiki.com/wiki/index.php?title=Volatility
    """

    try:
    	o = web.DataReader(sym, 'yahoo')['Open'][-days:] 
    	h = web.DataReader(sym, 'yahoo')['High'][-days:] 
    	l = web.DataReader(sym, 'yahoo')['Low'][-days:] 
        c = web.DataReader(sym, 'yahoo')['Close'][-days:]
    except Exception, e:
        print "Error getting data for symbol '{}'.\n".format(sym), e
        return None, None
    sigma = np.sqrt(252*sum((np.log(h/l))**2/2 - (2*np.log(2)-1)*(np.log(c/o)**2))/days)
    return sigma
    
    
if __name__ == "__main__":
    print gk_vol('FB', 30) # facebook: 0.223351260219

Black-Scholes Model

alt tag

# -*- coding: utf-8 -*-
# @Author: boyac
# @Date:   2016-05-02 18:28:28
# @Last Modified by:   boyac
# @Last Modified time: 2016-05-04 00:27:52

from __future__ import division
from scipy.stats import norm
from math import *

# Cumulative normal distribution
def CND(X):
    return norm.cdf(X)

# Black Sholes Function
def BlackScholes(CallPutFlag,S,K,t,r,s):
    """
    S = Current stock price
    t = Time until option exercise (years to maturity)
    K = Option striking price
    r = Risk-free interest rate
    N = Cumulative standard normal distribution
    e = Exponential term
    s = St. Deviation (volatility)
    Ln = NaturalLog
    """
    d1 = (log(S/K) + (r + (s ** 2)/2) * t)/(s * sqrt(t))
    d2 = d1 - s * sqrt(t)

    if CallPutFlag=='c':
        return S * CND(d1) - K * exp(-r * t) * CND(d2) # call option
    else:
        return K * exp(-r * t) * CND(-d2) - S * CND(-d1) # put option 


if __name__ == "__main__":
    # Number taken from: http://wiki.mbalib.com/wiki/Black-Scholes期权定价模型
    print BlackScholes('c', S=164.0, K=165.0, t=0.0959, r=0.0521, s=0.29) # 5.788529972549341

Exotic Options Example: Shout Options by Monte Carlo Approximation

alt tag alt tag

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].